4 typedef struct PSI_Token
{
11 typedef struct decl_type
{
14 struct decl_type
*real
;
17 static inline decl_type
*init_decl_type(token_t type
, char *name
) {
18 decl_type
*t
= malloc(sizeof(*t
));
20 t
->name
= strdup(name
);
24 static inline void free_decl_type(decl_type
*type
) {
29 typedef struct decl_typedef
{
34 static inline decl_typedef
*init_decl_typedef(char *name
, decl_type
*type
) {
35 decl_typedef
*t
= malloc(sizeof(*t
));
36 t
->alias
= strdup(name
);
41 static inline void free_decl_typedef(decl_typedef
*t
) {
43 free_decl_type(t
->type
);
47 typedef struct decl_typedefs
{
52 static decl_typedefs
*add_decl_typedef(decl_typedefs
*defs
, decl_typedef
*def
) {
54 defs
= calloc(1, sizeof(*defs
));
56 defs
->list
= realloc(defs
->list
, ++defs
->count
* sizeof(*defs
->list
));
57 defs
->list
[defs
->count
-1] = def
;
61 static void free_decl_typedefs(decl_typedefs
*defs
) {
64 for (i
= 0; i
< defs
->count
; ++i
) {
65 free_decl_typedef(defs
->list
[i
]);
71 typedef struct decl_var
{
73 unsigned pointer_level
;
76 static inline decl_var
*init_decl_var(char *name
, unsigned pl
) {
77 decl_var
*v
= malloc(sizeof(*v
));
78 v
->name
= (char *) strdup((const char *) name
);
79 v
->pointer_level
= pl
;
83 static inline void free_decl_var(decl_var
*var
) {
88 typedef struct decl_arg
{
93 static inline decl_arg
*init_decl_arg(decl_type
*type
, decl_var
*var
) {
94 decl_arg
*arg
= malloc(sizeof(*arg
));
100 static inline void free_decl_arg(decl_arg
*arg
) {
101 free_decl_type(arg
->type
);
102 free_decl_var(arg
->var
);
106 typedef struct decl_vars
{
111 static inline decl_vars
*init_decl_vars(decl_var
*var
) {
112 decl_vars
*vars
= malloc(sizeof(*vars
));
114 vars
->vars
= malloc(sizeof(*vars
->vars
));
119 static inline decl_vars
*add_decl_var(decl_vars
*vars
, decl_var
*var
) {
120 vars
->vars
= realloc(vars
->vars
, ++vars
->count
* sizeof(*vars
->vars
));
121 vars
->vars
[vars
->count
-1] = var
;
125 static inline void free_decl_vars(decl_vars
*vars
) {
128 for (i
= 0; i
< vars
->count
; ++i
) {
129 free_decl_var(vars
->vars
[i
]);
135 typedef struct decl_args
{
140 static inline decl_args
*init_decl_args(decl_arg
*arg
) {
141 decl_args
*args
= malloc(sizeof(*args
));
143 args
->args
= malloc(sizeof(*args
->args
));
148 static inline decl_args
*add_decl_arg(decl_args
*args
, decl_arg
*arg
) {
149 args
->args
= realloc(args
->args
, ++args
->count
* sizeof(*args
->args
));
150 args
->args
[args
->count
-1] = arg
;
154 static inline void free_decl_args(decl_args
*args
) {
157 for (i
= 0; i
< args
->count
; ++i
) {
158 free_decl_arg(args
->args
[i
]);
164 typedef struct decl_abi
{
168 static inline decl_abi
*init_decl_abi(char *convention
) {
169 decl_abi
*abi
= malloc(sizeof(*abi
));
170 abi
->convention
= strdup(convention
);
174 static inline void free_decl_abi(decl_abi
*abi
) {
175 free(abi
->convention
);
179 typedef struct decl
{
186 static inline decl
* init_decl(decl_abi
*abi
, decl_arg
*func
, decl_args
*args
) {
187 decl
*d
= malloc(sizeof(*d
));
194 static inline void free_decl(decl
*d
) {
195 free_decl_abi(d
->abi
);
196 free_decl_arg(d
->func
);
197 free_decl_args(d
->args
);
201 typedef struct decls
{
206 static inline decls
*add_decl(decls
*decls
, decl
*decl
) {
208 decls
= calloc(1, sizeof(*decls
));
210 decls
->list
= realloc(decls
->list
, ++decls
->count
* sizeof(*decls
->list
));
211 decls
->list
[decls
->count
-1] = decl
;
215 static inline void free_decls(decls
*decls
) {
218 for (i
= 0; i
< decls
->count
; ++i
) {
219 free_decl(decls
->list
[i
]);
225 typedef struct impl_type
{
230 static inline impl_type
*init_impl_type(token_t type
, char *name
) {
231 impl_type
*t
= malloc(sizeof(*t
));
234 t
->name
= (char *) strdup((const char *) name
);
238 static inline void free_impl_type(impl_type
*type
) {
243 typedef struct impl_var
{
245 unsigned reference
:1;
248 static inline impl_var
*init_impl_var(char *name
, int is_reference
) {
249 impl_var
*var
= malloc(sizeof(*var
));
250 var
->name
= (char *) strdup((const char *) name
);
251 var
->reference
= is_reference
;
255 static inline void free_impl_var(impl_var
*var
) {
260 typedef struct impl_def_val
{
269 static inline impl_def_val
*init_impl_def_val() {
270 impl_def_val
*def
= malloc(sizeof(*def
));
276 static inline void free_impl_def_val(impl_def_val
*def
) {
280 typedef struct impl_arg
{
286 static inline impl_arg
*init_impl_arg(impl_type
*type
, impl_var
*var
, impl_def_val
*def
) {
287 impl_arg
*arg
= malloc(sizeof(*arg
));
294 static inline void free_impl_arg(impl_arg
*arg
) {
295 free_impl_type(arg
->type
);
296 free_impl_var(arg
->var
);
298 free_impl_def_val(arg
->def
);
303 typedef struct impl_args
{
308 static inline impl_args
*init_impl_args(impl_arg
*arg
) {
309 impl_args
*args
= malloc(sizeof(*args
));
310 args
->args
= malloc(sizeof(*args
->args
));
321 static inline impl_args
*add_impl_arg(impl_args
*args
, impl_arg
*arg
) {
322 args
->args
= realloc(args
->args
, ++args
->count
* sizeof(*args
->args
));
323 args
->args
[args
->count
-1] = arg
;
327 static inline void free_impl_args(impl_args
*args
) {
330 for (i
= 0; i
< args
->count
; ++i
) {
331 free_impl_arg(args
->args
[i
]);
337 typedef struct impl_func
{
340 impl_type
*return_type
;
343 static inline impl_func
*init_impl_func(char *name
, impl_args
*args
, impl_type
*type
) {
344 impl_func
*func
= malloc(sizeof(*func
));
345 func
->name
= strdup(name
);
346 func
->args
= args
? args
: init_impl_args(NULL
);
347 func
->return_type
= type
;
351 static inline void free_impl_func(impl_func
*f
) {
352 free_impl_type(f
->return_type
);
353 free_impl_args(f
->args
);
358 typedef struct let_func
{
363 static inline let_func
*init_let_func(token_t type
, char *name
) {
364 let_func
*func
= malloc(sizeof(*func
));
366 func
->name
= (char *) strdup((const char *) name
);
370 static inline void free_let_func(let_func
*func
) {
375 typedef struct let_value
{
378 unsigned null_pointer_ref
:1;
381 static inline let_value
*init_let_value(let_func
*func
, impl_var
*var
, int null_pointer_ref
) {
382 let_value
*val
= malloc(sizeof(*val
));
383 val
->null_pointer_ref
= null_pointer_ref
;
389 static inline void free_let_value(let_value
*val
) {
391 free_let_func(val
->func
);
394 free_impl_var(val
->var
);
399 typedef struct let_stmt
{
404 static inline let_stmt
*init_let_stmt(decl_var
*var
, let_value
*val
) {
405 let_stmt
*let
= malloc(sizeof(*let
));
411 static inline void free_let_stmt(let_stmt
*stmt
) {
412 free_decl_var(stmt
->var
);
413 free_let_value(stmt
->val
);
417 typedef struct set_func
{
422 static inline set_func
*init_set_func(token_t type
, char *name
) {
423 set_func
*func
= malloc(sizeof(*func
));
425 func
->name
= (char *) strdup((const char *) name
);
429 static inline void free_set_func(set_func
*func
) {
434 typedef struct set_value
{
439 static inline set_value
*init_set_value(set_func
*func
, decl_vars
*vars
) {
440 set_value
*val
= malloc(sizeof(*val
));
446 static inline void free_set_value(set_value
*val
) {
447 free_set_func(val
->func
);
448 free_decl_vars(val
->vars
);
452 typedef struct set_stmt
{
457 static inline set_stmt
*init_set_stmt(impl_var
*var
, set_value
*val
) {
458 set_stmt
*set
= malloc(sizeof(*set
));
464 static inline void free_set_stmt(set_stmt
*set
) {
465 free_impl_var(set
->var
);
466 free_set_value(set
->val
);
470 typedef struct ret_stmt
{
475 static inline ret_stmt
*init_ret_stmt(set_func
*func
, decl_var
*decl
) {
476 ret_stmt
*ret
= malloc(sizeof(*ret
));
482 static inline void free_ret_stmt(ret_stmt
*ret
) {
483 free_set_func(ret
->func
);
484 free_decl_var(ret
->decl
);
488 typedef struct impl_stmt
{
498 static inline impl_stmt
*init_impl_stmt(token_t type
, void *ptr
) {
499 impl_stmt
*stmt
= malloc(sizeof(*stmt
));
505 static inline void free_impl_stmt(impl_stmt
*stmt
) {
506 switch (stmt
->type
) {
508 free_let_stmt(stmt
->s
.let
);
511 free_set_stmt(stmt
->s
.set
);
514 free_ret_stmt(stmt
->s
.ret
);
520 typedef struct impl_stmts
{
525 static inline impl_stmts
*init_impl_stmts(impl_stmt
*stmt
) {
526 impl_stmts
*stmts
= malloc(sizeof(*stmts
));
528 stmts
->stmts
= malloc(sizeof(*stmts
->stmts
));
529 stmts
->stmts
[0] = stmt
;
533 static inline impl_stmts
*add_impl_stmt(impl_stmts
*stmts
, impl_stmt
*stmt
) {
534 stmts
->stmts
= realloc(stmts
->stmts
, ++stmts
->count
* sizeof(*stmts
->stmts
));
535 stmts
->stmts
[stmts
->count
-1] = stmt
;
539 static inline void free_impl_stmts(impl_stmts
*stmts
) {
542 for (i
= 0; i
< stmts
->count
; ++i
) {
543 free_impl_stmt(stmts
->stmts
[i
]);
549 typedef struct impl
{
554 static inline impl
*init_impl(impl_func
*func
, impl_stmts
*stmts
) {
555 impl
*i
= malloc(sizeof(*i
));
561 static inline void free_impl(impl
*impl
) {
562 free_impl_func(impl
->func
);
563 free_impl_stmts(impl
->stmts
);
567 typedef struct impls
{
572 static impls
*add_impl(impls
*impls
, impl
*impl
) {
574 impls
= calloc(1, sizeof(*impls
));
576 impls
->list
= realloc(impls
->list
, ++impls
->count
* sizeof(*impls
->list
));
577 impls
->list
[impls
->count
-1] = impl
;
581 static void free_impls(impls
*impls
) {
584 for (i
= 0; i
< impls
->count
; ++i
) {
585 free_impl(impls
->list
[i
]);
591 typedef struct PSI_Data
{
599 EXPORT
static inline void PSI_DataExchange(PSI_Data
*dest
, PSI_Data
*src
) {
600 memcpy(dest
, src
, sizeof(*dest
));
601 memset(src
, 0, sizeof(*src
));
604 EXPORT
static inline void PSI_DataDtor(PSI_Data
*data
) {
606 free_decl_typedefs(data
->defs
);
609 free_decls(data
->decls
);
612 free_impls(data
->impls
);