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