autoconf: split into subdirectories; redirect calls in debug builds
[m6w6/ext-psi] / src / parser_proc.y
1 %include {
2 #ifdef HAVE_CONFIG_H
3 # include "config.h"
4 #else
5 # include "php_config.h"
6 #endif
7
8 #include <stddef.h>
9 #include <assert.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdarg.h>
13
14 #include "parser.h"
15 }
16 %name psi_parser_proc_
17 %token_prefix PSI_T_
18 %token_type {struct psi_token *}
19 %token_destructor {free($$);}
20 %default_destructor {(void)P;}
21 %extra_argument {struct psi_parser *P}
22 %syntax_error { ++P->errors; if (TOKEN && TOKEN->type != PSI_T_EOF) { psi_error(PSI_WARNING, TOKEN->file, TOKEN->line, "PSI syntax error: Unexpected token '%s' at pos %u", TOKEN->text, TOKEN->col); } else { psi_error(PSI_WARNING, P->psi.file.fn, P->line, "PSI syntax error: Unexpected end of input"); } }
23 %nonassoc NAME.
24 %left PLUS MINUS.
25 %left SLASH ASTERISK.
26 %fallback NAME TEMP FREE SET LET RETURN CALLOC CALLBACK ZVAL LIB STRING.
27 %token_class const_type_token BOOL INT FLOAT STRING.
28 %token_class decl_type_token FLOAT DOUBLE INT8 UINT8 INT16 UINT16 INT32 UINT32 INT64 UINT64 NAME.
29 %token_class impl_def_val_token NULL NUMBER TRUE FALSE QUOTED_STRING.
30 %token_class num_exp_token NUMBER NSNAME.
31 %token_class num_exp_op_token PLUS MINUS ASTERISK SLASH.
32 %token_class let_func_token ZVAL OBJVAL ARRVAL PATHVAL STRLEN STRVAL FLOATVAL INTVAL BOOLVAL.
33 %token_class set_func_token TO_OBJECT TO_ARRAY TO_STRING TO_INT TO_FLOAT TO_BOOL ZVAL VOID.
34 %token_class impl_type_token VOID MIXED BOOL INT FLOAT STRING ARRAY OBJECT CALLABLE.
35 %type decl_enum {decl_enum *}
36 %destructor decl_enum {free_decl_enum($$);}
37 %type decl_enum_items {decl_enum_items*}
38 %destructor decl_enum_items {free_decl_enum_items($$);}
39 %type decl_enum_item {decl_enum_item*}
40 %destructor decl_enum_item {free_decl_enum_item($$);}
41 %type decl_struct_args_block {decl_args*}
42 %destructor decl_struct_args_block {free_decl_args($$);}
43 %type decl_struct_args {decl_args*}
44 %destructor decl_struct_args {free_decl_args($$);}
45 %type decl_struct {decl_struct*}
46 %destructor decl_struct {free_decl_struct($$);}
47 %type align_and_size {decl_struct_layout}
48 %type decl_union {decl_union*}
49 %destructor decl_union {free_decl_union($$);}
50 %type const_type {const_type*}
51 %destructor const_type {free_const_type($$);}
52 %type constant {constant*}
53 %destructor constant {free_constant($$);}
54 %type decl_typedef {decl_arg*}
55 %destructor decl_typedef {free_decl_arg($$);}
56 %type decl_typedef_body_ex {decl_arg*}
57 %destructor decl_typedef_body_ex {free_decl_arg($$);}
58 %type decl_typedef_body {decl_arg*}
59 %destructor decl_typedef_body {free_decl_arg($$);}
60 %type decl_typedef_body_fn_args {decl_args *}
61 %destructor decl_typedef_body_fn_args {free_decl_args($$);}
62 %type decl {decl*}
63 %destructor decl {free_decl($$);}
64 %type decl_func {decl_arg*}
65 %destructor decl_func {free_decl_arg($$);}
66 %type decl_abi {decl_abi*}
67 %destructor decl_abi {free_decl_abi($$);}
68 %type decl_var {decl_var*}
69 %destructor decl_var {free_decl_var($$);}
70 %type decl_vars {decl_vars*}
71 %destructor decl_vars {free_decl_vars($$);}
72 %type decl_arg {decl_arg*}
73 %destructor decl_arg {free_decl_arg($$);}
74 %type decl_args {decl_args*}
75 %destructor decl_args {free_decl_args($$);}
76 %type struct_args {decl_args*}
77 %destructor struct_args {free_decl_args($$);}
78 %type struct_arg {decl_arg*}
79 %destructor struct_arg {free_decl_arg($$);}
80 %type struct_layout {decl_struct_layout*}
81 %destructor struct_layout {free_decl_struct_layout($$);}
82 %type decl_type {decl_type*}
83 %destructor decl_type {free_decl_type($$);}
84 %type const_decl_type {decl_type*}
85 %destructor const_decl_type {free_decl_type($$);}
86 %type impl {impl*}
87 %destructor impl {free_impl($$);}
88 %type impl_func {impl_func*}
89 %destructor impl_func {free_impl_func($$);}
90 %type impl_def_val {impl_def_val*}
91 %destructor impl_def_val {free_impl_def_val($$);}
92 %type impl_var {impl_var*}
93 %destructor impl_var {free_impl_var($$);}
94 %type impl_arg {impl_arg*}
95 %destructor impl_arg {free_impl_arg($$);}
96 %type impl_args {impl_args*}
97 %destructor impl_args {free_impl_args($$);}
98 %type impl_vararg {impl_arg*}
99 %destructor impl_vararg {free_impl_arg($$);}
100 %type impl_arg_list {impl_args*}
101 %destructor impl_arg_list {free_impl_args($$);}
102 %type impl_stmts {impl_stmts*}
103 %destructor impl_stmts {free_impl_stmts($$);}
104 %type impl_stmt {impl_stmt*}
105 %destructor impl_stmt {free_impl_stmt($$);}
106 %type num_exp {num_exp*}
107 %destructor num_exp {free_num_exp($$);}
108 %type let_stmt {let_stmt*}
109 %destructor let_stmt {free_let_stmt($$);}
110 %type let_calloc {let_calloc*}
111 %destructor let_calloc {free_let_calloc($$);}
112 %type let_func {let_func*}
113 %destructor let_func {free_let_func($$);}
114 %type callback_arg_list {set_values *}
115 %destructor callback_arg_list {free_set_values($$);}
116 %type callback_args {set_values *}
117 %destructor callback_args {free_set_values($$);}
118 %type let_val {let_val*}
119 %destructor let_val {free_let_val($$);}
120 %type let_vals {let_vals*}
121 %destructor let_vals {free_let_vals($$);}
122 %type set_stmt {set_stmt*}
123 %destructor set_stmt {free_set_stmt($$);}
124 %type set_value {set_value*}
125 %destructor set_value {free_set_value($$);}
126 %type set_vals {set_value*}
127 %destructor set_vals {free_set_value($$);}
128 %type set_func {set_func*}
129 %destructor set_func {free_set_func($$);}
130 %type return_stmt {return_stmt*}
131 %destructor return_stmt {free_return_stmt($$);}
132 %type free_stmt {free_stmt*}
133 %destructor free_stmt {free_free_stmt($$);}
134 %type free_calls {free_calls*}
135 %destructor free_calls {free_free_calls($$);}
136 %type free_call {free_call*}
137 %destructor free_call {free_free_call($$);}
138 %type impl_type {impl_type*}
139 %destructor impl_type {free_impl_type($$);}
140 %type reference {char}
141 %type indirection {unsigned}
142 %type pointers {unsigned}
143 file ::= blocks.
144 blocks ::= block.
145 blocks ::= blocks block.
146 block ::= EOF.
147 block ::= EOS.
148 block ::= LIB(token) QUOTED_STRING(libname) EOS. {
149 if (P->psi.file.ln) {
150 P->error(P, token, PSI_WARNING, "Extra 'lib %s' statement has no effect", libname->text);
151 } else {
152 P->psi.file.ln = strndup(libname->text + 1, libname->size - 2);
153 }
154 free(libname);
155 free(token);
156 }
157 block ::= decl(decl). {
158 P->decls = add_decl(P->decls, decl);
159 }
160 block ::= impl(impl). {
161 P->impls = add_impl(P->impls, impl);
162 }
163 block ::= decl_typedef(def). {
164 P->defs = add_decl_typedef(P->defs, def);
165 switch (def->type->type) {
166 case PSI_T_STRUCT:
167 if (def->type->real.strct) {
168 P->structs = add_decl_struct(P->structs, def->type->real.strct);
169 }
170 break;
171 case PSI_T_UNION:
172 if (def->type->real.unn) {
173 P->unions = add_decl_union(P->unions, def->type->real.unn);
174 }
175 break;
176 case PSI_T_ENUM:
177 if (def->type->real.enm) {
178 P->enums = add_decl_enum(P->enums, def->type->real.enm);
179 }
180 break;
181 }
182 }
183 block ::= constant(constant). {
184 P->consts = add_constant(P->consts, constant);
185 }
186 block ::= decl_struct(strct). {
187 P->structs = add_decl_struct(P->structs, strct);
188 }
189 block ::= decl_union(u). {
190 P->unions = add_decl_union(P->unions, u);
191 }
192 block ::= decl_enum(e). {
193 P->enums = add_decl_enum(P->enums, e);
194 }
195 optional_name(n) ::= . {
196 n = NULL;
197 }
198 optional_name(n) ::= NAME(N). {
199 n = N;
200 }
201 enum_name(n) ::= ENUM(E) optional_name(N). {
202 if (N) {
203 n = N;
204 free(E);
205 } else {
206 char digest[17];
207 psi_token_hash(E, digest);
208 n = psi_token_translit(psi_token_append(E, 1, digest), " ", "@");
209 }
210 }
211 decl_enum(e) ::= enum_name(N) LBRACE decl_enum_items(list) RBRACE. {
212 e = init_decl_enum(N->text, list);
213 e->token = N;
214 }
215 decl_enum_items(l) ::= decl_enum_item(i). {
216 l = init_decl_enum_items(i);
217 }
218 decl_enum_items(l) ::= decl_enum_items(l_) COMMA decl_enum_item(i). {
219 l = add_decl_enum_item(l_, i);
220 }
221 decl_enum_item(i) ::= NAME(N) EQUALS num_exp(num). {
222 i = init_decl_enum_item(N->text, num);
223 i->token = N;
224 }
225 decl_enum_item(i) ::= NAME(N). {
226 i = init_decl_enum_item(N->text, NULL);
227 i->token = N;
228 }
229 union_name(n) ::= UNION(U) optional_name(N). {
230 if (N) {
231 n = N;
232 free(U);
233 } else {
234 char digest[17];
235 psi_token_hash(U, digest);
236 n = psi_token_translit(psi_token_append(U, 1, digest), " ", "@");
237 }
238 }
239 struct_name(n) ::= STRUCT(S) optional_name(N). {
240 if (N) {
241 n = N;
242 free(S);
243 } else {
244 char digest[17];
245 psi_token_hash(S, digest);
246 n = psi_token_translit(psi_token_append(S, 1, digest), " ", "@");
247 }
248 }
249 decl_struct_args_block(args_) ::= LBRACE struct_args(args) RBRACE. {
250 args_ = args;
251 }
252 decl_struct_args(args_) ::= decl_struct_args_block(args). {
253 args_ = args;
254 }
255 decl_struct_args(args_) ::= EOS. {
256 args_ = init_decl_args(NULL);
257 }
258 decl_struct(strct) ::= STRUCT NAME(N) align_and_size(as) decl_struct_args(args). {
259 strct = init_decl_struct(N->text, args);
260 strct->align = as.pos;
261 strct->size = as.len;
262 strct->token = N;
263 }
264 align_and_size(as) ::= . {
265 as.pos = 0;
266 as.len = 0;
267 }
268 align_and_size(as) ::= COLON COLON LPAREN NUMBER(A) COMMA NUMBER(S) RPAREN. {
269 as.pos = atol(A->text);
270 as.len = atol(S->text);
271 free(A);
272 free(S);
273 }
274 decl_union(u) ::= UNION NAME(N) align_and_size(as) decl_struct_args(args). {
275 u = init_decl_union(N->text, args);
276 u->align = as.pos;
277 u->size = as.len;
278 u->token = N;
279 }
280 const_type(type_) ::= const_type_token(T). {
281 type_ = init_const_type(T->type, T->text);
282 free(T);
283 }
284 constant(constant) ::= CONST const_type(type) NSNAME(T) EQUALS impl_def_val(val) EOS. {
285 constant = init_constant(type, T->text, val);
286 free(T);
287 }
288 decl_typedef(def) ::= TYPEDEF(T) decl_typedef_body(def_) EOS. {
289 def = def_;
290 def->token = T;
291 }
292 decl_typedef_body_ex(def) ::= struct_name(N) align_and_size(as) decl_struct_args_block(args) decl_var(var). {
293 def = init_decl_arg(init_decl_type(PSI_T_STRUCT, N->text), var);
294 def->type->token = psi_token_copy(N);
295 def->type->real.strct = init_decl_struct(N->text, args);
296 def->type->real.strct->token = N;
297 def->type->real.strct->align = as.pos;
298 def->type->real.strct->size = as.len;
299 }
300 decl_typedef_body_ex(def) ::= union_name(N) align_and_size(as) decl_struct_args_block(args) decl_var(var). {
301 def = init_decl_arg(init_decl_type(PSI_T_UNION, N->text), var);
302 def->type->token = psi_token_copy(N);
303 def->type->real.unn = init_decl_union(N->text, args);
304 def->type->real.unn->token = N;
305 def->type->real.unn->align = as.pos;
306 def->type->real.unn->size = as.len;
307 }
308 decl_typedef_body_ex(def) ::= decl_enum(e) NAME(ALIAS). {
309 def = init_decl_arg(init_decl_type(PSI_T_ENUM, e->name), init_decl_var(ALIAS->text, 0, 0));
310 def->var->token = ALIAS;
311 def->type->token = psi_token_copy(e->token);
312 def->type->real.enm = e;
313 }
314 decl_typedef_body(def) ::= decl_typedef_body_ex(def_). {
315 def = def_;
316 }
317 decl_typedef_body_fn_args(args) ::= LPAREN decl_args(args_) RPAREN. {
318 args = args_;
319 }
320 decl_typedef_body(def) ::= decl_func(func_) decl_typedef_body_fn_args(args). {
321 def = init_decl_arg(init_decl_type(PSI_T_FUNCTION, func_->var->name), copy_decl_var(func_->var));
322 def->type->token = psi_token_copy(func_->token);
323 def->type->real.func = init_decl(init_decl_abi("default"), func_, args);
324 }
325 decl_typedef_body(def) ::= decl_arg(arg). {
326 def = arg;
327 }
328 decl(decl) ::= decl_abi(abi) decl_func(func) LPAREN decl_args(args) RPAREN EOS. {
329 decl = init_decl(abi, func, args);
330 }
331 decl_func(func) ::= decl_arg(arg). {
332 func = arg;
333 }
334 decl_func(func) ::= VOID(T) NAME(N). {
335 func = init_decl_arg(
336 init_decl_type(T->type, T->text),
337 init_decl_var(N->text, 0, 0)
338 );
339 func->type->token = T;
340 func->var->token = N;
341 func->token = N;
342 }
343 decl_typedef_body(def) ::= VOID(T) indirection(decl_i) LPAREN indirection(type_i) NAME(N) RPAREN decl_typedef_body_fn_args(args). {
344 decl_arg *func_ = init_decl_arg(
345 init_decl_type(T->type, T->text),
346 init_decl_var(N->text, decl_i, 0)
347 );
348 func_->type->token = T;
349 func_->var->token = N;
350 func_->token = N;
351 def = init_decl_arg(
352 init_decl_type(PSI_T_FUNCTION, func_->var->name),
353 copy_decl_var(func_->var)
354 );
355 def->var->pointer_level = type_i;
356 def->type->token = psi_token_copy(func_->token);
357 def->type->real.func = init_decl(init_decl_abi("default"), func_, args);
358 }
359 decl_typedef_body(def) ::= CONST VOID(T) pointers(decl_i) LPAREN indirection(type_i) NAME(N) RPAREN decl_typedef_body_fn_args(args). {
360 decl_arg *func_ = init_decl_arg(
361 init_decl_type(T->type, T->text),
362 init_decl_var(N->text, decl_i, 0)
363 );
364 func_->type->token = T;
365 func_->var->token = N;
366 func_->token = N;
367 def = init_decl_arg(
368 init_decl_type(PSI_T_FUNCTION, func_->var->name),
369 copy_decl_var(func_->var)
370 );
371 def->var->pointer_level = type_i;
372 def->type->token = psi_token_copy(func_->token);
373 def->type->real.func = init_decl(init_decl_abi("default"), func_, args);
374 }
375 decl_abi(abi) ::= NAME(T). {
376 abi = init_decl_abi(T->text);
377 abi->token = T;
378 }
379 decl_var(var) ::= indirection(p) NAME(T). {
380 var = init_decl_var(T->text, p, 0);
381 var->token = T;
382 }
383 decl_var(var) ::= indirection(p) NAME(T) LBRACKET NUMBER(D) RBRACKET. {
384 var = init_decl_var(T->text, p+1, atol(D->text));
385 var->token = T;
386 free(D);
387 }
388 decl_vars(vars) ::= decl_var(var). {
389 vars = init_decl_vars(var);
390 }
391 decl_vars(vars) ::= decl_vars(vars_) COMMA decl_var(var). {
392 vars = add_decl_var(vars_, var);
393 }
394 decl_arg(arg_) ::= const_decl_type(type) decl_var(var). {
395 arg_ = init_decl_arg(type, var);
396 }
397 decl_typedef_body(def) ::= const_decl_type(type_) indirection(decl_i) LPAREN indirection(type_i) NAME(N) RPAREN decl_typedef_body_fn_args(args). {
398 decl_arg *func_ = init_decl_arg(
399 type_,
400 init_decl_var(N->text, decl_i, 0)
401 );
402 func_->var->token = N;
403 func_->token = N;
404 def = init_decl_arg(
405 init_decl_type(PSI_T_FUNCTION, func_->var->name),
406 copy_decl_var(func_->var)
407 );
408 def->var->pointer_level = type_i;
409 def->type->token = psi_token_copy(func_->token);
410 def->type->real.func = init_decl(init_decl_abi("default"), func_, args);
411 }
412 decl_arg(arg_) ::= VOID(T) pointers(p) NAME(N). {
413 arg_ = init_decl_arg(
414 init_decl_type(T->type, T->text),
415 init_decl_var(N->text, p, 0)
416 );
417 arg_->type->token = T;
418 arg_->var->token = N;
419 arg_->token = N;
420 }
421 decl_arg(arg_) ::= CONST VOID(T) pointers(p) NAME(N). {
422 arg_ = init_decl_arg(
423 init_decl_type(T->type, T->text),
424 init_decl_var(N->text, p, 0)
425 );
426 arg_->type->token = T;
427 arg_->var->token = N;
428 arg_->token = N;
429 }
430 decl_args ::= .
431 decl_args ::= VOID.
432 decl_args(args) ::= decl_arg(arg). {
433 args = init_decl_args(arg);
434 }
435 decl_args(args) ::= decl_args(args_) COMMA decl_arg(arg). {
436 args = add_decl_arg(args_, arg);
437 }
438 decl_args(args) ::= decl_args(args_) COMMA ELLIPSIS. {
439 args = args_;
440 args->varargs = 1;
441 }
442 struct_args(args) ::= struct_arg(arg). {
443 args = init_decl_args(arg);
444 }
445 struct_args(args) ::= struct_args(args_) struct_arg(arg). {
446 args = add_decl_arg(args_, arg);
447 }
448 struct_arg(arg_) ::= decl_typedef_body_ex(def) EOS. {
449 arg_ = def;
450 switch (def->type->type) {
451 case PSI_T_STRUCT:
452 if (def->type->real.strct) {
453 P->structs = add_decl_struct(P->structs, def->type->real.strct);
454 }
455 break;
456 case PSI_T_UNION:
457 if (def->type->real.unn) {
458 P->unions = add_decl_union(P->unions, def->type->real.unn);
459 }
460 break;
461 case PSI_T_ENUM:
462 if (def->type->real.enm) {
463 P->enums = add_decl_enum(P->enums, def->type->real.enm);
464 }
465 break;
466 }
467 }
468 struct_arg(arg) ::= decl_arg(arg_) struct_layout(layout_) EOS. {
469 arg_->layout = layout_;
470 arg = arg_;
471 }
472 struct_layout(layout) ::= . {
473 layout = NULL;
474 }
475 struct_layout(layout) ::= COLON COLON LPAREN NUMBER(POS) COMMA NUMBER(SIZ) RPAREN. {
476 layout = init_decl_struct_layout(atol(POS->text), atol(SIZ->text));
477 free(POS);
478 free(SIZ);
479 }
480 decl_scalar_type(type_) ::= CHAR(C). {
481 type_ = C;
482 }
483 decl_scalar_type(type_) ::= SHORT(S) decl_scalar_type_short(s). {
484 if (s) {
485 type_ = psi_token_cat(2, S, s);
486 free(S);
487 free(s);
488 } else {
489 type_ = S;
490 }
491 }
492 decl_scalar_type_short(s) ::= . {
493 s = NULL;
494 }
495 decl_scalar_type_short(s) ::= INT(I). {
496 s = I;
497 }
498 decl_scalar_type(type_) ::= INT(I). {
499 type_ = I;
500 }
501 decl_scalar_type(type_) ::= LONG(L) decl_scalar_type_long(l). {
502 if (l) {
503 type_ = psi_token_cat(2, L, l);
504 free(L);
505 free(l);
506 } else {
507 type_ = L;
508 }
509 }
510 decl_scalar_type_long(l) ::= . {
511 l = NULL;
512 }
513 decl_scalar_type_long(l) ::= DOUBLE(D). {
514 l = D;
515 }
516 decl_scalar_type_long(l) ::= LONG(L) decl_scalar_type_long_long(ll). {
517 if (ll) {
518 l = psi_token_cat(2, L, ll);
519 free(L);
520 free(ll);
521 } else {
522 l = L;
523 }
524 }
525 decl_scalar_type_long_long(ll) ::= . {
526 ll = NULL;
527 }
528 decl_scalar_type_long_long(ll) ::= INT(I). {
529 ll = I;
530 }
531 decl_type(type_) ::= UNSIGNED(U) decl_scalar_type(N). {
532 struct psi_token *T = psi_token_cat(2, U, N);
533 type_ = init_decl_type(T->type, T->text);
534 type_->token = T;
535 free(U);
536 free(N);
537 }
538 decl_type(type_) ::= SIGNED(S) decl_scalar_type(N). {
539 struct psi_token *T = psi_token_cat(2, S, N);
540 type_ = init_decl_type(T->type, T->text);
541 type_->token = T;
542 free(S);
543 free(N);
544 }
545 decl_type(type_) ::= UNSIGNED(U). {
546 type_ = init_decl_type(PSI_T_NAME, U->text);
547 type_->token = U;
548 }
549 decl_type(type_) ::= SIGNED(S). {
550 type_ = init_decl_type(PSI_T_NAME, S->text);
551 type_->token = S;
552 }
553 decl_type(type_) ::= decl_scalar_type(N). {
554 type_ = init_decl_type(N->type, N->text);
555 type_->token = N;
556 }
557 decl_type(type_) ::= STRUCT(S) NAME(T). {
558 type_ = init_decl_type(S->type, T->text);
559 type_->token = T;
560 free(S);
561 }
562 decl_type(type_) ::= UNION(U) NAME(T). {
563 type_ = init_decl_type(U->type, T->text);
564 type_->token = T;
565 free(U);
566 }
567 decl_type(type_) ::= ENUM(E) NAME(T). {
568 type_ = init_decl_type(E->type, T->text);
569 type_->token = T;
570 free(E);
571 }
572 decl_type(type_) ::= decl_type_token(T). {
573 type_ = init_decl_type(T->type, T->text);
574 type_->token = T;
575 }
576 const_decl_type(type) ::= decl_type(type_). {
577 type = type_;
578 }
579 const_decl_type(type) ::= CONST decl_type(type_). {
580 type = type_;
581 }
582 impl(impl) ::= impl_func(func) LBRACE impl_stmts(stmts) RBRACE. {
583 impl = init_impl(func, stmts);
584 }
585 impl_func(func) ::= FUNCTION reference(r) NSNAME(NAME) impl_args(args) COLON impl_type(type). {
586 func = init_impl_func(NAME->text, args, type, r);
587 func->token = NAME;
588 }
589 impl_def_val(def) ::= impl_def_val_token(T). {
590 def = init_impl_def_val(T->type, T->text);
591 free(T);
592 }
593 impl_var(var) ::= reference(r) DOLLAR_NAME(T). {
594 var = init_impl_var(T->text, r);
595 var->token = T;
596 }
597 impl_arg(arg) ::= impl_type(type) impl_var(var). {
598 arg = init_impl_arg(type, var, NULL);
599 }
600 impl_arg(arg) ::= impl_type(type) impl_var(var) EQUALS impl_def_val(def). {
601 arg = init_impl_arg(type, var, def);
602 }
603 impl_args(args) ::= LPAREN RPAREN. {
604 args = NULL;
605 }
606 impl_args(args) ::= LPAREN impl_arg_list(args_) RPAREN. {
607 args = args_;
608 }
609 impl_args(args) ::= LPAREN impl_arg_list(args_) COMMA impl_vararg(va) RPAREN. {
610 args = args_;
611 args->vararg.name = va;
612 }
613 impl_vararg(va) ::= impl_type(type) reference(r) ELLIPSIS DOLLAR_NAME(T). {
614 va = init_impl_arg(type, init_impl_var(T->text, r), NULL);
615 free(T);
616 }
617 impl_arg_list(args) ::= impl_arg(arg). {
618 args = init_impl_args(arg);
619 }
620 impl_arg_list(args) ::= impl_arg_list(args_) COMMA impl_arg(arg). {
621 args = add_impl_arg(args_, arg);
622 }
623 impl_stmts(stmts) ::= impl_stmt(stmt). {
624 stmts = init_impl_stmts(stmt);
625 }
626 impl_stmts(stmts) ::= impl_stmts(stmts_) impl_stmt(stmt). {
627 stmts = add_impl_stmt(stmts_, stmt);
628 }
629 impl_stmt(stmt) ::= let_stmt(let). {
630 stmt = init_impl_stmt(PSI_T_LET, let);
631 }
632 impl_stmt(stmt) ::= set_stmt(set). {
633 stmt = init_impl_stmt(PSI_T_SET, set);
634 }
635 impl_stmt(stmt) ::= return_stmt(ret). {
636 stmt = init_impl_stmt(PSI_T_RETURN, ret);
637 }
638 impl_stmt(stmt) ::= free_stmt(free). {
639 stmt = init_impl_stmt(PSI_T_FREE, free);
640 }
641 num_exp(exp) ::= num_exp_token(tok). {
642 exp = init_num_exp(tok->type, tok->text);
643 exp->token = tok;
644 }
645 num_exp(exp) ::= decl_var(var). {
646 exp = init_num_exp(PSI_T_NAME, var);
647 exp->token = psi_token_copy(var->token);
648 }
649 num_exp(exp) ::= num_exp(exp_) num_exp_op_token(operator_) num_exp(operand_). {
650 exp_->operator = operator_->type;
651 exp_->operand = operand_;
652 exp = exp_;
653 free(operator_);
654 }
655 let_stmt(let) ::= LET decl_var(var) EOS. {
656 let = init_let_stmt(var, init_let_val(PSI_LET_NULL, NULL));
657 }
658 let_stmt(let) ::= LET decl_var(var) EQUALS reference(r) let_val(val) EOS. {
659 val->flags.one.is_reference = r ? 1 : 0;
660 let = init_let_stmt(var, val);
661 }
662 let_stmt(let) ::= TEMP decl_var(var) EQUALS decl_var(val) EOS. {
663 let = init_let_stmt(var, init_let_val(PSI_LET_TMP, val));
664 }
665 let_calloc(alloc) ::= num_exp(nmemb) COMMA num_exp(size). {
666 alloc = init_let_calloc(nmemb, size);
667 }
668 let_func(func) ::= let_func_token(T) LPAREN impl_var(var) RPAREN. {
669 func = init_let_func(T->type, T->text, var);
670 free(T);
671 }
672 let_vals(vals) ::= let_val(val). {
673 vals = init_let_vals(val);
674 }
675 let_vals(vals) ::= let_vals(vals_) COMMA let_val(val). {
676 vals = add_let_val(vals_, val);
677 }
678 let_func(func) ::= let_func_token(T) LPAREN impl_var(var) COMMA let_vals(vals) RPAREN. {
679 func = init_let_func(T->type, T->text, var);
680 func->inner = vals;
681 free(T);
682 }
683 callback_arg_list ::= .
684 callback_arg_list(args) ::= callback_args(args_). {
685 args = args_;
686 }
687 callback_args(args) ::= set_value(val). {
688 args = init_set_values(val);
689 }
690 callback_args(args) ::= callback_args(args_) COMMA set_value(val). {
691 args = add_set_value(args_, val);
692 }
693 callback_rval(rval) ::= let_func_token(F). {
694 rval = F;
695 }
696 callback_rval(rval) ::= VOID(V). {
697 rval = V;
698 }
699 let_val(val) ::= NULL. {
700 val = init_let_val(PSI_LET_NULL, NULL);
701 }
702 let_val(val) ::= num_exp(exp). {
703 val = init_let_val(PSI_LET_NUMEXP, exp);
704 }
705 let_val(val) ::= CALLOC LPAREN let_calloc(alloc) RPAREN. {
706 val = init_let_val(PSI_LET_CALLOC, alloc);
707 }
708 let_val(val) ::= let_func(func_). {
709 val = init_let_val(PSI_LET_FUNC, func_);
710 }
711 let_val(val) ::= CALLBACK callback_rval(F) LPAREN impl_var(var) LPAREN callback_arg_list(args_) RPAREN RPAREN. {
712 val = init_let_val(PSI_LET_CALLBACK, init_let_callback(
713 init_let_func(F->type, F->text, var), args_));
714 free(F);
715 }
716 set_stmt(set) ::= SET impl_var(var) EQUALS set_value(val) EOS. {
717 set = init_set_stmt(var, val);
718 }
719 set_value(val) ::= set_func(func) LPAREN decl_var(var) RPAREN. {
720 val = init_set_value(func, init_decl_vars(var));
721 }
722 set_value(val) ::= set_func(func) LPAREN decl_var(var) COMMA num_exp(num_) RPAREN. {
723 val = init_set_value(func, init_decl_vars(var));
724 val->num = num_;
725 }
726 set_value(val) ::= set_func(func_) LPAREN decl_var(var) COMMA ELLIPSIS(T) RPAREN. {
727 free_set_func(func_);
728 val = init_set_value(init_set_func(T->type, T->text), init_decl_vars(var));
729 val->func->token = T;
730 }
731 set_value(val) ::= set_func(func_) LPAREN decl_var(var) COMMA set_vals(vals) RPAREN. {
732 val = vals;
733 val->func = func_;
734 val->vars = init_decl_vars(var);
735 }
736 set_value(val) ::= set_func(func_) LPAREN decl_var(var) COMMA num_exp(num_) COMMA set_vals(vals) RPAREN. {
737 val = vals;
738 val->func = func_;
739 val->num = num_;
740 val->vars = init_decl_vars(var);
741 }
742 set_vals(vals) ::= set_value(val). {
743 vals = add_inner_set_value(init_set_value(NULL, NULL), val);
744 }
745 set_vals(vals) ::= set_vals(vals_) COMMA set_value(val). {
746 vals = add_inner_set_value(vals_, val);
747 }
748 set_func(func) ::= set_func_token(T). {
749 func = init_set_func(T->type, T->text);
750 func->token = T;
751 }
752 return_stmt(ret) ::= RETURN(T) set_value(val) EOS. {
753 ret = init_return_stmt(val);
754 ret->token = T;
755 }
756 free_stmt(free) ::= FREE free_calls(calls) EOS. {
757 free = init_free_stmt(calls);
758 }
759 free_calls(calls) ::= free_call(call). {
760 calls = init_free_calls(call);
761 }
762 free_calls(calls) ::= free_calls(calls_) COMMA free_call(call). {
763 calls = add_free_call(calls_, call);
764 }
765 free_call(call) ::= NAME(F) LPAREN decl_vars(vars) RPAREN. {
766 call = init_free_call(F->text, vars);
767 call->token = F;
768 }
769 impl_type(type_) ::= impl_type_token(T). {
770 type_ = init_impl_type(T->type, T->text);
771 free(T);
772 }
773 reference(r) ::= . {
774 r = 0;
775 }
776 reference(r) ::= AMPERSAND. {
777 r = 1;
778 }
779 indirection(i) ::= .{
780 i = 0;
781 }
782 indirection(i) ::= pointers(p). {
783 i = p;
784 }
785 pointers(p) ::= ASTERISK. {
786 p = 1;
787 }
788 pointers(p) ::= pointers(p_) ASTERISK. {
789 p = p_+1;
790 }