5 * Common Trace Format Metadata Grammar.
7 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
28 #include <babeltrace/list.h>
29 #include <babeltrace/babeltrace-internal.h>
30 #include "ctf-scanner.h"
31 #include "ctf-parser.h"
36 /* Join two lists, put "add" at the end of "head". */
38 _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
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;
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);
58 struct bt_list_head gc;
63 static const char *node_type_to_str[] = {
64 [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
65 [ NODE_ROOT ] = "NODE_ROOT",
66 [ NODE_EVENT ] = "NODE_EVENT",
67 [ NODE_ENV ] = "NODE_ENV",
68 [ NODE_STREAM ] = "NODE_STREAM",
69 [ NODE_TRACE ] = "NODE_TRACE",
70 [ NODE_CLOCK ] = "NODE_CLOCK",
71 [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
72 [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
73 [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
74 [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
75 [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
76 [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
77 [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
78 [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
79 [ NODE_POINTER ] = "NODE_POINTER",
80 [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
81 [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
82 [ NODE_INTEGER ] = "NODE_INTEGER",
83 [ NODE_STRING ] = "NODE_STRING",
84 [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
85 [ NODE_ENUM ] = "NODE_ENUM",
86 [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
87 [ NODE_VARIANT ] = "NODE_VARIANT",
88 [ NODE_STRUCT ] = "NODE_STRUCT",
91 const char *node_type(struct ctf_node *node)
93 if (node->type < NR_NODE_TYPES)
94 return node_type_to_str[node->type];
99 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
102 struct gc_string *gstr;
105 /* TODO: could be faster with find first bit or glib Gstring */
106 /* sizeof long to account for malloc header (int or long ?) */
107 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
110 gstr = malloc(alloclen);
111 bt_list_add(&gstr->gc, &scanner->allocated_strings);
112 gstr->alloclen = alloclen;
117 * note: never use gc_string_append on a string that has external references.
118 * gsrc will be garbage collected immediately, and gstr might be.
119 * Should only be used to append characters to a string literal or constant.
121 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
122 struct gc_string *gstr,
123 struct gc_string *gsrc)
125 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
128 /* TODO: could be faster with find first bit or glib Gstring */
129 /* sizeof long to account for malloc header (int or long ?) */
130 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
133 if (alloclen > gstr->alloclen) {
134 struct gc_string *newgstr;
136 newgstr = gc_string_alloc(scanner, newlen);
137 strcpy(newgstr->s, gstr->s);
138 strcat(newgstr->s, gsrc->s);
139 bt_list_del(&gstr->gc);
143 strcat(gstr->s, gsrc->s);
145 bt_list_del(&gsrc->gc);
150 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
152 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
153 strcpy(lvalp->gs->s, src);
156 static void init_scope(struct ctf_scanner_scope *scope,
157 struct ctf_scanner_scope *parent)
159 scope->parent = parent;
160 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
164 static void finalize_scope(struct ctf_scanner_scope *scope)
166 g_hash_table_destroy(scope->types);
169 static void push_scope(struct ctf_scanner *scanner)
171 struct ctf_scanner_scope *ns;
173 printf_debug("push scope\n");
174 ns = malloc(sizeof(struct ctf_scanner_scope));
175 init_scope(ns, scanner->cs);
179 static void pop_scope(struct ctf_scanner *scanner)
181 struct ctf_scanner_scope *os;
183 printf_debug("pop scope\n");
185 scanner->cs = os->parent;
190 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
194 ret = (int) (long) g_hash_table_lookup(s->types, id);
195 printf_debug("lookup %p %s %d\n", s, id, ret);
199 int is_type(struct ctf_scanner *scanner, const char *id)
201 struct ctf_scanner_scope *it;
204 for (it = scanner->cs; it != NULL; it = it->parent) {
205 if (lookup_type(it, id)) {
210 printf_debug("is type %s %d\n", id, ret);
214 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
216 printf_debug("add type %s\n", id->s);
217 if (lookup_type(scanner->cs, id->s))
219 g_hash_table_insert(scanner->cs->types, id->s, id->s);
222 static struct ctf_node *make_node(struct ctf_scanner *scanner,
225 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
226 struct ctf_node *node;
228 node = malloc(sizeof(*node));
231 memset(node, 0, sizeof(*node));
233 BT_INIT_LIST_HEAD(&node->tmp_head);
234 bt_list_add(&node->gc, &ast->allocated_nodes);
235 bt_list_add(&node->siblings, &node->tmp_head);
239 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
243 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
246 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
249 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
252 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
255 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
258 case NODE_CTF_EXPRESSION:
259 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
260 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
262 case NODE_UNARY_EXPRESSION:
266 BT_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
268 case NODE_TYPEALIAS_TARGET:
269 BT_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
271 case NODE_TYPEALIAS_ALIAS:
272 BT_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
277 case NODE_TYPE_SPECIFIER:
279 case NODE_TYPE_SPECIFIER_LIST:
280 BT_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
284 case NODE_TYPE_DECLARATOR:
285 BT_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
288 case NODE_FLOATING_POINT:
289 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
292 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
295 BT_INIT_LIST_HEAD(&node->u.string.expressions);
297 case NODE_ENUMERATOR:
298 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
301 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
303 case NODE_STRUCT_OR_VARIANT_DECLARATION:
304 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
307 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
310 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
311 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
316 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
324 static int reparent_ctf_expression(struct ctf_node *node,
325 struct ctf_node *parent)
327 switch (parent->type) {
329 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
332 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
335 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
338 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
341 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
343 case NODE_FLOATING_POINT:
344 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
347 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
350 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
354 case NODE_CTF_EXPRESSION:
356 case NODE_TYPEALIAS_TARGET:
357 case NODE_TYPEALIAS_ALIAS:
359 case NODE_TYPE_SPECIFIER:
360 case NODE_TYPE_SPECIFIER_LIST:
362 case NODE_TYPE_DECLARATOR:
363 case NODE_ENUMERATOR:
365 case NODE_STRUCT_OR_VARIANT_DECLARATION:
368 case NODE_UNARY_EXPRESSION:
373 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
380 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
382 switch (parent->type) {
384 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
387 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
390 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
393 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
396 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
399 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
402 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
405 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
408 case NODE_FLOATING_POINT:
411 case NODE_CTF_EXPRESSION:
413 case NODE_TYPEALIAS_TARGET:
414 case NODE_TYPEALIAS_ALIAS:
416 case NODE_TYPE_SPECIFIER:
417 case NODE_TYPE_SPECIFIER_LIST:
419 case NODE_TYPE_DECLARATOR:
420 case NODE_ENUMERATOR:
422 case NODE_STRUCT_OR_VARIANT_DECLARATION:
423 case NODE_UNARY_EXPRESSION:
428 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
435 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
437 switch (parent->type) {
439 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
442 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
445 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
448 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
451 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
454 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
457 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
460 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
463 case NODE_FLOATING_POINT:
466 case NODE_CTF_EXPRESSION:
468 case NODE_TYPEALIAS_TARGET:
469 case NODE_TYPEALIAS_ALIAS:
471 case NODE_TYPE_SPECIFIER:
472 case NODE_TYPE_SPECIFIER_LIST:
474 case NODE_TYPE_DECLARATOR:
475 case NODE_ENUMERATOR:
477 case NODE_STRUCT_OR_VARIANT_DECLARATION:
478 case NODE_UNARY_EXPRESSION:
483 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
490 static int reparent_type_specifier(struct ctf_node *node,
491 struct ctf_node *parent)
493 switch (parent->type) {
494 case NODE_TYPE_SPECIFIER_LIST:
495 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
498 case NODE_TYPE_SPECIFIER:
507 case NODE_TYPEALIAS_TARGET:
508 case NODE_TYPEALIAS_ALIAS:
509 case NODE_TYPE_DECLARATOR:
511 case NODE_STRUCT_OR_VARIANT_DECLARATION:
513 case NODE_FLOATING_POINT:
516 case NODE_CTF_EXPRESSION:
518 case NODE_ENUMERATOR:
519 case NODE_UNARY_EXPRESSION:
524 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
531 static int reparent_type_specifier_list(struct ctf_node *node,
532 struct ctf_node *parent)
534 switch (parent->type) {
536 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
539 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
542 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
545 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
548 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
551 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
554 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
557 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
560 parent->u._typedef.type_specifier_list = node;
562 case NODE_TYPEALIAS_TARGET:
563 parent->u.typealias_target.type_specifier_list = node;
565 case NODE_TYPEALIAS_ALIAS:
566 parent->u.typealias_alias.type_specifier_list = node;
569 parent->u._enum.container_type = node;
571 case NODE_STRUCT_OR_VARIANT_DECLARATION:
572 parent->u.struct_or_variant_declaration.type_specifier_list = node;
574 case NODE_TYPE_DECLARATOR:
575 case NODE_TYPE_SPECIFIER:
577 case NODE_FLOATING_POINT:
580 case NODE_CTF_EXPRESSION:
582 case NODE_ENUMERATOR:
583 case NODE_UNARY_EXPRESSION:
588 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
595 static int reparent_type_declarator(struct ctf_node *node,
596 struct ctf_node *parent)
598 switch (parent->type) {
599 case NODE_TYPE_DECLARATOR:
600 parent->u.type_declarator.type = TYPEDEC_NESTED;
601 parent->u.type_declarator.u.nested.type_declarator = node;
603 case NODE_STRUCT_OR_VARIANT_DECLARATION:
604 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
607 _bt_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
609 case NODE_TYPEALIAS_TARGET:
610 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
612 case NODE_TYPEALIAS_ALIAS:
613 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
626 case NODE_FLOATING_POINT:
629 case NODE_CTF_EXPRESSION:
630 case NODE_TYPE_SPECIFIER:
631 case NODE_TYPE_SPECIFIER_LIST:
633 case NODE_ENUMERATOR:
634 case NODE_UNARY_EXPRESSION:
639 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
649 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
650 * create the link declared by the input, -ENOENT if node or parent is NULL,
651 * -EINVAL if there is an internal structure problem.
653 static int set_parent_node(struct ctf_node *node,
654 struct ctf_node *parent)
656 if (!node || !parent)
659 /* Note: Linking to parent will be done only by an external visitor */
661 switch (node->type) {
663 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
667 if (parent->type == NODE_ROOT) {
668 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
674 if (parent->type == NODE_ROOT) {
675 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
681 if (parent->type == NODE_ROOT) {
682 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
688 if (parent->type == NODE_ROOT) {
689 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
695 if (parent->type == NODE_ROOT) {
696 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
702 case NODE_CTF_EXPRESSION:
703 return reparent_ctf_expression(node, parent);
704 case NODE_UNARY_EXPRESSION:
705 if (parent->type == NODE_TYPE_DECLARATOR)
706 parent->u.type_declarator.bitfield_len = node;
712 return reparent_typedef(node, parent);
713 case NODE_TYPEALIAS_TARGET:
714 if (parent->type == NODE_TYPEALIAS)
715 parent->u.typealias.target = node;
718 case NODE_TYPEALIAS_ALIAS:
719 if (parent->type == NODE_TYPEALIAS)
720 parent->u.typealias.alias = node;
724 return reparent_typealias(node, parent);
727 if (parent->type == NODE_TYPE_DECLARATOR) {
728 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
732 case NODE_TYPE_DECLARATOR:
733 return reparent_type_declarator(node, parent);
735 case NODE_TYPE_SPECIFIER_LIST:
736 return reparent_type_specifier_list(node, parent);
738 case NODE_TYPE_SPECIFIER:
739 return reparent_type_specifier(node, parent);
741 case NODE_FLOATING_POINT:
747 return -EINVAL; /* Dealt with internally within grammar */
749 case NODE_ENUMERATOR:
750 if (parent->type == NODE_ENUM) {
751 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
756 case NODE_STRUCT_OR_VARIANT_DECLARATION:
757 switch (parent->type) {
759 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
762 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
771 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
778 void yyerror(struct ctf_scanner *scanner, const char *str)
780 fprintf(stderr, "error %s\n", str);
788 #define reparent_error(scanner, str) \
790 yyerror(scanner, YY_("reparent_error: " str "\n")); \
794 static void free_strings(struct bt_list_head *list)
796 struct gc_string *gstr, *tmp;
798 bt_list_for_each_entry_safe(gstr, tmp, list, gc)
802 static struct ctf_ast *ctf_ast_alloc(void)
806 ast = malloc(sizeof(*ast));
809 memset(ast, 0, sizeof(*ast));
810 BT_INIT_LIST_HEAD(&ast->allocated_nodes);
811 ast->root.type = NODE_ROOT;
812 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
813 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
814 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
815 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
816 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
817 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
818 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
822 static void ctf_ast_free(struct ctf_ast *ast)
824 struct ctf_node *node, *tmp;
826 bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
830 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
832 return yyparse(scanner);
835 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
837 struct ctf_scanner *scanner;
840 yydebug = babeltrace_debug;
842 scanner = malloc(sizeof(*scanner));
845 memset(scanner, 0, sizeof(*scanner));
847 ret = yylex_init_extra(scanner, &scanner->scanner);
849 fprintf(stderr, "yylex_init error\n");
850 goto cleanup_scanner;
852 /* Start processing new stream */
853 yyrestart(input, scanner->scanner);
855 scanner->ast = ctf_ast_alloc();
858 init_scope(&scanner->root_scope, NULL);
859 scanner->cs = &scanner->root_scope;
860 BT_INIT_LIST_HEAD(&scanner->allocated_strings);
863 fprintf(stdout, "Scanner input is a%s.\n",
864 isatty(fileno(input)) ? "n interactive tty" :
865 " noninteractive file");
870 ret = yylex_destroy(scanner->scanner);
872 fprintf(stderr, "yylex_destroy error\n");
878 void ctf_scanner_free(struct ctf_scanner *scanner)
882 finalize_scope(&scanner->root_scope);
883 free_strings(&scanner->allocated_strings);
884 ctf_ast_free(scanner->ast);
885 ret = yylex_destroy(scanner->scanner);
887 fprintf(stderr, "yylex_destroy error\n");
895 %parse-param {struct ctf_scanner *scanner}
896 %lex-param {struct ctf_scanner *scanner}
898 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
899 * vs struct { int :value; } (unnamed bit-field). The default is to
900 * shift, so whenever we encounter an enumeration, we are doing the
901 * proper thing (shift). It is illegal to declare an enumeration
902 * "bit-field", so it is OK if this situation ends up in a parsing
907 %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
908 %token <gs> IDENTIFIER ID_TYPE
914 struct gc_string *gs;
919 %type <gs> s_char s_char_sequence c_char c_char_sequence
921 %type <n> postfix_expression unary_expression unary_expression_or_range
923 %type <n> declaration
924 %type <n> event_declaration
925 %type <n> stream_declaration
926 %type <n> env_declaration
927 %type <n> trace_declaration
928 %type <n> clock_declaration
929 %type <n> integer_declaration_specifiers
930 %type <n> declaration_specifiers
931 %type <n> alias_declaration_specifiers
933 %type <n> type_declarator_list
934 %type <n> integer_type_specifier
935 %type <n> type_specifier
936 %type <n> struct_type_specifier
937 %type <n> variant_type_specifier
938 %type <n> enum_type_specifier
939 %type <n> struct_or_variant_declaration_list
940 %type <n> struct_or_variant_declaration
941 %type <n> struct_or_variant_declarator_list
942 %type <n> struct_or_variant_declarator
943 %type <n> enumerator_list
945 %type <n> abstract_declarator_list
946 %type <n> abstract_declarator
947 %type <n> direct_abstract_declarator
948 %type <n> alias_abstract_declarator_list
949 %type <n> alias_abstract_declarator
950 %type <n> direct_alias_abstract_declarator
952 %type <n> direct_declarator
953 %type <n> type_declarator
954 %type <n> direct_type_declarator
956 %type <n> ctf_assignment_expression_list
957 %type <n> ctf_assignment_expression
964 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
965 reparent_error(scanner, "error reparenting to root");
969 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
970 reparent_error(scanner, "error reparenting to root");
1034 | c_char_sequence c_char
1035 { $$ = gc_string_append(scanner, $1, $2); }
1043 reparent_error(scanner, "escape sequences not supported yet");
1047 /* 1.6 String literals */
1052 | s_char_sequence s_char
1053 { $$ = gc_string_append(scanner, $1, $2); }
1061 reparent_error(scanner, "escape sequences not supported yet");
1065 /* 2: Phrase structure grammar */
1070 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1071 $$->u.unary_expression.type = UNARY_STRING;
1072 $$->u.unary_expression.u.string = yylval.gs->s;
1076 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1077 $$->u.unary_expression.type = UNARY_STRING;
1078 $$->u.unary_expression.u.string = yylval.gs->s;
1082 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1083 $$->u.unary_expression.type = UNARY_STRING;
1084 $$->u.unary_expression.u.string = yylval.gs->s;
1088 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1089 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1090 sscanf(yylval.gs->s, "%" PRIu64,
1091 &$$->u.unary_expression.u.unsigned_constant);
1095 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1096 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1097 sscanf(yylval.gs->s, "0%" PRIo64,
1098 &$$->u.unary_expression.u.unsigned_constant);
1100 | HEXADECIMAL_CONSTANT
1102 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1103 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1104 sscanf(yylval.gs->s, "0x%" PRIx64,
1105 &$$->u.unary_expression.u.unsigned_constant);
1107 | STRING_LITERAL_START DQUOTE
1109 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1110 $$->u.unary_expression.type = UNARY_STRING;
1111 $$->u.unary_expression.u.string = "";
1113 | STRING_LITERAL_START s_char_sequence DQUOTE
1115 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1116 $$->u.unary_expression.type = UNARY_STRING;
1117 $$->u.unary_expression.u.string = $2->s;
1119 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1121 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1122 $$->u.unary_expression.type = UNARY_STRING;
1123 $$->u.unary_expression.u.string = $2->s;
1125 | LPAREN unary_expression RPAREN
1127 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1128 $$->u.unary_expression.type = UNARY_NESTED;
1129 $$->u.unary_expression.u.nested_exp = $2;
1131 | postfix_expression LSBRAC unary_expression RSBRAC
1133 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1134 $$->u.unary_expression.type = UNARY_SBRAC;
1135 $$->u.unary_expression.u.sbrac_exp = $3;
1136 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1137 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1139 | postfix_expression DOT IDENTIFIER
1141 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1142 $$->u.unary_expression.type = UNARY_STRING;
1143 $$->u.unary_expression.u.string = yylval.gs->s;
1144 $$->u.unary_expression.link = UNARY_DOTLINK;
1145 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1146 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1148 | postfix_expression DOT ID_TYPE
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);
1157 | postfix_expression RARROW IDENTIFIER
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_ARROWLINK;
1163 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1164 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1166 | postfix_expression RARROW ID_TYPE
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);
1180 | PLUS postfix_expression
1182 | MINUS postfix_expression
1185 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1186 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1187 reparent_error(scanner, "expecting numeric constant");
1189 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1190 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1191 $$->u.unary_expression.u.signed_constant =
1192 -($$->u.unary_expression.u.unsigned_constant);
1194 $$->u.unary_expression.u.signed_constant =
1195 -($$->u.unary_expression.u.signed_constant);
1200 unary_expression_or_range:
1201 unary_expression DOTDOTDOT unary_expression
1204 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1205 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1211 /* 2.2: Declarations */
1214 declaration_specifiers SEMICOLON
1218 | stream_declaration
1226 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1228 struct ctf_node *list;
1230 $$ = make_node(scanner, NODE_TYPEDEF);
1231 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1232 $$->u._typedef.type_specifier_list = list;
1233 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1234 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1235 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1237 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1239 struct ctf_node *list;
1241 $$ = make_node(scanner, NODE_TYPEDEF);
1242 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1243 $$->u._typedef.type_specifier_list = list;
1244 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1245 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1247 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1249 struct ctf_node *list;
1251 $$ = make_node(scanner, NODE_TYPEDEF);
1252 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1253 $$->u._typedef.type_specifier_list = list;
1254 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1255 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1257 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1259 struct ctf_node *list;
1261 $$ = make_node(scanner, NODE_TYPEALIAS);
1262 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1263 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1265 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1266 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1267 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1268 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1270 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1271 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1272 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1273 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1278 event_declaration_begin event_declaration_end
1280 $$ = make_node(scanner, NODE_EVENT);
1282 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1284 $$ = make_node(scanner, NODE_EVENT);
1285 if (set_parent_node($2, $$))
1286 reparent_error(scanner, "event_declaration");
1290 event_declaration_begin:
1292 { push_scope(scanner); }
1295 event_declaration_end:
1297 { pop_scope(scanner); }
1302 stream_declaration_begin stream_declaration_end
1304 $$ = make_node(scanner, NODE_STREAM);
1306 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1308 $$ = make_node(scanner, NODE_STREAM);
1309 if (set_parent_node($2, $$))
1310 reparent_error(scanner, "stream_declaration");
1314 stream_declaration_begin:
1316 { push_scope(scanner); }
1319 stream_declaration_end:
1321 { pop_scope(scanner); }
1325 env_declaration_begin env_declaration_end
1327 $$ = make_node(scanner, NODE_ENV);
1329 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1331 $$ = make_node(scanner, NODE_ENV);
1332 if (set_parent_node($2, $$))
1333 reparent_error(scanner, "env declaration");
1337 env_declaration_begin:
1339 { push_scope(scanner); }
1342 env_declaration_end:
1344 { pop_scope(scanner); }
1348 trace_declaration_begin trace_declaration_end
1350 $$ = make_node(scanner, NODE_TRACE);
1352 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1354 $$ = make_node(scanner, NODE_TRACE);
1355 if (set_parent_node($2, $$))
1356 reparent_error(scanner, "trace_declaration");
1360 trace_declaration_begin:
1362 { push_scope(scanner); }
1365 trace_declaration_end:
1367 { pop_scope(scanner); }
1371 CLOCK clock_declaration_begin clock_declaration_end
1373 $$ = make_node(scanner, NODE_CLOCK);
1375 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1377 $$ = make_node(scanner, NODE_CLOCK);
1378 if (set_parent_node($3, $$))
1379 reparent_error(scanner, "trace_declaration");
1383 clock_declaration_begin:
1385 { push_scope(scanner); }
1388 clock_declaration_end:
1390 { pop_scope(scanner); }
1393 integer_declaration_specifiers:
1396 struct ctf_node *node;
1398 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1399 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1400 node->u.type_specifier.type = TYPESPEC_CONST;
1401 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1403 | integer_type_specifier
1405 struct ctf_node *node;
1407 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1409 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1411 | integer_declaration_specifiers CONST
1413 struct ctf_node *node;
1416 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1417 node->u.type_specifier.type = TYPESPEC_CONST;
1418 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1420 | integer_declaration_specifiers integer_type_specifier
1423 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1427 declaration_specifiers:
1430 struct ctf_node *node;
1432 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1433 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1434 node->u.type_specifier.type = TYPESPEC_CONST;
1435 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1439 struct ctf_node *node;
1441 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1443 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1445 | declaration_specifiers CONST
1447 struct ctf_node *node;
1450 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1451 node->u.type_specifier.type = TYPESPEC_CONST;
1452 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1454 | declaration_specifiers type_specifier
1457 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1461 type_declarator_list:
1464 | type_declarator_list COMMA type_declarator
1467 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1471 integer_type_specifier:
1474 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1475 $$->u.type_specifier.type = TYPESPEC_CHAR;
1479 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1480 $$->u.type_specifier.type = TYPESPEC_SHORT;
1484 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1485 $$->u.type_specifier.type = TYPESPEC_INT;
1489 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1490 $$->u.type_specifier.type = TYPESPEC_LONG;
1494 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1495 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1499 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1500 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1504 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1505 $$->u.type_specifier.type = TYPESPEC_BOOL;
1509 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1510 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1511 $$->u.type_specifier.id_type = yylval.gs->s;
1513 | INTEGER LBRAC RBRAC
1515 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1516 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1517 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1519 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1521 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1522 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1523 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1524 if (set_parent_node($3, $$->u.type_specifier.node))
1525 reparent_error(scanner, "integer reparent error");
1532 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1533 $$->u.type_specifier.type = TYPESPEC_VOID;
1537 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1538 $$->u.type_specifier.type = TYPESPEC_CHAR;
1542 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1543 $$->u.type_specifier.type = TYPESPEC_SHORT;
1547 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1548 $$->u.type_specifier.type = TYPESPEC_INT;
1552 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1553 $$->u.type_specifier.type = TYPESPEC_LONG;
1557 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1558 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1562 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1563 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1567 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1568 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1572 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1573 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1577 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1578 $$->u.type_specifier.type = TYPESPEC_BOOL;
1582 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1583 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1587 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1588 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1592 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1593 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1594 $$->u.type_specifier.id_type = yylval.gs->s;
1596 | FLOATING_POINT LBRAC RBRAC
1598 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1599 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1600 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1602 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1604 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1605 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1606 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1607 if (set_parent_node($3, $$->u.type_specifier.node))
1608 reparent_error(scanner, "floating point reparent error");
1610 | INTEGER LBRAC RBRAC
1612 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1613 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1614 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1616 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1618 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1619 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1620 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1621 if (set_parent_node($3, $$->u.type_specifier.node))
1622 reparent_error(scanner, "integer reparent error");
1626 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1627 $$->u.type_specifier.type = TYPESPEC_STRING;
1628 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1630 | STRING LBRAC RBRAC
1632 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1633 $$->u.type_specifier.type = TYPESPEC_STRING;
1634 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1636 | STRING LBRAC ctf_assignment_expression_list RBRAC
1638 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1639 $$->u.type_specifier.type = TYPESPEC_STRING;
1640 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1641 if (set_parent_node($3, $$->u.type_specifier.node))
1642 reparent_error(scanner, "string reparent error");
1644 | ENUM enum_type_specifier
1646 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1647 $$->u.type_specifier.type = TYPESPEC_ENUM;
1648 $$->u.type_specifier.node = $2;
1650 | VARIANT variant_type_specifier
1652 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1653 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1654 $$->u.type_specifier.node = $2;
1656 | STRUCT struct_type_specifier
1658 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1659 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1660 $$->u.type_specifier.node = $2;
1664 struct_type_specifier:
1665 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1667 $$ = make_node(scanner, NODE_STRUCT);
1668 $$->u._struct.has_body = 1;
1669 if ($2 && set_parent_node($2, $$))
1670 reparent_error(scanner, "struct reparent error");
1672 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1674 $$ = make_node(scanner, NODE_STRUCT);
1675 $$->u._struct.has_body = 1;
1676 $$->u._struct.name = $1->s;
1677 if ($3 && set_parent_node($3, $$))
1678 reparent_error(scanner, "struct reparent error");
1680 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1682 $$ = make_node(scanner, NODE_STRUCT);
1683 $$->u._struct.has_body = 1;
1684 $$->u._struct.name = $1->s;
1685 if ($3 && set_parent_node($3, $$))
1686 reparent_error(scanner, "struct reparent error");
1690 $$ = make_node(scanner, NODE_STRUCT);
1691 $$->u._struct.has_body = 0;
1692 $$->u._struct.name = $1->s;
1696 $$ = make_node(scanner, NODE_STRUCT);
1697 $$->u._struct.has_body = 0;
1698 $$->u._struct.name = $1->s;
1700 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1702 $$ = make_node(scanner, NODE_STRUCT);
1703 $$->u._struct.has_body = 1;
1704 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1705 if ($2 && set_parent_node($2, $$))
1706 reparent_error(scanner, "struct reparent error");
1708 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1710 $$ = make_node(scanner, NODE_STRUCT);
1711 $$->u._struct.has_body = 1;
1712 $$->u._struct.name = $1->s;
1713 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1714 if ($3 && set_parent_node($3, $$))
1715 reparent_error(scanner, "struct reparent error");
1717 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
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");
1728 struct_declaration_begin:
1730 { push_scope(scanner); }
1733 struct_declaration_end:
1735 { pop_scope(scanner); }
1738 variant_type_specifier:
1739 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1741 $$ = make_node(scanner, NODE_VARIANT);
1742 $$->u.variant.has_body = 1;
1743 if ($2 && set_parent_node($2, $$))
1744 reparent_error(scanner, "variant reparent error");
1746 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1748 $$ = make_node(scanner, NODE_VARIANT);
1749 $$->u.variant.has_body = 1;
1750 $$->u.variant.choice = $2->s;
1751 if ($5 && set_parent_node($5, $$))
1752 reparent_error(scanner, "variant reparent error");
1754 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1756 $$ = make_node(scanner, NODE_VARIANT);
1757 $$->u.variant.has_body = 1;
1758 $$->u.variant.choice = $2->s;
1759 if ($5 && set_parent_node($5, $$))
1760 reparent_error(scanner, "variant reparent error");
1762 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1764 $$ = make_node(scanner, NODE_VARIANT);
1765 $$->u.variant.has_body = 1;
1766 $$->u.variant.name = $1->s;
1767 if ($3 && set_parent_node($3, $$))
1768 reparent_error(scanner, "variant reparent error");
1770 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1772 $$ = make_node(scanner, NODE_VARIANT);
1773 $$->u.variant.has_body = 1;
1774 $$->u.variant.name = $1->s;
1775 $$->u.variant.choice = $3->s;
1776 if ($6 && set_parent_node($6, $$))
1777 reparent_error(scanner, "variant reparent error");
1779 | IDENTIFIER LT IDENTIFIER GT
1781 $$ = make_node(scanner, NODE_VARIANT);
1782 $$->u.variant.has_body = 0;
1783 $$->u.variant.name = $1->s;
1784 $$->u.variant.choice = $3->s;
1786 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1788 $$ = make_node(scanner, NODE_VARIANT);
1789 $$->u.variant.has_body = 1;
1790 $$->u.variant.name = $1->s;
1791 $$->u.variant.choice = $3->s;
1792 if ($6 && set_parent_node($6, $$))
1793 reparent_error(scanner, "variant reparent error");
1795 | IDENTIFIER LT ID_TYPE GT
1797 $$ = make_node(scanner, NODE_VARIANT);
1798 $$->u.variant.has_body = 0;
1799 $$->u.variant.name = $1->s;
1800 $$->u.variant.choice = $3->s;
1802 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1804 $$ = make_node(scanner, NODE_VARIANT);
1805 $$->u.variant.has_body = 1;
1806 $$->u.variant.name = $1->s;
1807 if ($3 && set_parent_node($3, $$))
1808 reparent_error(scanner, "variant reparent error");
1810 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1812 $$ = make_node(scanner, NODE_VARIANT);
1813 $$->u.variant.has_body = 1;
1814 $$->u.variant.name = $1->s;
1815 $$->u.variant.choice = $3->s;
1816 if ($6 && set_parent_node($6, $$))
1817 reparent_error(scanner, "variant reparent error");
1819 | ID_TYPE LT IDENTIFIER GT
1821 $$ = make_node(scanner, NODE_VARIANT);
1822 $$->u.variant.has_body = 0;
1823 $$->u.variant.name = $1->s;
1824 $$->u.variant.choice = $3->s;
1826 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1828 $$ = make_node(scanner, NODE_VARIANT);
1829 $$->u.variant.has_body = 1;
1830 $$->u.variant.name = $1->s;
1831 $$->u.variant.choice = $3->s;
1832 if ($6 && set_parent_node($6, $$))
1833 reparent_error(scanner, "variant reparent error");
1835 | ID_TYPE LT ID_TYPE GT
1837 $$ = make_node(scanner, NODE_VARIANT);
1838 $$->u.variant.has_body = 0;
1839 $$->u.variant.name = $1->s;
1840 $$->u.variant.choice = $3->s;
1844 variant_declaration_begin:
1846 { push_scope(scanner); }
1849 variant_declaration_end:
1851 { pop_scope(scanner); }
1854 enum_type_specifier:
1855 LBRAC enumerator_list RBRAC
1857 $$ = make_node(scanner, NODE_ENUM);
1858 $$->u._enum.has_body = 1;
1859 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1861 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1863 $$ = make_node(scanner, NODE_ENUM);
1864 $$->u._enum.has_body = 1;
1865 ($$)->u._enum.container_type = $2;
1866 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1868 | IDENTIFIER LBRAC enumerator_list RBRAC
1870 $$ = make_node(scanner, NODE_ENUM);
1871 $$->u._enum.has_body = 1;
1872 $$->u._enum.enum_id = $1->s;
1873 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1875 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1877 $$ = make_node(scanner, NODE_ENUM);
1878 $$->u._enum.has_body = 1;
1879 $$->u._enum.enum_id = $1->s;
1880 ($$)->u._enum.container_type = $3;
1881 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1883 | ID_TYPE LBRAC enumerator_list RBRAC
1885 $$ = make_node(scanner, NODE_ENUM);
1886 $$->u._enum.has_body = 1;
1887 $$->u._enum.enum_id = $1->s;
1888 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1890 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1892 $$ = make_node(scanner, NODE_ENUM);
1893 $$->u._enum.has_body = 1;
1894 $$->u._enum.enum_id = $1->s;
1895 ($$)->u._enum.container_type = $3;
1896 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1898 | LBRAC enumerator_list COMMA RBRAC
1900 $$ = make_node(scanner, NODE_ENUM);
1901 $$->u._enum.has_body = 1;
1902 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1904 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1906 $$ = make_node(scanner, NODE_ENUM);
1907 $$->u._enum.has_body = 1;
1908 ($$)->u._enum.container_type = $2;
1909 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1911 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1913 $$ = make_node(scanner, NODE_ENUM);
1914 $$->u._enum.has_body = 1;
1915 $$->u._enum.enum_id = $1->s;
1916 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1918 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1920 $$ = make_node(scanner, NODE_ENUM);
1921 $$->u._enum.has_body = 1;
1922 $$->u._enum.enum_id = $1->s;
1923 ($$)->u._enum.container_type = $3;
1924 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1928 $$ = make_node(scanner, NODE_ENUM);
1929 $$->u._enum.has_body = 0;
1930 $$->u._enum.enum_id = $1->s;
1932 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1934 $$ = make_node(scanner, NODE_ENUM);
1935 $$->u._enum.has_body = 1;
1936 $$->u._enum.enum_id = $1->s;
1937 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1939 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1941 $$ = make_node(scanner, NODE_ENUM);
1942 $$->u._enum.has_body = 1;
1943 $$->u._enum.enum_id = $1->s;
1944 ($$)->u._enum.container_type = $3;
1945 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1949 $$ = make_node(scanner, NODE_ENUM);
1950 $$->u._enum.has_body = 0;
1951 $$->u._enum.enum_id = $1->s;
1955 struct_or_variant_declaration_list:
1958 | struct_or_variant_declaration_list struct_or_variant_declaration
1962 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1965 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1970 struct_or_variant_declaration:
1971 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
1973 struct ctf_node *list;
1975 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1976 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1977 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1978 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1979 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
1981 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1983 struct ctf_node *list;
1985 $$ = make_node(scanner, NODE_TYPEDEF);
1986 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1987 $$->u._typedef.type_specifier_list = list;
1988 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1989 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1990 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1992 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1994 struct ctf_node *list;
1996 $$ = make_node(scanner, NODE_TYPEDEF);
1997 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1998 $$->u._typedef.type_specifier_list = list;
1999 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2000 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2002 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
2004 struct ctf_node *list;
2006 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2007 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2008 $$ = make_node(scanner, NODE_TYPEDEF);
2009 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2010 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2012 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
2014 struct ctf_node *list;
2016 $$ = make_node(scanner, NODE_TYPEALIAS);
2017 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2018 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2020 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2021 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2022 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2023 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2025 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2026 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2027 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2028 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2032 alias_declaration_specifiers:
2035 struct ctf_node *node;
2037 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2038 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2039 node->u.type_specifier.type = TYPESPEC_CONST;
2040 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2044 struct ctf_node *node;
2046 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2048 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2052 struct ctf_node *node;
2054 add_type(scanner, $1);
2055 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2056 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2057 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2058 node->u.type_specifier.id_type = yylval.gs->s;
2059 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2061 | alias_declaration_specifiers CONST
2063 struct ctf_node *node;
2066 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2067 node->u.type_specifier.type = TYPESPEC_CONST;
2068 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2070 | alias_declaration_specifiers type_specifier
2073 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2075 | alias_declaration_specifiers IDENTIFIER
2077 struct ctf_node *node;
2079 add_type(scanner, $2);
2081 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2082 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2083 node->u.type_specifier.id_type = yylval.gs->s;
2084 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2088 struct_or_variant_declarator_list:
2089 struct_or_variant_declarator
2091 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2094 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2098 struct_or_variant_declarator:
2101 | COLON unary_expression
2103 | declarator COLON unary_expression
2106 if (set_parent_node($3, $1))
2107 reparent_error(scanner, "struct_or_variant_declarator");
2114 | enumerator_list COMMA enumerator
2117 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2124 $$ = make_node(scanner, NODE_ENUMERATOR);
2125 $$->u.enumerator.id = $1->s;
2129 $$ = make_node(scanner, NODE_ENUMERATOR);
2130 $$->u.enumerator.id = $1->s;
2134 $$ = make_node(scanner, NODE_ENUMERATOR);
2135 $$->u.enumerator.id = $1->s;
2137 | STRING_LITERAL_START DQUOTE
2139 $$ = make_node(scanner, NODE_ENUMERATOR);
2140 $$->u.enumerator.id = "";
2142 | STRING_LITERAL_START s_char_sequence DQUOTE
2144 $$ = make_node(scanner, NODE_ENUMERATOR);
2145 $$->u.enumerator.id = $2->s;
2147 | IDENTIFIER EQUAL unary_expression_or_range
2149 $$ = make_node(scanner, NODE_ENUMERATOR);
2150 $$->u.enumerator.id = $1->s;
2151 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2153 | ID_TYPE EQUAL unary_expression_or_range
2155 $$ = make_node(scanner, NODE_ENUMERATOR);
2156 $$->u.enumerator.id = $1->s;
2157 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2159 | keywords EQUAL unary_expression_or_range
2161 $$ = make_node(scanner, NODE_ENUMERATOR);
2162 $$->u.enumerator.id = $1->s;
2163 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2165 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
2167 $$ = make_node(scanner, NODE_ENUMERATOR);
2168 $$->u.enumerator.id = "";
2169 bt_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
2171 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
2173 $$ = make_node(scanner, NODE_ENUMERATOR);
2174 $$->u.enumerator.id = $2->s;
2175 bt_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
2179 abstract_declarator_list:
2182 | abstract_declarator_list COMMA abstract_declarator
2185 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2189 abstract_declarator:
2190 direct_abstract_declarator
2192 | pointer direct_abstract_declarator
2195 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2199 direct_abstract_declarator:
2202 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2203 $$->u.type_declarator.type = TYPEDEC_ID;
2208 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2209 $$->u.type_declarator.type = TYPEDEC_ID;
2210 $$->u.type_declarator.u.id = $1->s;
2212 | LPAREN abstract_declarator RPAREN
2214 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2215 $$->u.type_declarator.type = TYPEDEC_NESTED;
2216 $$->u.type_declarator.u.nested.type_declarator = $2;
2218 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2220 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2221 $$->u.type_declarator.type = TYPEDEC_NESTED;
2222 $$->u.type_declarator.u.nested.type_declarator = $1;
2223 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2224 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2226 | direct_abstract_declarator LSBRAC RSBRAC
2228 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2229 $$->u.type_declarator.type = TYPEDEC_NESTED;
2230 $$->u.type_declarator.u.nested.type_declarator = $1;
2231 $$->u.type_declarator.u.nested.abstract_array = 1;
2235 alias_abstract_declarator_list:
2236 alias_abstract_declarator
2238 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2241 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2245 alias_abstract_declarator:
2246 direct_alias_abstract_declarator
2248 | pointer direct_alias_abstract_declarator
2251 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2255 direct_alias_abstract_declarator:
2258 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2259 $$->u.type_declarator.type = TYPEDEC_ID;
2262 | LPAREN alias_abstract_declarator RPAREN
2264 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2265 $$->u.type_declarator.type = TYPEDEC_NESTED;
2266 $$->u.type_declarator.u.nested.type_declarator = $2;
2268 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2270 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2271 $$->u.type_declarator.type = TYPEDEC_NESTED;
2272 $$->u.type_declarator.u.nested.type_declarator = $1;
2273 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2274 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2276 | direct_alias_abstract_declarator LSBRAC RSBRAC
2278 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2279 $$->u.type_declarator.type = TYPEDEC_NESTED;
2280 $$->u.type_declarator.u.nested.type_declarator = $1;
2281 $$->u.type_declarator.u.nested.abstract_array = 1;
2288 | pointer direct_declarator
2291 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2298 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2299 $$->u.type_declarator.type = TYPEDEC_ID;
2300 $$->u.type_declarator.u.id = $1->s;
2302 | LPAREN declarator RPAREN
2304 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2305 $$->u.type_declarator.type = TYPEDEC_NESTED;
2306 $$->u.type_declarator.u.nested.type_declarator = $2;
2308 | direct_declarator LSBRAC unary_expression RSBRAC
2310 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2311 $$->u.type_declarator.type = TYPEDEC_NESTED;
2312 $$->u.type_declarator.u.nested.type_declarator = $1;
2313 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2314 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2319 direct_type_declarator
2321 | pointer direct_type_declarator
2324 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2328 direct_type_declarator:
2331 add_type(scanner, $1);
2332 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2333 $$->u.type_declarator.type = TYPEDEC_ID;
2334 $$->u.type_declarator.u.id = $1->s;
2336 | LPAREN type_declarator RPAREN
2338 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2339 $$->u.type_declarator.type = TYPEDEC_NESTED;
2340 $$->u.type_declarator.u.nested.type_declarator = $2;
2342 | direct_type_declarator LSBRAC unary_expression RSBRAC
2344 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2345 $$->u.type_declarator.type = TYPEDEC_NESTED;
2346 $$->u.type_declarator.u.nested.type_declarator = $1;
2347 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2348 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2355 $$ = make_node(scanner, NODE_POINTER);
2359 $$ = make_node(scanner, NODE_POINTER);
2360 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2362 | STAR type_qualifier_list pointer
2364 $$ = make_node(scanner, NODE_POINTER);
2365 $$->u.pointer.const_qualifier = 1;
2366 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2370 type_qualifier_list:
2371 /* pointer assumes only const type qualifier */
2373 | type_qualifier_list CONST
2376 /* 2.3: CTF-specific declarations */
2378 ctf_assignment_expression_list:
2379 ctf_assignment_expression SEMICOLON
2381 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2384 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2388 ctf_assignment_expression:
2389 unary_expression EQUAL unary_expression
2392 * Because we have left and right, cannot use
2395 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2396 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2397 if ($1->u.unary_expression.type != UNARY_STRING)
2398 reparent_error(scanner, "ctf_assignment_expression left expects string");
2399 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2401 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2404 * Because we have left and right, cannot use
2407 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2408 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2409 if ($1->u.unary_expression.type != UNARY_STRING)
2410 reparent_error(scanner, "ctf_assignment_expression left expects string");
2411 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2413 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2415 struct ctf_node *list;
2417 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2418 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2419 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2420 $$ = make_node(scanner, NODE_TYPEDEF);
2421 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2422 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2424 | TYPEDEF declaration_specifiers type_declarator_list
2426 struct ctf_node *list;
2428 $$ = make_node(scanner, NODE_TYPEDEF);
2429 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2430 $$->u._typedef.type_specifier_list = list;
2431 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2432 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2434 | declaration_specifiers TYPEDEF type_declarator_list
2436 struct ctf_node *list;
2438 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2439 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2440 $$ = make_node(scanner, NODE_TYPEDEF);
2441 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2442 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2444 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2446 struct ctf_node *list;
2448 $$ = make_node(scanner, NODE_TYPEALIAS);
2449 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2450 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2452 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2453 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2454 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2455 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2457 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2458 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2459 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2460 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);