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