Fix unary constant use after error
[babeltrace.git] / formats / ctf / metadata / ctf-parser.y
1 %{
2 /*
3 * ctf-parser.y
4 *
5 * Common Trace Format Metadata Grammar.
6 *
7 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28 #include <stdio.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <assert.h>
33 #include <glib.h>
34 #include <errno.h>
35 #include <inttypes.h>
36 #include <babeltrace/list.h>
37 #include <babeltrace/babeltrace-internal.h>
38 #include "ctf-scanner.h"
39 #include "ctf-parser.h"
40 #include "ctf-ast.h"
41
42 BT_HIDDEN
43 int yydebug;
44
45 /* Join two lists, put "add" at the end of "head". */
46 static inline void
47 _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
48 {
49 /* Do nothing if the list which gets added is empty. */
50 if (add != add->next) {
51 add->next->prev = head->prev;
52 add->prev->next = head;
53 head->prev->next = add->next;
54 head->prev = add->prev;
55 }
56 }
57
58 BT_HIDDEN
59 int yyparse(struct ctf_scanner *scanner);
60 BT_HIDDEN
61 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
62 BT_HIDDEN
63 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
64 BT_HIDDEN
65 int yylex_destroy(yyscan_t yyscanner);
66 BT_HIDDEN
67 void yyrestart(FILE * in_str, yyscan_t scanner);
68 BT_HIDDEN
69 int yyget_lineno(yyscan_t yyscanner);
70 BT_HIDDEN
71 char *yyget_text(yyscan_t yyscanner);
72
73 struct gc_string {
74 struct bt_list_head gc;
75 size_t alloclen;
76 char s[];
77 };
78
79 static const char *node_type_to_str[] = {
80 [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
81 [ NODE_ROOT ] = "NODE_ROOT",
82 [ NODE_EVENT ] = "NODE_EVENT",
83 [ NODE_ENV ] = "NODE_ENV",
84 [ NODE_STREAM ] = "NODE_STREAM",
85 [ NODE_TRACE ] = "NODE_TRACE",
86 [ NODE_CLOCK ] = "NODE_CLOCK",
87 [ NODE_CALLSITE ] = "NODE_CALLSITE",
88 [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
89 [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
90 [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
91 [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
92 [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
93 [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
94 [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
95 [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
96 [ NODE_POINTER ] = "NODE_POINTER",
97 [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
98 [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
99 [ NODE_INTEGER ] = "NODE_INTEGER",
100 [ NODE_STRING ] = "NODE_STRING",
101 [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
102 [ NODE_ENUM ] = "NODE_ENUM",
103 [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
104 [ NODE_VARIANT ] = "NODE_VARIANT",
105 [ NODE_STRUCT ] = "NODE_STRUCT",
106 };
107
108 BT_HIDDEN
109 const char *node_type(struct ctf_node *node)
110 {
111 if (node->type < NR_NODE_TYPES)
112 return node_type_to_str[node->type];
113 else
114 return NULL;
115 }
116
117 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
118 size_t len)
119 {
120 struct gc_string *gstr;
121 size_t alloclen;
122
123 /* TODO: could be faster with find first bit or glib Gstring */
124 /* sizeof long to account for malloc header (int or long ?) */
125 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
126 alloclen *= 2);
127
128 gstr = malloc(alloclen);
129 bt_list_add(&gstr->gc, &scanner->allocated_strings);
130 gstr->alloclen = alloclen;
131 return gstr;
132 }
133
134 /*
135 * note: never use gc_string_append on a string that has external references.
136 * gsrc will be garbage collected immediately, and gstr might be.
137 * Should only be used to append characters to a string literal or constant.
138 */
139 BT_HIDDEN
140 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
141 struct gc_string *gstr,
142 struct gc_string *gsrc)
143 {
144 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
145 size_t alloclen;
146
147 /* TODO: could be faster with find first bit or glib Gstring */
148 /* sizeof long to account for malloc header (int or long ?) */
149 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
150 alloclen *= 2);
151
152 if (alloclen > gstr->alloclen) {
153 struct gc_string *newgstr;
154
155 newgstr = gc_string_alloc(scanner, newlen);
156 strcpy(newgstr->s, gstr->s);
157 strcat(newgstr->s, gsrc->s);
158 bt_list_del(&gstr->gc);
159 free(gstr);
160 gstr = newgstr;
161 } else {
162 strcat(gstr->s, gsrc->s);
163 }
164 bt_list_del(&gsrc->gc);
165 free(gsrc);
166 return gstr;
167 }
168
169 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
170 {
171 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
172 strcpy(lvalp->gs->s, src);
173 }
174
175 static void init_scope(struct ctf_scanner_scope *scope,
176 struct ctf_scanner_scope *parent)
177 {
178 scope->parent = parent;
179 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
180 NULL, NULL);
181 }
182
183 static void finalize_scope(struct ctf_scanner_scope *scope)
184 {
185 g_hash_table_destroy(scope->types);
186 }
187
188 static void push_scope(struct ctf_scanner *scanner)
189 {
190 struct ctf_scanner_scope *ns;
191
192 printf_debug("push scope\n");
193 ns = malloc(sizeof(struct ctf_scanner_scope));
194 init_scope(ns, scanner->cs);
195 scanner->cs = ns;
196 }
197
198 static void pop_scope(struct ctf_scanner *scanner)
199 {
200 struct ctf_scanner_scope *os;
201
202 printf_debug("pop scope\n");
203 os = scanner->cs;
204 scanner->cs = os->parent;
205 finalize_scope(os);
206 free(os);
207 }
208
209 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
210 {
211 int ret;
212
213 ret = (int) (long) g_hash_table_lookup(s->types, id);
214 printf_debug("lookup %p %s %d\n", s, id, ret);
215 return ret;
216 }
217
218 BT_HIDDEN
219 int is_type(struct ctf_scanner *scanner, const char *id)
220 {
221 struct ctf_scanner_scope *it;
222 int ret = 0;
223
224 for (it = scanner->cs; it != NULL; it = it->parent) {
225 if (lookup_type(it, id)) {
226 ret = 1;
227 break;
228 }
229 }
230 printf_debug("is type %s %d\n", id, ret);
231 return ret;
232 }
233
234 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
235 {
236 printf_debug("add type %s\n", id->s);
237 if (lookup_type(scanner->cs, id->s))
238 return;
239 g_hash_table_insert(scanner->cs->types, id->s, id->s);
240 }
241
242 static struct ctf_node *make_node(struct ctf_scanner *scanner,
243 enum node_type type)
244 {
245 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
246 struct ctf_node *node;
247
248 node = malloc(sizeof(*node));
249 if (!node)
250 return NULL;
251 memset(node, 0, sizeof(*node));
252 node->type = type;
253 node->lineno = yyget_lineno(scanner->scanner);
254 BT_INIT_LIST_HEAD(&node->tmp_head);
255 bt_list_add(&node->gc, &ast->allocated_nodes);
256 bt_list_add(&node->siblings, &node->tmp_head);
257
258 switch (type) {
259 case NODE_ROOT:
260 printfn_fatal(node, "trying to create root node");
261 break;
262
263 case NODE_EVENT:
264 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
265 break;
266 case NODE_STREAM:
267 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
268 break;
269 case NODE_ENV:
270 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
271 break;
272 case NODE_TRACE:
273 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
274 break;
275 case NODE_CLOCK:
276 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
277 break;
278 case NODE_CALLSITE:
279 BT_INIT_LIST_HEAD(&node->u.callsite.declaration_list);
280 break;
281
282 case NODE_CTF_EXPRESSION:
283 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
284 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
285 break;
286 case NODE_UNARY_EXPRESSION:
287 break;
288
289 case NODE_TYPEDEF:
290 BT_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
291 break;
292 case NODE_TYPEALIAS_TARGET:
293 BT_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
294 break;
295 case NODE_TYPEALIAS_ALIAS:
296 BT_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
297 break;
298 case NODE_TYPEALIAS:
299 break;
300
301 case NODE_TYPE_SPECIFIER:
302 break;
303 case NODE_TYPE_SPECIFIER_LIST:
304 BT_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
305 break;
306 case NODE_POINTER:
307 break;
308 case NODE_TYPE_DECLARATOR:
309 BT_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
310 break;
311
312 case NODE_FLOATING_POINT:
313 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
314 break;
315 case NODE_INTEGER:
316 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
317 break;
318 case NODE_STRING:
319 BT_INIT_LIST_HEAD(&node->u.string.expressions);
320 break;
321 case NODE_ENUMERATOR:
322 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
323 break;
324 case NODE_ENUM:
325 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
326 break;
327 case NODE_STRUCT_OR_VARIANT_DECLARATION:
328 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
329 break;
330 case NODE_VARIANT:
331 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
332 break;
333 case NODE_STRUCT:
334 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
335 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
336 break;
337
338 case NODE_UNKNOWN:
339 default:
340 printfn_fatal(node, "unknown node type '%d'", (int) type);
341 break;
342 }
343
344 return node;
345 }
346
347 static int reparent_ctf_expression(struct ctf_node *node,
348 struct ctf_node *parent)
349 {
350 switch (parent->type) {
351 case NODE_EVENT:
352 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
353 break;
354 case NODE_STREAM:
355 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
356 break;
357 case NODE_ENV:
358 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
359 break;
360 case NODE_TRACE:
361 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
362 break;
363 case NODE_CLOCK:
364 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
365 break;
366 case NODE_CALLSITE:
367 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
368 break;
369 case NODE_FLOATING_POINT:
370 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
371 break;
372 case NODE_INTEGER:
373 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
374 break;
375 case NODE_STRING:
376 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
377 break;
378
379 case NODE_ROOT:
380 case NODE_CTF_EXPRESSION:
381 case NODE_TYPEDEF:
382 case NODE_TYPEALIAS_TARGET:
383 case NODE_TYPEALIAS_ALIAS:
384 case NODE_TYPEALIAS:
385 case NODE_TYPE_SPECIFIER:
386 case NODE_TYPE_SPECIFIER_LIST:
387 case NODE_POINTER:
388 case NODE_TYPE_DECLARATOR:
389 case NODE_ENUMERATOR:
390 case NODE_ENUM:
391 case NODE_STRUCT_OR_VARIANT_DECLARATION:
392 case NODE_VARIANT:
393 case NODE_STRUCT:
394 case NODE_UNARY_EXPRESSION:
395 return -EPERM;
396
397 case NODE_UNKNOWN:
398 default:
399 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
400 return -EINVAL;
401 }
402 return 0;
403 }
404
405 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
406 {
407 switch (parent->type) {
408 case NODE_ROOT:
409 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
410 break;
411 case NODE_EVENT:
412 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
413 break;
414 case NODE_STREAM:
415 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
416 break;
417 case NODE_ENV:
418 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
419 break;
420 case NODE_TRACE:
421 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
422 break;
423 case NODE_CLOCK:
424 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
425 break;
426 case NODE_CALLSITE:
427 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
428 break;
429 case NODE_VARIANT:
430 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
431 break;
432 case NODE_STRUCT:
433 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
434 break;
435
436 case NODE_FLOATING_POINT:
437 case NODE_INTEGER:
438 case NODE_STRING:
439 case NODE_CTF_EXPRESSION:
440 case NODE_TYPEDEF:
441 case NODE_TYPEALIAS_TARGET:
442 case NODE_TYPEALIAS_ALIAS:
443 case NODE_TYPEALIAS:
444 case NODE_TYPE_SPECIFIER:
445 case NODE_TYPE_SPECIFIER_LIST:
446 case NODE_POINTER:
447 case NODE_TYPE_DECLARATOR:
448 case NODE_ENUMERATOR:
449 case NODE_ENUM:
450 case NODE_STRUCT_OR_VARIANT_DECLARATION:
451 case NODE_UNARY_EXPRESSION:
452 return -EPERM;
453
454 case NODE_UNKNOWN:
455 default:
456 printfn_fatal(node, "unknown node type %d", parent->type);
457 return -EINVAL;
458 }
459 return 0;
460 }
461
462 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
463 {
464 switch (parent->type) {
465 case NODE_ROOT:
466 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
467 break;
468 case NODE_EVENT:
469 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
470 break;
471 case NODE_STREAM:
472 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
473 break;
474 case NODE_ENV:
475 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
476 break;
477 case NODE_TRACE:
478 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
479 break;
480 case NODE_CLOCK:
481 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
482 break;
483 case NODE_CALLSITE:
484 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
485 break;
486 case NODE_VARIANT:
487 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
488 break;
489 case NODE_STRUCT:
490 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
491 break;
492
493 case NODE_FLOATING_POINT:
494 case NODE_INTEGER:
495 case NODE_STRING:
496 case NODE_CTF_EXPRESSION:
497 case NODE_TYPEDEF:
498 case NODE_TYPEALIAS_TARGET:
499 case NODE_TYPEALIAS_ALIAS:
500 case NODE_TYPEALIAS:
501 case NODE_TYPE_SPECIFIER:
502 case NODE_TYPE_SPECIFIER_LIST:
503 case NODE_POINTER:
504 case NODE_TYPE_DECLARATOR:
505 case NODE_ENUMERATOR:
506 case NODE_ENUM:
507 case NODE_STRUCT_OR_VARIANT_DECLARATION:
508 case NODE_UNARY_EXPRESSION:
509 return -EPERM;
510
511 case NODE_UNKNOWN:
512 default:
513 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
514 return -EINVAL;
515 }
516 return 0;
517 }
518
519 static int reparent_type_specifier(struct ctf_node *node,
520 struct ctf_node *parent)
521 {
522 switch (parent->type) {
523 case NODE_TYPE_SPECIFIER_LIST:
524 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
525 break;
526
527 case NODE_TYPE_SPECIFIER:
528 case NODE_EVENT:
529 case NODE_STREAM:
530 case NODE_ENV:
531 case NODE_TRACE:
532 case NODE_CLOCK:
533 case NODE_CALLSITE:
534 case NODE_VARIANT:
535 case NODE_STRUCT:
536 case NODE_TYPEDEF:
537 case NODE_TYPEALIAS_TARGET:
538 case NODE_TYPEALIAS_ALIAS:
539 case NODE_TYPE_DECLARATOR:
540 case NODE_ENUM:
541 case NODE_STRUCT_OR_VARIANT_DECLARATION:
542 case NODE_TYPEALIAS:
543 case NODE_FLOATING_POINT:
544 case NODE_INTEGER:
545 case NODE_STRING:
546 case NODE_CTF_EXPRESSION:
547 case NODE_POINTER:
548 case NODE_ENUMERATOR:
549 case NODE_UNARY_EXPRESSION:
550 return -EPERM;
551
552 case NODE_UNKNOWN:
553 default:
554 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
555 return -EINVAL;
556 }
557 return 0;
558 }
559
560 static int reparent_type_specifier_list(struct ctf_node *node,
561 struct ctf_node *parent)
562 {
563 switch (parent->type) {
564 case NODE_ROOT:
565 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
566 break;
567 case NODE_EVENT:
568 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
569 break;
570 case NODE_STREAM:
571 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
572 break;
573 case NODE_ENV:
574 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
575 break;
576 case NODE_TRACE:
577 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
578 break;
579 case NODE_CLOCK:
580 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
581 break;
582 case NODE_CALLSITE:
583 bt_list_add_tail(&node->siblings, &parent->u.callsite.declaration_list);
584 break;
585 case NODE_VARIANT:
586 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
587 break;
588 case NODE_STRUCT:
589 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
590 break;
591 case NODE_TYPEDEF:
592 parent->u._typedef.type_specifier_list = node;
593 break;
594 case NODE_TYPEALIAS_TARGET:
595 parent->u.typealias_target.type_specifier_list = node;
596 break;
597 case NODE_TYPEALIAS_ALIAS:
598 parent->u.typealias_alias.type_specifier_list = node;
599 break;
600 case NODE_ENUM:
601 parent->u._enum.container_type = node;
602 break;
603 case NODE_STRUCT_OR_VARIANT_DECLARATION:
604 parent->u.struct_or_variant_declaration.type_specifier_list = node;
605 break;
606 case NODE_TYPE_DECLARATOR:
607 case NODE_TYPE_SPECIFIER:
608 case NODE_TYPEALIAS:
609 case NODE_FLOATING_POINT:
610 case NODE_INTEGER:
611 case NODE_STRING:
612 case NODE_CTF_EXPRESSION:
613 case NODE_POINTER:
614 case NODE_ENUMERATOR:
615 case NODE_UNARY_EXPRESSION:
616 return -EPERM;
617
618 case NODE_UNKNOWN:
619 default:
620 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
621 return -EINVAL;
622 }
623 return 0;
624 }
625
626 static int reparent_type_declarator(struct ctf_node *node,
627 struct ctf_node *parent)
628 {
629 switch (parent->type) {
630 case NODE_TYPE_DECLARATOR:
631 parent->u.type_declarator.type = TYPEDEC_NESTED;
632 parent->u.type_declarator.u.nested.type_declarator = node;
633 break;
634 case NODE_STRUCT_OR_VARIANT_DECLARATION:
635 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
636 break;
637 case NODE_TYPEDEF:
638 _bt_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
639 break;
640 case NODE_TYPEALIAS_TARGET:
641 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
642 break;
643 case NODE_TYPEALIAS_ALIAS:
644 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
645 break;
646
647 case NODE_ROOT:
648 case NODE_EVENT:
649 case NODE_STREAM:
650 case NODE_ENV:
651 case NODE_TRACE:
652 case NODE_CLOCK:
653 case NODE_CALLSITE:
654 case NODE_VARIANT:
655 case NODE_STRUCT:
656 case NODE_TYPEALIAS:
657 case NODE_ENUM:
658 case NODE_FLOATING_POINT:
659 case NODE_INTEGER:
660 case NODE_STRING:
661 case NODE_CTF_EXPRESSION:
662 case NODE_TYPE_SPECIFIER:
663 case NODE_TYPE_SPECIFIER_LIST:
664 case NODE_POINTER:
665 case NODE_ENUMERATOR:
666 case NODE_UNARY_EXPRESSION:
667 return -EPERM;
668
669 case NODE_UNKNOWN:
670 default:
671 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
672 return -EINVAL;
673 }
674 return 0;
675 }
676
677 /*
678 * set_parent_node
679 *
680 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
681 * create the link declared by the input, -ENOENT if node or parent is NULL,
682 * -EINVAL if there is an internal structure problem.
683 */
684 static int set_parent_node(struct ctf_node *node,
685 struct ctf_node *parent)
686 {
687 if (!node || !parent)
688 return -ENOENT;
689
690 /* Note: Linking to parent will be done only by an external visitor */
691
692 switch (node->type) {
693 case NODE_ROOT:
694 printfn_fatal(node, "trying to reparent root node");
695 return -EINVAL;
696
697 case NODE_EVENT:
698 if (parent->type == NODE_ROOT) {
699 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
700 } else {
701 return -EPERM;
702 }
703 break;
704 case NODE_STREAM:
705 if (parent->type == NODE_ROOT) {
706 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
707 } else {
708 return -EPERM;
709 }
710 break;
711 case NODE_ENV:
712 if (parent->type == NODE_ROOT) {
713 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
714 } else {
715 return -EPERM;
716 }
717 break;
718 case NODE_TRACE:
719 if (parent->type == NODE_ROOT) {
720 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
721 } else {
722 return -EPERM;
723 }
724 break;
725 case NODE_CLOCK:
726 if (parent->type == NODE_ROOT) {
727 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
728 } else {
729 return -EPERM;
730 }
731 break;
732 case NODE_CALLSITE:
733 if (parent->type == NODE_ROOT) {
734 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.callsite);
735 } else {
736 return -EPERM;
737 }
738 break;
739
740 case NODE_CTF_EXPRESSION:
741 return reparent_ctf_expression(node, parent);
742 case NODE_UNARY_EXPRESSION:
743 if (parent->type == NODE_TYPE_DECLARATOR)
744 parent->u.type_declarator.bitfield_len = node;
745 else
746 return -EPERM;
747 break;
748
749 case NODE_TYPEDEF:
750 return reparent_typedef(node, parent);
751 case NODE_TYPEALIAS_TARGET:
752 if (parent->type == NODE_TYPEALIAS)
753 parent->u.typealias.target = node;
754 else
755 return -EINVAL;
756 case NODE_TYPEALIAS_ALIAS:
757 if (parent->type == NODE_TYPEALIAS)
758 parent->u.typealias.alias = node;
759 else
760 return -EINVAL;
761 case NODE_TYPEALIAS:
762 return reparent_typealias(node, parent);
763
764 case NODE_POINTER:
765 if (parent->type == NODE_TYPE_DECLARATOR) {
766 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
767 } else
768 return -EPERM;
769 break;
770 case NODE_TYPE_DECLARATOR:
771 return reparent_type_declarator(node, parent);
772
773 case NODE_TYPE_SPECIFIER_LIST:
774 return reparent_type_specifier_list(node, parent);
775
776 case NODE_TYPE_SPECIFIER:
777 return reparent_type_specifier(node, parent);
778
779 case NODE_FLOATING_POINT:
780 case NODE_INTEGER:
781 case NODE_STRING:
782 case NODE_ENUM:
783 case NODE_VARIANT:
784 case NODE_STRUCT:
785 return -EINVAL; /* Dealt with internally within grammar */
786
787 case NODE_ENUMERATOR:
788 if (parent->type == NODE_ENUM) {
789 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
790 } else {
791 return -EPERM;
792 }
793 break;
794 case NODE_STRUCT_OR_VARIANT_DECLARATION:
795 switch (parent->type) {
796 case NODE_STRUCT:
797 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
798 break;
799 case NODE_VARIANT:
800 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
801 break;
802 default:
803 return -EINVAL;
804 }
805 break;
806
807 case NODE_UNKNOWN:
808 default:
809 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
810 return -EINVAL;
811 }
812 return 0;
813 }
814
815 BT_HIDDEN
816 void yyerror(struct ctf_scanner *scanner, const char *str)
817 {
818 printfl_error(yyget_lineno(scanner->scanner),
819 "token \"%s\": %s\n",
820 yyget_text(scanner->scanner), str);
821 }
822
823 BT_HIDDEN
824 int yywrap(void)
825 {
826 return 1;
827 }
828
829 #define reparent_error(scanner, str) \
830 do { \
831 yyerror(scanner, YY_("reparent_error: " str)); \
832 YYERROR; \
833 } while (0)
834
835 static void free_strings(struct bt_list_head *list)
836 {
837 struct gc_string *gstr, *tmp;
838
839 bt_list_for_each_entry_safe(gstr, tmp, list, gc)
840 free(gstr);
841 }
842
843 static struct ctf_ast *ctf_ast_alloc(void)
844 {
845 struct ctf_ast *ast;
846
847 ast = malloc(sizeof(*ast));
848 if (!ast)
849 return NULL;
850 memset(ast, 0, sizeof(*ast));
851 BT_INIT_LIST_HEAD(&ast->allocated_nodes);
852 ast->root.type = NODE_ROOT;
853 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
854 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
855 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
856 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
857 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
858 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
859 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
860 BT_INIT_LIST_HEAD(&ast->root.u.root.callsite);
861 return ast;
862 }
863
864 static void ctf_ast_free(struct ctf_ast *ast)
865 {
866 struct ctf_node *node, *tmp;
867
868 bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
869 free(node);
870 free(ast);
871 }
872
873 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
874 {
875 return yyparse(scanner);
876 }
877
878 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
879 {
880 struct ctf_scanner *scanner;
881 int ret;
882
883 yydebug = babeltrace_debug;
884
885 scanner = malloc(sizeof(*scanner));
886 if (!scanner)
887 return NULL;
888 memset(scanner, 0, sizeof(*scanner));
889
890 ret = yylex_init_extra(scanner, &scanner->scanner);
891 if (ret) {
892 printf_fatal("yylex_init error");
893 goto cleanup_scanner;
894 }
895 /* Start processing new stream */
896 yyrestart(input, scanner->scanner);
897
898 scanner->ast = ctf_ast_alloc();
899 if (!scanner->ast)
900 goto cleanup_lexer;
901 init_scope(&scanner->root_scope, NULL);
902 scanner->cs = &scanner->root_scope;
903 BT_INIT_LIST_HEAD(&scanner->allocated_strings);
904
905 if (yydebug)
906 fprintf(stdout, "Scanner input is a%s.\n",
907 isatty(fileno(input)) ? "n interactive tty" :
908 " noninteractive file");
909
910 return scanner;
911
912 cleanup_lexer:
913 ret = yylex_destroy(scanner->scanner);
914 if (!ret)
915 printf_fatal("yylex_destroy error");
916 cleanup_scanner:
917 free(scanner);
918 return NULL;
919 }
920
921 void ctf_scanner_free(struct ctf_scanner *scanner)
922 {
923 int ret;
924
925 finalize_scope(&scanner->root_scope);
926 free_strings(&scanner->allocated_strings);
927 ctf_ast_free(scanner->ast);
928 ret = yylex_destroy(scanner->scanner);
929 if (ret)
930 printf_error("yylex_destroy error");
931 free(scanner);
932 }
933
934 %}
935
936 %define api.pure
937 /* %locations */
938 %error-verbose
939 %parse-param {struct ctf_scanner *scanner}
940 %lex-param {struct ctf_scanner *scanner}
941 /*
942 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
943 * vs struct { int :value; } (unnamed bit-field). The default is to
944 * shift, so whenever we encounter an enumeration, we are doing the
945 * proper thing (shift). It is illegal to declare an enumeration
946 * "bit-field", so it is OK if this situation ends up in a parsing
947 * error.
948 */
949 %expect 2
950 %start file
951 %token CHARACTER_CONSTANT_START SQUOTE STRING_LITERAL_START DQUOTE ESCSEQ CHAR_STRING_TOKEN LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM ENV EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE CALLSITE CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT TOK_ALIGN
952 %token <gs> IDENTIFIER ID_TYPE
953 %token ERROR
954 %union
955 {
956 long long ll;
957 char c;
958 struct gc_string *gs;
959 struct ctf_node *n;
960 }
961
962 %type <gs> keywords
963 %type <gs> s_char s_char_sequence c_char c_char_sequence
964
965 %type <n> postfix_expression unary_expression unary_expression_or_range
966
967 %type <n> declaration
968 %type <n> event_declaration
969 %type <n> stream_declaration
970 %type <n> env_declaration
971 %type <n> trace_declaration
972 %type <n> clock_declaration
973 %type <n> callsite_declaration
974 %type <n> integer_declaration_specifiers
975 %type <n> declaration_specifiers
976 %type <n> alias_declaration_specifiers
977
978 %type <n> type_declarator_list
979 %type <n> integer_type_specifier
980 %type <n> type_specifier
981 %type <n> struct_type_specifier
982 %type <n> variant_type_specifier
983 %type <n> enum_type_specifier
984 %type <n> struct_or_variant_declaration_list
985 %type <n> struct_or_variant_declaration
986 %type <n> struct_or_variant_declarator_list
987 %type <n> struct_or_variant_declarator
988 %type <n> enumerator_list
989 %type <n> enumerator
990 %type <n> abstract_declarator_list
991 %type <n> abstract_declarator
992 %type <n> direct_abstract_declarator
993 %type <n> alias_abstract_declarator_list
994 %type <n> alias_abstract_declarator
995 %type <n> direct_alias_abstract_declarator
996 %type <n> declarator
997 %type <n> direct_declarator
998 %type <n> type_declarator
999 %type <n> direct_type_declarator
1000 %type <n> pointer
1001 %type <n> ctf_assignment_expression_list
1002 %type <n> ctf_assignment_expression
1003
1004 %%
1005
1006 file:
1007 declaration
1008 {
1009 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
1010 reparent_error(scanner, "error reparenting to root");
1011 }
1012 | file declaration
1013 {
1014 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
1015 reparent_error(scanner, "error reparenting to root");
1016 }
1017 ;
1018
1019 keywords:
1020 VOID
1021 { $$ = yylval.gs; }
1022 | CHAR
1023 { $$ = yylval.gs; }
1024 | SHORT
1025 { $$ = yylval.gs; }
1026 | INT
1027 { $$ = yylval.gs; }
1028 | LONG
1029 { $$ = yylval.gs; }
1030 | FLOAT
1031 { $$ = yylval.gs; }
1032 | DOUBLE
1033 { $$ = yylval.gs; }
1034 | SIGNED
1035 { $$ = yylval.gs; }
1036 | UNSIGNED
1037 { $$ = yylval.gs; }
1038 | _BOOL
1039 { $$ = yylval.gs; }
1040 | _COMPLEX
1041 { $$ = yylval.gs; }
1042 | _IMAGINARY
1043 { $$ = yylval.gs; }
1044 | FLOATING_POINT
1045 { $$ = yylval.gs; }
1046 | INTEGER
1047 { $$ = yylval.gs; }
1048 | STRING
1049 { $$ = yylval.gs; }
1050 | ENUM
1051 { $$ = yylval.gs; }
1052 | VARIANT
1053 { $$ = yylval.gs; }
1054 | STRUCT
1055 { $$ = yylval.gs; }
1056 | CONST
1057 { $$ = yylval.gs; }
1058 | TYPEDEF
1059 { $$ = yylval.gs; }
1060 | EVENT
1061 { $$ = yylval.gs; }
1062 | STREAM
1063 { $$ = yylval.gs; }
1064 | ENV
1065 { $$ = yylval.gs; }
1066 | TRACE
1067 { $$ = yylval.gs; }
1068 | CLOCK
1069 { $$ = yylval.gs; }
1070 | CALLSITE
1071 { $$ = yylval.gs; }
1072 | TOK_ALIGN
1073 { $$ = yylval.gs; }
1074 ;
1075
1076 /* 1.5 Constants */
1077
1078 c_char_sequence:
1079 c_char
1080 { $$ = $1; }
1081 | c_char_sequence c_char
1082 { $$ = gc_string_append(scanner, $1, $2); }
1083 ;
1084
1085 c_char:
1086 CHAR_STRING_TOKEN
1087 { $$ = yylval.gs; }
1088 | ESCSEQ
1089 {
1090 reparent_error(scanner, "escape sequences not supported yet");
1091 }
1092 ;
1093
1094 /* 1.6 String literals */
1095
1096 s_char_sequence:
1097 s_char
1098 { $$ = $1; }
1099 | s_char_sequence s_char
1100 { $$ = gc_string_append(scanner, $1, $2); }
1101 ;
1102
1103 s_char:
1104 CHAR_STRING_TOKEN
1105 { $$ = yylval.gs; }
1106 | ESCSEQ
1107 {
1108 reparent_error(scanner, "escape sequences not supported yet");
1109 }
1110 ;
1111
1112 /* 2: Phrase structure grammar */
1113
1114 postfix_expression:
1115 IDENTIFIER
1116 {
1117 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1118 $$->u.unary_expression.type = UNARY_STRING;
1119 $$->u.unary_expression.u.string = yylval.gs->s;
1120 }
1121 | ID_TYPE
1122 {
1123 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1124 $$->u.unary_expression.type = UNARY_STRING;
1125 $$->u.unary_expression.u.string = yylval.gs->s;
1126 }
1127 | keywords
1128 {
1129 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1130 $$->u.unary_expression.type = UNARY_STRING;
1131 $$->u.unary_expression.u.string = yylval.gs->s;
1132 }
1133 | DECIMAL_CONSTANT
1134 {
1135 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1136 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1137 sscanf(yylval.gs->s, "%" PRIu64,
1138 &$$->u.unary_expression.u.unsigned_constant);
1139 }
1140 | OCTAL_CONSTANT
1141 {
1142 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1143 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1144 sscanf(yylval.gs->s, "0%" PRIo64,
1145 &$$->u.unary_expression.u.unsigned_constant);
1146 }
1147 | HEXADECIMAL_CONSTANT
1148 {
1149 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1150 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1151 sscanf(yylval.gs->s, "0x%" PRIx64,
1152 &$$->u.unary_expression.u.unsigned_constant);
1153 }
1154 | STRING_LITERAL_START DQUOTE
1155 {
1156 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1157 $$->u.unary_expression.type = UNARY_STRING;
1158 $$->u.unary_expression.u.string = "";
1159 }
1160 | STRING_LITERAL_START s_char_sequence DQUOTE
1161 {
1162 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1163 $$->u.unary_expression.type = UNARY_STRING;
1164 $$->u.unary_expression.u.string = $2->s;
1165 }
1166 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1167 {
1168 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1169 $$->u.unary_expression.type = UNARY_STRING;
1170 $$->u.unary_expression.u.string = $2->s;
1171 }
1172 | LPAREN unary_expression RPAREN
1173 {
1174 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1175 $$->u.unary_expression.type = UNARY_NESTED;
1176 $$->u.unary_expression.u.nested_exp = $2;
1177 }
1178 | postfix_expression LSBRAC unary_expression RSBRAC
1179 {
1180 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1181 $$->u.unary_expression.type = UNARY_SBRAC;
1182 $$->u.unary_expression.u.sbrac_exp = $3;
1183 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1184 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1185 }
1186 | postfix_expression DOT IDENTIFIER
1187 {
1188 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1189 $$->u.unary_expression.type = UNARY_STRING;
1190 $$->u.unary_expression.u.string = yylval.gs->s;
1191 $$->u.unary_expression.link = UNARY_DOTLINK;
1192 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1193 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1194 }
1195 | postfix_expression DOT ID_TYPE
1196 {
1197 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1198 $$->u.unary_expression.type = UNARY_STRING;
1199 $$->u.unary_expression.u.string = yylval.gs->s;
1200 $$->u.unary_expression.link = UNARY_DOTLINK;
1201 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1202 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1203 }
1204 | postfix_expression RARROW IDENTIFIER
1205 {
1206 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1207 $$->u.unary_expression.type = UNARY_STRING;
1208 $$->u.unary_expression.u.string = yylval.gs->s;
1209 $$->u.unary_expression.link = UNARY_ARROWLINK;
1210 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1211 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1212 }
1213 | postfix_expression RARROW ID_TYPE
1214 {
1215 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1216 $$->u.unary_expression.type = UNARY_STRING;
1217 $$->u.unary_expression.u.string = yylval.gs->s;
1218 $$->u.unary_expression.link = UNARY_ARROWLINK;
1219 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1220 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1221 }
1222 ;
1223
1224 unary_expression:
1225 postfix_expression
1226 { $$ = $1; }
1227 | PLUS postfix_expression
1228 { $$ = $2; }
1229 | MINUS postfix_expression
1230 {
1231 $$ = $2;
1232 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1233 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1234 $$->u.unary_expression.u.signed_constant =
1235 -($$->u.unary_expression.u.unsigned_constant);
1236 } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1237 $$->u.unary_expression.u.signed_constant =
1238 -($$->u.unary_expression.u.signed_constant);
1239 } else {
1240 reparent_error(scanner, "expecting numeric constant");
1241 }
1242 }
1243 ;
1244
1245 unary_expression_or_range:
1246 unary_expression DOTDOTDOT unary_expression
1247 {
1248 $$ = $1;
1249 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1250 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1251 }
1252 | unary_expression
1253 { $$ = $1; }
1254 ;
1255
1256 /* 2.2: Declarations */
1257
1258 declaration:
1259 declaration_specifiers SEMICOLON
1260 { $$ = $1; }
1261 | event_declaration
1262 { $$ = $1; }
1263 | stream_declaration
1264 { $$ = $1; }
1265 | env_declaration
1266 { $$ = $1; }
1267 | trace_declaration
1268 { $$ = $1; }
1269 | clock_declaration
1270 { $$ = $1; }
1271 | callsite_declaration
1272 { $$ = $1; }
1273 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1274 {
1275 struct ctf_node *list;
1276
1277 $$ = make_node(scanner, NODE_TYPEDEF);
1278 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1279 $$->u._typedef.type_specifier_list = list;
1280 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1281 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1282 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1283 }
1284 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1285 {
1286 struct ctf_node *list;
1287
1288 $$ = make_node(scanner, NODE_TYPEDEF);
1289 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1290 $$->u._typedef.type_specifier_list = list;
1291 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1292 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1293 }
1294 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1295 {
1296 struct ctf_node *list;
1297
1298 $$ = make_node(scanner, NODE_TYPEDEF);
1299 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1300 $$->u._typedef.type_specifier_list = list;
1301 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1302 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1303 }
1304 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1305 {
1306 struct ctf_node *list;
1307
1308 $$ = make_node(scanner, NODE_TYPEALIAS);
1309 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1310 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1311
1312 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1313 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1314 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1315 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1316
1317 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1318 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1319 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1320 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1321 }
1322 ;
1323
1324 event_declaration:
1325 event_declaration_begin event_declaration_end
1326 {
1327 $$ = make_node(scanner, NODE_EVENT);
1328 }
1329 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1330 {
1331 $$ = make_node(scanner, NODE_EVENT);
1332 if (set_parent_node($2, $$))
1333 reparent_error(scanner, "event_declaration");
1334 }
1335 ;
1336
1337 event_declaration_begin:
1338 EVENT LBRAC
1339 { push_scope(scanner); }
1340 ;
1341
1342 event_declaration_end:
1343 RBRAC SEMICOLON
1344 { pop_scope(scanner); }
1345 ;
1346
1347
1348 stream_declaration:
1349 stream_declaration_begin stream_declaration_end
1350 {
1351 $$ = make_node(scanner, NODE_STREAM);
1352 }
1353 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1354 {
1355 $$ = make_node(scanner, NODE_STREAM);
1356 if (set_parent_node($2, $$))
1357 reparent_error(scanner, "stream_declaration");
1358 }
1359 ;
1360
1361 stream_declaration_begin:
1362 STREAM LBRAC
1363 { push_scope(scanner); }
1364 ;
1365
1366 stream_declaration_end:
1367 RBRAC SEMICOLON
1368 { pop_scope(scanner); }
1369 ;
1370
1371 env_declaration:
1372 env_declaration_begin env_declaration_end
1373 {
1374 $$ = make_node(scanner, NODE_ENV);
1375 }
1376 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1377 {
1378 $$ = make_node(scanner, NODE_ENV);
1379 if (set_parent_node($2, $$))
1380 reparent_error(scanner, "env declaration");
1381 }
1382 ;
1383
1384 env_declaration_begin:
1385 ENV LBRAC
1386 { push_scope(scanner); }
1387 ;
1388
1389 env_declaration_end:
1390 RBRAC SEMICOLON
1391 { pop_scope(scanner); }
1392 ;
1393
1394 trace_declaration:
1395 trace_declaration_begin trace_declaration_end
1396 {
1397 $$ = make_node(scanner, NODE_TRACE);
1398 }
1399 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1400 {
1401 $$ = make_node(scanner, NODE_TRACE);
1402 if (set_parent_node($2, $$))
1403 reparent_error(scanner, "trace_declaration");
1404 }
1405 ;
1406
1407 trace_declaration_begin:
1408 TRACE LBRAC
1409 { push_scope(scanner); }
1410 ;
1411
1412 trace_declaration_end:
1413 RBRAC SEMICOLON
1414 { pop_scope(scanner); }
1415 ;
1416
1417 clock_declaration:
1418 CLOCK clock_declaration_begin clock_declaration_end
1419 {
1420 $$ = make_node(scanner, NODE_CLOCK);
1421 }
1422 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1423 {
1424 $$ = make_node(scanner, NODE_CLOCK);
1425 if (set_parent_node($3, $$))
1426 reparent_error(scanner, "trace_declaration");
1427 }
1428 ;
1429
1430 clock_declaration_begin:
1431 LBRAC
1432 { push_scope(scanner); }
1433 ;
1434
1435 clock_declaration_end:
1436 RBRAC SEMICOLON
1437 { pop_scope(scanner); }
1438 ;
1439
1440 callsite_declaration:
1441 CALLSITE callsite_declaration_begin callsite_declaration_end
1442 {
1443 $$ = make_node(scanner, NODE_CALLSITE);
1444 }
1445 | CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1446 {
1447 $$ = make_node(scanner, NODE_CALLSITE);
1448 if (set_parent_node($3, $$))
1449 reparent_error(scanner, "trace_declaration");
1450 }
1451 ;
1452
1453 callsite_declaration_begin:
1454 LBRAC
1455 { push_scope(scanner); }
1456 ;
1457
1458 callsite_declaration_end:
1459 RBRAC SEMICOLON
1460 { pop_scope(scanner); }
1461 ;
1462
1463 integer_declaration_specifiers:
1464 CONST
1465 {
1466 struct ctf_node *node;
1467
1468 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1469 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1470 node->u.type_specifier.type = TYPESPEC_CONST;
1471 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1472 }
1473 | integer_type_specifier
1474 {
1475 struct ctf_node *node;
1476
1477 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1478 node = $1;
1479 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1480 }
1481 | integer_declaration_specifiers CONST
1482 {
1483 struct ctf_node *node;
1484
1485 $$ = $1;
1486 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1487 node->u.type_specifier.type = TYPESPEC_CONST;
1488 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1489 }
1490 | integer_declaration_specifiers integer_type_specifier
1491 {
1492 $$ = $1;
1493 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1494 }
1495 ;
1496
1497 declaration_specifiers:
1498 CONST
1499 {
1500 struct ctf_node *node;
1501
1502 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1503 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1504 node->u.type_specifier.type = TYPESPEC_CONST;
1505 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1506 }
1507 | type_specifier
1508 {
1509 struct ctf_node *node;
1510
1511 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1512 node = $1;
1513 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1514 }
1515 | declaration_specifiers CONST
1516 {
1517 struct ctf_node *node;
1518
1519 $$ = $1;
1520 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1521 node->u.type_specifier.type = TYPESPEC_CONST;
1522 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1523 }
1524 | declaration_specifiers type_specifier
1525 {
1526 $$ = $1;
1527 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1528 }
1529 ;
1530
1531 type_declarator_list:
1532 type_declarator
1533 { $$ = $1; }
1534 | type_declarator_list COMMA type_declarator
1535 {
1536 $$ = $1;
1537 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1538 }
1539 ;
1540
1541 integer_type_specifier:
1542 CHAR
1543 {
1544 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1545 $$->u.type_specifier.type = TYPESPEC_CHAR;
1546 }
1547 | SHORT
1548 {
1549 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1550 $$->u.type_specifier.type = TYPESPEC_SHORT;
1551 }
1552 | INT
1553 {
1554 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1555 $$->u.type_specifier.type = TYPESPEC_INT;
1556 }
1557 | LONG
1558 {
1559 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1560 $$->u.type_specifier.type = TYPESPEC_LONG;
1561 }
1562 | SIGNED
1563 {
1564 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1565 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1566 }
1567 | UNSIGNED
1568 {
1569 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1570 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1571 }
1572 | _BOOL
1573 {
1574 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1575 $$->u.type_specifier.type = TYPESPEC_BOOL;
1576 }
1577 | ID_TYPE
1578 {
1579 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1580 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1581 $$->u.type_specifier.id_type = yylval.gs->s;
1582 }
1583 | INTEGER LBRAC RBRAC
1584 {
1585 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1586 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1587 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1588 }
1589 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1590 {
1591 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1592 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1593 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1594 if (set_parent_node($3, $$->u.type_specifier.node))
1595 reparent_error(scanner, "integer reparent error");
1596 }
1597 ;
1598
1599 type_specifier:
1600 VOID
1601 {
1602 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1603 $$->u.type_specifier.type = TYPESPEC_VOID;
1604 }
1605 | CHAR
1606 {
1607 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1608 $$->u.type_specifier.type = TYPESPEC_CHAR;
1609 }
1610 | SHORT
1611 {
1612 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1613 $$->u.type_specifier.type = TYPESPEC_SHORT;
1614 }
1615 | INT
1616 {
1617 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1618 $$->u.type_specifier.type = TYPESPEC_INT;
1619 }
1620 | LONG
1621 {
1622 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1623 $$->u.type_specifier.type = TYPESPEC_LONG;
1624 }
1625 | FLOAT
1626 {
1627 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1628 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1629 }
1630 | DOUBLE
1631 {
1632 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1633 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1634 }
1635 | SIGNED
1636 {
1637 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1638 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1639 }
1640 | UNSIGNED
1641 {
1642 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1643 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1644 }
1645 | _BOOL
1646 {
1647 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1648 $$->u.type_specifier.type = TYPESPEC_BOOL;
1649 }
1650 | _COMPLEX
1651 {
1652 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1653 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1654 }
1655 | _IMAGINARY
1656 {
1657 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1658 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1659 }
1660 | ID_TYPE
1661 {
1662 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1663 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1664 $$->u.type_specifier.id_type = yylval.gs->s;
1665 }
1666 | FLOATING_POINT LBRAC RBRAC
1667 {
1668 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1669 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1670 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1671 }
1672 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1673 {
1674 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1675 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1676 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1677 if (set_parent_node($3, $$->u.type_specifier.node))
1678 reparent_error(scanner, "floating point reparent error");
1679 }
1680 | INTEGER LBRAC RBRAC
1681 {
1682 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1683 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1684 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1685 }
1686 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1687 {
1688 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1689 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1690 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1691 if (set_parent_node($3, $$->u.type_specifier.node))
1692 reparent_error(scanner, "integer reparent error");
1693 }
1694 | STRING
1695 {
1696 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1697 $$->u.type_specifier.type = TYPESPEC_STRING;
1698 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1699 }
1700 | STRING LBRAC RBRAC
1701 {
1702 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1703 $$->u.type_specifier.type = TYPESPEC_STRING;
1704 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1705 }
1706 | STRING LBRAC ctf_assignment_expression_list RBRAC
1707 {
1708 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1709 $$->u.type_specifier.type = TYPESPEC_STRING;
1710 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1711 if (set_parent_node($3, $$->u.type_specifier.node))
1712 reparent_error(scanner, "string reparent error");
1713 }
1714 | ENUM enum_type_specifier
1715 {
1716 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1717 $$->u.type_specifier.type = TYPESPEC_ENUM;
1718 $$->u.type_specifier.node = $2;
1719 }
1720 | VARIANT variant_type_specifier
1721 {
1722 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1723 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1724 $$->u.type_specifier.node = $2;
1725 }
1726 | STRUCT struct_type_specifier
1727 {
1728 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1729 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1730 $$->u.type_specifier.node = $2;
1731 }
1732 ;
1733
1734 struct_type_specifier:
1735 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1736 {
1737 $$ = make_node(scanner, NODE_STRUCT);
1738 $$->u._struct.has_body = 1;
1739 if ($2 && set_parent_node($2, $$))
1740 reparent_error(scanner, "struct reparent error");
1741 }
1742 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1743 {
1744 $$ = make_node(scanner, NODE_STRUCT);
1745 $$->u._struct.has_body = 1;
1746 $$->u._struct.name = $1->s;
1747 if ($3 && set_parent_node($3, $$))
1748 reparent_error(scanner, "struct reparent error");
1749 }
1750 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1751 {
1752 $$ = make_node(scanner, NODE_STRUCT);
1753 $$->u._struct.has_body = 1;
1754 $$->u._struct.name = $1->s;
1755 if ($3 && set_parent_node($3, $$))
1756 reparent_error(scanner, "struct reparent error");
1757 }
1758 | IDENTIFIER
1759 {
1760 $$ = make_node(scanner, NODE_STRUCT);
1761 $$->u._struct.has_body = 0;
1762 $$->u._struct.name = $1->s;
1763 }
1764 | ID_TYPE
1765 {
1766 $$ = make_node(scanner, NODE_STRUCT);
1767 $$->u._struct.has_body = 0;
1768 $$->u._struct.name = $1->s;
1769 }
1770 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1771 {
1772 $$ = make_node(scanner, NODE_STRUCT);
1773 $$->u._struct.has_body = 1;
1774 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1775 if ($2 && set_parent_node($2, $$))
1776 reparent_error(scanner, "struct reparent error");
1777 }
1778 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1779 {
1780 $$ = make_node(scanner, NODE_STRUCT);
1781 $$->u._struct.has_body = 1;
1782 $$->u._struct.name = $1->s;
1783 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1784 if ($3 && set_parent_node($3, $$))
1785 reparent_error(scanner, "struct reparent error");
1786 }
1787 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1788 {
1789 $$ = make_node(scanner, NODE_STRUCT);
1790 $$->u._struct.has_body = 1;
1791 $$->u._struct.name = $1->s;
1792 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1793 if ($3 && set_parent_node($3, $$))
1794 reparent_error(scanner, "struct reparent error");
1795 }
1796 ;
1797
1798 struct_declaration_begin:
1799 LBRAC
1800 { push_scope(scanner); }
1801 ;
1802
1803 struct_declaration_end:
1804 RBRAC
1805 { pop_scope(scanner); }
1806 ;
1807
1808 variant_type_specifier:
1809 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1810 {
1811 $$ = make_node(scanner, NODE_VARIANT);
1812 $$->u.variant.has_body = 1;
1813 if ($2 && set_parent_node($2, $$))
1814 reparent_error(scanner, "variant reparent error");
1815 }
1816 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1817 {
1818 $$ = make_node(scanner, NODE_VARIANT);
1819 $$->u.variant.has_body = 1;
1820 $$->u.variant.choice = $2->s;
1821 if ($5 && set_parent_node($5, $$))
1822 reparent_error(scanner, "variant reparent error");
1823 }
1824 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1825 {
1826 $$ = make_node(scanner, NODE_VARIANT);
1827 $$->u.variant.has_body = 1;
1828 $$->u.variant.choice = $2->s;
1829 if ($5 && set_parent_node($5, $$))
1830 reparent_error(scanner, "variant reparent error");
1831 }
1832 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1833 {
1834 $$ = make_node(scanner, NODE_VARIANT);
1835 $$->u.variant.has_body = 1;
1836 $$->u.variant.name = $1->s;
1837 if ($3 && set_parent_node($3, $$))
1838 reparent_error(scanner, "variant reparent error");
1839 }
1840 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1841 {
1842 $$ = make_node(scanner, NODE_VARIANT);
1843 $$->u.variant.has_body = 1;
1844 $$->u.variant.name = $1->s;
1845 $$->u.variant.choice = $3->s;
1846 if ($6 && set_parent_node($6, $$))
1847 reparent_error(scanner, "variant reparent error");
1848 }
1849 | IDENTIFIER LT IDENTIFIER GT
1850 {
1851 $$ = make_node(scanner, NODE_VARIANT);
1852 $$->u.variant.has_body = 0;
1853 $$->u.variant.name = $1->s;
1854 $$->u.variant.choice = $3->s;
1855 }
1856 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1857 {
1858 $$ = make_node(scanner, NODE_VARIANT);
1859 $$->u.variant.has_body = 1;
1860 $$->u.variant.name = $1->s;
1861 $$->u.variant.choice = $3->s;
1862 if ($6 && set_parent_node($6, $$))
1863 reparent_error(scanner, "variant reparent error");
1864 }
1865 | IDENTIFIER LT ID_TYPE GT
1866 {
1867 $$ = make_node(scanner, NODE_VARIANT);
1868 $$->u.variant.has_body = 0;
1869 $$->u.variant.name = $1->s;
1870 $$->u.variant.choice = $3->s;
1871 }
1872 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1873 {
1874 $$ = make_node(scanner, NODE_VARIANT);
1875 $$->u.variant.has_body = 1;
1876 $$->u.variant.name = $1->s;
1877 if ($3 && set_parent_node($3, $$))
1878 reparent_error(scanner, "variant reparent error");
1879 }
1880 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1881 {
1882 $$ = make_node(scanner, NODE_VARIANT);
1883 $$->u.variant.has_body = 1;
1884 $$->u.variant.name = $1->s;
1885 $$->u.variant.choice = $3->s;
1886 if ($6 && set_parent_node($6, $$))
1887 reparent_error(scanner, "variant reparent error");
1888 }
1889 | ID_TYPE LT IDENTIFIER GT
1890 {
1891 $$ = make_node(scanner, NODE_VARIANT);
1892 $$->u.variant.has_body = 0;
1893 $$->u.variant.name = $1->s;
1894 $$->u.variant.choice = $3->s;
1895 }
1896 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1897 {
1898 $$ = make_node(scanner, NODE_VARIANT);
1899 $$->u.variant.has_body = 1;
1900 $$->u.variant.name = $1->s;
1901 $$->u.variant.choice = $3->s;
1902 if ($6 && set_parent_node($6, $$))
1903 reparent_error(scanner, "variant reparent error");
1904 }
1905 | ID_TYPE LT ID_TYPE GT
1906 {
1907 $$ = make_node(scanner, NODE_VARIANT);
1908 $$->u.variant.has_body = 0;
1909 $$->u.variant.name = $1->s;
1910 $$->u.variant.choice = $3->s;
1911 }
1912 ;
1913
1914 variant_declaration_begin:
1915 LBRAC
1916 { push_scope(scanner); }
1917 ;
1918
1919 variant_declaration_end:
1920 RBRAC
1921 { pop_scope(scanner); }
1922 ;
1923
1924 enum_type_specifier:
1925 LBRAC enumerator_list RBRAC
1926 {
1927 $$ = make_node(scanner, NODE_ENUM);
1928 $$->u._enum.has_body = 1;
1929 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1930 }
1931 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1932 {
1933 $$ = make_node(scanner, NODE_ENUM);
1934 $$->u._enum.has_body = 1;
1935 ($$)->u._enum.container_type = $2;
1936 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1937 }
1938 | IDENTIFIER LBRAC enumerator_list RBRAC
1939 {
1940 $$ = make_node(scanner, NODE_ENUM);
1941 $$->u._enum.has_body = 1;
1942 $$->u._enum.enum_id = $1->s;
1943 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1944 }
1945 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1946 {
1947 $$ = make_node(scanner, NODE_ENUM);
1948 $$->u._enum.has_body = 1;
1949 $$->u._enum.enum_id = $1->s;
1950 ($$)->u._enum.container_type = $3;
1951 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1952 }
1953 | ID_TYPE LBRAC enumerator_list RBRAC
1954 {
1955 $$ = make_node(scanner, NODE_ENUM);
1956 $$->u._enum.has_body = 1;
1957 $$->u._enum.enum_id = $1->s;
1958 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1959 }
1960 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1961 {
1962 $$ = make_node(scanner, NODE_ENUM);
1963 $$->u._enum.has_body = 1;
1964 $$->u._enum.enum_id = $1->s;
1965 ($$)->u._enum.container_type = $3;
1966 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1967 }
1968 | LBRAC enumerator_list COMMA RBRAC
1969 {
1970 $$ = make_node(scanner, NODE_ENUM);
1971 $$->u._enum.has_body = 1;
1972 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1973 }
1974 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1975 {
1976 $$ = make_node(scanner, NODE_ENUM);
1977 $$->u._enum.has_body = 1;
1978 ($$)->u._enum.container_type = $2;
1979 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1980 }
1981 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1982 {
1983 $$ = make_node(scanner, NODE_ENUM);
1984 $$->u._enum.has_body = 1;
1985 $$->u._enum.enum_id = $1->s;
1986 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1987 }
1988 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1989 {
1990 $$ = make_node(scanner, NODE_ENUM);
1991 $$->u._enum.has_body = 1;
1992 $$->u._enum.enum_id = $1->s;
1993 ($$)->u._enum.container_type = $3;
1994 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1995 }
1996 | IDENTIFIER
1997 {
1998 $$ = make_node(scanner, NODE_ENUM);
1999 $$->u._enum.has_body = 0;
2000 $$->u._enum.enum_id = $1->s;
2001 }
2002 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
2003 {
2004 $$ = make_node(scanner, NODE_ENUM);
2005 $$->u._enum.has_body = 1;
2006 $$->u._enum.enum_id = $1->s;
2007 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2008 }
2009 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2010 {
2011 $$ = make_node(scanner, NODE_ENUM);
2012 $$->u._enum.has_body = 1;
2013 $$->u._enum.enum_id = $1->s;
2014 ($$)->u._enum.container_type = $3;
2015 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2016 }
2017 | ID_TYPE
2018 {
2019 $$ = make_node(scanner, NODE_ENUM);
2020 $$->u._enum.has_body = 0;
2021 $$->u._enum.enum_id = $1->s;
2022 }
2023 ;
2024
2025 struct_or_variant_declaration_list:
2026 /* empty */
2027 { $$ = NULL; }
2028 | struct_or_variant_declaration_list struct_or_variant_declaration
2029 {
2030 if ($1) {
2031 $$ = $1;
2032 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2033 } else {
2034 $$ = $2;
2035 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
2036 }
2037 }
2038 ;
2039
2040 struct_or_variant_declaration:
2041 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
2042 {
2043 struct ctf_node *list;
2044
2045 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2046 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2047 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
2048 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2049 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
2050 }
2051 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2052 {
2053 struct ctf_node *list;
2054
2055 $$ = make_node(scanner, NODE_TYPEDEF);
2056 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2057 $$->u._typedef.type_specifier_list = list;
2058 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2059 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2060 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2061 }
2062 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2063 {
2064 struct ctf_node *list;
2065
2066 $$ = make_node(scanner, NODE_TYPEDEF);
2067 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2068 $$->u._typedef.type_specifier_list = list;
2069 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2070 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2071 }
2072 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
2073 {
2074 struct ctf_node *list;
2075
2076 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2077 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2078 $$ = make_node(scanner, NODE_TYPEDEF);
2079 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2080 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2081 }
2082 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
2083 {
2084 struct ctf_node *list;
2085
2086 $$ = make_node(scanner, NODE_TYPEALIAS);
2087 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2088 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2089
2090 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2091 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2092 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2093 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2094
2095 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2096 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2097 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2098 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2099 }
2100 ;
2101
2102 alias_declaration_specifiers:
2103 CONST
2104 {
2105 struct ctf_node *node;
2106
2107 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2108 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2109 node->u.type_specifier.type = TYPESPEC_CONST;
2110 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2111 }
2112 | type_specifier
2113 {
2114 struct ctf_node *node;
2115
2116 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2117 node = $1;
2118 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2119 }
2120 | IDENTIFIER
2121 {
2122 struct ctf_node *node;
2123
2124 add_type(scanner, $1);
2125 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2126 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2127 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2128 node->u.type_specifier.id_type = yylval.gs->s;
2129 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2130 }
2131 | alias_declaration_specifiers CONST
2132 {
2133 struct ctf_node *node;
2134
2135 $$ = $1;
2136 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2137 node->u.type_specifier.type = TYPESPEC_CONST;
2138 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2139 }
2140 | alias_declaration_specifiers type_specifier
2141 {
2142 $$ = $1;
2143 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2144 }
2145 | alias_declaration_specifiers IDENTIFIER
2146 {
2147 struct ctf_node *node;
2148
2149 add_type(scanner, $2);
2150 $$ = $1;
2151 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2152 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2153 node->u.type_specifier.id_type = yylval.gs->s;
2154 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2155 }
2156 ;
2157
2158 struct_or_variant_declarator_list:
2159 struct_or_variant_declarator
2160 { $$ = $1; }
2161 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2162 {
2163 $$ = $1;
2164 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2165 }
2166 ;
2167
2168 struct_or_variant_declarator:
2169 declarator
2170 { $$ = $1; }
2171 | COLON unary_expression
2172 { $$ = $2; }
2173 | declarator COLON unary_expression
2174 {
2175 $$ = $1;
2176 if (set_parent_node($3, $1))
2177 reparent_error(scanner, "struct_or_variant_declarator");
2178 }
2179 ;
2180
2181 enumerator_list:
2182 enumerator
2183 { $$ = $1; }
2184 | enumerator_list COMMA enumerator
2185 {
2186 $$ = $1;
2187 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2188 }
2189 ;
2190
2191 enumerator:
2192 IDENTIFIER
2193 {
2194 $$ = make_node(scanner, NODE_ENUMERATOR);
2195 $$->u.enumerator.id = $1->s;
2196 }
2197 | ID_TYPE
2198 {
2199 $$ = make_node(scanner, NODE_ENUMERATOR);
2200 $$->u.enumerator.id = $1->s;
2201 }
2202 | keywords
2203 {
2204 $$ = make_node(scanner, NODE_ENUMERATOR);
2205 $$->u.enumerator.id = $1->s;
2206 }
2207 | STRING_LITERAL_START DQUOTE
2208 {
2209 $$ = make_node(scanner, NODE_ENUMERATOR);
2210 $$->u.enumerator.id = "";
2211 }
2212 | STRING_LITERAL_START s_char_sequence DQUOTE
2213 {
2214 $$ = make_node(scanner, NODE_ENUMERATOR);
2215 $$->u.enumerator.id = $2->s;
2216 }
2217 | IDENTIFIER EQUAL unary_expression_or_range
2218 {
2219 $$ = make_node(scanner, NODE_ENUMERATOR);
2220 $$->u.enumerator.id = $1->s;
2221 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2222 }
2223 | ID_TYPE EQUAL unary_expression_or_range
2224 {
2225 $$ = make_node(scanner, NODE_ENUMERATOR);
2226 $$->u.enumerator.id = $1->s;
2227 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2228 }
2229 | keywords EQUAL unary_expression_or_range
2230 {
2231 $$ = make_node(scanner, NODE_ENUMERATOR);
2232 $$->u.enumerator.id = $1->s;
2233 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2234 }
2235 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
2236 {
2237 $$ = make_node(scanner, NODE_ENUMERATOR);
2238 $$->u.enumerator.id = "";
2239 bt_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
2240 }
2241 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
2242 {
2243 $$ = make_node(scanner, NODE_ENUMERATOR);
2244 $$->u.enumerator.id = $2->s;
2245 bt_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
2246 }
2247 ;
2248
2249 abstract_declarator_list:
2250 abstract_declarator
2251 { $$ = $1; }
2252 | abstract_declarator_list COMMA abstract_declarator
2253 {
2254 $$ = $1;
2255 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2256 }
2257 ;
2258
2259 abstract_declarator:
2260 direct_abstract_declarator
2261 { $$ = $1; }
2262 | pointer direct_abstract_declarator
2263 {
2264 $$ = $2;
2265 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2266 }
2267 ;
2268
2269 direct_abstract_declarator:
2270 /* empty */
2271 {
2272 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2273 $$->u.type_declarator.type = TYPEDEC_ID;
2274 /* id is NULL */
2275 }
2276 | IDENTIFIER
2277 {
2278 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2279 $$->u.type_declarator.type = TYPEDEC_ID;
2280 $$->u.type_declarator.u.id = $1->s;
2281 }
2282 | LPAREN abstract_declarator RPAREN
2283 {
2284 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2285 $$->u.type_declarator.type = TYPEDEC_NESTED;
2286 $$->u.type_declarator.u.nested.type_declarator = $2;
2287 }
2288 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2289 {
2290 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2291 $$->u.type_declarator.type = TYPEDEC_NESTED;
2292 $$->u.type_declarator.u.nested.type_declarator = $1;
2293 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2294 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2295 }
2296 | direct_abstract_declarator LSBRAC RSBRAC
2297 {
2298 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2299 $$->u.type_declarator.type = TYPEDEC_NESTED;
2300 $$->u.type_declarator.u.nested.type_declarator = $1;
2301 $$->u.type_declarator.u.nested.abstract_array = 1;
2302 }
2303 ;
2304
2305 alias_abstract_declarator_list:
2306 alias_abstract_declarator
2307 { $$ = $1; }
2308 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2309 {
2310 $$ = $1;
2311 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2312 }
2313 ;
2314
2315 alias_abstract_declarator:
2316 direct_alias_abstract_declarator
2317 { $$ = $1; }
2318 | pointer direct_alias_abstract_declarator
2319 {
2320 $$ = $2;
2321 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2322 }
2323 ;
2324
2325 direct_alias_abstract_declarator:
2326 /* empty */
2327 {
2328 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2329 $$->u.type_declarator.type = TYPEDEC_ID;
2330 /* id is NULL */
2331 }
2332 | LPAREN alias_abstract_declarator RPAREN
2333 {
2334 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2335 $$->u.type_declarator.type = TYPEDEC_NESTED;
2336 $$->u.type_declarator.u.nested.type_declarator = $2;
2337 }
2338 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2339 {
2340 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2341 $$->u.type_declarator.type = TYPEDEC_NESTED;
2342 $$->u.type_declarator.u.nested.type_declarator = $1;
2343 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2344 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2345 }
2346 | direct_alias_abstract_declarator LSBRAC RSBRAC
2347 {
2348 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2349 $$->u.type_declarator.type = TYPEDEC_NESTED;
2350 $$->u.type_declarator.u.nested.type_declarator = $1;
2351 $$->u.type_declarator.u.nested.abstract_array = 1;
2352 }
2353 ;
2354
2355 declarator:
2356 direct_declarator
2357 { $$ = $1; }
2358 | pointer direct_declarator
2359 {
2360 $$ = $2;
2361 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2362 }
2363 ;
2364
2365 direct_declarator:
2366 IDENTIFIER
2367 {
2368 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2369 $$->u.type_declarator.type = TYPEDEC_ID;
2370 $$->u.type_declarator.u.id = $1->s;
2371 }
2372 | LPAREN declarator RPAREN
2373 {
2374 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2375 $$->u.type_declarator.type = TYPEDEC_NESTED;
2376 $$->u.type_declarator.u.nested.type_declarator = $2;
2377 }
2378 | direct_declarator LSBRAC unary_expression RSBRAC
2379 {
2380 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2381 $$->u.type_declarator.type = TYPEDEC_NESTED;
2382 $$->u.type_declarator.u.nested.type_declarator = $1;
2383 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2384 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2385 }
2386 ;
2387
2388 type_declarator:
2389 direct_type_declarator
2390 { $$ = $1; }
2391 | pointer direct_type_declarator
2392 {
2393 $$ = $2;
2394 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2395 }
2396 ;
2397
2398 direct_type_declarator:
2399 IDENTIFIER
2400 {
2401 add_type(scanner, $1);
2402 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2403 $$->u.type_declarator.type = TYPEDEC_ID;
2404 $$->u.type_declarator.u.id = $1->s;
2405 }
2406 | LPAREN type_declarator RPAREN
2407 {
2408 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2409 $$->u.type_declarator.type = TYPEDEC_NESTED;
2410 $$->u.type_declarator.u.nested.type_declarator = $2;
2411 }
2412 | direct_type_declarator LSBRAC unary_expression RSBRAC
2413 {
2414 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2415 $$->u.type_declarator.type = TYPEDEC_NESTED;
2416 $$->u.type_declarator.u.nested.type_declarator = $1;
2417 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2418 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2419 }
2420 ;
2421
2422 pointer:
2423 STAR
2424 {
2425 $$ = make_node(scanner, NODE_POINTER);
2426 }
2427 | STAR pointer
2428 {
2429 $$ = make_node(scanner, NODE_POINTER);
2430 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2431 }
2432 | STAR type_qualifier_list pointer
2433 {
2434 $$ = make_node(scanner, NODE_POINTER);
2435 $$->u.pointer.const_qualifier = 1;
2436 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2437 }
2438 ;
2439
2440 type_qualifier_list:
2441 /* pointer assumes only const type qualifier */
2442 CONST
2443 | type_qualifier_list CONST
2444 ;
2445
2446 /* 2.3: CTF-specific declarations */
2447
2448 ctf_assignment_expression_list:
2449 ctf_assignment_expression SEMICOLON
2450 { $$ = $1; }
2451 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2452 {
2453 $$ = $1;
2454 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2455 }
2456 ;
2457
2458 ctf_assignment_expression:
2459 unary_expression EQUAL unary_expression
2460 {
2461 /*
2462 * Because we have left and right, cannot use
2463 * set_parent_node.
2464 */
2465 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2466 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2467 if ($1->u.unary_expression.type != UNARY_STRING)
2468 reparent_error(scanner, "ctf_assignment_expression left expects string");
2469 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2470 }
2471 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2472 {
2473 /*
2474 * Because we have left and right, cannot use
2475 * set_parent_node.
2476 */
2477 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2478 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2479 if ($1->u.unary_expression.type != UNARY_STRING)
2480 reparent_error(scanner, "ctf_assignment_expression left expects string");
2481 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2482 }
2483 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2484 {
2485 struct ctf_node *list;
2486
2487 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2488 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2489 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2490 $$ = make_node(scanner, NODE_TYPEDEF);
2491 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2492 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2493 }
2494 | TYPEDEF declaration_specifiers type_declarator_list
2495 {
2496 struct ctf_node *list;
2497
2498 $$ = make_node(scanner, NODE_TYPEDEF);
2499 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2500 $$->u._typedef.type_specifier_list = list;
2501 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2502 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2503 }
2504 | declaration_specifiers TYPEDEF type_declarator_list
2505 {
2506 struct ctf_node *list;
2507
2508 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2509 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2510 $$ = make_node(scanner, NODE_TYPEDEF);
2511 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2512 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2513 }
2514 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2515 {
2516 struct ctf_node *list;
2517
2518 $$ = make_node(scanner, NODE_TYPEALIAS);
2519 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2520 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2521
2522 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2523 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2524 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2525 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2526
2527 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2528 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2529 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2530 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2531 }
2532 ;
This page took 0.112351 seconds and 4 git commands to generate.