42106b21d68979c3f1a3587cd3bc3bb57887b077
[m6w6/ext-psi] / src / parser_def.h
1 #define _CONCAT(x,y) x##y
2 #define CONCAT(x,y) _CONCAT(x,y)
3 #define COUNTED(x) CONCAT(parse_ ##x## _, __LINE__)
4
5 #ifdef GENERATE
6 #define DEF(dn, dv) dn dv
7 #define PASS(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.
11 #define TOKEN(t) t
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}
16 #else
17 #ifndef TEST
18 #include "parser.h"
19 #endif
20 #define DEF(dn, dv)
21 #define PASS(nt, rule) \
22 static void COUNTED(nt) (struct psi_parser *P) { \
23 (void) #rule; \
24 }
25 #define PARSE(nt, rule) \
26 static void COUNTED(nt) (struct psi_parser *P rule)
27 #define PARSE_NAMED(nt, nt_name, rule) \
28 static void COUNTED(nt) (struct psi_parser *P NAMED(nt, nt_name) rule)
29 #define PARSE_TYPED(nt, nt_name, rule) \
30 static void COUNTED(nt) (struct psi_parser *P TYPED(nt, nt_name) rule)
31 #define TOKEN(t)
32 #define NAMED(t, name) , struct psi_token *name
33 #define TYPED(t, name) , TOKEN_TYPE_NAME(t) name
34 #define TOKEN_TYPE_NAME(token) ##token##_parse_t
35 #define TOKEN_TYPE(token, type) typedef type TOKEN_TYPE_NAME(token);
36 #define TOKEN_DTOR(token, dtor)
37 #endif
38
39 DEF(%name, psi_parser_proc_)
40 DEF(%token_prefix, PSI_T_)
41 DEF(%token_type, {struct psi_token *})
42 DEF(%token_destructor, {free($$);})
43 DEF(%default_destructor, {(void)P;})
44 DEF(%extra_argument, {struct psi_parser *P})
45
46 /* TOKEN is defined inside syntax_error */
47 DEF(%syntax_error, {
48 ++P->errors;
49 if (TOKEN && TOKEN->type != PSI_T_EOF) {
50 psi_error(PSI_WARNING, TOKEN->file, TOKEN->line, "PSI syntax error: Unexpected token '%s' at pos %u", TOKEN->text, TOKEN->col);
51 } else {
52 psi_error(PSI_WARNING, P->psi.file.fn, P->line, "PSI syntax error: Unexpected end of input");
53 }
54 })
55
56 DEF(%nonassoc, NAME.)
57 DEF(%left, PLUS MINUS.)
58 DEF(%left, ASTERISK SLASH.)
59 DEF(%nonassoc, AMPERSAND.)
60 DEF(%fallback, NAME TEMP FREE SET LET RETURN CALLOC CALLBACK ZVAL LIB STRING COUNT.)
61
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 COUNT.)
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.)
70
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(let_vals, let_vals*)
157 TOKEN_DTOR(let_vals, free_let_vals($$);)
158 TOKEN_TYPE(set_stmt, set_stmt*)
159 TOKEN_DTOR(set_stmt, free_set_stmt($$);)
160 TOKEN_TYPE(set_value, set_value*)
161 TOKEN_DTOR(set_value, free_set_value($$);)
162 TOKEN_TYPE(set_vals, set_value*)
163 TOKEN_DTOR(set_vals, free_set_value($$);)
164 TOKEN_TYPE(set_func, set_func*)
165 TOKEN_DTOR(set_func, free_set_func($$);)
166 TOKEN_TYPE(return_stmt, return_stmt*)
167 TOKEN_DTOR(return_stmt, free_return_stmt($$);)
168 TOKEN_TYPE(free_stmt, free_stmt*)
169 TOKEN_DTOR(free_stmt, free_free_stmt($$);)
170 TOKEN_TYPE(free_calls, free_calls*)
171 TOKEN_DTOR(free_calls, free_free_calls($$);)
172 TOKEN_TYPE(free_call, free_call*)
173 TOKEN_DTOR(free_call, free_free_call($$);)
174 TOKEN_TYPE(impl_type, impl_type*)
175 TOKEN_DTOR(impl_type, free_impl_type($$);)
176 TOKEN_TYPE(reference, char)
177 TOKEN_TYPE(indirection, unsigned)
178 TOKEN_TYPE(pointers, unsigned)
179
180 PASS(file, blocks)
181 PASS(blocks, block)
182 PASS(blocks, blocks block)
183
184 PASS(block, EOF)
185 PASS(block, EOS)
186
187 PARSE(block, NAMED(LIB, token) NAMED(QUOTED_STRING, libname) TOKEN(EOS)) {
188 if (P->psi.file.ln) {
189 P->error(P, token, PSI_WARNING, "Extra 'lib %s' statement has no effect", libname->text);
190 } else {
191 P->psi.file.ln = strndup(libname->text + 1, libname->size - 2);
192 }
193 free(libname);
194 free(token);
195 }
196 PARSE(block, TYPED(decl, decl)) {
197 P->decls = add_decl(P->decls, decl);
198 }
199
200 PARSE(block, TYPED(impl, impl)) {
201 P->impls = add_impl(P->impls, impl);
202 }
203
204 PARSE(block, TYPED(decl_typedef, def)) {
205 P->defs = add_decl_typedef(P->defs, def);
206 switch (def->type->type) {
207 case PSI_T_STRUCT:
208 if (def->type->real.strct) {
209 P->structs = add_decl_struct(P->structs, def->type->real.strct);
210 }
211 break;
212 case PSI_T_UNION:
213 if (def->type->real.unn) {
214 P->unions = add_decl_union(P->unions, def->type->real.unn);
215 }
216 break;
217 case PSI_T_ENUM:
218 if (def->type->real.enm) {
219 P->enums = add_decl_enum(P->enums, def->type->real.enm);
220 }
221 break;
222 }
223 }
224
225 PARSE(block, TYPED(constant, constant)) {
226 P->consts = add_constant(P->consts, constant);
227 }
228
229 PARSE(block, TYPED(decl_struct, strct)) {
230 P->structs = add_decl_struct(P->structs, strct);
231 }
232
233 PARSE(block, TYPED(decl_union, u)) {
234 P->unions = add_decl_union(P->unions, u);
235 }
236
237 PARSE(block, TYPED(decl_enum, e)) {
238 P->enums = add_decl_enum(P->enums, e);
239 }
240
241 PARSE_NAMED(optional_name, n, ) {
242 n = NULL;
243 }
244
245 PARSE_NAMED(optional_name, n,
246 NAMED(NAME, N)) {
247 n = N;
248 }
249
250 PARSE_NAMED(enum_name, n,
251 NAMED(ENUM, E) NAMED(optional_name, N)) {
252 if (N) {
253 n = N;
254 free(E);
255 } else {
256 char digest[17];
257
258 psi_token_hash(E, digest);
259 n = psi_token_translit(psi_token_append(E, 1, digest), " ", "@");
260 }
261 }
262
263 PARSE_TYPED(decl_enum, e,
264 NAMED(enum_name, N)
265 TOKEN(LBRACE)
266 TYPED(decl_enum_items, list)
267 TOKEN(RBRACE)) {
268 e = init_decl_enum(N->text, list);
269 e->token = N;
270 }
271
272 PARSE_TYPED(decl_enum_items, l,
273 TYPED(decl_enum_item, i)) {
274 l = init_decl_enum_items(i);
275 }
276 PARSE_TYPED(decl_enum_items, l,
277 TYPED(decl_enum_items, l_)
278 TOKEN(COMMA)
279 TYPED(decl_enum_item, i)) {
280 l = add_decl_enum_item(l_, i);
281 }
282
283 PARSE_TYPED(decl_enum_item, i,
284 NAMED(NAME, N)
285 TOKEN(EQUALS)
286 TYPED(num_exp, num)) {
287 i = init_decl_enum_item(N->text, num);
288 i->token = N;
289 }
290 PARSE_TYPED(decl_enum_item, i,
291 NAMED(NAME, N)) {
292 i = init_decl_enum_item(N->text, NULL);
293 i->token = N;
294 }
295
296 PARSE_NAMED(union_name, n,
297 NAMED(UNION, U)
298 NAMED(optional_name, N)) {
299 if (N) {
300 n = N;
301 free(U);
302 } else {
303 char digest[17];
304
305 psi_token_hash(U, digest);
306 n = psi_token_translit(psi_token_append(U, 1, digest), " ", "@");
307 }
308 }
309
310 PARSE_NAMED(struct_name, n,
311 NAMED(STRUCT, S)
312 NAMED(optional_name, N)) {
313 if (N) {
314 n = N;
315 free(S);
316 } else {
317 char digest[17];
318
319 psi_token_hash(S, digest);
320 n = psi_token_translit(psi_token_append(S, 1, digest), " ", "@");
321 }
322 }
323
324 PARSE_TYPED(decl_struct_args_block, args_,
325 TOKEN(LBRACE)
326 TYPED(struct_args, args)
327 TOKEN(RBRACE)) {
328 args_ = args;
329 }
330
331 PARSE_TYPED(decl_struct_args, args_,
332 TYPED(decl_struct_args_block, args)) {
333 args_ = args;
334 }
335 PARSE_TYPED(decl_struct_args, args_,
336 TOKEN(EOS)) {
337 args_ = init_decl_args(NULL);
338 }
339
340 PARSE_TYPED(decl_struct, strct,
341 TOKEN(STRUCT)
342 NAMED(NAME, N)
343 TYPED(align_and_size, as)
344 TYPED(decl_struct_args, args)) {
345 strct = init_decl_struct(N->text, args);
346 strct->align = as.pos;
347 strct->size = as.len;
348 strct->token = N;
349 }
350
351 PARSE_TYPED(align_and_size, as, ) {
352 as.pos = 0;
353 as.len = 0;
354 }
355 PARSE_TYPED(align_and_size, as,
356 TOKEN(COLON)
357 TOKEN(COLON)
358 TOKEN(LPAREN)
359 NAMED(NUMBER, A)
360 TOKEN(COMMA)
361 NAMED(NUMBER, S)
362 TOKEN(RPAREN)) {
363 as.pos = atol(A->text);
364 as.len = atol(S->text);
365 free(A);
366 free(S);
367 }
368
369 PARSE_TYPED(decl_union, u,
370 TOKEN(UNION)
371 NAMED(NAME, N)
372 TYPED(align_and_size, as)
373 TYPED(decl_struct_args, args)) {
374 u = init_decl_union(N->text, args);
375 u->align = as.pos;
376 u->size = as.len;
377 u->token = N;
378 }
379
380 PARSE_TYPED(const_type, type_,
381 NAMED(const_type_token, T)) {
382 type_ = init_const_type(T->type, T->text);
383 free(T);
384 }
385
386 PARSE_TYPED(constant, constant,
387 TOKEN(CONST)
388 TYPED(const_type, type)
389 NAMED(NSNAME, T)
390 TOKEN(EQUALS)
391 TYPED(impl_def_val, val)
392 TOKEN(EOS)) {
393 constant = init_constant(type, T->text, val);
394 free(T);
395 }
396
397 PARSE_TYPED(decl_typedef, def,
398 NAMED(TYPEDEF, T)
399 TYPED(decl_typedef_body, def_)
400 TOKEN(EOS)) {
401 def = def_;
402 def->token = T;
403 }
404
405 PARSE_TYPED(decl_typedef_body_ex, def,
406 NAMED(struct_name, N)
407 TYPED(align_and_size, as)
408 TYPED(decl_struct_args_block, args)
409 TYPED(decl_var, var)) {
410 def = init_decl_arg(init_decl_type(PSI_T_STRUCT, N->text), var);
411 def->type->token = psi_token_copy(N);
412 def->type->real.strct = init_decl_struct(N->text, args);
413 def->type->real.strct->token = N;
414 def->type->real.strct->align = as.pos;
415 def->type->real.strct->size = as.len;
416 }
417 PARSE_TYPED(decl_typedef_body_ex, def,
418 NAMED(union_name, N)
419 TYPED(align_and_size, as)
420 TYPED(decl_struct_args_block, args)
421 TYPED(decl_var, var)) {
422 def = init_decl_arg(init_decl_type(PSI_T_UNION, N->text), var);
423 def->type->token = psi_token_copy(N);
424 def->type->real.unn = init_decl_union(N->text, args);
425 def->type->real.unn->token = N;
426 def->type->real.unn->align = as.pos;
427 def->type->real.unn->size = as.len;
428 }
429 PARSE_TYPED(decl_typedef_body_ex, def,
430 TYPED(decl_enum, e)
431 NAMED(NAME, ALIAS)) {
432 def = init_decl_arg(init_decl_type(PSI_T_ENUM, e->name), init_decl_var(ALIAS->text, 0, 0));
433 def->var->token = ALIAS;
434 def->type->token = psi_token_copy(e->token);
435 def->type->real.enm = e;
436 }
437
438 PARSE_TYPED(decl_typedef_body, def,
439 TYPED(decl_typedef_body_ex, def_)) {
440 def = def_;
441 }
442
443 PARSE_TYPED(decl_typedef_body_fn_args, args,
444 TOKEN(LPAREN)
445 TYPED(decl_args, args_)
446 TOKEN(RPAREN)) {
447 args = args_;
448 }
449 PARSE_TYPED(decl_typedef_body, def,
450 TYPED(decl_func, func_)
451 TYPED(decl_typedef_body_fn_args, args)) {
452 def = init_decl_arg(init_decl_type(PSI_T_FUNCTION, func_->var->name), copy_decl_var(func_->var));
453 def->type->token = psi_token_copy(func_->token);
454 def->type->real.func = init_decl(init_decl_abi("default"), func_, args);
455 }
456 PARSE_TYPED(decl_typedef_body, def,
457 TYPED(decl_arg, arg)) {
458 def = arg;
459 }
460
461 PARSE_TYPED(decl, decl,
462 TYPED(decl_abi, abi)
463 TYPED(decl_func, func)
464 TOKEN(LPAREN)
465 TYPED(decl_args, args)
466 TOKEN(RPAREN)
467 TOKEN(EOS)) {
468 decl = init_decl(abi, func, args);
469 }
470
471 PARSE_TYPED(decl_func, func,
472 TYPED(decl_arg, arg)) {
473 func = arg;
474 }
475 /* special case for void functions */
476 PARSE_TYPED(decl_func, func,
477 NAMED(VOID, T)
478 NAMED(NAME, N)) {
479 func = init_decl_arg(
480 init_decl_type(T->type, T->text),
481 init_decl_var(N->text, 0, 0)
482 );
483 func->type->token = T;
484 func->var->token = N;
485 func->token = N;
486 }
487 PARSE_TYPED(decl_typedef_body, def,
488 NAMED(VOID, T)
489 TYPED(indirection, decl_i)
490 TOKEN(LPAREN)
491 TYPED(indirection, type_i)
492 NAMED(NAME, N)
493 TOKEN(RPAREN)
494 TYPED(decl_typedef_body_fn_args, args)) {
495 decl_arg *func_ = init_decl_arg(
496 init_decl_type(T->type, T->text),
497 init_decl_var(N->text, decl_i, 0)
498 );
499 func_->type->token = T;
500 func_->var->token = N;
501 func_->token = N;
502
503 def = init_decl_arg(
504 init_decl_type(PSI_T_FUNCTION, func_->var->name),
505 copy_decl_var(func_->var)
506 );
507 def->var->pointer_level = type_i;
508 def->type->token = psi_token_copy(func_->token);
509 def->type->real.func = init_decl(init_decl_abi("default"), func_, args);
510 }
511 PARSE_TYPED(decl_typedef_body, def,
512 TOKEN(CONST)
513 NAMED(VOID, T)
514 TYPED(pointers, decl_i)
515 TOKEN(LPAREN)
516 TYPED(indirection, type_i)
517 NAMED(NAME, N)
518 TOKEN(RPAREN)
519 TYPED(decl_typedef_body_fn_args, args)) {
520 decl_arg *func_ = init_decl_arg(
521 init_decl_type(T->type, T->text),
522 init_decl_var(N->text, decl_i, 0)
523 );
524 func_->type->token = T;
525 func_->var->token = N;
526 func_->token = N;
527
528 def = init_decl_arg(
529 init_decl_type(PSI_T_FUNCTION, func_->var->name),
530 copy_decl_var(func_->var)
531 );
532 def->var->pointer_level = type_i;
533 def->type->token = psi_token_copy(func_->token);
534 def->type->real.func = init_decl(init_decl_abi("default"), func_, args);
535 }
536
537 PARSE_TYPED(decl_abi, abi,
538 NAMED(NAME, T)) {
539 abi = init_decl_abi(T->text);
540 abi->token = T;
541 }
542
543 PARSE_TYPED(decl_var, var,
544 NAMED(NAME, T)
545 NAMED(decl_var_array_size, as)) {
546 var = init_decl_var(T->text, 0, as?atol(as->text):0);
547 var->token = T;
548 if (as) {
549 free(as);
550 }
551 }
552 PARSE_TYPED(decl_var, var,
553 TYPED(pointers, p)
554 NAMED(NAME, T)
555 NAMED(decl_var_array_size, as)) {
556 var = init_decl_var(T->text, p+!!as, as?atol(as->text):0);
557 var->token = T;
558 if (as) {
559 free(as);
560 }
561 }
562 PARSE_NAMED(decl_var_array_size, as, ) {
563 as = NULL;
564 }
565 PARSE_NAMED(decl_var_array_size, as,
566 TOKEN(LBRACKET)
567 NAMED(NUMBER, D)
568 TOKEN(RBRACKET)) {
569 as = D;
570 }
571
572 PARSE_TYPED(decl_vars, vars,
573 TYPED(decl_var, var)) {
574 vars = init_decl_vars(var);
575 }
576 PARSE_TYPED(decl_vars, vars,
577 TYPED(decl_vars, vars_)
578 TOKEN(COMMA)
579 TYPED(decl_var, var)) {
580 vars = add_decl_var(vars_, var);
581 }
582
583 PARSE_TYPED(decl_arg, arg_,
584 TYPED(const_decl_type, type)
585 TYPED(decl_var, var)) {
586 arg_ = init_decl_arg(type, var);
587 }
588 PARSE_TYPED(decl_typedef_body, def,
589 TYPED(const_decl_type, type_)
590 TYPED(indirection, decl_i)
591 TOKEN(LPAREN)
592 TYPED(indirection, type_i)
593 NAMED(NAME, N)
594 TOKEN(RPAREN)
595 TYPED(decl_typedef_body_fn_args, args)) {
596 decl_arg *func_ = init_decl_arg(
597 type_,
598 init_decl_var(N->text, decl_i, 0)
599 );
600 func_->var->token = N;
601 func_->token = N;
602
603 def = init_decl_arg(
604 init_decl_type(PSI_T_FUNCTION, func_->var->name),
605 copy_decl_var(func_->var)
606 );
607 def->var->pointer_level = type_i;
608 def->type->token = psi_token_copy(func_->token);
609 def->type->real.func = init_decl(init_decl_abi("default"), func_, args);
610 }
611
612 /* void pointers need a specific rule */
613 PARSE_TYPED(decl_arg, arg_,
614 NAMED(VOID, T)
615 TYPED(pointers, p)
616 NAMED(NAME, N)) {
617 arg_ = init_decl_arg(
618 init_decl_type(T->type, T->text),
619 init_decl_var(N->text, p, 0)
620 );
621 arg_->type->token = T;
622 arg_->var->token = N;
623 arg_->token = N;
624 }
625 PARSE_TYPED(decl_arg, arg_,
626 TOKEN(CONST)
627 NAMED(VOID, T)
628 TYPED(pointers, p)
629 NAMED(NAME, N)) {
630 arg_ = init_decl_arg(
631 init_decl_type(T->type, T->text),
632 init_decl_var(N->text, p, 0)
633 );
634 arg_->type->token = T;
635 arg_->var->token = N;
636 arg_->token = N;
637 }
638
639 PASS(decl_args, )
640 PASS(decl_args, VOID)
641 PARSE_TYPED(decl_args, args,
642 TYPED(decl_arg, arg)) {
643 args = init_decl_args(arg);
644 }
645 PARSE_TYPED(decl_args, args,
646 TYPED(decl_args, args_)
647 TOKEN(COMMA)
648 TYPED(decl_arg, arg)) {
649 args = add_decl_arg(args_, arg);
650 }
651 PARSE_TYPED(decl_args, args,
652 TYPED(decl_args, args_)
653 TOKEN(COMMA)
654 TOKEN(ELLIPSIS)) {
655 args = args_;
656 args->varargs = 1;
657 }
658
659 PARSE_TYPED(struct_args, args,
660 TYPED(struct_arg, arg)) {
661 args = init_decl_args(arg);
662 }
663 PARSE_TYPED(struct_args, args,
664 TYPED(struct_args, args_)
665 TYPED(struct_arg, arg)) {
666 args = add_decl_arg(args_, arg);
667 }
668
669 PARSE_TYPED(struct_arg, arg_,
670 TYPED(decl_typedef_body_ex, def)
671 TOKEN(EOS)) {
672 arg_ = def;
673 switch (def->type->type) {
674 case PSI_T_STRUCT:
675 if (def->type->real.strct) {
676 P->structs = add_decl_struct(P->structs, def->type->real.strct);
677 }
678 break;
679 case PSI_T_UNION:
680 if (def->type->real.unn) {
681 P->unions = add_decl_union(P->unions, def->type->real.unn);
682 }
683 break;
684 case PSI_T_ENUM:
685 if (def->type->real.enm) {
686 P->enums = add_decl_enum(P->enums, def->type->real.enm);
687 }
688 break;
689 }
690 }
691 PARSE_TYPED(struct_arg, arg,
692 TYPED(decl_arg, arg_)
693 TYPED(struct_layout, layout_)
694 TOKEN(EOS)) {
695 arg_->layout = layout_;
696 arg = arg_;
697 }
698
699 PARSE_TYPED(struct_layout, layout, ) {
700 layout = NULL;
701 }
702 PARSE_TYPED(struct_layout, layout,
703 TOKEN(COLON)
704 TOKEN(COLON)
705 TOKEN(LPAREN)
706 NAMED(NUMBER, POS)
707 TOKEN(COMMA)
708 NAMED(NUMBER, SIZ)
709 TOKEN(RPAREN)) {
710 layout = init_decl_struct_layout(atol(POS->text), atol(SIZ->text));
711 free(POS);
712 free(SIZ);
713 }
714
715 /* un/signed, urgh */
716 PARSE_NAMED(decl_scalar_type, type_,
717 NAMED(CHAR, C)) {
718 type_ = C;
719 }
720 PARSE_NAMED(decl_scalar_type, type_,
721 NAMED(SHORT, S)
722 NAMED(decl_scalar_type_short, s)) {
723 if (s) {
724 type_ = psi_token_cat(2, S, s);
725 free(S);
726 free(s);
727 } else {
728 type_ = S;
729 }
730 }
731 PARSE_NAMED(decl_scalar_type_short, s, ) {
732 s = NULL;
733 }
734
735 PARSE_NAMED(decl_scalar_type_short, s,
736 NAMED(INT, I)) {
737 s = I;
738 }
739 PARSE_NAMED(decl_scalar_type, type_,
740 NAMED(INT, I)) {
741 type_ = I;
742 }
743 PARSE_NAMED(decl_scalar_type, type_,
744 NAMED(LONG, L)
745 NAMED(decl_scalar_type_long, l)) {
746 if (l) {
747 type_ = psi_token_cat(2, L, l);
748 free(L);
749 free(l);
750 } else {
751 type_ = L;
752 }
753 }
754 PARSE_NAMED(decl_scalar_type_long, l, ) {
755 l = NULL;
756 }
757 PARSE_NAMED(decl_scalar_type_long, l,
758 NAMED(DOUBLE, D)) {
759 l = D;
760 }
761 PARSE_NAMED(decl_scalar_type_long, l,
762 NAMED(LONG, L)
763 NAMED(decl_scalar_type_long_long, ll)) {
764 if (ll) {
765 l = psi_token_cat(2, L, ll);
766 free(L);
767 free(ll);
768 } else {
769 l = L;
770 }
771 }
772 PARSE_NAMED(decl_scalar_type_long_long, ll, ) {
773 ll = NULL;
774 }
775 PARSE_NAMED(decl_scalar_type_long_long, ll,
776 NAMED(INT, I)) {
777 ll = I;
778 }
779 PARSE_TYPED(decl_type, type_,
780 NAMED(UNSIGNED, U)
781 NAMED(decl_scalar_type, N)) {
782 struct psi_token *T = psi_token_cat(2, U, N);
783 type_ = init_decl_type(T->type, T->text);
784 type_->token = T;
785 free(U);
786 free(N);
787 }
788 PARSE_TYPED(decl_type, type_,
789 NAMED(SIGNED, S)
790 NAMED(decl_scalar_type, N)) {
791 struct psi_token *T = psi_token_cat(2, S, N);
792 type_ = init_decl_type(T->type, T->text);
793 type_->token = T;
794 free(S);
795 free(N);
796 }
797 PARSE_TYPED(decl_type, type_,
798 NAMED(UNSIGNED, U)) {
799 type_ = init_decl_type(PSI_T_NAME, U->text);
800 type_->token = U;
801 }
802 PARSE_TYPED(decl_type, type_,
803 NAMED(SIGNED, S)) {
804 type_ = init_decl_type(PSI_T_NAME, S->text);
805 type_->token = S;
806 }
807 PARSE_TYPED(decl_type, type_,
808 NAMED(decl_scalar_type, N)) {
809 type_ = init_decl_type(N->type, N->text);
810 type_->token = N;
811 }
812 /* structs ! */
813 PARSE_TYPED(decl_type, type_,
814 NAMED(STRUCT, S)
815 NAMED(NAME, T)) {
816 type_ = init_decl_type(S->type, T->text);
817 type_->token = T;
818 free(S);
819 }
820 PARSE_TYPED(decl_type, type_,
821 NAMED(UNION, U)
822 NAMED(NAME, T)) {
823 type_ = init_decl_type(U->type, T->text);
824 type_->token = T;
825 free(U);
826 }
827 PARSE_TYPED(decl_type, type_,
828 NAMED(ENUM, E)
829 NAMED(NAME, T)) {
830 type_ = init_decl_type(E->type, T->text);
831 type_->token = T;
832 free(E);
833 }
834 PARSE_TYPED(decl_type, type_,
835 NAMED(decl_type_token, T)) {
836 type_ = init_decl_type(T->type, T->text);
837 type_->token = T;
838 }
839
840
841 PARSE_TYPED(const_decl_type, type,
842 TYPED(decl_type, type_)) {
843 type = type_;
844 }
845 PARSE_TYPED(const_decl_type, type,
846 TOKEN(CONST)
847 TYPED(decl_type, type_)) {
848 type = type_;
849 }
850
851 PARSE_TYPED(impl, impl,
852 TYPED(impl_func, func)
853 TOKEN(LBRACE)
854 TYPED(impl_stmts, stmts)
855 TOKEN(RBRACE)) {
856 impl = init_impl(func, stmts);
857 }
858
859 PARSE_TYPED(impl_func, func,
860 TOKEN(FUNCTION)
861 TYPED(reference, r)
862 NAMED(NSNAME, NAME)
863 TYPED(impl_args, args)
864 TOKEN(COLON)
865 TYPED(impl_type, type)) {
866 func = init_impl_func(NAME->text, args, type, r);
867 func->token = NAME;
868 }
869
870 PARSE_TYPED(impl_def_val, def,
871 NAMED(impl_def_val_token, T)) {
872 def = init_impl_def_val(T->type, T->text);
873 free(T);
874 }
875
876 PARSE_TYPED(impl_var, var,
877 TYPED(reference, r)
878 NAMED(DOLLAR_NAME, T)) {
879 var = init_impl_var(T->text, r);
880 var->token = T;
881 }
882
883 PARSE_TYPED(impl_arg, arg,
884 TYPED(impl_type, type)
885 TYPED(impl_var, var)) {
886 arg = init_impl_arg(type, var, NULL);
887 }
888 PARSE_TYPED(impl_arg, arg,
889 TYPED(impl_type, type)
890 TYPED(impl_var, var)
891 TOKEN(EQUALS)
892 TYPED(impl_def_val, def)) {
893 arg = init_impl_arg(type, var, def);
894 }
895
896 PARSE_TYPED(impl_args, args,
897 TOKEN(LPAREN)
898 TOKEN(RPAREN)) {
899 args = NULL;
900 }
901 PARSE_TYPED(impl_args, args,
902 TOKEN(LPAREN)
903 TYPED(impl_arg_list, args_)
904 TOKEN(RPAREN)) {
905 args = args_;
906 }
907 PARSE_TYPED(impl_args, args,
908 TOKEN(LPAREN)
909 TYPED(impl_arg_list, args_)
910 TOKEN(COMMA)
911 TYPED(impl_vararg, va)
912 TOKEN(RPAREN)) {
913 args = args_;
914 args->vararg.name = va;
915 }
916
917 PARSE_TYPED(impl_vararg, va,
918 TYPED(impl_type, type)
919 TYPED(reference, r)
920 TOKEN(ELLIPSIS)
921 NAMED(DOLLAR_NAME, T)) {
922 va = init_impl_arg(type, init_impl_var(T->text, r), NULL);
923 free(T);
924 }
925
926 PARSE_TYPED(impl_arg_list, args,
927 TYPED(impl_arg, arg)) {
928 args = init_impl_args(arg);
929 }
930 PARSE_TYPED(impl_arg_list, args,
931 TYPED(impl_arg_list, args_)
932 TOKEN(COMMA)
933 TYPED(impl_arg, arg)) {
934 args = add_impl_arg(args_, arg);
935 }
936
937 PARSE_TYPED(impl_stmts, stmts,
938 TYPED(impl_stmt, stmt)) {
939 stmts = init_impl_stmts(stmt);
940 }
941 PARSE_TYPED(impl_stmts, stmts,
942 TYPED(impl_stmts, stmts_)
943 TYPED(impl_stmt, stmt)) {
944 stmts = add_impl_stmt(stmts_, stmt);
945 }
946
947 PARSE_TYPED(impl_stmt, stmt,
948 TYPED(let_stmt, let)) {
949 stmt = init_impl_stmt(PSI_T_LET, let);
950 }
951 PARSE_TYPED(impl_stmt, stmt,
952 TYPED(set_stmt, set)) {
953 stmt = init_impl_stmt(PSI_T_SET, set);
954 }
955 PARSE_TYPED(impl_stmt, stmt,
956 TYPED(return_stmt, ret)) {
957 stmt = init_impl_stmt(PSI_T_RETURN, ret);
958 }
959 PARSE_TYPED(impl_stmt, stmt,
960 TYPED(free_stmt, free)) {
961 stmt = init_impl_stmt(PSI_T_FREE, free);
962 }
963
964 PARSE_TYPED(num_exp, exp,
965 NAMED(num_exp_token, tok)) {
966 exp = init_num_exp(tok->type, tok->text);
967 exp->token = tok;
968 }
969 PARSE_TYPED(num_exp, exp,
970 TYPED(decl_var, var)) {
971 exp = init_num_exp(PSI_T_NAME, var);
972 exp->token = psi_token_copy(var->token);
973 }
974 PARSE_TYPED(num_exp, exp,
975 TYPED(num_exp, exp_)
976 NAMED(num_exp_op_token, operator_)
977 TYPED(num_exp, operand_)) {
978 exp_->operator = operator_->type;
979 exp_->operand = operand_;
980 exp = exp_;
981 free(operator_);
982 }
983
984 TOKEN_TYPE(let_exp, let_val*)
985 TOKEN_DTOR(let_exp, free_let_val($$);)
986
987 TOKEN_TYPE(let_callback, let_callback*)
988 TOKEN_DTOR(let_callback, free_let_callback($$);)
989
990 /*
991 * let_val: NULL
992 */
993 PARSE_TYPED(let_val, val,
994 TOKEN(NULL)) {
995 val = init_let_val(PSI_LET_NULL, NULL);
996 }
997 /*
998 * let_val: &NULL
999 */
1000 PARSE_TYPED(let_val, val,
1001 TOKEN(AMPERSAND)
1002 TOKEN(NULL)) {
1003 val = init_let_val(PSI_LET_NULL, NULL);
1004 val->is_reference = 1;
1005 }
1006 /*
1007 * let_val: callback
1008 */
1009 PARSE_TYPED(let_val, val,
1010 TYPED(let_callback, cb)) {
1011 val = init_let_val(PSI_LET_CALLBACK, cb);
1012 }
1013 /*
1014 * let_val: calloc
1015 */
1016 PARSE_TYPED(let_val, val,
1017 TYPED(let_calloc, ca)) {
1018 val = init_let_val(PSI_LET_CALLOC, ca);
1019 }
1020 /*
1021 * let_val: &calloc
1022 */
1023 PARSE_TYPED(let_val, val,
1024 TOKEN(AMPERSAND)
1025 TYPED(let_calloc, ca)) {
1026 val = init_let_val(PSI_LET_CALLOC, ca);
1027 val->is_reference = 1;
1028 }
1029 /*
1030 * let_val: func
1031 */
1032 PARSE_TYPED(let_val, val,
1033 TYPED(let_func, fn)) {
1034 val = init_let_val_ex(NULL, PSI_LET_FUNC, fn);
1035 }
1036 /*
1037 * let_val: &func
1038 */
1039 PARSE_TYPED(let_val, val,
1040 TOKEN(AMPERSAND)
1041 TYPED(let_func, fn)) {
1042 val = init_let_val_ex(NULL, PSI_LET_FUNC, fn);
1043 val->is_reference = 1;
1044 }
1045 /*
1046 * let_val: 1234
1047 */
1048 PARSE_TYPED(let_val, val,
1049 TYPED(num_exp, exp)) {
1050 val = init_let_val_ex(NULL, PSI_LET_NUMEXP, exp);
1051 }
1052 /*
1053 * let_val: &1234
1054 */
1055 PARSE_TYPED(let_val, val,
1056 TOKEN(AMPERSAND)
1057 TYPED(num_exp, exp)) {
1058 val = init_let_val_ex(NULL, PSI_LET_NUMEXP, exp);
1059 val->is_reference = 1;
1060 }
1061
1062 /*
1063 * let_exp: var = val
1064 */
1065 PARSE_TYPED(let_exp, exp,
1066 TYPED(decl_var, var_)
1067 TOKEN(EQUALS)
1068 TYPED(let_val, val)) {
1069 exp = val;
1070 exp->var = var_;
1071 }
1072
1073 /*
1074 * let_stmt: LET exp ;
1075 */
1076 PARSE_TYPED(let_stmt, let,
1077 NAMED(LET, T)
1078 TYPED(let_exp, val)
1079 TOKEN(EOS)) {
1080 let = init_let_stmt(val);
1081 let->token = T;
1082 }
1083
1084 /*
1085 * let_stmt: TEMP foo = bar ;
1086 */
1087 PARSE_TYPED(let_stmt, let,
1088 NAMED(TEMP, T)
1089 TYPED(decl_var, var)
1090 TOKEN(EQUALS)
1091 TYPED(reference, r)
1092 TYPED(decl_var, val_)
1093 TOKEN(EOS)) {
1094 let = init_let_stmt(init_let_val_ex(var, PSI_LET_TMP, val_));
1095 let->token = T;
1096 let->val->is_reference = r ? 1 : 0;
1097 }
1098
1099 /*
1100 * let_callback: CALLBACK cast($var($args))
1101 */
1102 PARSE_TYPED(let_callback, cb,
1103 TOKEN(CALLBACK)
1104 NAMED(callback_rval, F)
1105 TOKEN(LPAREN)
1106 TYPED(impl_var, var)
1107 TOKEN(LPAREN)
1108 TYPED(callback_arg_list, args_)
1109 TOKEN(RPAREN)
1110 TOKEN(RPAREN)) {
1111 cb = init_let_callback(init_let_func(F->type, F->text, var), args_);
1112 free(F);
1113 }
1114
1115 /*
1116 * let_calloc: CALLOC ( num_exp nmemb , num_exp size )
1117 */
1118 PARSE_TYPED(let_calloc, alloc,
1119 TOKEN(CALLOC)
1120 TOKEN(LPAREN)
1121 TYPED(num_exp, nmemb)
1122 TOKEN(COMMA)
1123 TYPED(num_exp, size)
1124 TOKEN(RPAREN)) {
1125 alloc = init_let_calloc(nmemb, size);
1126 }
1127
1128 /*
1129 * let_func: FUNC ( $var )
1130 */
1131 PARSE_TYPED(let_func, func,
1132 NAMED(let_func_token, T)
1133 TOKEN(LPAREN)
1134 TYPED(impl_var, var)
1135 TOKEN(RPAREN)) {
1136 func = init_let_func(T->type, T->text, var);
1137 free(T);
1138 }
1139 /*
1140 * let_func: FUNC ( $var (,exps)? )
1141 */
1142 PARSE_TYPED(let_func, func,
1143 NAMED(let_func_token, T)
1144 TOKEN(LPAREN)
1145 TYPED(impl_var, var)
1146 TOKEN(COMMA)
1147 TYPED(let_vals, vals)
1148 TOKEN(RPAREN)) {
1149 func = init_let_func(T->type, T->text, var);
1150 func->inner = vals;
1151 free(T);
1152 }
1153 /*
1154 * let_vals: exps = exp
1155 */
1156 PARSE_TYPED(let_vals, vals,
1157 TYPED(let_exp, val)) {
1158 vals = init_let_vals(val);
1159 }
1160 PARSE_TYPED(let_vals, vals,
1161 TYPED(let_val, val)) {
1162 vals = init_let_vals(val);
1163 }
1164 /*
1165 * let_vals: exps = exps, exp
1166 */
1167 PARSE_TYPED(let_vals, vals,
1168 TYPED(let_vals, vals_)
1169 TOKEN(COMMA)
1170 TYPED(let_exp, val)) {
1171 vals = add_let_val(vals_, val);
1172 }
1173 PARSE_TYPED(let_vals, vals,
1174 TYPED(let_vals, vals_)
1175 TOKEN(COMMA)
1176 TYPED(let_val, val)) {
1177 vals = add_let_val(vals_, val);
1178 }
1179
1180 PASS(callback_arg_list, )
1181 PARSE_TYPED(callback_arg_list, args,
1182 TYPED(callback_args, args_)) {
1183 args = args_;
1184 }
1185
1186 PARSE_TYPED(callback_args, args,
1187 TYPED(set_value, val)) {
1188 args = init_set_values(val);
1189 }
1190 PARSE_TYPED(callback_args, args,
1191 TYPED(callback_args, args_)
1192 TOKEN(COMMA)
1193 TYPED(set_value, val)) {
1194 args = add_set_value(args_, val);
1195 }
1196 PARSE_NAMED(callback_rval, rval,
1197 NAMED(let_func_token, F)) {
1198 rval = F;
1199 }
1200 PARSE_NAMED(callback_rval, rval,
1201 NAMED(VOID, V)) {
1202 rval = V;
1203 }
1204
1205 PARSE_TYPED(set_stmt, set,
1206 TOKEN(SET)
1207 TYPED(impl_var, var)
1208 TOKEN(EQUALS)
1209 TYPED(set_value, val)
1210 TOKEN(EOS)) {
1211 set = init_set_stmt(var, val);
1212 }
1213
1214 PARSE_TYPED(set_value, val,
1215 TYPED(set_func, func)
1216 TOKEN(LPAREN)
1217 TYPED(decl_var, var)
1218 TOKEN(RPAREN)) {
1219 val = init_set_value(func, init_decl_vars(var));
1220 }
1221 PARSE_TYPED(set_value, val,
1222 TYPED(set_func, func)
1223 TOKEN(LPAREN)
1224 TYPED(decl_var, var)
1225 TOKEN(COMMA)
1226 TYPED(num_exp, num_)
1227 TOKEN(RPAREN)) {
1228 val = init_set_value(func, init_decl_vars(var));
1229 val->num = num_;
1230 }
1231 PARSE_TYPED(set_value, val,
1232 TYPED(set_func, func_)
1233 TOKEN(LPAREN)
1234 TYPED(decl_var, var)
1235 TOKEN(COMMA)
1236 NAMED(ELLIPSIS, T)
1237 TOKEN(RPAREN)) {
1238 free_set_func(func_);
1239 val = init_set_value(init_set_func(T->type, T->text), init_decl_vars(var));
1240 val->func->token = T;
1241 }
1242 PARSE_TYPED(set_value, val,
1243 TYPED(set_func, func_)
1244 TOKEN(LPAREN)
1245 TYPED(decl_var, var)
1246 TOKEN(COMMA)
1247 TYPED(set_vals, vals)
1248 TOKEN(RPAREN)) {
1249 val = vals;
1250 val->func = func_;
1251 val->vars = init_decl_vars(var);
1252 }
1253 PARSE_TYPED(set_value, val,
1254 TYPED(set_func, func_)
1255 TOKEN(LPAREN)
1256 TYPED(decl_var, var)
1257 TOKEN(COMMA)
1258 TYPED(num_exp, num_)
1259 TOKEN(COMMA)
1260 TYPED(set_vals, vals)
1261 TOKEN(RPAREN)) {
1262 val = vals;
1263 val->func = func_;
1264 val->num = num_;
1265 val->vars = init_decl_vars(var);
1266 }
1267
1268 PARSE_TYPED(set_vals, vals,
1269 TYPED(set_value, val)) {
1270 vals = add_inner_set_value(init_set_value(NULL, NULL), val);
1271 }
1272 PARSE_TYPED(set_vals, vals,
1273 TYPED(set_vals, vals_)
1274 TOKEN(COMMA)
1275 TYPED(set_value, val)) {
1276 vals = add_inner_set_value(vals_, val);
1277 }
1278
1279 PARSE_TYPED(set_func, func,
1280 NAMED(set_func_token, T)) {
1281 func = init_set_func(T->type, T->text);
1282 func->token = T;
1283 }
1284
1285 PARSE_TYPED(return_stmt, ret,
1286 NAMED(RETURN, T)
1287 TYPED(set_value, val)
1288 TOKEN(EOS)) {
1289 ret = init_return_stmt(val);
1290 ret->token = T;
1291 }
1292
1293 PARSE_TYPED(free_stmt, free,
1294 TOKEN(FREE)
1295 TYPED(free_calls, calls)
1296 TOKEN(EOS)) {
1297 free = init_free_stmt(calls);
1298 }
1299
1300 PARSE_TYPED(free_calls, calls,
1301 TYPED(free_call, call)) {
1302 calls = init_free_calls(call);
1303 }
1304 PARSE_TYPED(free_calls, calls,
1305 TYPED(free_calls, calls_)
1306 TOKEN(COMMA)
1307 TYPED(free_call, call)) {
1308 calls = add_free_call(calls_, call);
1309 }
1310
1311 PARSE_TYPED(free_call, call,
1312 NAMED(NAME, F)
1313 TOKEN(LPAREN)
1314 TYPED(decl_vars, vars)
1315 TOKEN(RPAREN)) {
1316 call = init_free_call(F->text, vars);
1317 call->token = F;
1318 }
1319
1320 PARSE_TYPED(impl_type, type_,
1321 NAMED(impl_type_token, T)) {
1322 type_ = init_impl_type(T->type, T->text);
1323 free(T);
1324 }
1325
1326 PARSE_TYPED(reference, r, ) {
1327 r = 0;
1328 }
1329 PARSE_TYPED(reference, r,
1330 TOKEN(AMPERSAND)) {
1331 r = 1;
1332 }
1333
1334 PARSE_TYPED(indirection, i, ){
1335 i = 0;
1336 }
1337 PARSE_TYPED(indirection, i,
1338 TYPED(pointers, p)) {
1339 i = p;
1340 }
1341
1342 PARSE_TYPED(pointers, p,
1343 TOKEN(ASTERISK)) {
1344 p = 1;
1345 }
1346 PARSE_TYPED(pointers, p,
1347 TYPED(pointers, p_)
1348 TOKEN(ASTERISK)) {
1349 p = p_+1;
1350 }