2 typedef struct decl_type
{
7 static inline decl_type
*init_decl_type(token_t type
, text
*name
) {
8 decl_type
*t
= malloc(sizeof(*t
));
10 t
->name
= strdup(name
);
14 static inline void free_decl_type(decl_type
*type
) {
19 typedef struct decl_typedef
{
24 static inline decl_typedef
*init_decl_typedef(text
*name
, decl_type
*type
) {
25 decl_typedef
*t
= malloc(sizeof(*t
));
26 t
->alias
= strdup(name
);
31 static inline void free_decl_typedef(decl_typedef
*t
) {
33 free_decl_type(t
->type
);
37 typedef struct decl_typedefs
{
42 static decl_typedefs
*add_decl_typedef(decl_typedefs
*defs
, decl_typedef
*def
) {
44 defs
= calloc(1, sizeof(*defs
));
46 defs
->list
= realloc(defs
->list
, ++defs
->count
* sizeof(*defs
->list
));
47 defs
->list
[defs
->count
-1] = def
;
51 static void free_decl_typedefs(decl_typedefs
*defs
) {
54 for (i
= 0; i
< defs
->count
; ++i
) {
55 free_decl_typedef(defs
->list
[i
]);
61 typedef struct decl_var
{
63 unsigned pointer_level
;
66 static inline decl_var
*init_decl_var(text
*name
, unsigned pl
) {
67 decl_var
*v
= malloc(sizeof(*v
));
68 v
->name
= (text
*) strdup((const char *) name
);
69 v
->pointer_level
= pl
;
73 static inline void free_decl_var(decl_var
*var
) {
78 typedef struct decl_arg
{
83 static inline decl_arg
*init_decl_arg(decl_type
*type
, decl_var
*var
) {
84 decl_arg
*arg
= malloc(sizeof(*arg
));
90 static inline void free_decl_arg(decl_arg
*arg
) {
91 free_decl_type(arg
->type
);
92 free_decl_var(arg
->var
);
96 typedef struct decl_vars
{
101 static inline decl_vars
*init_decl_vars(decl_var
*var
) {
102 decl_vars
*vars
= malloc(sizeof(*vars
));
104 vars
->vars
= malloc(sizeof(*vars
->vars
));
109 static inline decl_vars
*add_decl_var(decl_vars
*vars
, decl_var
*var
) {
110 vars
->vars
= realloc(vars
->vars
, ++vars
->count
* sizeof(*vars
->vars
));
111 vars
->vars
[vars
->count
-1] = var
;
115 static inline void free_decl_vars(decl_vars
*vars
) {
118 for (i
= 0; i
< vars
->count
; ++i
) {
119 free_decl_var(vars
->vars
[i
]);
125 typedef struct decl_args
{
130 static inline decl_args
*init_decl_args(decl_arg
*arg
) {
131 decl_args
*args
= malloc(sizeof(*args
));
133 args
->args
= malloc(sizeof(*args
->args
));
138 static inline decl_args
*add_decl_arg(decl_args
*args
, decl_arg
*arg
) {
139 args
->args
= realloc(args
->args
, ++args
->count
* sizeof(*args
->args
));
140 args
->args
[args
->count
-1] = arg
;
144 static inline void free_decl_args(decl_args
*args
) {
147 for (i
= 0; i
< args
->count
; ++i
) {
148 free_decl_arg(args
->args
[i
]);
154 typedef struct decl
{
159 static inline decl
* init_decl(decl_arg
*func
, decl_args
*args
) {
160 decl
*d
= malloc(sizeof(*d
));
166 static inline void free_decl(decl
*d
) {
167 free_decl_arg(d
->func
);
168 free_decl_args(d
->args
);
172 typedef struct decls
{
177 static inline decls
*add_decl(decls
*decls
, decl
*decl
) {
179 decls
= calloc(1, sizeof(*decls
));
181 decls
->list
= realloc(decls
->list
, ++decls
->count
* sizeof(*decls
->list
));
182 decls
->list
[decls
->count
-1] = decl
;
186 static inline void free_decls(decls
*decls
) {
189 for (i
= 0; i
< decls
->count
; ++i
) {
190 free_decl(decls
->list
[i
]);
196 typedef struct impl_type
{
201 static inline impl_type
*init_impl_type(token_t type
, text
*name
) {
202 impl_type
*t
= malloc(sizeof(*t
));
205 t
->name
= (text
*) strdup((const char *) name
);
209 static inline void free_impl_type(impl_type
*type
) {
214 typedef struct impl_var
{
216 unsigned reference
:1;
219 static inline impl_var
*init_impl_var(text
*name
, int is_reference
) {
220 impl_var
*var
= malloc(sizeof(*var
));
221 var
->name
= (text
*) strdup((const char *) name
);
222 var
->reference
= is_reference
;
226 static inline void free_impl_var(impl_var
*var
) {
231 typedef struct impl_def_val
{
240 static inline impl_def_val
*init_impl_def_val() {
241 impl_def_val
*def
= malloc(sizeof(*def
));
247 static inline void free_impl_def_val(impl_def_val
*def
) {
251 typedef struct impl_arg
{
257 static inline impl_arg
*init_impl_arg(impl_type
*type
, impl_var
*var
, impl_def_val
*def
) {
258 impl_arg
*arg
= malloc(sizeof(*arg
));
265 static inline void free_impl_arg(impl_arg
*arg
) {
266 free_impl_type(arg
->type
);
267 free_impl_var(arg
->var
);
269 free_impl_def_val(arg
->def
);
274 typedef struct impl_args
{
279 static inline impl_args
*init_impl_args(impl_arg
*arg
) {
280 impl_args
*args
= malloc(sizeof(*args
));
281 args
->args
= malloc(sizeof(*args
->args
));
292 static inline impl_args
*add_impl_arg(impl_args
*args
, impl_arg
*arg
) {
293 args
->args
= realloc(args
->args
, ++args
->count
* sizeof(*args
->args
));
294 args
->args
[args
->count
-1] = arg
;
298 static inline void free_impl_args(impl_args
*args
) {
301 for (i
= 0; i
< args
->count
; ++i
) {
302 free_impl_arg(args
->args
[i
]);
308 typedef struct impl_func
{
311 impl_type
*return_type
;
314 static inline impl_func
*init_impl_func(text
*name
, impl_args
*args
, impl_type
*type
) {
315 impl_func
*func
= malloc(sizeof(*func
));
316 func
->name
= strdup(name
);
317 func
->args
= args
? args
: init_impl_args(NULL
);
318 func
->return_type
= type
;
322 static inline void free_impl_func(impl_func
*f
) {
323 free_impl_type(f
->return_type
);
324 free_impl_args(f
->args
);
329 typedef struct let_func
{
334 static inline let_func
*init_let_func(token_t type
, text
*name
) {
335 let_func
*func
= malloc(sizeof(*func
));
337 func
->name
= (text
*) strdup((const char *) name
);
341 static inline void free_let_func(let_func
*func
) {
346 typedef struct let_value
{
349 unsigned null_pointer_ref
:1;
352 static inline let_value
*init_let_value(let_func
*func
, impl_var
*var
, int null_pointer_ref
) {
353 let_value
*val
= malloc(sizeof(*val
));
354 val
->null_pointer_ref
= null_pointer_ref
;
360 static inline void free_let_value(let_value
*val
) {
362 free_let_func(val
->func
);
365 free_impl_var(val
->var
);
370 typedef struct let_stmt
{
375 static inline let_stmt
*init_let_stmt(decl_var
*var
, let_value
*val
) {
376 let_stmt
*let
= malloc(sizeof(*let
));
382 static inline void free_let_stmt(let_stmt
*stmt
) {
383 free_decl_var(stmt
->var
);
384 free_let_value(stmt
->val
);
388 typedef struct set_func
{
393 static inline set_func
*init_set_func(token_t type
, text
*name
) {
394 set_func
*func
= malloc(sizeof(*func
));
396 func
->name
= (text
*) strdup((const char *) name
);
400 static inline void free_set_func(set_func
*func
) {
405 typedef struct set_value
{
410 static inline set_value
*init_set_value(set_func
*func
, decl_vars
*vars
) {
411 set_value
*val
= malloc(sizeof(*val
));
417 static inline void free_set_value(set_value
*val
) {
418 free_set_func(val
->func
);
419 free_decl_vars(val
->vars
);
423 typedef struct set_stmt
{
428 static inline set_stmt
*init_set_stmt(impl_var
*var
, set_value
*val
) {
429 set_stmt
*set
= malloc(sizeof(*set
));
435 static inline void free_set_stmt(set_stmt
*set
) {
436 free_impl_var(set
->var
);
437 free_set_value(set
->val
);
441 typedef struct ret_stmt
{
446 static inline ret_stmt
*init_ret_stmt(set_func
*func
, decl_var
*decl
) {
447 ret_stmt
*ret
= malloc(sizeof(*ret
));
453 static inline void free_ret_stmt(ret_stmt
*ret
) {
454 free_set_func(ret
->func
);
455 free_decl_var(ret
->decl
);
459 typedef struct impl_stmt
{
469 static inline impl_stmt
*init_impl_stmt(token_t type
, void *ptr
) {
470 impl_stmt
*stmt
= malloc(sizeof(*stmt
));
476 static inline void free_impl_stmt(impl_stmt
*stmt
) {
477 switch (stmt
->type
) {
479 free_let_stmt(stmt
->s
.let
);
482 free_set_stmt(stmt
->s
.set
);
485 free_ret_stmt(stmt
->s
.ret
);
491 typedef struct impl_stmts
{
496 static inline impl_stmts
*init_impl_stmts(impl_stmt
*stmt
) {
497 impl_stmts
*stmts
= malloc(sizeof(*stmts
));
499 stmts
->stmts
= malloc(sizeof(*stmts
->stmts
));
500 stmts
->stmts
[0] = stmt
;
504 static inline impl_stmts
*add_impl_stmt(impl_stmts
*stmts
, impl_stmt
*stmt
) {
505 stmts
->stmts
= realloc(stmts
->stmts
, ++stmts
->count
* sizeof(*stmts
->stmts
));
506 stmts
->stmts
[stmts
->count
-1] = stmt
;
510 static inline void free_impl_stmts(impl_stmts
*stmts
) {
513 for (i
= 0; i
< stmts
->count
; ++i
) {
514 free_impl_stmt(stmts
->stmts
[i
]);
520 typedef struct impl
{
525 static inline impl
*init_impl(impl_func
*func
, impl_stmts
*stmts
) {
526 impl
*i
= malloc(sizeof(*i
));
532 static inline void free_impl(impl
*impl
) {
533 free_impl_func(impl
->func
);
534 free_impl_stmts(impl
->stmts
);
538 typedef struct impls
{
543 static impls
*add_impl(impls
*impls
, impl
*impl
) {
545 impls
= calloc(1, sizeof(*impls
));
547 impls
->list
= realloc(impls
->list
, ++impls
->count
* sizeof(*impls
->list
));
548 impls
->list
[impls
->count
-1] = impl
;
552 static void free_impls(impls
*impls
) {
555 for (i
= 0; i
< impls
->count
; ++i
) {
556 free_impl(impls
->list
[i
]);