My Project
Loading...
Searching...
No Matches
macro.c
Go to the documentation of this file.
1#include "gwion_util.h"
2#include "gwion_ast.h"
3
4MacroArg new_macroarg(MemPool p, const m_str name) {
5 const MacroArg a = mp_calloc(p, MacroArg);
6 a->name = mstrdup(p, name);
7 text_init(&a->text, p);
8 return a;
9}
10
11void clean_macroarg(const MacroArg a) {
12 if (a->next) clean_macroarg(a->next);
13 text_release(&a->text);
14}
15
16static void free_args(MemPool p, const MacroArg a) {
17 if (a->next) free_args(p, a->next);
18 text_release(&a->text);
19 free_mstr(p, a->name);
20 mp_free(p, MacroArg, a);
21}
22
23void free_entry(MemPool p, void *data) {
24 const Macro s = (Macro)data;
25 if (s->next) free_entry(p, s->next);
26 free_mstr(p, s->name);
27 free_text(s->text);
28 if (s->base) free_args(p, s->base);
29 mp_free(p, Macro, s);
30}
31
32static inline Macro mkentry(MemPool p, const m_str name, const Macro next) {
33 const Macro s = mp_calloc(p, Macro);
34 s->name = mstrdup(p, name);
35 s->next = next;
36 s->text = new_text(p);
37 return s;
38}
39
40hstraction(Macro, Macro, has, , return sym;, , return NULL)
42 , , return h->table[idx] = mkentry(h->p, arg, sym);)
43 hstraction(Macro, bool, rem, Macro prev = NULL;
44 , if (prev) prev->next = s->next; else h->table[idx] = NULL;
45 s->next = NULL; free_entry(h->p, s); return false;, prev = s;
46 , return true;)
47
48 ANN void macro_del(const Hash h) {
49 hdel(h, free_entry);
50}
include this file to use gwion-ast library
void free_entry(MemPool p, void *data)
Definition macro.c:23
void clean_macroarg(const MacroArg a)
Definition macro.c:11
return NULL
Definition macro.c:41
add
Definition macro.c:41
hstraction(Macro, Macro, has,, return sym;,, return NULL) hstraction(Macro
Macro
Definition macro.c:41
static Macro mkentry(MemPool p, const m_str name, const Macro next)
Definition macro.c:32
static void free_args(MemPool p, const MacroArg a)
Definition macro.c:16
MacroArg new_macroarg(MemPool p, const m_str name)
Definition macro.c:4
void macro_del(const Hash)
MacroArg next
Definition macro.h:14
char * name
Definition macro.h:12
GwText text
Definition macro.h:13
Definition macro.h:22
MacroArg base
Definition macro.h:25
Macro next
Definition macro.h:27
GwText * text
Definition macro.h:24
char * name
Definition macro.h:23