My Project
Loading...
Searching...
No Matches
pp.c
Go to the documentation of this file.
1#include "gwion_util.h"
2#include "gwion_ast.h"
3#include "bison_compat.h"
4
5ANN PPState *new_ppstate(MemPool p, const char* filename) {
6 PPState *ppstate = mp_calloc(p, PPState);
7 ppstate->filename = filename;
8 return ppstate;
9};
10
11ANEW PP *new_pp(MemPool p, const uint size, const char* name) {
12 PP *pp = (PP *)mp_calloc(p, PP);
13 vector_init(&pp->data);
14 pp->macros = (Hash)mp_calloc(p, Hash);
15 hini(pp->macros, size);
16 pp->macros->p = p; // in ctor ?
17 vector_init(&pp->state);
18 vector_init(&pp->global_undef);
19 PPState *pps = new_ppstate(p, name);
20 pos_ini(&pps->loc.first);
21 pos_ini(&pps->loc.last);
22 vector_add(&pp->state, (vtype)pps);
23 return pp;
24}
25
26static void pp_post(PP *pp, void *data) {
27 for (m_uint i = 1; i < vector_size(&pp->state); ++i) {
28 void *ppstate = (void *)vector_at(&pp->state, i);
29 clear_buffer(ppstate, data);
30 }
31 mp_free(pp->macros->p, PPState, (PPState*)vector_front(&pp->state));
32 pp->entry = NULL;
33 vector_clear(&pp->state);
34 vector_clear(&pp->global_undef);
35 macro_del(pp->macros);
36}
37
38ANN void free_pp(MemPool p, PP *pp, void *data) {
39 pp_post(pp, data);
40 vector_release(&pp->state);
41 vector_release(&pp->global_undef);
42 hend(pp->macros);
43 mp_free(p, Hash, pp->macros);
44 vector_release(&pp->data);
45 mp_free(p, PP, pp);
46}
helper for bison locations
ANN void clear_buffer(void *state, void *scan)
include this file to use gwion-ast library
ANN void pos_ini(pos_t *pos)
Definition gwlog.c:11
return NULL
Definition macro.c:41
void macro_del(const Hash)
ANEW PP * new_pp(MemPool p, const uint size, const char *name)
Definition pp.c:11
ANN void free_pp(MemPool p, PP *pp, void *data)
Definition pp.c:38
ANN PPState * new_ppstate(MemPool p, const char *filename)
Definition pp.c:5
static void pp_post(PP *pp, void *data)
Definition pp.c:26
Definition pp.h:14
char * filename
Definition pp.h:21
loc_t loc
Definition pp.h:22
Definition pp.h:26
struct Hash_ * macros
Definition pp.h:28
struct Macro_ * entry
Definition pp.h:30
struct Vector_ global_undef
Definition pp.h:29
struct Vector_ state
Definition pp.h:27
struct Vector_ data
Definition pp.h:31
struct pos_t last
Definition gwlog.h:17
struct pos_t first
Definition gwlog.h:16