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);
71 char *yyget_text(yyscan_t yyscanner);
74 struct bt_list_head gc;
79 static const char *node_type_to_str[] = {
80 [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
81 [ NODE_ROOT ] = "NODE_ROOT",
82 [ NODE_EVENT ] = "NODE_EVENT",
83 [ NODE_ENV ] = "NODE_ENV",
84 [ NODE_STREAM ] = "NODE_STREAM",
85 [ NODE_TRACE ] = "NODE_TRACE",
86 [ NODE_CLOCK ] = "NODE_CLOCK",
87 [ NODE_CALLSITE ] = "NODE_CALLSITE",
88 [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
89 [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
90 [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
91 [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
92 [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
93 [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
94 [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
95 [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
96 [ NODE_POINTER ] = "NODE_POINTER",
97 [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
98 [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
99 [ NODE_INTEGER ] = "NODE_INTEGER",
100 [ NODE_STRING ] = "NODE_STRING",
101 [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
102 [ NODE_ENUM ] = "NODE_ENUM",
103 [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
104 [ NODE_VARIANT ] = "NODE_VARIANT",
105 [ NODE_STRUCT ] = "NODE_STRUCT",
109 const char *node_type(struct ctf_node *node)
111 if (node->type < NR_NODE_TYPES)
112 return node_type_to_str[node->type];
117 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
120 struct gc_string *gstr;
123 /* TODO: could be faster with find first bit or glib Gstring */
124 /* sizeof long to account for malloc header (int or long ?) */
125 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
128 gstr = malloc(alloclen);
129 bt_list_add(&gstr->gc, &scanner->allocated_strings);
130 gstr->alloclen = alloclen;
135 * note: never use gc_string_append on a string that has external references.
136 * gsrc will be garbage collected immediately, and gstr might be.
137 * Should only be used to append characters to a string literal or constant.
140 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
141 struct gc_string *gstr,
142 struct gc_string *gsrc)
144 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
147 /* TODO: could be faster with find first bit or glib Gstring */
148 /* sizeof long to account for malloc header (int or long ?) */
149 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
152 if (alloclen > gstr->alloclen) {
153 struct gc_string *newgstr;
155 newgstr = gc_string_alloc(scanner, newlen);
156 strcpy(newgstr->s, gstr->s);
157 strcat(newgstr->s, gsrc->s);
158 bt_list_del(&gstr->gc);
162 strcat(gstr->s, gsrc->s);
164 bt_list_del(&gsrc->gc);
169 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
171 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
172 strcpy(lvalp->gs->s, src);
175 static void init_scope(struct ctf_scanner_scope *scope,
176 struct ctf_scanner_scope *parent)
178 scope->parent = parent;
179 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
183 static void finalize_scope(struct ctf_scanner_scope *scope)
185 g_hash_table_destroy(scope->types);
188 static void push_scope(struct ctf_scanner *scanner)
190 struct ctf_scanner_scope *ns;
192 printf_debug("push scope\n");
193 ns = malloc(sizeof(struct ctf_scanner_scope));
194 init_scope(ns, scanner->cs);
198 static void pop_scope(struct ctf_scanner *scanner)
200 struct ctf_scanner_scope *os;
202 printf_debug("pop scope\n");
204 scanner->cs = os->parent;
209 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
213 ret = (int) (long) g_hash_table_lookup(s->types, id);
214 printf_debug("lookup %p %s %d\n", s, id, ret);
219 int is_type(struct ctf_scanner *scanner, const char *id)
221 struct ctf_scanner_scope *it;
224 for (it = scanner->cs; it != NULL; it = it->parent) {
225 if (lookup_type(it, id)) {
230 printf_debug("is type %s %d\n", id, ret);
234 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
236 printf_debug("add type %s\n", id->s);
237 if (lookup_type(scanner->cs, id->s))
239 g_hash_table_insert(scanner->cs->types, id->s, id->s);
242 static struct ctf_node *make_node(struct ctf_scanner *scanner,
245 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
246 struct ctf_node *node;
248 node = malloc(sizeof(*node));
251 memset(node, 0, sizeof(*node));
253 node->lineno = yyget_lineno(scanner->scanner);
254 BT_INIT_LIST_HEAD(&node->tmp_head);
255 bt_list_add(&node->gc, &ast->allocated_nodes);
256 bt_list_add(&node->siblings, &node->tmp_head);
260 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
264 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
267 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
270 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
273 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
276 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
279 BT_INIT_LIST_HEAD(&node->u.callsite.declaration_list);
282 case NODE_CTF_EXPRESSION:
283 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
284 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
286 case NODE_UNARY_EXPRESSION:
290 BT_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
292 case NODE_TYPEALIAS_TARGET:
293 BT_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
295 case NODE_TYPEALIAS_ALIAS:
296 BT_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
301 case NODE_TYPE_SPECIFIER:
303 case NODE_TYPE_SPECIFIER_LIST:
304 BT_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
308 case NODE_TYPE_DECLARATOR:
309 BT_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
312 case NODE_FLOATING_POINT:
313 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
316 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
319 BT_INIT_LIST_HEAD(&node->u.string.expressions);
321 case NODE_ENUMERATOR:
322 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
325 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
327 case NODE_STRUCT_OR_VARIANT_DECLARATION:
328 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
331 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
334 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
335 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
340 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
348 static int reparent_ctf_expression(struct ctf_node *node,
349 struct ctf_node *parent)
351 switch (parent->type) {
353 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
356 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
359 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
362 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
365 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
368 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
370 case NODE_FLOATING_POINT:
371 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
374 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
377 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
381 case NODE_CTF_EXPRESSION:
383 case NODE_TYPEALIAS_TARGET:
384 case NODE_TYPEALIAS_ALIAS:
386 case NODE_TYPE_SPECIFIER:
387 case NODE_TYPE_SPECIFIER_LIST:
389 case NODE_TYPE_DECLARATOR:
390 case NODE_ENUMERATOR:
392 case NODE_STRUCT_OR_VARIANT_DECLARATION:
395 case NODE_UNARY_EXPRESSION:
400 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
407 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
409 switch (parent->type) {
411 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
414 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
417 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
420 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
423 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
426 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
429 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
432 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
435 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
438 case NODE_FLOATING_POINT:
441 case NODE_CTF_EXPRESSION:
443 case NODE_TYPEALIAS_TARGET:
444 case NODE_TYPEALIAS_ALIAS:
446 case NODE_TYPE_SPECIFIER:
447 case NODE_TYPE_SPECIFIER_LIST:
449 case NODE_TYPE_DECLARATOR:
450 case NODE_ENUMERATOR:
452 case NODE_STRUCT_OR_VARIANT_DECLARATION:
453 case NODE_UNARY_EXPRESSION:
458 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
465 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
467 switch (parent->type) {
469 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
472 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
475 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
478 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
481 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
484 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
487 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
490 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
493 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
496 case NODE_FLOATING_POINT:
499 case NODE_CTF_EXPRESSION:
501 case NODE_TYPEALIAS_TARGET:
502 case NODE_TYPEALIAS_ALIAS:
504 case NODE_TYPE_SPECIFIER:
505 case NODE_TYPE_SPECIFIER_LIST:
507 case NODE_TYPE_DECLARATOR:
508 case NODE_ENUMERATOR:
510 case NODE_STRUCT_OR_VARIANT_DECLARATION:
511 case NODE_UNARY_EXPRESSION:
516 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
523 static int reparent_type_specifier(struct ctf_node *node,
524 struct ctf_node *parent)
526 switch (parent->type) {
527 case NODE_TYPE_SPECIFIER_LIST:
528 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
531 case NODE_TYPE_SPECIFIER:
541 case NODE_TYPEALIAS_TARGET:
542 case NODE_TYPEALIAS_ALIAS:
543 case NODE_TYPE_DECLARATOR:
545 case NODE_STRUCT_OR_VARIANT_DECLARATION:
547 case NODE_FLOATING_POINT:
550 case NODE_CTF_EXPRESSION:
552 case NODE_ENUMERATOR:
553 case NODE_UNARY_EXPRESSION:
558 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
565 static int reparent_type_specifier_list(struct ctf_node *node,
566 struct ctf_node *parent)
568 switch (parent->type) {
570 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
573 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
576 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
579 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
582 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
585 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
588 bt_list_add_tail(&node->siblings, &parent->u.callsite.declaration_list);
591 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
594 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
597 parent->u._typedef.type_specifier_list = node;
599 case NODE_TYPEALIAS_TARGET:
600 parent->u.typealias_target.type_specifier_list = node;
602 case NODE_TYPEALIAS_ALIAS:
603 parent->u.typealias_alias.type_specifier_list = node;
606 parent->u._enum.container_type = node;
608 case NODE_STRUCT_OR_VARIANT_DECLARATION:
609 parent->u.struct_or_variant_declaration.type_specifier_list = node;
611 case NODE_TYPE_DECLARATOR:
612 case NODE_TYPE_SPECIFIER:
614 case NODE_FLOATING_POINT:
617 case NODE_CTF_EXPRESSION:
619 case NODE_ENUMERATOR:
620 case NODE_UNARY_EXPRESSION:
625 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
632 static int reparent_type_declarator(struct ctf_node *node,
633 struct ctf_node *parent)
635 switch (parent->type) {
636 case NODE_TYPE_DECLARATOR:
637 parent->u.type_declarator.type = TYPEDEC_NESTED;
638 parent->u.type_declarator.u.nested.type_declarator = node;
640 case NODE_STRUCT_OR_VARIANT_DECLARATION:
641 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
644 _bt_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
646 case NODE_TYPEALIAS_TARGET:
647 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
649 case NODE_TYPEALIAS_ALIAS:
650 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
664 case NODE_FLOATING_POINT:
667 case NODE_CTF_EXPRESSION:
668 case NODE_TYPE_SPECIFIER:
669 case NODE_TYPE_SPECIFIER_LIST:
671 case NODE_ENUMERATOR:
672 case NODE_UNARY_EXPRESSION:
677 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
687 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
688 * create the link declared by the input, -ENOENT if node or parent is NULL,
689 * -EINVAL if there is an internal structure problem.
691 static int set_parent_node(struct ctf_node *node,
692 struct ctf_node *parent)
694 if (!node || !parent)
697 /* Note: Linking to parent will be done only by an external visitor */
699 switch (node->type) {
701 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
705 if (parent->type == NODE_ROOT) {
706 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
712 if (parent->type == NODE_ROOT) {
713 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
719 if (parent->type == NODE_ROOT) {
720 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
726 if (parent->type == NODE_ROOT) {
727 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
733 if (parent->type == NODE_ROOT) {
734 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
740 if (parent->type == NODE_ROOT) {
741 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.callsite);
747 case NODE_CTF_EXPRESSION:
748 return reparent_ctf_expression(node, parent);
749 case NODE_UNARY_EXPRESSION:
750 if (parent->type == NODE_TYPE_DECLARATOR)
751 parent->u.type_declarator.bitfield_len = node;
757 return reparent_typedef(node, parent);
758 case NODE_TYPEALIAS_TARGET:
759 if (parent->type == NODE_TYPEALIAS)
760 parent->u.typealias.target = node;
763 case NODE_TYPEALIAS_ALIAS:
764 if (parent->type == NODE_TYPEALIAS)
765 parent->u.typealias.alias = node;
769 return reparent_typealias(node, parent);
772 if (parent->type == NODE_TYPE_DECLARATOR) {
773 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
777 case NODE_TYPE_DECLARATOR:
778 return reparent_type_declarator(node, parent);
780 case NODE_TYPE_SPECIFIER_LIST:
781 return reparent_type_specifier_list(node, parent);
783 case NODE_TYPE_SPECIFIER:
784 return reparent_type_specifier(node, parent);
786 case NODE_FLOATING_POINT:
792 return -EINVAL; /* Dealt with internally within grammar */
794 case NODE_ENUMERATOR:
795 if (parent->type == NODE_ENUM) {
796 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
801 case NODE_STRUCT_OR_VARIANT_DECLARATION:
802 switch (parent->type) {
804 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
807 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
816 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
824 void yyerror(struct ctf_scanner *scanner, const char *str)
826 fprintf(stderr, "error at line %d, token \"%s\": %s\n",
827 yyget_lineno(scanner->scanner),
828 yyget_text(scanner->scanner), str);
837 #define reparent_error(scanner, str) \
839 yyerror(scanner, YY_("reparent_error: " str "\n")); \
843 static void free_strings(struct bt_list_head *list)
845 struct gc_string *gstr, *tmp;
847 bt_list_for_each_entry_safe(gstr, tmp, list, gc)
851 static struct ctf_ast *ctf_ast_alloc(void)
855 ast = malloc(sizeof(*ast));
858 memset(ast, 0, sizeof(*ast));
859 BT_INIT_LIST_HEAD(&ast->allocated_nodes);
860 ast->root.type = NODE_ROOT;
861 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
862 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
863 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
864 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
865 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
866 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
867 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
868 BT_INIT_LIST_HEAD(&ast->root.u.root.callsite);
872 static void ctf_ast_free(struct ctf_ast *ast)
874 struct ctf_node *node, *tmp;
876 bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
881 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
883 return yyparse(scanner);
886 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
888 struct ctf_scanner *scanner;
891 yydebug = babeltrace_debug;
893 scanner = malloc(sizeof(*scanner));
896 memset(scanner, 0, sizeof(*scanner));
898 ret = yylex_init_extra(scanner, &scanner->scanner);
900 fprintf(stderr, "yylex_init error\n");
901 goto cleanup_scanner;
903 /* Start processing new stream */
904 yyrestart(input, scanner->scanner);
906 scanner->ast = ctf_ast_alloc();
909 init_scope(&scanner->root_scope, NULL);
910 scanner->cs = &scanner->root_scope;
911 BT_INIT_LIST_HEAD(&scanner->allocated_strings);
914 fprintf(stdout, "Scanner input is a%s.\n",
915 isatty(fileno(input)) ? "n interactive tty" :
916 " noninteractive file");
921 ret = yylex_destroy(scanner->scanner);
923 fprintf(stderr, "yylex_destroy error\n");
929 void ctf_scanner_free(struct ctf_scanner *scanner)
933 finalize_scope(&scanner->root_scope);
934 free_strings(&scanner->allocated_strings);
935 ctf_ast_free(scanner->ast);
936 ret = yylex_destroy(scanner->scanner);
938 fprintf(stderr, "yylex_destroy error\n");
947 %parse-param {struct ctf_scanner *scanner}
948 %lex-param {struct ctf_scanner *scanner}
950 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
951 * vs struct { int :value; } (unnamed bit-field). The default is to
952 * shift, so whenever we encounter an enumeration, we are doing the
953 * proper thing (shift). It is illegal to declare an enumeration
954 * "bit-field", so it is OK if this situation ends up in a parsing
959 %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
960 %token <gs> IDENTIFIER ID_TYPE
966 struct gc_string *gs;
971 %type <gs> s_char s_char_sequence c_char c_char_sequence
973 %type <n> postfix_expression unary_expression unary_expression_or_range
975 %type <n> declaration
976 %type <n> event_declaration
977 %type <n> stream_declaration
978 %type <n> env_declaration
979 %type <n> trace_declaration
980 %type <n> clock_declaration
981 %type <n> callsite_declaration
982 %type <n> integer_declaration_specifiers
983 %type <n> declaration_specifiers
984 %type <n> alias_declaration_specifiers
986 %type <n> type_declarator_list
987 %type <n> integer_type_specifier
988 %type <n> type_specifier
989 %type <n> struct_type_specifier
990 %type <n> variant_type_specifier
991 %type <n> enum_type_specifier
992 %type <n> struct_or_variant_declaration_list
993 %type <n> struct_or_variant_declaration
994 %type <n> struct_or_variant_declarator_list
995 %type <n> struct_or_variant_declarator
996 %type <n> enumerator_list
998 %type <n> abstract_declarator_list
999 %type <n> abstract_declarator
1000 %type <n> direct_abstract_declarator
1001 %type <n> alias_abstract_declarator_list
1002 %type <n> alias_abstract_declarator
1003 %type <n> direct_alias_abstract_declarator
1004 %type <n> declarator
1005 %type <n> direct_declarator
1006 %type <n> type_declarator
1007 %type <n> direct_type_declarator
1009 %type <n> ctf_assignment_expression_list
1010 %type <n> ctf_assignment_expression
1017 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
1018 reparent_error(scanner, "error reparenting to root");
1022 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
1023 reparent_error(scanner, "error reparenting to root");
1089 | c_char_sequence c_char
1090 { $$ = gc_string_append(scanner, $1, $2); }
1098 reparent_error(scanner, "escape sequences not supported yet");
1102 /* 1.6 String literals */
1107 | s_char_sequence s_char
1108 { $$ = gc_string_append(scanner, $1, $2); }
1116 reparent_error(scanner, "escape sequences not supported yet");
1120 /* 2: Phrase structure grammar */
1125 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1126 $$->u.unary_expression.type = UNARY_STRING;
1127 $$->u.unary_expression.u.string = yylval.gs->s;
1131 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1132 $$->u.unary_expression.type = UNARY_STRING;
1133 $$->u.unary_expression.u.string = yylval.gs->s;
1137 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1138 $$->u.unary_expression.type = UNARY_STRING;
1139 $$->u.unary_expression.u.string = yylval.gs->s;
1143 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1144 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1145 sscanf(yylval.gs->s, "%" PRIu64,
1146 &$$->u.unary_expression.u.unsigned_constant);
1150 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1151 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1152 sscanf(yylval.gs->s, "0%" PRIo64,
1153 &$$->u.unary_expression.u.unsigned_constant);
1155 | HEXADECIMAL_CONSTANT
1157 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1158 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1159 sscanf(yylval.gs->s, "0x%" PRIx64,
1160 &$$->u.unary_expression.u.unsigned_constant);
1162 | STRING_LITERAL_START DQUOTE
1164 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1165 $$->u.unary_expression.type = UNARY_STRING;
1166 $$->u.unary_expression.u.string = "";
1168 | STRING_LITERAL_START s_char_sequence DQUOTE
1170 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1171 $$->u.unary_expression.type = UNARY_STRING;
1172 $$->u.unary_expression.u.string = $2->s;
1174 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1176 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1177 $$->u.unary_expression.type = UNARY_STRING;
1178 $$->u.unary_expression.u.string = $2->s;
1180 | LPAREN unary_expression RPAREN
1182 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1183 $$->u.unary_expression.type = UNARY_NESTED;
1184 $$->u.unary_expression.u.nested_exp = $2;
1186 | postfix_expression LSBRAC unary_expression RSBRAC
1188 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1189 $$->u.unary_expression.type = UNARY_SBRAC;
1190 $$->u.unary_expression.u.sbrac_exp = $3;
1191 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1192 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1194 | postfix_expression DOT IDENTIFIER
1196 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1197 $$->u.unary_expression.type = UNARY_STRING;
1198 $$->u.unary_expression.u.string = yylval.gs->s;
1199 $$->u.unary_expression.link = UNARY_DOTLINK;
1200 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1201 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1203 | postfix_expression DOT ID_TYPE
1205 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1206 $$->u.unary_expression.type = UNARY_STRING;
1207 $$->u.unary_expression.u.string = yylval.gs->s;
1208 $$->u.unary_expression.link = UNARY_DOTLINK;
1209 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1210 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1212 | postfix_expression RARROW IDENTIFIER
1214 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1215 $$->u.unary_expression.type = UNARY_STRING;
1216 $$->u.unary_expression.u.string = yylval.gs->s;
1217 $$->u.unary_expression.link = UNARY_ARROWLINK;
1218 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1219 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1221 | postfix_expression RARROW ID_TYPE
1223 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1224 $$->u.unary_expression.type = UNARY_STRING;
1225 $$->u.unary_expression.u.string = yylval.gs->s;
1226 $$->u.unary_expression.link = UNARY_ARROWLINK;
1227 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1228 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1235 | PLUS postfix_expression
1237 | MINUS postfix_expression
1240 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1241 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1242 reparent_error(scanner, "expecting numeric constant");
1244 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1245 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1246 $$->u.unary_expression.u.signed_constant =
1247 -($$->u.unary_expression.u.unsigned_constant);
1249 $$->u.unary_expression.u.signed_constant =
1250 -($$->u.unary_expression.u.signed_constant);
1255 unary_expression_or_range:
1256 unary_expression DOTDOTDOT unary_expression
1259 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1260 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1266 /* 2.2: Declarations */
1269 declaration_specifiers SEMICOLON
1273 | stream_declaration
1281 | callsite_declaration
1283 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1285 struct ctf_node *list;
1287 $$ = make_node(scanner, NODE_TYPEDEF);
1288 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1289 $$->u._typedef.type_specifier_list = list;
1290 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1291 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1292 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1294 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1296 struct ctf_node *list;
1298 $$ = make_node(scanner, NODE_TYPEDEF);
1299 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1300 $$->u._typedef.type_specifier_list = list;
1301 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1302 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1304 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1306 struct ctf_node *list;
1308 $$ = make_node(scanner, NODE_TYPEDEF);
1309 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1310 $$->u._typedef.type_specifier_list = list;
1311 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1312 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1314 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1316 struct ctf_node *list;
1318 $$ = make_node(scanner, NODE_TYPEALIAS);
1319 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1320 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1322 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1323 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1324 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1325 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1327 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1328 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1329 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1330 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1335 event_declaration_begin event_declaration_end
1337 $$ = make_node(scanner, NODE_EVENT);
1339 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1341 $$ = make_node(scanner, NODE_EVENT);
1342 if (set_parent_node($2, $$))
1343 reparent_error(scanner, "event_declaration");
1347 event_declaration_begin:
1349 { push_scope(scanner); }
1352 event_declaration_end:
1354 { pop_scope(scanner); }
1359 stream_declaration_begin stream_declaration_end
1361 $$ = make_node(scanner, NODE_STREAM);
1363 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1365 $$ = make_node(scanner, NODE_STREAM);
1366 if (set_parent_node($2, $$))
1367 reparent_error(scanner, "stream_declaration");
1371 stream_declaration_begin:
1373 { push_scope(scanner); }
1376 stream_declaration_end:
1378 { pop_scope(scanner); }
1382 env_declaration_begin env_declaration_end
1384 $$ = make_node(scanner, NODE_ENV);
1386 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1388 $$ = make_node(scanner, NODE_ENV);
1389 if (set_parent_node($2, $$))
1390 reparent_error(scanner, "env declaration");
1394 env_declaration_begin:
1396 { push_scope(scanner); }
1399 env_declaration_end:
1401 { pop_scope(scanner); }
1405 trace_declaration_begin trace_declaration_end
1407 $$ = make_node(scanner, NODE_TRACE);
1409 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1411 $$ = make_node(scanner, NODE_TRACE);
1412 if (set_parent_node($2, $$))
1413 reparent_error(scanner, "trace_declaration");
1417 trace_declaration_begin:
1419 { push_scope(scanner); }
1422 trace_declaration_end:
1424 { pop_scope(scanner); }
1428 CLOCK clock_declaration_begin clock_declaration_end
1430 $$ = make_node(scanner, NODE_CLOCK);
1432 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1434 $$ = make_node(scanner, NODE_CLOCK);
1435 if (set_parent_node($3, $$))
1436 reparent_error(scanner, "trace_declaration");
1440 clock_declaration_begin:
1442 { push_scope(scanner); }
1445 clock_declaration_end:
1447 { pop_scope(scanner); }
1450 callsite_declaration:
1451 CALLSITE callsite_declaration_begin callsite_declaration_end
1453 $$ = make_node(scanner, NODE_CALLSITE);
1455 | CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1457 $$ = make_node(scanner, NODE_CALLSITE);
1458 if (set_parent_node($3, $$))
1459 reparent_error(scanner, "trace_declaration");
1463 callsite_declaration_begin:
1465 { push_scope(scanner); }
1468 callsite_declaration_end:
1470 { pop_scope(scanner); }
1473 integer_declaration_specifiers:
1476 struct ctf_node *node;
1478 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1479 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1480 node->u.type_specifier.type = TYPESPEC_CONST;
1481 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1483 | integer_type_specifier
1485 struct ctf_node *node;
1487 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1489 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1491 | integer_declaration_specifiers CONST
1493 struct ctf_node *node;
1496 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1497 node->u.type_specifier.type = TYPESPEC_CONST;
1498 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1500 | integer_declaration_specifiers integer_type_specifier
1503 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1507 declaration_specifiers:
1510 struct ctf_node *node;
1512 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1513 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1514 node->u.type_specifier.type = TYPESPEC_CONST;
1515 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1519 struct ctf_node *node;
1521 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1523 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1525 | declaration_specifiers CONST
1527 struct ctf_node *node;
1530 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1531 node->u.type_specifier.type = TYPESPEC_CONST;
1532 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1534 | declaration_specifiers type_specifier
1537 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1541 type_declarator_list:
1544 | type_declarator_list COMMA type_declarator
1547 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1551 integer_type_specifier:
1554 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1555 $$->u.type_specifier.type = TYPESPEC_CHAR;
1559 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1560 $$->u.type_specifier.type = TYPESPEC_SHORT;
1564 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1565 $$->u.type_specifier.type = TYPESPEC_INT;
1569 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1570 $$->u.type_specifier.type = TYPESPEC_LONG;
1574 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1575 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1579 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1580 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1584 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1585 $$->u.type_specifier.type = TYPESPEC_BOOL;
1589 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1590 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1591 $$->u.type_specifier.id_type = yylval.gs->s;
1593 | INTEGER LBRAC RBRAC
1595 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1596 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1597 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1599 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1601 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1602 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1603 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1604 if (set_parent_node($3, $$->u.type_specifier.node))
1605 reparent_error(scanner, "integer reparent error");
1612 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1613 $$->u.type_specifier.type = TYPESPEC_VOID;
1617 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1618 $$->u.type_specifier.type = TYPESPEC_CHAR;
1622 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1623 $$->u.type_specifier.type = TYPESPEC_SHORT;
1627 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1628 $$->u.type_specifier.type = TYPESPEC_INT;
1632 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1633 $$->u.type_specifier.type = TYPESPEC_LONG;
1637 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1638 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1642 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1643 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1647 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1648 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1652 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1653 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1657 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1658 $$->u.type_specifier.type = TYPESPEC_BOOL;
1662 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1663 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1667 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1668 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1672 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1673 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1674 $$->u.type_specifier.id_type = yylval.gs->s;
1676 | FLOATING_POINT LBRAC RBRAC
1678 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1679 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1680 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1682 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1684 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1685 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1686 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1687 if (set_parent_node($3, $$->u.type_specifier.node))
1688 reparent_error(scanner, "floating point reparent error");
1690 | INTEGER LBRAC RBRAC
1692 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1693 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1694 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1696 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1698 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1699 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1700 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1701 if (set_parent_node($3, $$->u.type_specifier.node))
1702 reparent_error(scanner, "integer reparent error");
1706 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1707 $$->u.type_specifier.type = TYPESPEC_STRING;
1708 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1710 | STRING LBRAC RBRAC
1712 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1713 $$->u.type_specifier.type = TYPESPEC_STRING;
1714 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1716 | STRING LBRAC ctf_assignment_expression_list RBRAC
1718 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1719 $$->u.type_specifier.type = TYPESPEC_STRING;
1720 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1721 if (set_parent_node($3, $$->u.type_specifier.node))
1722 reparent_error(scanner, "string reparent error");
1724 | ENUM enum_type_specifier
1726 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1727 $$->u.type_specifier.type = TYPESPEC_ENUM;
1728 $$->u.type_specifier.node = $2;
1730 | VARIANT variant_type_specifier
1732 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1733 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1734 $$->u.type_specifier.node = $2;
1736 | STRUCT struct_type_specifier
1738 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1739 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1740 $$->u.type_specifier.node = $2;
1744 struct_type_specifier:
1745 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1747 $$ = make_node(scanner, NODE_STRUCT);
1748 $$->u._struct.has_body = 1;
1749 if ($2 && set_parent_node($2, $$))
1750 reparent_error(scanner, "struct reparent error");
1752 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1754 $$ = make_node(scanner, NODE_STRUCT);
1755 $$->u._struct.has_body = 1;
1756 $$->u._struct.name = $1->s;
1757 if ($3 && set_parent_node($3, $$))
1758 reparent_error(scanner, "struct reparent error");
1760 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1762 $$ = make_node(scanner, NODE_STRUCT);
1763 $$->u._struct.has_body = 1;
1764 $$->u._struct.name = $1->s;
1765 if ($3 && set_parent_node($3, $$))
1766 reparent_error(scanner, "struct reparent error");
1770 $$ = make_node(scanner, NODE_STRUCT);
1771 $$->u._struct.has_body = 0;
1772 $$->u._struct.name = $1->s;
1776 $$ = make_node(scanner, NODE_STRUCT);
1777 $$->u._struct.has_body = 0;
1778 $$->u._struct.name = $1->s;
1780 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1782 $$ = make_node(scanner, NODE_STRUCT);
1783 $$->u._struct.has_body = 1;
1784 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1785 if ($2 && set_parent_node($2, $$))
1786 reparent_error(scanner, "struct reparent error");
1788 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1790 $$ = make_node(scanner, NODE_STRUCT);
1791 $$->u._struct.has_body = 1;
1792 $$->u._struct.name = $1->s;
1793 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1794 if ($3 && set_parent_node($3, $$))
1795 reparent_error(scanner, "struct reparent error");
1797 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1799 $$ = make_node(scanner, NODE_STRUCT);
1800 $$->u._struct.has_body = 1;
1801 $$->u._struct.name = $1->s;
1802 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1803 if ($3 && set_parent_node($3, $$))
1804 reparent_error(scanner, "struct reparent error");
1808 struct_declaration_begin:
1810 { push_scope(scanner); }
1813 struct_declaration_end:
1815 { pop_scope(scanner); }
1818 variant_type_specifier:
1819 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1821 $$ = make_node(scanner, NODE_VARIANT);
1822 $$->u.variant.has_body = 1;
1823 if ($2 && set_parent_node($2, $$))
1824 reparent_error(scanner, "variant reparent error");
1826 | LT IDENTIFIER 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.choice = $2->s;
1831 if ($5 && set_parent_node($5, $$))
1832 reparent_error(scanner, "variant reparent error");
1834 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1836 $$ = make_node(scanner, NODE_VARIANT);
1837 $$->u.variant.has_body = 1;
1838 $$->u.variant.choice = $2->s;
1839 if ($5 && set_parent_node($5, $$))
1840 reparent_error(scanner, "variant reparent error");
1842 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1844 $$ = make_node(scanner, NODE_VARIANT);
1845 $$->u.variant.has_body = 1;
1846 $$->u.variant.name = $1->s;
1847 if ($3 && set_parent_node($3, $$))
1848 reparent_error(scanner, "variant reparent error");
1850 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1852 $$ = make_node(scanner, NODE_VARIANT);
1853 $$->u.variant.has_body = 1;
1854 $$->u.variant.name = $1->s;
1855 $$->u.variant.choice = $3->s;
1856 if ($6 && set_parent_node($6, $$))
1857 reparent_error(scanner, "variant reparent error");
1859 | IDENTIFIER LT IDENTIFIER GT
1861 $$ = make_node(scanner, NODE_VARIANT);
1862 $$->u.variant.has_body = 0;
1863 $$->u.variant.name = $1->s;
1864 $$->u.variant.choice = $3->s;
1866 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1868 $$ = make_node(scanner, NODE_VARIANT);
1869 $$->u.variant.has_body = 1;
1870 $$->u.variant.name = $1->s;
1871 $$->u.variant.choice = $3->s;
1872 if ($6 && set_parent_node($6, $$))
1873 reparent_error(scanner, "variant reparent error");
1875 | IDENTIFIER LT ID_TYPE GT
1877 $$ = make_node(scanner, NODE_VARIANT);
1878 $$->u.variant.has_body = 0;
1879 $$->u.variant.name = $1->s;
1880 $$->u.variant.choice = $3->s;
1882 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1884 $$ = make_node(scanner, NODE_VARIANT);
1885 $$->u.variant.has_body = 1;
1886 $$->u.variant.name = $1->s;
1887 if ($3 && set_parent_node($3, $$))
1888 reparent_error(scanner, "variant reparent error");
1890 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1892 $$ = make_node(scanner, NODE_VARIANT);
1893 $$->u.variant.has_body = 1;
1894 $$->u.variant.name = $1->s;
1895 $$->u.variant.choice = $3->s;
1896 if ($6 && set_parent_node($6, $$))
1897 reparent_error(scanner, "variant reparent error");
1899 | ID_TYPE LT IDENTIFIER GT
1901 $$ = make_node(scanner, NODE_VARIANT);
1902 $$->u.variant.has_body = 0;
1903 $$->u.variant.name = $1->s;
1904 $$->u.variant.choice = $3->s;
1906 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1908 $$ = make_node(scanner, NODE_VARIANT);
1909 $$->u.variant.has_body = 1;
1910 $$->u.variant.name = $1->s;
1911 $$->u.variant.choice = $3->s;
1912 if ($6 && set_parent_node($6, $$))
1913 reparent_error(scanner, "variant reparent error");
1915 | ID_TYPE LT ID_TYPE GT
1917 $$ = make_node(scanner, NODE_VARIANT);
1918 $$->u.variant.has_body = 0;
1919 $$->u.variant.name = $1->s;
1920 $$->u.variant.choice = $3->s;
1924 variant_declaration_begin:
1926 { push_scope(scanner); }
1929 variant_declaration_end:
1931 { pop_scope(scanner); }
1934 enum_type_specifier:
1935 LBRAC enumerator_list RBRAC
1937 $$ = make_node(scanner, NODE_ENUM);
1938 $$->u._enum.has_body = 1;
1939 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1941 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1943 $$ = make_node(scanner, NODE_ENUM);
1944 $$->u._enum.has_body = 1;
1945 ($$)->u._enum.container_type = $2;
1946 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1948 | IDENTIFIER LBRAC enumerator_list RBRAC
1950 $$ = make_node(scanner, NODE_ENUM);
1951 $$->u._enum.has_body = 1;
1952 $$->u._enum.enum_id = $1->s;
1953 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1955 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1957 $$ = make_node(scanner, NODE_ENUM);
1958 $$->u._enum.has_body = 1;
1959 $$->u._enum.enum_id = $1->s;
1960 ($$)->u._enum.container_type = $3;
1961 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1963 | ID_TYPE LBRAC enumerator_list RBRAC
1965 $$ = make_node(scanner, NODE_ENUM);
1966 $$->u._enum.has_body = 1;
1967 $$->u._enum.enum_id = $1->s;
1968 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1970 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1972 $$ = make_node(scanner, NODE_ENUM);
1973 $$->u._enum.has_body = 1;
1974 $$->u._enum.enum_id = $1->s;
1975 ($$)->u._enum.container_type = $3;
1976 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1978 | LBRAC enumerator_list COMMA RBRAC
1980 $$ = make_node(scanner, NODE_ENUM);
1981 $$->u._enum.has_body = 1;
1982 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1984 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1986 $$ = make_node(scanner, NODE_ENUM);
1987 $$->u._enum.has_body = 1;
1988 ($$)->u._enum.container_type = $2;
1989 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1991 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1993 $$ = make_node(scanner, NODE_ENUM);
1994 $$->u._enum.has_body = 1;
1995 $$->u._enum.enum_id = $1->s;
1996 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1998 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2000 $$ = make_node(scanner, NODE_ENUM);
2001 $$->u._enum.has_body = 1;
2002 $$->u._enum.enum_id = $1->s;
2003 ($$)->u._enum.container_type = $3;
2004 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2008 $$ = make_node(scanner, NODE_ENUM);
2009 $$->u._enum.has_body = 0;
2010 $$->u._enum.enum_id = $1->s;
2012 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
2014 $$ = make_node(scanner, NODE_ENUM);
2015 $$->u._enum.has_body = 1;
2016 $$->u._enum.enum_id = $1->s;
2017 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2019 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2021 $$ = make_node(scanner, NODE_ENUM);
2022 $$->u._enum.has_body = 1;
2023 $$->u._enum.enum_id = $1->s;
2024 ($$)->u._enum.container_type = $3;
2025 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2029 $$ = make_node(scanner, NODE_ENUM);
2030 $$->u._enum.has_body = 0;
2031 $$->u._enum.enum_id = $1->s;
2035 struct_or_variant_declaration_list:
2038 | struct_or_variant_declaration_list struct_or_variant_declaration
2042 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2045 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
2050 struct_or_variant_declaration:
2051 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
2053 struct ctf_node *list;
2055 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2056 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2057 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
2058 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2059 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
2061 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2063 struct ctf_node *list;
2065 $$ = make_node(scanner, NODE_TYPEDEF);
2066 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2067 $$->u._typedef.type_specifier_list = list;
2068 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2069 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2070 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2072 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2074 struct ctf_node *list;
2076 $$ = make_node(scanner, NODE_TYPEDEF);
2077 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2078 $$->u._typedef.type_specifier_list = list;
2079 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2080 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2082 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
2084 struct ctf_node *list;
2086 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2087 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2088 $$ = make_node(scanner, NODE_TYPEDEF);
2089 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2090 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2092 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
2094 struct ctf_node *list;
2096 $$ = make_node(scanner, NODE_TYPEALIAS);
2097 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2098 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2100 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2101 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2102 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2103 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2105 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2106 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2107 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2108 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2112 alias_declaration_specifiers:
2115 struct ctf_node *node;
2117 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2118 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2119 node->u.type_specifier.type = TYPESPEC_CONST;
2120 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2124 struct ctf_node *node;
2126 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2128 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2132 struct ctf_node *node;
2134 add_type(scanner, $1);
2135 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2136 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2137 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2138 node->u.type_specifier.id_type = yylval.gs->s;
2139 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2141 | alias_declaration_specifiers CONST
2143 struct ctf_node *node;
2146 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2147 node->u.type_specifier.type = TYPESPEC_CONST;
2148 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2150 | alias_declaration_specifiers type_specifier
2153 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2155 | alias_declaration_specifiers IDENTIFIER
2157 struct ctf_node *node;
2159 add_type(scanner, $2);
2161 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2162 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2163 node->u.type_specifier.id_type = yylval.gs->s;
2164 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2168 struct_or_variant_declarator_list:
2169 struct_or_variant_declarator
2171 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2174 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2178 struct_or_variant_declarator:
2181 | COLON unary_expression
2183 | declarator COLON unary_expression
2186 if (set_parent_node($3, $1))
2187 reparent_error(scanner, "struct_or_variant_declarator");
2194 | enumerator_list COMMA enumerator
2197 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2204 $$ = make_node(scanner, NODE_ENUMERATOR);
2205 $$->u.enumerator.id = $1->s;
2209 $$ = make_node(scanner, NODE_ENUMERATOR);
2210 $$->u.enumerator.id = $1->s;
2214 $$ = make_node(scanner, NODE_ENUMERATOR);
2215 $$->u.enumerator.id = $1->s;
2217 | STRING_LITERAL_START DQUOTE
2219 $$ = make_node(scanner, NODE_ENUMERATOR);
2220 $$->u.enumerator.id = "";
2222 | STRING_LITERAL_START s_char_sequence DQUOTE
2224 $$ = make_node(scanner, NODE_ENUMERATOR);
2225 $$->u.enumerator.id = $2->s;
2227 | IDENTIFIER EQUAL unary_expression_or_range
2229 $$ = make_node(scanner, NODE_ENUMERATOR);
2230 $$->u.enumerator.id = $1->s;
2231 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2233 | ID_TYPE EQUAL unary_expression_or_range
2235 $$ = make_node(scanner, NODE_ENUMERATOR);
2236 $$->u.enumerator.id = $1->s;
2237 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2239 | keywords EQUAL unary_expression_or_range
2241 $$ = make_node(scanner, NODE_ENUMERATOR);
2242 $$->u.enumerator.id = $1->s;
2243 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2245 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
2247 $$ = make_node(scanner, NODE_ENUMERATOR);
2248 $$->u.enumerator.id = "";
2249 bt_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
2251 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
2253 $$ = make_node(scanner, NODE_ENUMERATOR);
2254 $$->u.enumerator.id = $2->s;
2255 bt_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
2259 abstract_declarator_list:
2262 | abstract_declarator_list COMMA abstract_declarator
2265 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2269 abstract_declarator:
2270 direct_abstract_declarator
2272 | pointer direct_abstract_declarator
2275 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2279 direct_abstract_declarator:
2282 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2283 $$->u.type_declarator.type = TYPEDEC_ID;
2288 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2289 $$->u.type_declarator.type = TYPEDEC_ID;
2290 $$->u.type_declarator.u.id = $1->s;
2292 | LPAREN abstract_declarator RPAREN
2294 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2295 $$->u.type_declarator.type = TYPEDEC_NESTED;
2296 $$->u.type_declarator.u.nested.type_declarator = $2;
2298 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2300 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2301 $$->u.type_declarator.type = TYPEDEC_NESTED;
2302 $$->u.type_declarator.u.nested.type_declarator = $1;
2303 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2304 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2306 | direct_abstract_declarator LSBRAC RSBRAC
2308 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2309 $$->u.type_declarator.type = TYPEDEC_NESTED;
2310 $$->u.type_declarator.u.nested.type_declarator = $1;
2311 $$->u.type_declarator.u.nested.abstract_array = 1;
2315 alias_abstract_declarator_list:
2316 alias_abstract_declarator
2318 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2321 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2325 alias_abstract_declarator:
2326 direct_alias_abstract_declarator
2328 | pointer direct_alias_abstract_declarator
2331 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2335 direct_alias_abstract_declarator:
2338 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2339 $$->u.type_declarator.type = TYPEDEC_ID;
2342 | LPAREN alias_abstract_declarator RPAREN
2344 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2345 $$->u.type_declarator.type = TYPEDEC_NESTED;
2346 $$->u.type_declarator.u.nested.type_declarator = $2;
2348 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2350 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2351 $$->u.type_declarator.type = TYPEDEC_NESTED;
2352 $$->u.type_declarator.u.nested.type_declarator = $1;
2353 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2354 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2356 | direct_alias_abstract_declarator LSBRAC RSBRAC
2358 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2359 $$->u.type_declarator.type = TYPEDEC_NESTED;
2360 $$->u.type_declarator.u.nested.type_declarator = $1;
2361 $$->u.type_declarator.u.nested.abstract_array = 1;
2368 | pointer direct_declarator
2371 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2378 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2379 $$->u.type_declarator.type = TYPEDEC_ID;
2380 $$->u.type_declarator.u.id = $1->s;
2382 | LPAREN declarator RPAREN
2384 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2385 $$->u.type_declarator.type = TYPEDEC_NESTED;
2386 $$->u.type_declarator.u.nested.type_declarator = $2;
2388 | direct_declarator LSBRAC unary_expression RSBRAC
2390 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2391 $$->u.type_declarator.type = TYPEDEC_NESTED;
2392 $$->u.type_declarator.u.nested.type_declarator = $1;
2393 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2394 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2399 direct_type_declarator
2401 | pointer direct_type_declarator
2404 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2408 direct_type_declarator:
2411 add_type(scanner, $1);
2412 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2413 $$->u.type_declarator.type = TYPEDEC_ID;
2414 $$->u.type_declarator.u.id = $1->s;
2416 | LPAREN type_declarator RPAREN
2418 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2419 $$->u.type_declarator.type = TYPEDEC_NESTED;
2420 $$->u.type_declarator.u.nested.type_declarator = $2;
2422 | direct_type_declarator LSBRAC unary_expression RSBRAC
2424 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2425 $$->u.type_declarator.type = TYPEDEC_NESTED;
2426 $$->u.type_declarator.u.nested.type_declarator = $1;
2427 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2428 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2435 $$ = make_node(scanner, NODE_POINTER);
2439 $$ = make_node(scanner, NODE_POINTER);
2440 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2442 | STAR type_qualifier_list pointer
2444 $$ = make_node(scanner, NODE_POINTER);
2445 $$->u.pointer.const_qualifier = 1;
2446 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2450 type_qualifier_list:
2451 /* pointer assumes only const type qualifier */
2453 | type_qualifier_list CONST
2456 /* 2.3: CTF-specific declarations */
2458 ctf_assignment_expression_list:
2459 ctf_assignment_expression SEMICOLON
2461 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2464 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2468 ctf_assignment_expression:
2469 unary_expression EQUAL unary_expression
2472 * Because we have left and right, cannot use
2475 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2476 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2477 if ($1->u.unary_expression.type != UNARY_STRING)
2478 reparent_error(scanner, "ctf_assignment_expression left expects string");
2479 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2481 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2484 * Because we have left and right, cannot use
2487 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2488 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2489 if ($1->u.unary_expression.type != UNARY_STRING)
2490 reparent_error(scanner, "ctf_assignment_expression left expects string");
2491 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2493 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2495 struct ctf_node *list;
2497 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2498 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2499 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2500 $$ = make_node(scanner, NODE_TYPEDEF);
2501 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2502 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2504 | TYPEDEF declaration_specifiers type_declarator_list
2506 struct ctf_node *list;
2508 $$ = make_node(scanner, NODE_TYPEDEF);
2509 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2510 $$->u._typedef.type_specifier_list = list;
2511 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2512 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2514 | declaration_specifiers TYPEDEF type_declarator_list
2516 struct ctf_node *list;
2518 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2519 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2520 $$ = make_node(scanner, NODE_TYPEDEF);
2521 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2522 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2524 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2526 struct ctf_node *list;
2528 $$ = make_node(scanner, NODE_TYPEALIAS);
2529 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2530 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2532 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2533 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2534 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2535 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2537 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2538 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2539 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2540 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);