7225b5d7966f847e043778e2fc27882e34ee7db4
1 typedef struct PSI_Data
{
9 static inline void PSI_DataExchange(PSI_Data
*dest
, PSI_Data
*src
) {
10 memcpy(dest
, src
, sizeof(*dest
));
11 memset(src
, 0, sizeof(*src
));
16 typedef struct decl_type
{
19 struct decl_type
*real
;
22 static inline decl_type
*init_decl_type(token_t type
, char *name
) {
23 decl_type
*t
= malloc(sizeof(*t
));
25 t
->name
= strdup(name
);
29 static inline void free_decl_type(decl_type
*type
) {
34 typedef struct decl_typedef
{
39 static inline decl_typedef
*init_decl_typedef(char *name
, decl_type
*type
) {
40 decl_typedef
*t
= malloc(sizeof(*t
));
41 t
->alias
= strdup(name
);
46 static inline void free_decl_typedef(decl_typedef
*t
) {
48 free_decl_type(t
->type
);
52 typedef struct decl_typedefs
{
57 static decl_typedefs
*add_decl_typedef(decl_typedefs
*defs
, decl_typedef
*def
) {
59 defs
= calloc(1, sizeof(*defs
));
61 defs
->list
= realloc(defs
->list
, ++defs
->count
* sizeof(*defs
->list
));
62 defs
->list
[defs
->count
-1] = def
;
66 static void free_decl_typedefs(decl_typedefs
*defs
) {
69 for (i
= 0; i
< defs
->count
; ++i
) {
70 free_decl_typedef(defs
->list
[i
]);
76 typedef struct decl_var
{
78 unsigned pointer_level
;
81 static inline decl_var
*init_decl_var(char *name
, unsigned pl
) {
82 decl_var
*v
= malloc(sizeof(*v
));
83 v
->name
= (char *) strdup((const char *) name
);
84 v
->pointer_level
= pl
;
88 static inline void free_decl_var(decl_var
*var
) {
93 typedef struct decl_arg
{
98 static inline decl_arg
*init_decl_arg(decl_type
*type
, decl_var
*var
) {
99 decl_arg
*arg
= malloc(sizeof(*arg
));
105 static inline void free_decl_arg(decl_arg
*arg
) {
106 free_decl_type(arg
->type
);
107 free_decl_var(arg
->var
);
111 typedef struct decl_vars
{
116 static inline decl_vars
*init_decl_vars(decl_var
*var
) {
117 decl_vars
*vars
= malloc(sizeof(*vars
));
119 vars
->vars
= malloc(sizeof(*vars
->vars
));
124 static inline decl_vars
*add_decl_var(decl_vars
*vars
, decl_var
*var
) {
125 vars
->vars
= realloc(vars
->vars
, ++vars
->count
* sizeof(*vars
->vars
));
126 vars
->vars
[vars
->count
-1] = var
;
130 static inline void free_decl_vars(decl_vars
*vars
) {
133 for (i
= 0; i
< vars
->count
; ++i
) {
134 free_decl_var(vars
->vars
[i
]);
140 typedef struct decl_args
{
145 static inline decl_args
*init_decl_args(decl_arg
*arg
) {
146 decl_args
*args
= malloc(sizeof(*args
));
148 args
->args
= malloc(sizeof(*args
->args
));
153 static inline decl_args
*add_decl_arg(decl_args
*args
, decl_arg
*arg
) {
154 args
->args
= realloc(args
->args
, ++args
->count
* sizeof(*args
->args
));
155 args
->args
[args
->count
-1] = arg
;
159 static inline void free_decl_args(decl_args
*args
) {
162 for (i
= 0; i
< args
->count
; ++i
) {
163 free_decl_arg(args
->args
[i
]);
169 typedef struct decl_abi
{
173 static inline decl_abi
*init_decl_abi(char *convention
) {
174 decl_abi
*abi
= malloc(sizeof(*abi
));
175 abi
->convention
= strdup(convention
);
179 static inline void free_decl_abi(decl_abi
*abi
) {
180 free(abi
->convention
);
184 typedef struct decl
{
191 static inline decl
* init_decl(decl_abi
*abi
, decl_arg
*func
, decl_args
*args
) {
192 decl
*d
= malloc(sizeof(*d
));
199 static inline void free_decl(decl
*d
) {
200 free_decl_abi(d
->abi
);
201 free_decl_arg(d
->func
);
202 free_decl_args(d
->args
);
206 typedef struct decls
{
211 static inline decls
*add_decl(decls
*decls
, decl
*decl
) {
213 decls
= calloc(1, sizeof(*decls
));
215 decls
->list
= realloc(decls
->list
, ++decls
->count
* sizeof(*decls
->list
));
216 decls
->list
[decls
->count
-1] = decl
;
220 static inline void free_decls(decls
*decls
) {
223 for (i
= 0; i
< decls
->count
; ++i
) {
224 free_decl(decls
->list
[i
]);
230 typedef struct impl_type
{
235 static inline impl_type
*init_impl_type(token_t type
, char *name
) {
236 impl_type
*t
= malloc(sizeof(*t
));
239 t
->name
= (char *) strdup((const char *) name
);
243 static inline void free_impl_type(impl_type
*type
) {
248 typedef struct impl_var
{
250 unsigned reference
:1;
253 static inline impl_var
*init_impl_var(char *name
, int is_reference
) {
254 impl_var
*var
= malloc(sizeof(*var
));
255 var
->name
= (char *) strdup((const char *) name
);
256 var
->reference
= is_reference
;
260 static inline void free_impl_var(impl_var
*var
) {
265 typedef struct impl_def_val
{
274 static inline impl_def_val
*init_impl_def_val() {
275 impl_def_val
*def
= malloc(sizeof(*def
));
281 static inline void free_impl_def_val(impl_def_val
*def
) {
285 typedef struct impl_arg
{
291 static inline impl_arg
*init_impl_arg(impl_type
*type
, impl_var
*var
, impl_def_val
*def
) {
292 impl_arg
*arg
= malloc(sizeof(*arg
));
299 static inline void free_impl_arg(impl_arg
*arg
) {
300 free_impl_type(arg
->type
);
301 free_impl_var(arg
->var
);
303 free_impl_def_val(arg
->def
);
308 typedef struct impl_args
{
313 static inline impl_args
*init_impl_args(impl_arg
*arg
) {
314 impl_args
*args
= malloc(sizeof(*args
));
315 args
->args
= malloc(sizeof(*args
->args
));
326 static inline impl_args
*add_impl_arg(impl_args
*args
, impl_arg
*arg
) {
327 args
->args
= realloc(args
->args
, ++args
->count
* sizeof(*args
->args
));
328 args
->args
[args
->count
-1] = arg
;
332 static inline void free_impl_args(impl_args
*args
) {
335 for (i
= 0; i
< args
->count
; ++i
) {
336 free_impl_arg(args
->args
[i
]);
342 typedef struct impl_func
{
345 impl_type
*return_type
;
348 static inline impl_func
*init_impl_func(char *name
, impl_args
*args
, impl_type
*type
) {
349 impl_func
*func
= malloc(sizeof(*func
));
350 func
->name
= strdup(name
);
351 func
->args
= args
? args
: init_impl_args(NULL
);
352 func
->return_type
= type
;
356 static inline void free_impl_func(impl_func
*f
) {
357 free_impl_type(f
->return_type
);
358 free_impl_args(f
->args
);
363 typedef struct let_func
{
368 static inline let_func
*init_let_func(token_t type
, char *name
) {
369 let_func
*func
= malloc(sizeof(*func
));
371 func
->name
= (char *) strdup((const char *) name
);
375 static inline void free_let_func(let_func
*func
) {
380 typedef struct let_value
{
383 unsigned null_pointer_ref
:1;
386 static inline let_value
*init_let_value(let_func
*func
, impl_var
*var
, int null_pointer_ref
) {
387 let_value
*val
= malloc(sizeof(*val
));
388 val
->null_pointer_ref
= null_pointer_ref
;
394 static inline void free_let_value(let_value
*val
) {
396 free_let_func(val
->func
);
399 free_impl_var(val
->var
);
404 typedef struct let_stmt
{
409 static inline let_stmt
*init_let_stmt(decl_var
*var
, let_value
*val
) {
410 let_stmt
*let
= malloc(sizeof(*let
));
416 static inline void free_let_stmt(let_stmt
*stmt
) {
417 free_decl_var(stmt
->var
);
418 free_let_value(stmt
->val
);
422 typedef struct set_func
{
427 static inline set_func
*init_set_func(token_t type
, char *name
) {
428 set_func
*func
= malloc(sizeof(*func
));
430 func
->name
= (char *) strdup((const char *) name
);
434 static inline void free_set_func(set_func
*func
) {
439 typedef struct set_value
{
444 static inline set_value
*init_set_value(set_func
*func
, decl_vars
*vars
) {
445 set_value
*val
= malloc(sizeof(*val
));
451 static inline void free_set_value(set_value
*val
) {
452 free_set_func(val
->func
);
453 free_decl_vars(val
->vars
);
457 typedef struct set_stmt
{
462 static inline set_stmt
*init_set_stmt(impl_var
*var
, set_value
*val
) {
463 set_stmt
*set
= malloc(sizeof(*set
));
469 static inline void free_set_stmt(set_stmt
*set
) {
470 free_impl_var(set
->var
);
471 free_set_value(set
->val
);
475 typedef struct ret_stmt
{
480 static inline ret_stmt
*init_ret_stmt(set_func
*func
, decl_var
*decl
) {
481 ret_stmt
*ret
= malloc(sizeof(*ret
));
487 static inline void free_ret_stmt(ret_stmt
*ret
) {
488 free_set_func(ret
->func
);
489 free_decl_var(ret
->decl
);
493 typedef struct impl_stmt
{
503 static inline impl_stmt
*init_impl_stmt(token_t type
, void *ptr
) {
504 impl_stmt
*stmt
= malloc(sizeof(*stmt
));
510 static inline void free_impl_stmt(impl_stmt
*stmt
) {
511 switch (stmt
->type
) {
513 free_let_stmt(stmt
->s
.let
);
516 free_set_stmt(stmt
->s
.set
);
519 free_ret_stmt(stmt
->s
.ret
);
525 typedef struct impl_stmts
{
530 static inline impl_stmts
*init_impl_stmts(impl_stmt
*stmt
) {
531 impl_stmts
*stmts
= malloc(sizeof(*stmts
));
533 stmts
->stmts
= malloc(sizeof(*stmts
->stmts
));
534 stmts
->stmts
[0] = stmt
;
538 static inline impl_stmts
*add_impl_stmt(impl_stmts
*stmts
, impl_stmt
*stmt
) {
539 stmts
->stmts
= realloc(stmts
->stmts
, ++stmts
->count
* sizeof(*stmts
->stmts
));
540 stmts
->stmts
[stmts
->count
-1] = stmt
;
544 static inline void free_impl_stmts(impl_stmts
*stmts
) {
547 for (i
= 0; i
< stmts
->count
; ++i
) {
548 free_impl_stmt(stmts
->stmts
[i
]);
554 typedef struct impl
{
559 static inline impl
*init_impl(impl_func
*func
, impl_stmts
*stmts
) {
560 impl
*i
= malloc(sizeof(*i
));
566 static inline void free_impl(impl
*impl
) {
567 free_impl_func(impl
->func
);
568 free_impl_stmts(impl
->stmts
);
572 typedef struct impls
{
577 static impls
*add_impl(impls
*impls
, impl
*impl
) {
579 impls
= calloc(1, sizeof(*impls
));
581 impls
->list
= realloc(impls
->list
, ++impls
->count
* sizeof(*impls
->list
));
582 impls
->list
[impls
->count
-1] = impl
;
586 static void free_impls(impls
*impls
) {
589 for (i
= 0; i
< impls
->count
; ++i
) {
590 free_impl(impls
->list
[i
]);