1 #define _CONCAT(x,y) x##y
2 #define CONCAT(x,y) _CONCAT(x,y)
3 #define COUNTED(x) CONCAT(parse_ ##x## _, __LINE__)
6 #define DEF(dn, dv) dn dv
7 #define LET(nt, rule) nt ::= rule.
8 #define PARSE(nt, rule) nt ::= rule.
9 #define PARSE_NAMED(nt, nt_name, rule) NAMED(nt, nt_name) ::= rule.
10 #define PARSE_TYPED(nt, nt_name, rule) TYPED(nt, nt_name) ::= rule.
12 #define NAMED(t, name) t(name)
13 #define TYPED(t, name) t(name)
14 #define TOKEN_TYPE(token, type_) %type token {type_}
15 #define TOKEN_DTOR(token, dtor) %destructor token {dtor}
22 #define PARSE(nt, rule) \
23 static void COUNTED(nt) (PSI_Parser *P rule)
24 #define PARSE_NAMED(nt, nt_name, rule) \
25 static void COUNTED(nt) (PSI_Parser *P NAMED(nt, nt_name) rule)
26 #define PARSE_TYPED(nt, nt_name, rule) \
27 static void COUNTED(nt) (PSI_Parser *P TYPED(nt, nt_name) rule)
29 #define NAMED(t, name) , PSI_Token *name
30 #define TYPED(t, name) , TOKEN_TYPE_NAME(t) name
31 #define TOKEN_TYPE_NAME(token) _##token##_type
32 #define TOKEN_TYPE(token, type) typedef type TOKEN_TYPE_NAME(token);
33 #define TOKEN_DTOR(token, dtor)
37 void psi_error(int, const char *, int, const char *, ...);
40 DEF(%name
, PSI_ParserProc
)
41 DEF(%token_prefix
, PSI_T_
)
42 DEF(%token_type
, {PSI_Token
*})
43 DEF(%token_destructor
, {free($$
);})
44 DEF(%default_destructor
, {(void)P
;})
45 DEF(%extra_argument
, {PSI_Parser
*P
})
47 /* TOKEN is defined inside syntax_error */
50 if (TOKEN
&& TOKEN
->type
!= PSI_T_EOF
) {
51 psi_error(PSI_WARNING
, TOKEN
->file
, TOKEN
->line
, "PSI syntax error: Unexpected token '%s'", TOKEN
->text
);
53 psi_error(PSI_WARNING
, P
->psi
.file
.fn
, P
->line
, "PSI syntax error: Unexpected end of input");
58 DEF(%left
, PLUS MINUS
.)
59 DEF(%left
, SLASH ASTERISK
.)
60 DEF(%fallback
, NAME TEMP FREE SET LET RETURN CALLOC CALLBACK ZVAL LIB STRING
.)
62 DEF(%token_class
, const_type_token BOOL INT FLOAT STRING
.)
63 DEF(%token_class
, decl_type_token FLOAT DOUBLE INT8 UINT8 INT16 UINT16 INT32 UINT32 INT64 UINT64 NAME
.)
64 DEF(%token_class
, impl_def_val_token NULL NUMBER TRUE FALSE QUOTED_STRING
.)
65 DEF(%token_class
, num_exp_token NUMBER NSNAME
.)
66 DEF(%token_class
, num_exp_op_token PLUS MINUS ASTERISK SLASH
.)
67 DEF(%token_class
, let_func_token ZVAL OBJVAL ARRVAL PATHVAL STRLEN STRVAL FLOATVAL INTVAL BOOLVAL
.)
68 DEF(%token_class
, set_func_token TO_OBJECT TO_ARRAY TO_STRING TO_INT TO_FLOAT TO_BOOL ZVAL VOID
.)
69 DEF(%token_class
, impl_type_token VOID MIXED BOOL INT FLOAT STRING ARRAY OBJECT CALLABLE
.)
71 TOKEN_TYPE(decl_enum
, decl_enum
*)
72 TOKEN_DTOR(decl_enum
, free_decl_enum($$
);)
73 TOKEN_TYPE(decl_enum_items
, decl_enum_items
*)
74 TOKEN_DTOR(decl_enum_items
, free_decl_enum_items($$
);)
75 TOKEN_TYPE(decl_enum_item
, decl_enum_item
*)
76 TOKEN_DTOR(decl_enum_item
, free_decl_enum_item($$
);)
77 TOKEN_TYPE(decl_struct_args_block
, decl_args
*)
78 TOKEN_DTOR(decl_struct_args_block
, free_decl_args($$
);) /* there was a typo */
79 TOKEN_TYPE(decl_struct_args
, decl_args
*)
80 TOKEN_DTOR(decl_struct_args
, free_decl_args($$
);)
81 TOKEN_TYPE(decl_struct
, decl_struct
*)
82 TOKEN_DTOR(decl_struct
, free_decl_struct($$
);)
83 TOKEN_TYPE(align_and_size
, decl_struct_layout
)
84 TOKEN_TYPE(decl_union
, decl_union
*)
85 TOKEN_DTOR(decl_union
, free_decl_union($$
);)
86 TOKEN_TYPE(const_type
, const_type
*)
87 TOKEN_DTOR(const_type
, free_const_type($$
);)
88 TOKEN_TYPE(constant
, constant
*)
89 TOKEN_DTOR(constant
, free_constant($$
);)
90 TOKEN_TYPE(decl_typedef
, decl_arg
*)
91 TOKEN_DTOR(decl_typedef
, free_decl_arg($$
);)
92 TOKEN_TYPE(decl_typedef_body_ex
, decl_arg
*)
93 TOKEN_DTOR(decl_typedef_body_ex
, free_decl_arg($$
);)
94 TOKEN_TYPE(decl_typedef_body
, decl_arg
*)
95 TOKEN_DTOR(decl_typedef_body
, free_decl_arg($$
);)
96 TOKEN_TYPE(decl_typedef_body_fn_args
, decl_args
*)
97 TOKEN_DTOR(decl_typedef_body_fn_args
, free_decl_args($$
);)
98 TOKEN_TYPE(decl
, decl
*)
99 TOKEN_DTOR(decl
, free_decl($$
);)
100 TOKEN_TYPE(decl_func
, decl_arg
*)
101 TOKEN_DTOR(decl_func
, free_decl_arg($$
);)
102 TOKEN_TYPE(decl_abi
, decl_abi
*)
103 TOKEN_DTOR(decl_abi
, free_decl_abi($$
);)
104 TOKEN_TYPE(decl_var
, decl_var
*)
105 TOKEN_DTOR(decl_var
, free_decl_var($$
);)
106 TOKEN_TYPE(decl_vars
, decl_vars
*)
107 TOKEN_DTOR(decl_vars
, free_decl_vars($$
);)
108 TOKEN_TYPE(decl_arg
, decl_arg
*)
109 TOKEN_DTOR(decl_arg
, free_decl_arg($$
);)
110 TOKEN_TYPE(decl_args
, decl_args
*)
111 TOKEN_DTOR(decl_args
, free_decl_args($$
);)
112 TOKEN_TYPE(struct_args
, decl_args
*)
113 TOKEN_DTOR(struct_args
, free_decl_args($$
);)
114 TOKEN_TYPE(struct_arg
, decl_arg
*)
115 TOKEN_DTOR(struct_arg
, free_decl_arg($$
);)
116 TOKEN_TYPE(struct_layout
, decl_struct_layout
*)
117 TOKEN_DTOR(struct_layout
, free_decl_struct_layout($$
);)
118 TOKEN_TYPE(decl_type
, decl_type
*)
119 TOKEN_DTOR(decl_type
, free_decl_type($$
);)
120 TOKEN_TYPE(const_decl_type
, decl_type
*)
121 TOKEN_DTOR(const_decl_type
, free_decl_type($$
);)
122 TOKEN_TYPE(impl
, impl
*)
123 TOKEN_DTOR(impl
, free_impl($$
);)
124 TOKEN_TYPE(impl_func
, impl_func
*)
125 TOKEN_DTOR(impl_func
, free_impl_func($$
);)
126 TOKEN_TYPE(impl_def_val
, impl_def_val
*)
127 TOKEN_DTOR(impl_def_val
, free_impl_def_val($$
);)
128 TOKEN_TYPE(impl_var
, impl_var
*)
129 TOKEN_DTOR(impl_var
, free_impl_var($$
);)
130 TOKEN_TYPE(impl_arg
, impl_arg
*)
131 TOKEN_DTOR(impl_arg
, free_impl_arg($$
);)
132 TOKEN_TYPE(impl_args
, impl_args
*)
133 TOKEN_DTOR(impl_args
, free_impl_args($$
);)
134 TOKEN_TYPE(impl_vararg
, impl_arg
*)
135 TOKEN_DTOR(impl_vararg
, free_impl_arg($$
);)
136 TOKEN_TYPE(impl_arg_list
, impl_args
*)
137 TOKEN_DTOR(impl_arg_list
, free_impl_args($$
);)
138 TOKEN_TYPE(impl_stmts
, impl_stmts
*)
139 TOKEN_DTOR(impl_stmts
, free_impl_stmts($$
);)
140 TOKEN_TYPE(impl_stmt
, impl_stmt
*)
141 TOKEN_DTOR(impl_stmt
, free_impl_stmt($$
);)
142 TOKEN_TYPE(num_exp
, num_exp
*)
143 TOKEN_DTOR(num_exp
, free_num_exp($$
);)
144 TOKEN_TYPE(let_stmt
, let_stmt
*)
145 TOKEN_DTOR(let_stmt
, free_let_stmt($$
);)
146 TOKEN_TYPE(let_calloc
, let_calloc
*)
147 TOKEN_DTOR(let_calloc
, free_let_calloc($$
);)
148 TOKEN_TYPE(let_func
, let_func
*)
149 TOKEN_DTOR(let_func
, free_let_func($$
);)
150 TOKEN_TYPE(callback_arg_list
, set_values
*)
151 TOKEN_DTOR(callback_arg_list
, free_set_values($$
);)
152 TOKEN_TYPE(callback_args
, set_values
*)
153 TOKEN_DTOR(callback_args
, free_set_values($$
);)
154 TOKEN_TYPE(let_val
, let_val
*)
155 TOKEN_DTOR(let_val
, free_let_val($$
);)
156 TOKEN_TYPE(set_stmt
, set_stmt
*)
157 TOKEN_DTOR(set_stmt
, free_set_stmt($$
);)
158 TOKEN_TYPE(set_value
, set_value
*)
159 TOKEN_DTOR(set_value
, free_set_value($$
);)
160 TOKEN_TYPE(set_vals
, set_value
*)
161 TOKEN_DTOR(set_vals
, free_set_value($$
);)
162 TOKEN_TYPE(set_func
, set_func
*)
163 TOKEN_DTOR(set_func
, free_set_func($$
);)
164 TOKEN_TYPE(return_stmt
, return_stmt
*)
165 TOKEN_DTOR(return_stmt
, free_return_stmt($$
);)
166 TOKEN_TYPE(free_stmt
, free_stmt
*)
167 TOKEN_DTOR(free_stmt
, free_free_stmt($$
);)
168 TOKEN_TYPE(free_calls
, free_calls
*)
169 TOKEN_DTOR(free_calls
, free_free_calls($$
);)
170 TOKEN_TYPE(free_call
, free_call
*)
171 TOKEN_DTOR(free_call
, free_free_call($$
);)
172 TOKEN_TYPE(impl_type
, impl_type
*)
173 TOKEN_DTOR(impl_type
, free_impl_type($$
);)
174 TOKEN_TYPE(reference
, char)
175 TOKEN_TYPE(indirection
, unsigned)
176 TOKEN_TYPE(pointers
, unsigned)
180 LET(blocks
, blocks block
)
185 PARSE(block
, NAMED(LIB
, token
) NAMED(QUOTED_STRING
, libname
) TOKEN(EOS
)) {
186 if (P
->psi
.file
.ln
) {
187 P
->error(P
, token
, PSI_WARNING
, "Extra 'lib %s' statement has no effect", libname
->text
);
189 P
->psi
.file
.ln
= strndup(libname
->text
+ 1, libname
->size
- 2);
194 PARSE(block
, TYPED(decl
, decl
)) {
195 P
->decls
= add_decl(P
->decls
, decl
);
198 PARSE(block
, TYPED(impl
, impl
)) {
199 P
->impls
= add_impl(P
->impls
, impl
);
202 PARSE(block
, TYPED(decl_typedef
, def
)) {
203 P
->defs
= add_decl_typedef(P
->defs
, def
);
204 switch (def
->type
->type
) {
206 if (def
->type
->real
.strct
) {
207 P
->structs
= add_decl_struct(P
->structs
, def
->type
->real
.strct
);
211 if (def
->type
->real
.unn
) {
212 P
->unions
= add_decl_union(P
->unions
, def
->type
->real
.unn
);
216 if (def
->type
->real
.enm
) {
217 P
->enums
= add_decl_enum(P
->enums
, def
->type
->real
.enm
);
223 PARSE(block
, TYPED(constant
, constant
)) {
224 P
->consts
= add_constant(P
->consts
, constant
);
227 PARSE(block
, TYPED(decl_struct
, strct
)) {
228 P
->structs
= add_decl_struct(P
->structs
, strct
);
231 PARSE(block
, TYPED(decl_union
, u
)) {
232 P
->unions
= add_decl_union(P
->unions
, u
);
235 PARSE(block
, TYPED(decl_enum
, e
)) {
236 P
->enums
= add_decl_enum(P
->enums
, e
);
239 PARSE_NAMED(optional_name
, n
, ) {
243 PARSE_NAMED(optional_name
, n
,
248 PARSE_NAMED(enum_name
, n
,
249 NAMED(ENUM
, E
) NAMED(optional_name
, N
)) {
256 PSI_TokenHash(E
, digest
);
257 n
= PSI_TokenTranslit(PSI_TokenAppend(E
, 1, digest
), " ", "@");
261 PARSE_TYPED(decl_enum
, e
,
264 TYPED(decl_enum_items
, list
)
266 e
= init_decl_enum(N
->text
, list
);
270 PARSE_TYPED(decl_enum_items
, l
,
271 TYPED(decl_enum_item
, i
)) {
272 l
= init_decl_enum_items(i
);
274 PARSE_TYPED(decl_enum_items
, l
,
275 TYPED(decl_enum_items
, l_
)
277 TYPED(decl_enum_item
, i
)) {
278 l
= add_decl_enum_item(l_
, i
);
281 PARSE_TYPED(decl_enum_item
, i
,
284 TYPED(num_exp
, num
)) {
285 i
= init_decl_enum_item(N
->text
, num
);
288 PARSE_TYPED(decl_enum_item
, i
,
290 i
= init_decl_enum_item(N
->text
, NULL
);
294 PARSE_NAMED(union_name
, n
,
296 NAMED(optional_name
, N
)) {
303 PSI_TokenHash(U
, digest
);
304 n
= PSI_TokenTranslit(PSI_TokenAppend(U
, 1, digest
), " ", "@");
308 PARSE_NAMED(struct_name
, n
,
310 NAMED(optional_name
, N
)) {
317 PSI_TokenHash(S
, digest
);
318 n
= PSI_TokenTranslit(PSI_TokenAppend(S
, 1, digest
), " ", "@");
322 PARSE_TYPED(decl_struct_args_block
, args_
,
324 TYPED(struct_args
, args
)
329 PARSE_TYPED(decl_struct_args
, args_
,
330 TYPED(decl_struct_args_block
, args
)) {
333 PARSE_TYPED(decl_struct_args
, args_
,
335 args_
= init_decl_args(NULL
);
338 PARSE_TYPED(decl_struct
, strct
,
341 TYPED(align_and_size
, as
)
342 TYPED(decl_struct_args
, args
)) {
343 strct
= init_decl_struct(N
->text
, args
);
344 strct
->align
= as
.pos
;
345 strct
->size
= as
.len
;
349 PARSE_TYPED(align_and_size
, as
, ) {
353 PARSE_TYPED(align_and_size
, as
,
361 as
.pos
= atol(A
->text
);
362 as
.len
= atol(S
->text
);
367 PARSE_TYPED(decl_union
, u
,
370 TYPED(align_and_size
, as
)
371 TYPED(decl_struct_args
, args
)) {
372 u
= init_decl_union(N
->text
, args
);
378 PARSE_TYPED(const_type
, type_
,
379 NAMED(const_type_token
, T
)) {
380 type_
= init_const_type(T
->type
, T
->text
);
384 PARSE_TYPED(constant
, constant
,
386 TYPED(const_type
, type
)
389 TYPED(impl_def_val
, val
)
391 constant
= init_constant(type
, T
->text
, val
);
395 PARSE_TYPED(decl_typedef
, def
,
397 TYPED(decl_typedef_body
, def_
)
403 PARSE_TYPED(decl_typedef_body_ex
, def
,
404 NAMED(struct_name
, N
)
405 TYPED(align_and_size
, as
)
406 TYPED(decl_struct_args_block
, args
)
407 TYPED(decl_var
, var
)) {
408 def
= init_decl_arg(init_decl_type(PSI_T_STRUCT
, N
->text
), var
);
409 def
->type
->token
= PSI_TokenCopy(N
);
410 def
->type
->real
.strct
= init_decl_struct(N
->text
, args
);
411 def
->type
->real
.strct
->token
= N
;
412 def
->type
->real
.strct
->align
= as
.pos
;
413 def
->type
->real
.strct
->size
= as
.len
;
415 PARSE_TYPED(decl_typedef_body_ex
, def
,
417 TYPED(align_and_size
, as
)
418 TYPED(decl_struct_args_block
, args
)
419 TYPED(decl_var
, var
)) {
420 def
= init_decl_arg(init_decl_type(PSI_T_UNION
, N
->text
), var
);
421 def
->type
->token
= PSI_TokenCopy(N
);
422 def
->type
->real
.unn
= init_decl_union(N
->text
, args
);
423 def
->type
->real
.unn
->token
= N
;
424 def
->type
->real
.unn
->align
= as
.pos
;
425 def
->type
->real
.unn
->size
= as
.len
;
427 PARSE_TYPED(decl_typedef_body_ex
, def
,
429 NAMED(NAME
, ALIAS
)) {
430 def
= init_decl_arg(init_decl_type(PSI_T_ENUM
, e
->name
), init_decl_var(ALIAS
->text
, 0, 0));
431 def
->var
->token
= ALIAS
;
432 def
->type
->token
= PSI_TokenCopy(e
->token
);
433 def
->type
->real
.enm
= e
;
436 PARSE_TYPED(decl_typedef_body
, def
,
437 TYPED(decl_typedef_body_ex
, def_
)) {
441 PARSE_TYPED(decl_typedef_body_fn_args
, args
,
443 TYPED(decl_args
, args_
)
447 PARSE_TYPED(decl_typedef_body
, def
,
448 TYPED(decl_func
, func_
)
449 TYPED(decl_typedef_body_fn_args
, args
)) {
450 def
= init_decl_arg(init_decl_type(PSI_T_FUNCTION
, func_
->var
->name
), copy_decl_var(func_
->var
));
451 def
->type
->token
= PSI_TokenCopy(func_
->token
);
452 def
->type
->real
.func
= init_decl(init_decl_abi("default"), func_
, args
);
454 PARSE_TYPED(decl_typedef_body
, def
,
455 TYPED(decl_arg
, arg
)) {
459 PARSE_TYPED(decl
, decl
,
461 TYPED(decl_func
, func
)
463 TYPED(decl_args
, args
)
466 decl
= init_decl(abi
, func
, args
);
469 PARSE_TYPED(decl_func
, func
,
470 TYPED(decl_arg
, arg
)) {
473 /* special case for void functions */
474 PARSE_TYPED(decl_func
, func
,
477 func
= init_decl_arg(
478 init_decl_type(T
->type
, T
->text
),
479 init_decl_var(N
->text
, 0, 0)
481 func
->type
->token
= T
;
482 func
->var
->token
= N
;
485 PARSE_TYPED(decl_typedef_body
, def
,
487 TYPED(indirection
, decl_i
)
489 TYPED(indirection
, type_i
)
492 TYPED(decl_typedef_body_fn_args
, args
)) {
493 decl_arg
*func_
= init_decl_arg(
494 init_decl_type(T
->type
, T
->text
),
495 init_decl_var(N
->text
, decl_i
, 0)
497 func_
->type
->token
= T
;
498 func_
->var
->token
= N
;
502 init_decl_type(PSI_T_FUNCTION
, func_
->var
->name
),
503 copy_decl_var(func_
->var
)
505 def
->var
->pointer_level
= type_i
;
506 def
->type
->token
= PSI_TokenCopy(func_
->token
);
507 def
->type
->real
.func
= init_decl(init_decl_abi("default"), func_
, args
);
509 PARSE_TYPED(decl_typedef_body
, def
,
512 TYPED(pointers
, decl_i
)
514 TYPED(indirection
, type_i
)
517 TYPED(decl_typedef_body_fn_args
, args
)) {
518 decl_arg
*func_
= init_decl_arg(
519 init_decl_type(T
->type
, T
->text
),
520 init_decl_var(N
->text
, decl_i
, 0)
522 func_
->type
->token
= T
;
523 func_
->var
->token
= N
;
527 init_decl_type(PSI_T_FUNCTION
, func_
->var
->name
),
528 copy_decl_var(func_
->var
)
530 def
->var
->pointer_level
= type_i
;
531 def
->type
->token
= PSI_TokenCopy(func_
->token
);
532 def
->type
->real
.func
= init_decl(init_decl_abi("default"), func_
, args
);
535 PARSE_TYPED(decl_abi
, abi
,
537 abi
= init_decl_abi(T
->text
);
541 PARSE_TYPED(decl_var
, var
,
542 TYPED(indirection
, p
)
544 var
= init_decl_var(T
->text
, p
, 0);
547 PARSE_TYPED(decl_var
, var
,
548 TYPED(indirection
, p
)
553 var
= init_decl_var(T
->text
, p
+1, atol(D
->text
));
558 PARSE_TYPED(decl_vars
, vars
,
559 TYPED(decl_var
, var
)) {
560 vars
= init_decl_vars(var
);
562 PARSE_TYPED(decl_vars
, vars
,
563 TYPED(decl_vars
, vars_
)
565 TYPED(decl_var
, var
)) {
566 vars
= add_decl_var(vars_
, var
);
569 PARSE_TYPED(decl_arg
, arg_
,
570 TYPED(const_decl_type
, type
)
571 TYPED(decl_var
, var
)) {
572 arg_
= init_decl_arg(type
, var
);
574 PARSE_TYPED(decl_typedef_body
, def
,
575 TYPED(const_decl_type
, type_
)
576 TYPED(indirection
, decl_i
)
578 TYPED(indirection
, type_i
)
581 TYPED(decl_typedef_body_fn_args
, args
)) {
582 decl_arg
*func_
= init_decl_arg(
584 init_decl_var(N
->text
, decl_i
, 0)
586 func_
->var
->token
= N
;
590 init_decl_type(PSI_T_FUNCTION
, func_
->var
->name
),
591 copy_decl_var(func_
->var
)
593 def
->var
->pointer_level
= type_i
;
594 def
->type
->token
= PSI_TokenCopy(func_
->token
);
595 def
->type
->real
.func
= init_decl(init_decl_abi("default"), func_
, args
);
598 /* void pointers need a specific rule */
599 PARSE_TYPED(decl_arg
, arg_
,
603 arg_
= init_decl_arg(
604 init_decl_type(T
->type
, T
->text
),
605 init_decl_var(N
->text
, p
, 0)
607 arg_
->type
->token
= T
;
608 arg_
->var
->token
= N
;
611 PARSE_TYPED(decl_arg
, arg_
,
616 arg_
= init_decl_arg(
617 init_decl_type(T
->type
, T
->text
),
618 init_decl_var(N
->text
, p
, 0)
620 arg_
->type
->token
= T
;
621 arg_
->var
->token
= N
;
627 PARSE_TYPED(decl_args
, args
,
628 TYPED(decl_arg
, arg
)) {
629 args
= init_decl_args(arg
);
631 PARSE_TYPED(decl_args
, args
,
632 TYPED(decl_args
, args_
)
634 TYPED(decl_arg
, arg
)) {
635 args
= add_decl_arg(args_
, arg
);
637 PARSE_TYPED(decl_args
, args
,
638 TYPED(decl_args
, args_
)
645 PARSE_TYPED(struct_args
, args
,
646 TYPED(struct_arg
, arg
)) {
647 args
= init_decl_args(arg
);
649 PARSE_TYPED(struct_args
, args
,
650 TYPED(struct_args
, args_
)
651 TYPED(struct_arg
, arg
)) {
652 args
= add_decl_arg(args_
, arg
);
655 PARSE_TYPED(struct_arg
, arg_
,
656 TYPED(decl_typedef_body_ex
, def
)
659 switch (def
->type
->type
) {
661 if (def
->type
->real
.strct
) {
662 P
->structs
= add_decl_struct(P
->structs
, def
->type
->real
.strct
);
666 if (def
->type
->real
.unn
) {
667 P
->unions
= add_decl_union(P
->unions
, def
->type
->real
.unn
);
671 if (def
->type
->real
.enm
) {
672 P
->enums
= add_decl_enum(P
->enums
, def
->type
->real
.enm
);
677 PARSE_TYPED(struct_arg
, arg
,
678 TYPED(decl_arg
, arg_
)
679 TYPED(struct_layout
, layout_
)
681 arg_
->layout
= layout_
;
685 PARSE_TYPED(struct_layout
, layout
, ) {
688 PARSE_TYPED(struct_layout
, layout
,
696 layout
= init_decl_struct_layout(atol(POS
->text
), atol(SIZ
->text
));
701 /* un/signed, urgh */
702 PARSE_NAMED(decl_scalar_type
, type_
,
706 PARSE_NAMED(decl_scalar_type
, type_
,
708 NAMED(decl_scalar_type_short
, s
)) {
710 type_
= PSI_TokenCat(2, S
, s
);
717 PARSE_NAMED(decl_scalar_type_short
, s
, ) {
721 PARSE_NAMED(decl_scalar_type_short
, s
,
725 PARSE_NAMED(decl_scalar_type
, type_
,
729 PARSE_NAMED(decl_scalar_type
, type_
,
731 NAMED(decl_scalar_type_long
, l
)) {
733 type_
= PSI_TokenCat(2, L
, l
);
740 PARSE_NAMED(decl_scalar_type_long
, l
, ) {
743 PARSE_NAMED(decl_scalar_type_long
, l
,
747 PARSE_NAMED(decl_scalar_type_long
, l
,
749 NAMED(decl_scalar_type_long_long
, ll
)) {
751 l
= PSI_TokenCat(2, L
, ll
);
758 PARSE_NAMED(decl_scalar_type_long_long
, ll
, ) {
761 PARSE_NAMED(decl_scalar_type_long_long
, ll
,
765 PARSE_TYPED(decl_type
, type_
,
767 NAMED(decl_scalar_type
, N
)) {
768 PSI_Token
*T
= PSI_TokenCat(2, U
, N
);
769 type_
= init_decl_type(T
->type
, T
->text
);
774 PARSE_TYPED(decl_type
, type_
,
776 NAMED(decl_scalar_type
, N
)) {
777 PSI_Token
*T
= PSI_TokenCat(2, S
, N
);
778 type_
= init_decl_type(T
->type
, T
->text
);
783 PARSE_TYPED(decl_type
, type_
,
784 NAMED(UNSIGNED
, U
)) {
785 type_
= init_decl_type(PSI_T_NAME
, U
->text
);
788 PARSE_TYPED(decl_type
, type_
,
790 type_
= init_decl_type(PSI_T_NAME
, S
->text
);
793 PARSE_TYPED(decl_type
, type_
,
794 NAMED(decl_scalar_type
, N
)) {
795 type_
= init_decl_type(N
->type
, N
->text
);
799 PARSE_TYPED(decl_type
, type_
,
802 type_
= init_decl_type(S
->type
, T
->text
);
806 PARSE_TYPED(decl_type
, type_
,
809 type_
= init_decl_type(U
->type
, T
->text
);
813 PARSE_TYPED(decl_type
, type_
,
816 type_
= init_decl_type(E
->type
, T
->text
);
820 PARSE_TYPED(decl_type
, type_
,
821 NAMED(decl_type_token
, T
)) {
822 type_
= init_decl_type(T
->type
, T
->text
);
827 PARSE_TYPED(const_decl_type
, type
,
828 TYPED(decl_type
, type_
)) {
831 PARSE_TYPED(const_decl_type
, type
,
833 TYPED(decl_type
, type_
)) {
837 PARSE_TYPED(impl
, impl
,
838 TYPED(impl_func
, func
)
840 TYPED(impl_stmts
, stmts
)
842 impl
= init_impl(func
, stmts
);
845 PARSE_TYPED(impl_func
, func
,
849 TYPED(impl_args
, args
)
851 TYPED(impl_type
, type
)) {
852 func
= init_impl_func(NAME
->text
, args
, type
, r
);
856 PARSE_TYPED(impl_def_val
, def
,
857 NAMED(impl_def_val_token
, T
)) {
858 def
= init_impl_def_val(T
->type
, T
->text
);
862 PARSE_TYPED(impl_var
, var
,
864 NAMED(DOLLAR_NAME
, T
)) {
865 var
= init_impl_var(T
->text
, r
);
869 PARSE_TYPED(impl_arg
, arg
,
870 TYPED(impl_type
, type
)
871 TYPED(impl_var
, var
)) {
872 arg
= init_impl_arg(type
, var
, NULL
);
874 PARSE_TYPED(impl_arg
, arg
,
875 TYPED(impl_type
, type
)
878 TYPED(impl_def_val
, def
)) {
879 arg
= init_impl_arg(type
, var
, def
);
882 PARSE_TYPED(impl_args
, args
,
887 PARSE_TYPED(impl_args
, args
,
889 TYPED(impl_arg_list
, args_
)
893 PARSE_TYPED(impl_args
, args
,
895 TYPED(impl_arg_list
, args_
)
897 TYPED(impl_vararg
, va
)
900 args
->vararg
.name
= va
;
903 PARSE_TYPED(impl_vararg
, va
,
904 TYPED(impl_type
, type
)
907 NAMED(DOLLAR_NAME
, T
)) {
908 va
= init_impl_arg(type
, init_impl_var(T
->text
, r
), NULL
);
912 PARSE_TYPED(impl_arg_list
, args
,
913 TYPED(impl_arg
, arg
)) {
914 args
= init_impl_args(arg
);
916 PARSE_TYPED(impl_arg_list
, args
,
917 TYPED(impl_arg_list
, args_
)
919 TYPED(impl_arg
, arg
)) {
920 args
= add_impl_arg(args_
, arg
);
923 PARSE_TYPED(impl_stmts
, stmts
,
924 TYPED(impl_stmt
, stmt
)) {
925 stmts
= init_impl_stmts(stmt
);
927 PARSE_TYPED(impl_stmts
, stmts
,
928 TYPED(impl_stmts
, stmts_
)
929 TYPED(impl_stmt
, stmt
)) {
930 stmts
= add_impl_stmt(stmts_
, stmt
);
933 PARSE_TYPED(impl_stmt
, stmt
,
934 TYPED(let_stmt
, let
)) {
935 stmt
= init_impl_stmt(PSI_T_LET
, let
);
937 PARSE_TYPED(impl_stmt
, stmt
,
938 TYPED(set_stmt
, set
)) {
939 stmt
= init_impl_stmt(PSI_T_SET
, set
);
941 PARSE_TYPED(impl_stmt
, stmt
,
942 TYPED(return_stmt
, ret
)) {
943 stmt
= init_impl_stmt(PSI_T_RETURN
, ret
);
945 PARSE_TYPED(impl_stmt
, stmt
,
946 TYPED(free_stmt
, free
)) {
947 stmt
= init_impl_stmt(PSI_T_FREE
, free
);
950 PARSE_TYPED(num_exp
, exp
,
951 NAMED(num_exp_token
, tok
)) {
952 exp
= init_num_exp(tok
->type
, tok
->text
);
955 PARSE_TYPED(num_exp
, exp
,
956 TYPED(decl_var
, var
)) {
957 exp
= init_num_exp(PSI_T_NAME
, var
);
958 exp
->token
= PSI_TokenCopy(var
->token
);
960 PARSE_TYPED(num_exp
, exp
,
962 NAMED(num_exp_op_token
, operator_
)
963 TYPED(num_exp
, operand_
)) {
964 exp_
->operator = operator_
->type
;
965 exp_
->operand
= operand_
;
970 PARSE_TYPED(let_stmt
, let
,
974 let
= init_let_stmt(var
, init_let_val(PSI_LET_NULL
, NULL
));
976 PARSE_TYPED(let_stmt
, let
,
983 val
->flags
.one
.is_reference
= r
? 1 : 0;
984 let
= init_let_stmt(var
, val
);
986 PARSE_TYPED(let_stmt
, let
,
992 let
= init_let_stmt(var
, init_let_val(PSI_LET_TMP
, val
));
995 PARSE_TYPED(let_calloc
, alloc
,
996 TYPED(num_exp
, nmemb
)
998 TYPED(num_exp
, size
)) {
999 alloc
= init_let_calloc(nmemb
, size
);
1002 PARSE_TYPED(let_func
, func
,
1003 NAMED(let_func_token
, T
)
1005 TYPED(impl_var
, var
)
1007 func
= init_let_func(T
->type
, T
->text
, var
);
1011 LET(callback_arg_list
, )
1012 PARSE_TYPED(callback_arg_list
, args
,
1013 TYPED(callback_args
, args_
)) {
1017 PARSE_TYPED(callback_args
, args
,
1018 TYPED(set_value
, val
)) {
1019 args
= init_set_values(val
);
1021 PARSE_TYPED(callback_args
, args
,
1022 TYPED(callback_args
, args_
)
1024 TYPED(set_value
, val
)) {
1025 args
= add_set_value(args_
, val
);
1028 PARSE_TYPED(let_val
, val
,
1030 val
= init_let_val(PSI_LET_NULL
, NULL
);
1032 PARSE_TYPED(let_val
, val
,
1033 TYPED(num_exp
, exp
)) {
1034 val
= init_let_val(PSI_LET_NUMEXP
, exp
);
1036 PARSE_TYPED(let_val
, val
,
1039 TYPED(let_calloc
, alloc
)
1041 val
= init_let_val(PSI_LET_CALLOC
, alloc
);
1043 PARSE_TYPED(let_val
, val
,
1044 TYPED(let_func
, func
)) {
1045 val
= init_let_val(PSI_LET_FUNC
, func
);
1047 PARSE_TYPED(let_val
, val
,
1049 NAMED(let_func_token
, F
)
1051 TYPED(impl_var
, var
)
1053 TYPED(callback_arg_list
, args_
)
1056 val
= init_let_val(PSI_LET_CALLBACK
, init_let_callback(
1057 init_let_func(F
->type
, F
->text
, var
), args_
));
1061 PARSE_TYPED(set_stmt
, set
,
1063 TYPED(impl_var
, var
)
1065 TYPED(set_value
, val
)
1067 set
= init_set_stmt(var
, val
);
1070 PARSE_TYPED(set_value
, val
,
1071 TYPED(set_func
, func
)
1073 TYPED(decl_var
, var
)
1075 val
= init_set_value(func
, init_decl_vars(var
));
1077 PARSE_TYPED(set_value
, val
,
1078 TYPED(set_func
, func
)
1080 TYPED(decl_var
, var
)
1082 TYPED(num_exp
, num_
)
1084 val
= init_set_value(func
, init_decl_vars(var
));
1087 PARSE_TYPED(set_value
, val
,
1088 TYPED(set_func
, func_
)
1090 TYPED(decl_var
, var
)
1094 free_set_func(func_
);
1095 val
= init_set_value(init_set_func(T
->type
, T
->text
), init_decl_vars(var
));
1096 val
->func
->token
= T
;
1098 PARSE_TYPED(set_value
, val
,
1099 TYPED(set_func
, func_
)
1101 TYPED(decl_var
, var
)
1103 TYPED(set_vals
, vals
)
1107 val
->vars
= init_decl_vars(var
);
1109 PARSE_TYPED(set_value
, val
,
1110 TYPED(set_func
, func_
)
1112 TYPED(decl_var
, var
)
1114 TYPED(num_exp
, num_
)
1116 TYPED(set_vals
, vals
)
1121 val
->vars
= init_decl_vars(var
);
1124 PARSE_TYPED(set_vals
, vals
,
1125 TYPED(set_value
, val
)) {
1126 vals
= add_inner_set_value(init_set_value(NULL
, NULL
), val
);
1128 PARSE_TYPED(set_vals
, vals
,
1129 TYPED(set_vals
, vals_
)
1131 TYPED(set_value
, val
)) {
1132 vals
= add_inner_set_value(vals_
, val
);
1135 PARSE_TYPED(set_func
, func
,
1136 NAMED(set_func_token
, T
)) {
1137 func
= init_set_func(T
->type
, T
->text
);
1141 PARSE_TYPED(return_stmt
, ret
,
1143 TYPED(set_value
, val
)
1145 ret
= init_return_stmt(val
);
1149 PARSE_TYPED(free_stmt
, free
,
1151 TYPED(free_calls
, calls
)
1153 free
= init_free_stmt(calls
);
1156 PARSE_TYPED(free_calls
, calls
,
1157 TYPED(free_call
, call
)) {
1158 calls
= init_free_calls(call
);
1160 PARSE_TYPED(free_calls
, calls
,
1161 TYPED(free_calls
, calls_
)
1163 TYPED(free_call
, call
)) {
1164 calls
= add_free_call(calls_
, call
);
1167 PARSE_TYPED(free_call
, call
,
1170 TYPED(decl_vars
, vars
)
1172 call
= init_free_call(F
->text
, vars
);
1176 PARSE_TYPED(impl_type
, type_
,
1177 NAMED(impl_type_token
, T
)) {
1178 type_
= init_impl_type(T
->type
, T
->text
);
1182 PARSE_TYPED(reference
, r
, ) {
1185 PARSE_TYPED(reference
, r
,
1190 PARSE_TYPED(indirection
, i
, ){
1193 PARSE_TYPED(indirection
, i
,
1194 TYPED(pointers
, p
)) {
1198 PARSE_TYPED(pointers
, p
,
1202 PARSE_TYPED(pointers
, p
,