My Project
Loading...
Searching...
No Matches
scanner.c File Reference
#include "gwion_util.h"
#include "gwion_ast.h"
#include "parser.h"
#include "lexer.h"

Go to the source code of this file.

Macros

#define PP_SIZE   127
 

Functions

static ANEW Scannernew_scanner (AstGetter *arg)
 
static ANN void free_scanner (Scanner *scan)
 
static ANN Ast get_ast (MemPool mp, Scanner *s)
 
ANN Ast parse_pos (struct AstGetter_ *const arg, const pos_t pos)
 
static ANN char * get_filename (Scanner *scan, const PPState *ppstate)
 
static ANN void secondary (Scanner *scan)
 
int scanner_error (Scanner *scan, const char *main, const char *explain, const loc_t loc, const uint error_code)
 
ANN int scanner_secondary (Scanner *scan, const char *main, const loc_t loc)
 

Macro Definition Documentation

◆ PP_SIZE

#define PP_SIZE   127

Definition at line 6 of file scanner.c.

Function Documentation

◆ free_scanner()

static ANN void free_scanner ( Scanner * scan)
static

Definition at line 23 of file scanner.c.

23 {
24 vector_release(&scan->hashes);
25 free_pp(scan->st->p, scan->pp, scan->scanner);
26 gwion_lex_destroy(scan->scanner);
27 mp_free(scan->st->p, Scanner, scan);
28}
ANN void free_pp(MemPool p, PP *pp, void *data)
Definition pp.c:38
struct PP_ * pp
Definition scanner.h:10
struct Vector_ hashes
Definition scanner.h:12
void * scanner
Definition scanner.h:8
SymTable * st
Definition scanner.h:9

◆ get_ast()

static ANN Ast get_ast ( MemPool mp,
Scanner * s )
static

Definition at line 30 of file scanner.c.

30 {
31 if (!gwion_parse(s)) return s->getter->ppa->ast;
32 if (s->getter->ppa->ast) free_ast(mp, s->getter->ppa->ast);
33 return NULL;
34}
ANN void free_ast(MemPool p, Ast)
return NULL
Definition macro.c:41
PPArg * ppa
Definition ast_getter.h:25
Ast ast
Definition pparg.h:10
AstGetter * getter
Definition scanner.h:11

◆ get_filename()

static ANN char * get_filename ( Scanner * scan,
const PPState * ppstate )
static

Definition at line 44 of file scanner.c.

44 {
45 m_str filename = ppstate->filename;
46 if (!scan->pp->npar) {
47 m_uint i = vector_size(&scan->pp->state) - 1;
48 if (*filename == '@') {
49 while (*filename == '@') {
50 --i;
51 const PPState *pps = (PPState*)vector_at(&scan->pp->state, i);
52 filename = pps->filename;
53 }
54 }
55 } else {
56 const PPState *pps = (PPState*)vector_front(&scan->pp->state);
57 filename = pps->filename;
58 }
59 return filename;
60}
Definition pp.h:14
char * filename
Definition pp.h:21
int npar
Definition pp.h:32
struct Vector_ state
Definition pp.h:27

◆ new_scanner()

static ANEW Scanner * new_scanner ( AstGetter * arg)
static

Definition at line 8 of file scanner.c.

8 {
9 Scanner *scan = (Scanner *)mp_calloc(arg->st->p, Scanner);
10 vector_init(&scan->hashes);
11 gwion_lex_init(&scan->scanner);
12 gwion_set_extra(scan, scan->scanner);
13 scan->pp = new_pp(arg->st->p, PP_SIZE, arg->name);
14 gwion_set_in(arg->f, scan->scanner);
15 scan->st = arg->st;
16 scan->getter = arg;
17 pos_ini(&scan->pos);
18// pos_ini(&scan->old);
19 scan->getter->ppa->ast = NULL; // ???
20 return scan;
21}
ANN void pos_ini(pos_t *pos)
Definition gwlog.c:11
ANEW PP * new_pp(MemPool p, const uint size, const char *name)
Definition pp.c:11
#define PP_SIZE
Definition scanner.c:6
FILE * f
Definition ast_getter.h:23
const char * name
Definition ast_getter.h:22
SymTable * st
Definition ast_getter.h:24
struct pos_t pos
Definition scanner.h:13

◆ parse_pos()

ANN Ast parse_pos ( struct AstGetter_ *const arg,
const pos_t pos )

Definition at line 36 of file scanner.c.

36 {
37 Scanner * s = new_scanner(arg);
38 s->pos = pos;
39 const Ast ast = get_ast(arg->ppa->hash.p, s);
40 free_scanner(s);
41 return ast;
42}
struct SectionList * Ast
Definition absyn.h:23
static ANEW Scanner * new_scanner(AstGetter *arg)
Definition scanner.c:8
static ANN void free_scanner(Scanner *scan)
Definition scanner.c:23
static ANN Ast get_ast(MemPool mp, Scanner *s)
Definition scanner.c:30
struct Hash_ hash
Definition pparg.h:9

◆ scanner_error()

int scanner_error ( Scanner * scan,
const char * main,
const char * explain,
const loc_t loc,
const uint error_code )

Definition at line 70 of file scanner.c.

71 {
72 const PPState *ppstate = (PPState*)vector_back(&scan->pp->state);
73 const m_str filename = get_filename(scan, ppstate);
74 gwlog_error(main, explain, filename, loc, error_code);
75 secondary(scan);
76 return 0;
77}
void gwlog_error(const char *main, const char *explain, const char *filename, const loc_t loc, const uint error_code)
Definition gwlog.c:115
int main(int argc, char **argv)
Definition main.c:4
static ANN char * get_filename(Scanner *scan, const PPState *ppstate)
Definition scanner.c:44
static ANN void secondary(Scanner *scan)
Definition scanner.c:62

◆ scanner_secondary()

ANN int scanner_secondary ( Scanner * scan,
const char * main,
const loc_t loc )

Definition at line 79 of file scanner.c.

79 {
80 const PPState *ppstate = (PPState*)vector_back(&scan->pp->state);
81 const m_str filename = get_filename(scan, ppstate);
82 gwlog_warning(main, filename, loc);
83 return 0;
84}
ANN void gwlog_warning(const char *main, const char *filename, const loc_t loc)
Definition gwlog.c:146

◆ secondary()

static ANN void secondary ( Scanner * scan)
static

Definition at line 62 of file scanner.c.

62 {
63 for (m_uint i = 0; i < vector_size(&scan->pp->state) - 1; i++) {
64 const PPState *pp = (PPState*)vector_at(&scan->pp->state, i);
65 gwlog_related("expanded from here", get_filename(scan, pp), pp->loc);
66 }
67}
ANN void gwlog_related(const char *main, const char *filename, const loc_t loc)
Definition gwlog.c:155
loc_t loc
Definition pp.h:22