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.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #include <babeltrace/list.h>
37 #include <babeltrace/babeltrace-internal.h>
38 #include "ctf-scanner.h"
39 #include "ctf-parser.h"
45 /* Join two lists, put "add" at the end of "head". */
47 _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
49 /* Do nothing if the list which gets added is empty. */
50 if (add != add->next) {
51 add->next->prev = head->prev;
52 add->prev->next = head;
53 head->prev->next = add->next;
54 head->prev = add->prev;
59 int yyparse(struct ctf_scanner *scanner);
61 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
63 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
65 int yylex_destroy(yyscan_t yyscanner);
67 void yyrestart(FILE * in_str, yyscan_t scanner);
69 int yyget_lineno(yyscan_t yyscanner);
72 struct bt_list_head gc;
77 static const char *node_type_to_str[] = {
78 [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
79 [ NODE_ROOT ] = "NODE_ROOT",
80 [ NODE_EVENT ] = "NODE_EVENT",
81 [ NODE_ENV ] = "NODE_ENV",
82 [ NODE_STREAM ] = "NODE_STREAM",
83 [ NODE_TRACE ] = "NODE_TRACE",
84 [ NODE_CLOCK ] = "NODE_CLOCK",
85 [ NODE_CALLSITE ] = "NODE_CALLSITE",
86 [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
87 [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
88 [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
89 [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
90 [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
91 [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
92 [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
93 [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
94 [ NODE_POINTER ] = "NODE_POINTER",
95 [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
96 [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
97 [ NODE_INTEGER ] = "NODE_INTEGER",
98 [ NODE_STRING ] = "NODE_STRING",
99 [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
100 [ NODE_ENUM ] = "NODE_ENUM",
101 [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
102 [ NODE_VARIANT ] = "NODE_VARIANT",
103 [ NODE_STRUCT ] = "NODE_STRUCT",
107 const char *node_type(struct ctf_node *node)
109 if (node->type < NR_NODE_TYPES)
110 return node_type_to_str[node->type];
115 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
118 struct gc_string *gstr;
121 /* TODO: could be faster with find first bit or glib Gstring */
122 /* sizeof long to account for malloc header (int or long ?) */
123 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
126 gstr = malloc(alloclen);
127 bt_list_add(&gstr->gc, &scanner->allocated_strings);
128 gstr->alloclen = alloclen;
133 * note: never use gc_string_append on a string that has external references.
134 * gsrc will be garbage collected immediately, and gstr might be.
135 * Should only be used to append characters to a string literal or constant.
138 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
139 struct gc_string *gstr,
140 struct gc_string *gsrc)
142 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
145 /* TODO: could be faster with find first bit or glib Gstring */
146 /* sizeof long to account for malloc header (int or long ?) */
147 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
150 if (alloclen > gstr->alloclen) {
151 struct gc_string *newgstr;
153 newgstr = gc_string_alloc(scanner, newlen);
154 strcpy(newgstr->s, gstr->s);
155 strcat(newgstr->s, gsrc->s);
156 bt_list_del(&gstr->gc);
160 strcat(gstr->s, gsrc->s);
162 bt_list_del(&gsrc->gc);
167 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
169 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
170 strcpy(lvalp->gs->s, src);
173 static void init_scope(struct ctf_scanner_scope *scope,
174 struct ctf_scanner_scope *parent)
176 scope->parent = parent;
177 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
181 static void finalize_scope(struct ctf_scanner_scope *scope)
183 g_hash_table_destroy(scope->types);
186 static void push_scope(struct ctf_scanner *scanner)
188 struct ctf_scanner_scope *ns;
190 printf_debug("push scope\n");
191 ns = malloc(sizeof(struct ctf_scanner_scope));
192 init_scope(ns, scanner->cs);
196 static void pop_scope(struct ctf_scanner *scanner)
198 struct ctf_scanner_scope *os;
200 printf_debug("pop scope\n");
202 scanner->cs = os->parent;
207 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
211 ret = (int) (long) g_hash_table_lookup(s->types, id);
212 printf_debug("lookup %p %s %d\n", s, id, ret);
217 int is_type(struct ctf_scanner *scanner, const char *id)
219 struct ctf_scanner_scope *it;
222 for (it = scanner->cs; it != NULL; it = it->parent) {
223 if (lookup_type(it, id)) {
228 printf_debug("is type %s %d\n", id, ret);
232 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
234 printf_debug("add type %s\n", id->s);
235 if (lookup_type(scanner->cs, id->s))
237 g_hash_table_insert(scanner->cs->types, id->s, id->s);
240 static struct ctf_node *make_node(struct ctf_scanner *scanner,
243 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
244 struct ctf_node *node;
246 node = malloc(sizeof(*node));
249 memset(node, 0, sizeof(*node));
251 BT_INIT_LIST_HEAD(&node->tmp_head);
252 bt_list_add(&node->gc, &ast->allocated_nodes);
253 bt_list_add(&node->siblings, &node->tmp_head);
257 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
261 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
264 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
267 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
270 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
273 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
276 BT_INIT_LIST_HEAD(&node->u.callsite.declaration_list);
279 case NODE_CTF_EXPRESSION:
280 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
281 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
283 case NODE_UNARY_EXPRESSION:
287 BT_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
289 case NODE_TYPEALIAS_TARGET:
290 BT_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
292 case NODE_TYPEALIAS_ALIAS:
293 BT_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
298 case NODE_TYPE_SPECIFIER:
300 case NODE_TYPE_SPECIFIER_LIST:
301 BT_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
305 case NODE_TYPE_DECLARATOR:
306 BT_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
309 case NODE_FLOATING_POINT:
310 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
313 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
316 BT_INIT_LIST_HEAD(&node->u.string.expressions);
318 case NODE_ENUMERATOR:
319 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
322 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
324 case NODE_STRUCT_OR_VARIANT_DECLARATION:
325 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
328 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
331 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
332 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
337 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
345 static int reparent_ctf_expression(struct ctf_node *node,
346 struct ctf_node *parent)
348 switch (parent->type) {
350 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
353 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
356 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
359 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
362 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
365 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
367 case NODE_FLOATING_POINT:
368 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
371 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
374 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
378 case NODE_CTF_EXPRESSION:
380 case NODE_TYPEALIAS_TARGET:
381 case NODE_TYPEALIAS_ALIAS:
383 case NODE_TYPE_SPECIFIER:
384 case NODE_TYPE_SPECIFIER_LIST:
386 case NODE_TYPE_DECLARATOR:
387 case NODE_ENUMERATOR:
389 case NODE_STRUCT_OR_VARIANT_DECLARATION:
392 case NODE_UNARY_EXPRESSION:
397 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
404 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
406 switch (parent->type) {
408 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
411 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
414 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
417 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
420 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
423 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
426 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
429 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
432 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
435 case NODE_FLOATING_POINT:
438 case NODE_CTF_EXPRESSION:
440 case NODE_TYPEALIAS_TARGET:
441 case NODE_TYPEALIAS_ALIAS:
443 case NODE_TYPE_SPECIFIER:
444 case NODE_TYPE_SPECIFIER_LIST:
446 case NODE_TYPE_DECLARATOR:
447 case NODE_ENUMERATOR:
449 case NODE_STRUCT_OR_VARIANT_DECLARATION:
450 case NODE_UNARY_EXPRESSION:
455 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
462 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
464 switch (parent->type) {
466 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
469 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
472 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
475 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
478 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
481 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
484 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
487 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
490 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
493 case NODE_FLOATING_POINT:
496 case NODE_CTF_EXPRESSION:
498 case NODE_TYPEALIAS_TARGET:
499 case NODE_TYPEALIAS_ALIAS:
501 case NODE_TYPE_SPECIFIER:
502 case NODE_TYPE_SPECIFIER_LIST:
504 case NODE_TYPE_DECLARATOR:
505 case NODE_ENUMERATOR:
507 case NODE_STRUCT_OR_VARIANT_DECLARATION:
508 case NODE_UNARY_EXPRESSION:
513 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
520 static int reparent_type_specifier(struct ctf_node *node,
521 struct ctf_node *parent)
523 switch (parent->type) {
524 case NODE_TYPE_SPECIFIER_LIST:
525 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
528 case NODE_TYPE_SPECIFIER:
538 case NODE_TYPEALIAS_TARGET:
539 case NODE_TYPEALIAS_ALIAS:
540 case NODE_TYPE_DECLARATOR:
542 case NODE_STRUCT_OR_VARIANT_DECLARATION:
544 case NODE_FLOATING_POINT:
547 case NODE_CTF_EXPRESSION:
549 case NODE_ENUMERATOR:
550 case NODE_UNARY_EXPRESSION:
555 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
562 static int reparent_type_specifier_list(struct ctf_node *node,
563 struct ctf_node *parent)
565 switch (parent->type) {
567 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
570 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
573 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
576 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
579 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
582 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
585 bt_list_add_tail(&node->siblings, &parent->u.callsite.declaration_list);
588 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
591 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
594 parent->u._typedef.type_specifier_list = node;
596 case NODE_TYPEALIAS_TARGET:
597 parent->u.typealias_target.type_specifier_list = node;
599 case NODE_TYPEALIAS_ALIAS:
600 parent->u.typealias_alias.type_specifier_list = node;
603 parent->u._enum.container_type = node;
605 case NODE_STRUCT_OR_VARIANT_DECLARATION:
606 parent->u.struct_or_variant_declaration.type_specifier_list = node;
608 case NODE_TYPE_DECLARATOR:
609 case NODE_TYPE_SPECIFIER:
611 case NODE_FLOATING_POINT:
614 case NODE_CTF_EXPRESSION:
616 case NODE_ENUMERATOR:
617 case NODE_UNARY_EXPRESSION:
622 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
629 static int reparent_type_declarator(struct ctf_node *node,
630 struct ctf_node *parent)
632 switch (parent->type) {
633 case NODE_TYPE_DECLARATOR:
634 parent->u.type_declarator.type = TYPEDEC_NESTED;
635 parent->u.type_declarator.u.nested.type_declarator = node;
637 case NODE_STRUCT_OR_VARIANT_DECLARATION:
638 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
641 _bt_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
643 case NODE_TYPEALIAS_TARGET:
644 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
646 case NODE_TYPEALIAS_ALIAS:
647 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
661 case NODE_FLOATING_POINT:
664 case NODE_CTF_EXPRESSION:
665 case NODE_TYPE_SPECIFIER:
666 case NODE_TYPE_SPECIFIER_LIST:
668 case NODE_ENUMERATOR:
669 case NODE_UNARY_EXPRESSION:
674 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
684 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
685 * create the link declared by the input, -ENOENT if node or parent is NULL,
686 * -EINVAL if there is an internal structure problem.
688 static int set_parent_node(struct ctf_node *node,
689 struct ctf_node *parent)
691 if (!node || !parent)
694 /* Note: Linking to parent will be done only by an external visitor */
696 switch (node->type) {
698 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
702 if (parent->type == NODE_ROOT) {
703 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
709 if (parent->type == NODE_ROOT) {
710 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
716 if (parent->type == NODE_ROOT) {
717 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
723 if (parent->type == NODE_ROOT) {
724 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
730 if (parent->type == NODE_ROOT) {
731 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
737 if (parent->type == NODE_ROOT) {
738 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.callsite);
744 case NODE_CTF_EXPRESSION:
745 return reparent_ctf_expression(node, parent);
746 case NODE_UNARY_EXPRESSION:
747 if (parent->type == NODE_TYPE_DECLARATOR)
748 parent->u.type_declarator.bitfield_len = node;
754 return reparent_typedef(node, parent);
755 case NODE_TYPEALIAS_TARGET:
756 if (parent->type == NODE_TYPEALIAS)
757 parent->u.typealias.target = node;
760 case NODE_TYPEALIAS_ALIAS:
761 if (parent->type == NODE_TYPEALIAS)
762 parent->u.typealias.alias = node;
766 return reparent_typealias(node, parent);
769 if (parent->type == NODE_TYPE_DECLARATOR) {
770 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
774 case NODE_TYPE_DECLARATOR:
775 return reparent_type_declarator(node, parent);
777 case NODE_TYPE_SPECIFIER_LIST:
778 return reparent_type_specifier_list(node, parent);
780 case NODE_TYPE_SPECIFIER:
781 return reparent_type_specifier(node, parent);
783 case NODE_FLOATING_POINT:
789 return -EINVAL; /* Dealt with internally within grammar */
791 case NODE_ENUMERATOR:
792 if (parent->type == NODE_ENUM) {
793 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
798 case NODE_STRUCT_OR_VARIANT_DECLARATION:
799 switch (parent->type) {
801 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
804 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
813 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
821 void yyerror(struct ctf_scanner *scanner, const char *str)
823 fprintf(stderr, "error at line %d: %s\n",
824 yyget_lineno(scanner->scanner), str);
833 #define reparent_error(scanner, str) \
835 yyerror(scanner, YY_("reparent_error: " str "\n")); \
839 static void free_strings(struct bt_list_head *list)
841 struct gc_string *gstr, *tmp;
843 bt_list_for_each_entry_safe(gstr, tmp, list, gc)
847 static struct ctf_ast *ctf_ast_alloc(void)
851 ast = malloc(sizeof(*ast));
854 memset(ast, 0, sizeof(*ast));
855 BT_INIT_LIST_HEAD(&ast->allocated_nodes);
856 ast->root.type = NODE_ROOT;
857 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
858 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
859 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
860 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
861 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
862 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
863 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
864 BT_INIT_LIST_HEAD(&ast->root.u.root.callsite);
868 static void ctf_ast_free(struct ctf_ast *ast)
870 struct ctf_node *node, *tmp;
872 bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
877 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
879 return yyparse(scanner);
882 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
884 struct ctf_scanner *scanner;
887 yydebug = babeltrace_debug;
889 scanner = malloc(sizeof(*scanner));
892 memset(scanner, 0, sizeof(*scanner));
894 ret = yylex_init_extra(scanner, &scanner->scanner);
896 fprintf(stderr, "yylex_init error\n");
897 goto cleanup_scanner;
899 /* Start processing new stream */
900 yyrestart(input, scanner->scanner);
902 scanner->ast = ctf_ast_alloc();
905 init_scope(&scanner->root_scope, NULL);
906 scanner->cs = &scanner->root_scope;
907 BT_INIT_LIST_HEAD(&scanner->allocated_strings);
910 fprintf(stdout, "Scanner input is a%s.\n",
911 isatty(fileno(input)) ? "n interactive tty" :
912 " noninteractive file");
917 ret = yylex_destroy(scanner->scanner);
919 fprintf(stderr, "yylex_destroy error\n");
925 void ctf_scanner_free(struct ctf_scanner *scanner)
929 finalize_scope(&scanner->root_scope);
930 free_strings(&scanner->allocated_strings);
931 ctf_ast_free(scanner->ast);
932 ret = yylex_destroy(scanner->scanner);
934 fprintf(stderr, "yylex_destroy error\n");
943 %parse-param {struct ctf_scanner *scanner}
944 %lex-param {struct ctf_scanner *scanner}
946 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
947 * vs struct { int :value; } (unnamed bit-field). The default is to
948 * shift, so whenever we encounter an enumeration, we are doing the
949 * proper thing (shift). It is illegal to declare an enumeration
950 * "bit-field", so it is OK if this situation ends up in a parsing
955 %token CHARACTER_CONSTANT_START SQUOTE STRING_LITERAL_START DQUOTE ESCSEQ CHAR_STRING_TOKEN LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM ENV EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE CALLSITE CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT TOK_ALIGN
956 %token <gs> IDENTIFIER ID_TYPE
962 struct gc_string *gs;
967 %type <gs> s_char s_char_sequence c_char c_char_sequence
969 %type <n> postfix_expression unary_expression unary_expression_or_range
971 %type <n> declaration
972 %type <n> event_declaration
973 %type <n> stream_declaration
974 %type <n> env_declaration
975 %type <n> trace_declaration
976 %type <n> clock_declaration
977 %type <n> callsite_declaration
978 %type <n> integer_declaration_specifiers
979 %type <n> declaration_specifiers
980 %type <n> alias_declaration_specifiers
982 %type <n> type_declarator_list
983 %type <n> integer_type_specifier
984 %type <n> type_specifier
985 %type <n> struct_type_specifier
986 %type <n> variant_type_specifier
987 %type <n> enum_type_specifier
988 %type <n> struct_or_variant_declaration_list
989 %type <n> struct_or_variant_declaration
990 %type <n> struct_or_variant_declarator_list
991 %type <n> struct_or_variant_declarator
992 %type <n> enumerator_list
994 %type <n> abstract_declarator_list
995 %type <n> abstract_declarator
996 %type <n> direct_abstract_declarator
997 %type <n> alias_abstract_declarator_list
998 %type <n> alias_abstract_declarator
999 %type <n> direct_alias_abstract_declarator
1000 %type <n> declarator
1001 %type <n> direct_declarator
1002 %type <n> type_declarator
1003 %type <n> direct_type_declarator
1005 %type <n> ctf_assignment_expression_list
1006 %type <n> ctf_assignment_expression
1013 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
1014 reparent_error(scanner, "error reparenting to root");
1018 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
1019 reparent_error(scanner, "error reparenting to root");
1085 | c_char_sequence c_char
1086 { $$ = gc_string_append(scanner, $1, $2); }
1094 reparent_error(scanner, "escape sequences not supported yet");
1098 /* 1.6 String literals */
1103 | s_char_sequence s_char
1104 { $$ = gc_string_append(scanner, $1, $2); }
1112 reparent_error(scanner, "escape sequences not supported yet");
1116 /* 2: Phrase structure grammar */
1121 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1122 $$->u.unary_expression.type = UNARY_STRING;
1123 $$->u.unary_expression.u.string = yylval.gs->s;
1127 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1128 $$->u.unary_expression.type = UNARY_STRING;
1129 $$->u.unary_expression.u.string = yylval.gs->s;
1133 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1134 $$->u.unary_expression.type = UNARY_STRING;
1135 $$->u.unary_expression.u.string = yylval.gs->s;
1139 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1140 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1141 sscanf(yylval.gs->s, "%" PRIu64,
1142 &$$->u.unary_expression.u.unsigned_constant);
1146 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1147 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1148 sscanf(yylval.gs->s, "0%" PRIo64,
1149 &$$->u.unary_expression.u.unsigned_constant);
1151 | HEXADECIMAL_CONSTANT
1153 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1154 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1155 sscanf(yylval.gs->s, "0x%" PRIx64,
1156 &$$->u.unary_expression.u.unsigned_constant);
1158 | STRING_LITERAL_START DQUOTE
1160 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1161 $$->u.unary_expression.type = UNARY_STRING;
1162 $$->u.unary_expression.u.string = "";
1164 | STRING_LITERAL_START s_char_sequence DQUOTE
1166 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1167 $$->u.unary_expression.type = UNARY_STRING;
1168 $$->u.unary_expression.u.string = $2->s;
1170 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1172 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1173 $$->u.unary_expression.type = UNARY_STRING;
1174 $$->u.unary_expression.u.string = $2->s;
1176 | LPAREN unary_expression RPAREN
1178 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1179 $$->u.unary_expression.type = UNARY_NESTED;
1180 $$->u.unary_expression.u.nested_exp = $2;
1182 | postfix_expression LSBRAC unary_expression RSBRAC
1184 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1185 $$->u.unary_expression.type = UNARY_SBRAC;
1186 $$->u.unary_expression.u.sbrac_exp = $3;
1187 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1188 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1190 | postfix_expression DOT IDENTIFIER
1192 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1193 $$->u.unary_expression.type = UNARY_STRING;
1194 $$->u.unary_expression.u.string = yylval.gs->s;
1195 $$->u.unary_expression.link = UNARY_DOTLINK;
1196 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1197 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1199 | postfix_expression DOT ID_TYPE
1201 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1202 $$->u.unary_expression.type = UNARY_STRING;
1203 $$->u.unary_expression.u.string = yylval.gs->s;
1204 $$->u.unary_expression.link = UNARY_DOTLINK;
1205 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1206 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1208 | postfix_expression RARROW IDENTIFIER
1210 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1211 $$->u.unary_expression.type = UNARY_STRING;
1212 $$->u.unary_expression.u.string = yylval.gs->s;
1213 $$->u.unary_expression.link = UNARY_ARROWLINK;
1214 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1215 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1217 | postfix_expression RARROW ID_TYPE
1219 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1220 $$->u.unary_expression.type = UNARY_STRING;
1221 $$->u.unary_expression.u.string = yylval.gs->s;
1222 $$->u.unary_expression.link = UNARY_ARROWLINK;
1223 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1224 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1231 | PLUS postfix_expression
1233 | MINUS postfix_expression
1236 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1237 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1238 reparent_error(scanner, "expecting numeric constant");
1240 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1241 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1242 $$->u.unary_expression.u.signed_constant =
1243 -($$->u.unary_expression.u.unsigned_constant);
1245 $$->u.unary_expression.u.signed_constant =
1246 -($$->u.unary_expression.u.signed_constant);
1251 unary_expression_or_range:
1252 unary_expression DOTDOTDOT unary_expression
1255 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1256 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1262 /* 2.2: Declarations */
1265 declaration_specifiers SEMICOLON
1269 | stream_declaration
1277 | callsite_declaration
1279 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1281 struct ctf_node *list;
1283 $$ = make_node(scanner, NODE_TYPEDEF);
1284 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1285 $$->u._typedef.type_specifier_list = list;
1286 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1287 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1288 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1290 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1292 struct ctf_node *list;
1294 $$ = make_node(scanner, NODE_TYPEDEF);
1295 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1296 $$->u._typedef.type_specifier_list = list;
1297 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1298 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1300 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1302 struct ctf_node *list;
1304 $$ = make_node(scanner, NODE_TYPEDEF);
1305 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1306 $$->u._typedef.type_specifier_list = list;
1307 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1308 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1310 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1312 struct ctf_node *list;
1314 $$ = make_node(scanner, NODE_TYPEALIAS);
1315 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1316 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1318 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1319 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1320 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1321 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1323 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1324 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1325 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1326 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1331 event_declaration_begin event_declaration_end
1333 $$ = make_node(scanner, NODE_EVENT);
1335 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1337 $$ = make_node(scanner, NODE_EVENT);
1338 if (set_parent_node($2, $$))
1339 reparent_error(scanner, "event_declaration");
1343 event_declaration_begin:
1345 { push_scope(scanner); }
1348 event_declaration_end:
1350 { pop_scope(scanner); }
1355 stream_declaration_begin stream_declaration_end
1357 $$ = make_node(scanner, NODE_STREAM);
1359 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1361 $$ = make_node(scanner, NODE_STREAM);
1362 if (set_parent_node($2, $$))
1363 reparent_error(scanner, "stream_declaration");
1367 stream_declaration_begin:
1369 { push_scope(scanner); }
1372 stream_declaration_end:
1374 { pop_scope(scanner); }
1378 env_declaration_begin env_declaration_end
1380 $$ = make_node(scanner, NODE_ENV);
1382 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1384 $$ = make_node(scanner, NODE_ENV);
1385 if (set_parent_node($2, $$))
1386 reparent_error(scanner, "env declaration");
1390 env_declaration_begin:
1392 { push_scope(scanner); }
1395 env_declaration_end:
1397 { pop_scope(scanner); }
1401 trace_declaration_begin trace_declaration_end
1403 $$ = make_node(scanner, NODE_TRACE);
1405 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1407 $$ = make_node(scanner, NODE_TRACE);
1408 if (set_parent_node($2, $$))
1409 reparent_error(scanner, "trace_declaration");
1413 trace_declaration_begin:
1415 { push_scope(scanner); }
1418 trace_declaration_end:
1420 { pop_scope(scanner); }
1424 CLOCK clock_declaration_begin clock_declaration_end
1426 $$ = make_node(scanner, NODE_CLOCK);
1428 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1430 $$ = make_node(scanner, NODE_CLOCK);
1431 if (set_parent_node($3, $$))
1432 reparent_error(scanner, "trace_declaration");
1436 clock_declaration_begin:
1438 { push_scope(scanner); }
1441 clock_declaration_end:
1443 { pop_scope(scanner); }
1446 callsite_declaration:
1447 CALLSITE callsite_declaration_begin callsite_declaration_end
1449 $$ = make_node(scanner, NODE_CALLSITE);
1451 | CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1453 $$ = make_node(scanner, NODE_CALLSITE);
1454 if (set_parent_node($3, $$))
1455 reparent_error(scanner, "trace_declaration");
1459 callsite_declaration_begin:
1461 { push_scope(scanner); }
1464 callsite_declaration_end:
1466 { pop_scope(scanner); }
1469 integer_declaration_specifiers:
1472 struct ctf_node *node;
1474 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1475 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1476 node->u.type_specifier.type = TYPESPEC_CONST;
1477 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1479 | integer_type_specifier
1481 struct ctf_node *node;
1483 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1485 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1487 | integer_declaration_specifiers CONST
1489 struct ctf_node *node;
1492 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1493 node->u.type_specifier.type = TYPESPEC_CONST;
1494 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1496 | integer_declaration_specifiers integer_type_specifier
1499 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1503 declaration_specifiers:
1506 struct ctf_node *node;
1508 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1509 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1510 node->u.type_specifier.type = TYPESPEC_CONST;
1511 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1515 struct ctf_node *node;
1517 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1519 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1521 | declaration_specifiers CONST
1523 struct ctf_node *node;
1526 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1527 node->u.type_specifier.type = TYPESPEC_CONST;
1528 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1530 | declaration_specifiers type_specifier
1533 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1537 type_declarator_list:
1540 | type_declarator_list COMMA type_declarator
1543 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1547 integer_type_specifier:
1550 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1551 $$->u.type_specifier.type = TYPESPEC_CHAR;
1555 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1556 $$->u.type_specifier.type = TYPESPEC_SHORT;
1560 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1561 $$->u.type_specifier.type = TYPESPEC_INT;
1565 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1566 $$->u.type_specifier.type = TYPESPEC_LONG;
1570 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1571 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1575 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1576 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1580 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1581 $$->u.type_specifier.type = TYPESPEC_BOOL;
1585 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1586 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1587 $$->u.type_specifier.id_type = yylval.gs->s;
1589 | INTEGER LBRAC RBRAC
1591 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1592 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1593 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1595 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1597 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1598 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1599 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1600 if (set_parent_node($3, $$->u.type_specifier.node))
1601 reparent_error(scanner, "integer reparent error");
1608 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1609 $$->u.type_specifier.type = TYPESPEC_VOID;
1613 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1614 $$->u.type_specifier.type = TYPESPEC_CHAR;
1618 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1619 $$->u.type_specifier.type = TYPESPEC_SHORT;
1623 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1624 $$->u.type_specifier.type = TYPESPEC_INT;
1628 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1629 $$->u.type_specifier.type = TYPESPEC_LONG;
1633 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1634 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1638 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1639 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1643 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1644 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1648 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1649 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1653 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1654 $$->u.type_specifier.type = TYPESPEC_BOOL;
1658 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1659 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1663 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1664 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1668 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1669 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1670 $$->u.type_specifier.id_type = yylval.gs->s;
1672 | FLOATING_POINT LBRAC RBRAC
1674 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1675 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1676 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1678 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1680 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1681 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1682 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1683 if (set_parent_node($3, $$->u.type_specifier.node))
1684 reparent_error(scanner, "floating point reparent error");
1686 | INTEGER LBRAC RBRAC
1688 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1689 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1690 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1692 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1694 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1695 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1696 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1697 if (set_parent_node($3, $$->u.type_specifier.node))
1698 reparent_error(scanner, "integer reparent error");
1702 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1703 $$->u.type_specifier.type = TYPESPEC_STRING;
1704 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1706 | STRING LBRAC RBRAC
1708 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1709 $$->u.type_specifier.type = TYPESPEC_STRING;
1710 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1712 | STRING LBRAC ctf_assignment_expression_list RBRAC
1714 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1715 $$->u.type_specifier.type = TYPESPEC_STRING;
1716 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1717 if (set_parent_node($3, $$->u.type_specifier.node))
1718 reparent_error(scanner, "string reparent error");
1720 | ENUM enum_type_specifier
1722 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1723 $$->u.type_specifier.type = TYPESPEC_ENUM;
1724 $$->u.type_specifier.node = $2;
1726 | VARIANT variant_type_specifier
1728 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1729 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1730 $$->u.type_specifier.node = $2;
1732 | STRUCT struct_type_specifier
1734 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1735 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1736 $$->u.type_specifier.node = $2;
1740 struct_type_specifier:
1741 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1743 $$ = make_node(scanner, NODE_STRUCT);
1744 $$->u._struct.has_body = 1;
1745 if ($2 && set_parent_node($2, $$))
1746 reparent_error(scanner, "struct reparent error");
1748 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1750 $$ = make_node(scanner, NODE_STRUCT);
1751 $$->u._struct.has_body = 1;
1752 $$->u._struct.name = $1->s;
1753 if ($3 && set_parent_node($3, $$))
1754 reparent_error(scanner, "struct reparent error");
1756 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1758 $$ = make_node(scanner, NODE_STRUCT);
1759 $$->u._struct.has_body = 1;
1760 $$->u._struct.name = $1->s;
1761 if ($3 && set_parent_node($3, $$))
1762 reparent_error(scanner, "struct reparent error");
1766 $$ = make_node(scanner, NODE_STRUCT);
1767 $$->u._struct.has_body = 0;
1768 $$->u._struct.name = $1->s;
1772 $$ = make_node(scanner, NODE_STRUCT);
1773 $$->u._struct.has_body = 0;
1774 $$->u._struct.name = $1->s;
1776 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1778 $$ = make_node(scanner, NODE_STRUCT);
1779 $$->u._struct.has_body = 1;
1780 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1781 if ($2 && set_parent_node($2, $$))
1782 reparent_error(scanner, "struct reparent error");
1784 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1786 $$ = make_node(scanner, NODE_STRUCT);
1787 $$->u._struct.has_body = 1;
1788 $$->u._struct.name = $1->s;
1789 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1790 if ($3 && set_parent_node($3, $$))
1791 reparent_error(scanner, "struct reparent error");
1793 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1795 $$ = make_node(scanner, NODE_STRUCT);
1796 $$->u._struct.has_body = 1;
1797 $$->u._struct.name = $1->s;
1798 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1799 if ($3 && set_parent_node($3, $$))
1800 reparent_error(scanner, "struct reparent error");
1804 struct_declaration_begin:
1806 { push_scope(scanner); }
1809 struct_declaration_end:
1811 { pop_scope(scanner); }
1814 variant_type_specifier:
1815 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1817 $$ = make_node(scanner, NODE_VARIANT);
1818 $$->u.variant.has_body = 1;
1819 if ($2 && set_parent_node($2, $$))
1820 reparent_error(scanner, "variant reparent error");
1822 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1824 $$ = make_node(scanner, NODE_VARIANT);
1825 $$->u.variant.has_body = 1;
1826 $$->u.variant.choice = $2->s;
1827 if ($5 && set_parent_node($5, $$))
1828 reparent_error(scanner, "variant reparent error");
1830 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1832 $$ = make_node(scanner, NODE_VARIANT);
1833 $$->u.variant.has_body = 1;
1834 $$->u.variant.choice = $2->s;
1835 if ($5 && set_parent_node($5, $$))
1836 reparent_error(scanner, "variant reparent error");
1838 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1840 $$ = make_node(scanner, NODE_VARIANT);
1841 $$->u.variant.has_body = 1;
1842 $$->u.variant.name = $1->s;
1843 if ($3 && set_parent_node($3, $$))
1844 reparent_error(scanner, "variant reparent error");
1846 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1848 $$ = make_node(scanner, NODE_VARIANT);
1849 $$->u.variant.has_body = 1;
1850 $$->u.variant.name = $1->s;
1851 $$->u.variant.choice = $3->s;
1852 if ($6 && set_parent_node($6, $$))
1853 reparent_error(scanner, "variant reparent error");
1855 | IDENTIFIER LT IDENTIFIER GT
1857 $$ = make_node(scanner, NODE_VARIANT);
1858 $$->u.variant.has_body = 0;
1859 $$->u.variant.name = $1->s;
1860 $$->u.variant.choice = $3->s;
1862 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1864 $$ = make_node(scanner, NODE_VARIANT);
1865 $$->u.variant.has_body = 1;
1866 $$->u.variant.name = $1->s;
1867 $$->u.variant.choice = $3->s;
1868 if ($6 && set_parent_node($6, $$))
1869 reparent_error(scanner, "variant reparent error");
1871 | IDENTIFIER LT ID_TYPE GT
1873 $$ = make_node(scanner, NODE_VARIANT);
1874 $$->u.variant.has_body = 0;
1875 $$->u.variant.name = $1->s;
1876 $$->u.variant.choice = $3->s;
1878 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1880 $$ = make_node(scanner, NODE_VARIANT);
1881 $$->u.variant.has_body = 1;
1882 $$->u.variant.name = $1->s;
1883 if ($3 && set_parent_node($3, $$))
1884 reparent_error(scanner, "variant reparent error");
1886 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1888 $$ = make_node(scanner, NODE_VARIANT);
1889 $$->u.variant.has_body = 1;
1890 $$->u.variant.name = $1->s;
1891 $$->u.variant.choice = $3->s;
1892 if ($6 && set_parent_node($6, $$))
1893 reparent_error(scanner, "variant reparent error");
1895 | ID_TYPE LT IDENTIFIER GT
1897 $$ = make_node(scanner, NODE_VARIANT);
1898 $$->u.variant.has_body = 0;
1899 $$->u.variant.name = $1->s;
1900 $$->u.variant.choice = $3->s;
1902 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1904 $$ = make_node(scanner, NODE_VARIANT);
1905 $$->u.variant.has_body = 1;
1906 $$->u.variant.name = $1->s;
1907 $$->u.variant.choice = $3->s;
1908 if ($6 && set_parent_node($6, $$))
1909 reparent_error(scanner, "variant reparent error");
1911 | ID_TYPE LT ID_TYPE GT
1913 $$ = make_node(scanner, NODE_VARIANT);
1914 $$->u.variant.has_body = 0;
1915 $$->u.variant.name = $1->s;
1916 $$->u.variant.choice = $3->s;
1920 variant_declaration_begin:
1922 { push_scope(scanner); }
1925 variant_declaration_end:
1927 { pop_scope(scanner); }
1930 enum_type_specifier:
1931 LBRAC enumerator_list RBRAC
1933 $$ = make_node(scanner, NODE_ENUM);
1934 $$->u._enum.has_body = 1;
1935 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1937 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1939 $$ = make_node(scanner, NODE_ENUM);
1940 $$->u._enum.has_body = 1;
1941 ($$)->u._enum.container_type = $2;
1942 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1944 | IDENTIFIER LBRAC enumerator_list RBRAC
1946 $$ = make_node(scanner, NODE_ENUM);
1947 $$->u._enum.has_body = 1;
1948 $$->u._enum.enum_id = $1->s;
1949 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1951 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1953 $$ = make_node(scanner, NODE_ENUM);
1954 $$->u._enum.has_body = 1;
1955 $$->u._enum.enum_id = $1->s;
1956 ($$)->u._enum.container_type = $3;
1957 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1959 | ID_TYPE LBRAC enumerator_list RBRAC
1961 $$ = make_node(scanner, NODE_ENUM);
1962 $$->u._enum.has_body = 1;
1963 $$->u._enum.enum_id = $1->s;
1964 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1966 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1968 $$ = make_node(scanner, NODE_ENUM);
1969 $$->u._enum.has_body = 1;
1970 $$->u._enum.enum_id = $1->s;
1971 ($$)->u._enum.container_type = $3;
1972 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1974 | LBRAC enumerator_list COMMA RBRAC
1976 $$ = make_node(scanner, NODE_ENUM);
1977 $$->u._enum.has_body = 1;
1978 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1980 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1982 $$ = make_node(scanner, NODE_ENUM);
1983 $$->u._enum.has_body = 1;
1984 ($$)->u._enum.container_type = $2;
1985 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1987 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1989 $$ = make_node(scanner, NODE_ENUM);
1990 $$->u._enum.has_body = 1;
1991 $$->u._enum.enum_id = $1->s;
1992 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1994 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1996 $$ = make_node(scanner, NODE_ENUM);
1997 $$->u._enum.has_body = 1;
1998 $$->u._enum.enum_id = $1->s;
1999 ($$)->u._enum.container_type = $3;
2000 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2004 $$ = make_node(scanner, NODE_ENUM);
2005 $$->u._enum.has_body = 0;
2006 $$->u._enum.enum_id = $1->s;
2008 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
2010 $$ = make_node(scanner, NODE_ENUM);
2011 $$->u._enum.has_body = 1;
2012 $$->u._enum.enum_id = $1->s;
2013 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2015 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2017 $$ = make_node(scanner, NODE_ENUM);
2018 $$->u._enum.has_body = 1;
2019 $$->u._enum.enum_id = $1->s;
2020 ($$)->u._enum.container_type = $3;
2021 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2025 $$ = make_node(scanner, NODE_ENUM);
2026 $$->u._enum.has_body = 0;
2027 $$->u._enum.enum_id = $1->s;
2031 struct_or_variant_declaration_list:
2034 | struct_or_variant_declaration_list struct_or_variant_declaration
2038 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2041 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
2046 struct_or_variant_declaration:
2047 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
2049 struct ctf_node *list;
2051 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2052 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2053 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
2054 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2055 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
2057 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2059 struct ctf_node *list;
2061 $$ = make_node(scanner, NODE_TYPEDEF);
2062 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2063 $$->u._typedef.type_specifier_list = list;
2064 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2065 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2066 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2068 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2070 struct ctf_node *list;
2072 $$ = make_node(scanner, NODE_TYPEDEF);
2073 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2074 $$->u._typedef.type_specifier_list = list;
2075 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2076 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2078 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
2080 struct ctf_node *list;
2082 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2083 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2084 $$ = make_node(scanner, NODE_TYPEDEF);
2085 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2086 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2088 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
2090 struct ctf_node *list;
2092 $$ = make_node(scanner, NODE_TYPEALIAS);
2093 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2094 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2096 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2097 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2098 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2099 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2101 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2102 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2103 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2104 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2108 alias_declaration_specifiers:
2111 struct ctf_node *node;
2113 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2114 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2115 node->u.type_specifier.type = TYPESPEC_CONST;
2116 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2120 struct ctf_node *node;
2122 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2124 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2128 struct ctf_node *node;
2130 add_type(scanner, $1);
2131 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2132 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2133 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2134 node->u.type_specifier.id_type = yylval.gs->s;
2135 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2137 | alias_declaration_specifiers CONST
2139 struct ctf_node *node;
2142 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2143 node->u.type_specifier.type = TYPESPEC_CONST;
2144 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2146 | alias_declaration_specifiers type_specifier
2149 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2151 | alias_declaration_specifiers IDENTIFIER
2153 struct ctf_node *node;
2155 add_type(scanner, $2);
2157 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2158 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2159 node->u.type_specifier.id_type = yylval.gs->s;
2160 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2164 struct_or_variant_declarator_list:
2165 struct_or_variant_declarator
2167 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2170 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2174 struct_or_variant_declarator:
2177 | COLON unary_expression
2179 | declarator COLON unary_expression
2182 if (set_parent_node($3, $1))
2183 reparent_error(scanner, "struct_or_variant_declarator");
2190 | enumerator_list COMMA enumerator
2193 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2200 $$ = make_node(scanner, NODE_ENUMERATOR);
2201 $$->u.enumerator.id = $1->s;
2205 $$ = make_node(scanner, NODE_ENUMERATOR);
2206 $$->u.enumerator.id = $1->s;
2210 $$ = make_node(scanner, NODE_ENUMERATOR);
2211 $$->u.enumerator.id = $1->s;
2213 | STRING_LITERAL_START DQUOTE
2215 $$ = make_node(scanner, NODE_ENUMERATOR);
2216 $$->u.enumerator.id = "";
2218 | STRING_LITERAL_START s_char_sequence DQUOTE
2220 $$ = make_node(scanner, NODE_ENUMERATOR);
2221 $$->u.enumerator.id = $2->s;
2223 | IDENTIFIER EQUAL unary_expression_or_range
2225 $$ = make_node(scanner, NODE_ENUMERATOR);
2226 $$->u.enumerator.id = $1->s;
2227 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2229 | ID_TYPE EQUAL unary_expression_or_range
2231 $$ = make_node(scanner, NODE_ENUMERATOR);
2232 $$->u.enumerator.id = $1->s;
2233 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2235 | keywords EQUAL unary_expression_or_range
2237 $$ = make_node(scanner, NODE_ENUMERATOR);
2238 $$->u.enumerator.id = $1->s;
2239 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2241 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
2243 $$ = make_node(scanner, NODE_ENUMERATOR);
2244 $$->u.enumerator.id = "";
2245 bt_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
2247 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
2249 $$ = make_node(scanner, NODE_ENUMERATOR);
2250 $$->u.enumerator.id = $2->s;
2251 bt_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
2255 abstract_declarator_list:
2258 | abstract_declarator_list COMMA abstract_declarator
2261 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2265 abstract_declarator:
2266 direct_abstract_declarator
2268 | pointer direct_abstract_declarator
2271 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2275 direct_abstract_declarator:
2278 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2279 $$->u.type_declarator.type = TYPEDEC_ID;
2284 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2285 $$->u.type_declarator.type = TYPEDEC_ID;
2286 $$->u.type_declarator.u.id = $1->s;
2288 | LPAREN abstract_declarator RPAREN
2290 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2291 $$->u.type_declarator.type = TYPEDEC_NESTED;
2292 $$->u.type_declarator.u.nested.type_declarator = $2;
2294 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2296 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2297 $$->u.type_declarator.type = TYPEDEC_NESTED;
2298 $$->u.type_declarator.u.nested.type_declarator = $1;
2299 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2300 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2302 | direct_abstract_declarator LSBRAC RSBRAC
2304 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2305 $$->u.type_declarator.type = TYPEDEC_NESTED;
2306 $$->u.type_declarator.u.nested.type_declarator = $1;
2307 $$->u.type_declarator.u.nested.abstract_array = 1;
2311 alias_abstract_declarator_list:
2312 alias_abstract_declarator
2314 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2317 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2321 alias_abstract_declarator:
2322 direct_alias_abstract_declarator
2324 | pointer direct_alias_abstract_declarator
2327 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2331 direct_alias_abstract_declarator:
2334 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2335 $$->u.type_declarator.type = TYPEDEC_ID;
2338 | LPAREN alias_abstract_declarator RPAREN
2340 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2341 $$->u.type_declarator.type = TYPEDEC_NESTED;
2342 $$->u.type_declarator.u.nested.type_declarator = $2;
2344 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2346 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2347 $$->u.type_declarator.type = TYPEDEC_NESTED;
2348 $$->u.type_declarator.u.nested.type_declarator = $1;
2349 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2350 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2352 | direct_alias_abstract_declarator LSBRAC RSBRAC
2354 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2355 $$->u.type_declarator.type = TYPEDEC_NESTED;
2356 $$->u.type_declarator.u.nested.type_declarator = $1;
2357 $$->u.type_declarator.u.nested.abstract_array = 1;
2364 | pointer direct_declarator
2367 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2374 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2375 $$->u.type_declarator.type = TYPEDEC_ID;
2376 $$->u.type_declarator.u.id = $1->s;
2378 | LPAREN declarator RPAREN
2380 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2381 $$->u.type_declarator.type = TYPEDEC_NESTED;
2382 $$->u.type_declarator.u.nested.type_declarator = $2;
2384 | direct_declarator LSBRAC unary_expression RSBRAC
2386 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2387 $$->u.type_declarator.type = TYPEDEC_NESTED;
2388 $$->u.type_declarator.u.nested.type_declarator = $1;
2389 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2390 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2395 direct_type_declarator
2397 | pointer direct_type_declarator
2400 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2404 direct_type_declarator:
2407 add_type(scanner, $1);
2408 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2409 $$->u.type_declarator.type = TYPEDEC_ID;
2410 $$->u.type_declarator.u.id = $1->s;
2412 | LPAREN type_declarator RPAREN
2414 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2415 $$->u.type_declarator.type = TYPEDEC_NESTED;
2416 $$->u.type_declarator.u.nested.type_declarator = $2;
2418 | direct_type_declarator LSBRAC unary_expression RSBRAC
2420 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2421 $$->u.type_declarator.type = TYPEDEC_NESTED;
2422 $$->u.type_declarator.u.nested.type_declarator = $1;
2423 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2424 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2431 $$ = make_node(scanner, NODE_POINTER);
2435 $$ = make_node(scanner, NODE_POINTER);
2436 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2438 | STAR type_qualifier_list pointer
2440 $$ = make_node(scanner, NODE_POINTER);
2441 $$->u.pointer.const_qualifier = 1;
2442 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2446 type_qualifier_list:
2447 /* pointer assumes only const type qualifier */
2449 | type_qualifier_list CONST
2452 /* 2.3: CTF-specific declarations */
2454 ctf_assignment_expression_list:
2455 ctf_assignment_expression SEMICOLON
2457 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2460 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2464 ctf_assignment_expression:
2465 unary_expression EQUAL unary_expression
2468 * Because we have left and right, cannot use
2471 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2472 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2473 if ($1->u.unary_expression.type != UNARY_STRING)
2474 reparent_error(scanner, "ctf_assignment_expression left expects string");
2475 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2477 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2480 * Because we have left and right, cannot use
2483 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2484 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2485 if ($1->u.unary_expression.type != UNARY_STRING)
2486 reparent_error(scanner, "ctf_assignment_expression left expects string");
2487 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2489 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2491 struct ctf_node *list;
2493 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2494 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2495 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2496 $$ = make_node(scanner, NODE_TYPEDEF);
2497 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2498 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2500 | TYPEDEF declaration_specifiers type_declarator_list
2502 struct ctf_node *list;
2504 $$ = make_node(scanner, NODE_TYPEDEF);
2505 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2506 $$->u._typedef.type_specifier_list = list;
2507 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2508 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2510 | declaration_specifiers TYPEDEF type_declarator_list
2512 struct ctf_node *list;
2514 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2515 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2516 $$ = make_node(scanner, NODE_TYPEDEF);
2517 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2518 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2520 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2522 struct ctf_node *list;
2524 $$ = make_node(scanner, NODE_TYPEALIAS);
2525 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2526 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2528 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2529 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2530 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2531 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2533 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2534 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2535 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2536 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);