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
37 #include <babeltrace/list.h>
38 #include <babeltrace/babeltrace-internal.h>
39 #include "ctf-scanner.h"
40 #include "ctf-parser.h"
46 /* Join two lists, put "add" at the end of "head". */
48 _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
50 /* Do nothing if the list which gets added is empty. */
51 if (add != add->next) {
52 add->next->prev = head->prev;
53 add->prev->next = head;
54 head->prev->next = add->next;
55 head->prev = add->prev;
60 int yyparse(struct ctf_scanner *scanner);
62 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
64 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
66 int yylex_destroy(yyscan_t yyscanner);
68 void yyrestart(FILE * in_str, yyscan_t scanner);
70 int yyget_lineno(yyscan_t yyscanner);
72 char *yyget_text(yyscan_t yyscanner);
75 struct bt_list_head gc;
80 static const char *node_type_to_str[] = {
81 #define ENTRY(S) [S] = #S,
82 FOREACH_CTF_NODES(ENTRY)
87 * Static node for out of memory errors. Only "type" is used. lineno is
88 * always left at 0. The rest of the node content can be overwritten,
91 static struct ctf_node error_node = {
96 const char *node_type(struct ctf_node *node)
98 if (node->type < NR_NODE_TYPES)
99 return node_type_to_str[node->type];
104 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
107 struct gc_string *gstr;
110 /* TODO: could be faster with find first bit or glib Gstring */
111 /* sizeof long to account for malloc header (int or long ?) */
112 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
115 gstr = malloc(alloclen);
116 bt_list_add(&gstr->gc, &scanner->allocated_strings);
117 gstr->alloclen = alloclen;
121 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
123 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
124 strcpy(lvalp->gs->s, src);
128 int str_check(size_t str_len, size_t offset, size_t len)
131 if (offset + len < offset)
133 if (offset + len > str_len)
139 int bt_isodigit(int c)
157 int parse_base_sequence(const char *src, size_t len, size_t pos,
158 char *buffer, size_t *buf_len, int base)
160 const size_t max_char = 3;
163 while (!str_check(len, pos, 1) && nr_char < max_char) {
168 buffer[nr_char++] = c;
171 } else if (base == 16) {
173 buffer[nr_char++] = c;
178 /* Unsupported base */
183 buffer[nr_char] = '\0';
189 int import_basic_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
190 size_t len, const char *src, char delim)
192 size_t pos = 0, dpos = 0;
194 if (str_check(len, pos, 1))
196 if (src[pos++] != delim)
199 while (src[pos] != delim) {
202 if (str_check(len, pos, 1))
206 if (str_check(len, pos, 1))
256 if (parse_base_sequence(src, len, pos - 1,
257 oct_buffer, &oct_len, 8))
259 c = strtoul(&oct_buffer[0], NULL, 8);
268 if (parse_base_sequence(src, len, pos,
269 hex_buffer, &hex_len, 16))
271 c = strtoul(&hex_buffer[0], NULL, 16);
279 if (str_check(len, dpos, 1))
281 lvalp->gs->s[dpos++] = c;
284 if (str_check(len, dpos, 1))
286 lvalp->gs->s[dpos++] = '\0';
288 if (str_check(len, pos, 1))
290 if (src[pos++] != delim)
293 if (str_check(len, pos, 1))
295 if (src[pos] != '\0')
300 int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
301 const char *src, char delim)
305 len = strlen(src) + 1;
306 lvalp->gs = gc_string_alloc(scanner, len);
308 // TODO: import wide string
309 printfl_error(yyget_lineno(scanner),
310 "Wide string not supported yet.");
313 return import_basic_string(scanner, lvalp, len, src, delim);
317 static void init_scope(struct ctf_scanner_scope *scope,
318 struct ctf_scanner_scope *parent)
320 scope->parent = parent;
321 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
325 static void finalize_scope(struct ctf_scanner_scope *scope)
327 g_hash_table_destroy(scope->types);
330 static void push_scope(struct ctf_scanner *scanner)
332 struct ctf_scanner_scope *ns;
334 printf_debug("push scope\n");
335 ns = malloc(sizeof(struct ctf_scanner_scope));
336 init_scope(ns, scanner->cs);
340 static void pop_scope(struct ctf_scanner *scanner)
342 struct ctf_scanner_scope *os;
344 printf_debug("pop scope\n");
346 scanner->cs = os->parent;
351 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
355 ret = (int) (long) g_hash_table_lookup(s->types, id);
356 printf_debug("lookup %p %s %d\n", s, id, ret);
361 int is_type(struct ctf_scanner *scanner, const char *id)
363 struct ctf_scanner_scope *it;
366 for (it = scanner->cs; it != NULL; it = it->parent) {
367 if (lookup_type(it, id)) {
372 printf_debug("is type %s %d\n", id, ret);
376 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
378 printf_debug("add type %s\n", id->s);
379 if (lookup_type(scanner->cs, id->s))
381 g_hash_table_insert(scanner->cs->types, id->s, id->s);
384 static struct ctf_node *make_node(struct ctf_scanner *scanner,
387 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
388 struct ctf_node *node;
390 node = malloc(sizeof(*node));
392 printfl_fatal(yyget_lineno(scanner->scanner), "out of memory");
395 memset(node, 0, sizeof(*node));
397 node->lineno = yyget_lineno(scanner->scanner);
398 BT_INIT_LIST_HEAD(&node->tmp_head);
399 bt_list_add(&node->gc, &ast->allocated_nodes);
400 bt_list_add(&node->siblings, &node->tmp_head);
404 node->type = NODE_ERROR;
405 printfn_fatal(node, "trying to create root node");
409 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
412 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
415 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
418 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
421 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
424 BT_INIT_LIST_HEAD(&node->u.callsite.declaration_list);
427 case NODE_CTF_EXPRESSION:
428 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
429 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
431 case NODE_UNARY_EXPRESSION:
435 BT_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
437 case NODE_TYPEALIAS_TARGET:
438 BT_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
440 case NODE_TYPEALIAS_ALIAS:
441 BT_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
446 case NODE_TYPE_SPECIFIER:
448 case NODE_TYPE_SPECIFIER_LIST:
449 BT_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
453 case NODE_TYPE_DECLARATOR:
454 BT_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
457 case NODE_FLOATING_POINT:
458 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
461 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
464 BT_INIT_LIST_HEAD(&node->u.string.expressions);
466 case NODE_ENUMERATOR:
467 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
470 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
472 case NODE_STRUCT_OR_VARIANT_DECLARATION:
473 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
476 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
479 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
480 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
485 node->type = NODE_ERROR;
486 printfn_fatal(node, "unknown node type '%d'", (int) type);
493 static int reparent_ctf_expression(struct ctf_node *node,
494 struct ctf_node *parent)
496 switch (parent->type) {
498 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
501 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
504 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
507 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
510 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
513 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
515 case NODE_FLOATING_POINT:
516 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
519 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
522 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
526 case NODE_CTF_EXPRESSION:
528 case NODE_TYPEALIAS_TARGET:
529 case NODE_TYPEALIAS_ALIAS:
531 case NODE_TYPE_SPECIFIER:
532 case NODE_TYPE_SPECIFIER_LIST:
534 case NODE_TYPE_DECLARATOR:
535 case NODE_ENUMERATOR:
537 case NODE_STRUCT_OR_VARIANT_DECLARATION:
540 case NODE_UNARY_EXPRESSION:
545 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
551 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
553 switch (parent->type) {
555 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
558 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
561 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
564 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
567 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
570 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
573 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
576 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
579 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
582 case NODE_FLOATING_POINT:
585 case NODE_CTF_EXPRESSION:
587 case NODE_TYPEALIAS_TARGET:
588 case NODE_TYPEALIAS_ALIAS:
590 case NODE_TYPE_SPECIFIER:
591 case NODE_TYPE_SPECIFIER_LIST:
593 case NODE_TYPE_DECLARATOR:
594 case NODE_ENUMERATOR:
596 case NODE_STRUCT_OR_VARIANT_DECLARATION:
597 case NODE_UNARY_EXPRESSION:
602 printfn_fatal(node, "unknown node type %d", parent->type);
608 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
610 switch (parent->type) {
612 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
615 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
618 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
621 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
624 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
627 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
630 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
633 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
636 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
639 case NODE_FLOATING_POINT:
642 case NODE_CTF_EXPRESSION:
644 case NODE_TYPEALIAS_TARGET:
645 case NODE_TYPEALIAS_ALIAS:
647 case NODE_TYPE_SPECIFIER:
648 case NODE_TYPE_SPECIFIER_LIST:
650 case NODE_TYPE_DECLARATOR:
651 case NODE_ENUMERATOR:
653 case NODE_STRUCT_OR_VARIANT_DECLARATION:
654 case NODE_UNARY_EXPRESSION:
659 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
665 static int reparent_type_specifier(struct ctf_node *node,
666 struct ctf_node *parent)
668 switch (parent->type) {
669 case NODE_TYPE_SPECIFIER_LIST:
670 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
673 case NODE_TYPE_SPECIFIER:
683 case NODE_TYPEALIAS_TARGET:
684 case NODE_TYPEALIAS_ALIAS:
685 case NODE_TYPE_DECLARATOR:
687 case NODE_STRUCT_OR_VARIANT_DECLARATION:
689 case NODE_FLOATING_POINT:
692 case NODE_CTF_EXPRESSION:
694 case NODE_ENUMERATOR:
695 case NODE_UNARY_EXPRESSION:
700 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
706 static int reparent_type_specifier_list(struct ctf_node *node,
707 struct ctf_node *parent)
709 switch (parent->type) {
711 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
714 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
717 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
720 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
723 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
726 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
729 bt_list_add_tail(&node->siblings, &parent->u.callsite.declaration_list);
732 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
735 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
738 parent->u._typedef.type_specifier_list = node;
740 case NODE_TYPEALIAS_TARGET:
741 parent->u.typealias_target.type_specifier_list = node;
743 case NODE_TYPEALIAS_ALIAS:
744 parent->u.typealias_alias.type_specifier_list = node;
747 parent->u._enum.container_type = node;
749 case NODE_STRUCT_OR_VARIANT_DECLARATION:
750 parent->u.struct_or_variant_declaration.type_specifier_list = node;
752 case NODE_TYPE_DECLARATOR:
753 case NODE_TYPE_SPECIFIER:
755 case NODE_FLOATING_POINT:
758 case NODE_CTF_EXPRESSION:
760 case NODE_ENUMERATOR:
761 case NODE_UNARY_EXPRESSION:
766 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
772 static int reparent_type_declarator(struct ctf_node *node,
773 struct ctf_node *parent)
775 switch (parent->type) {
776 case NODE_TYPE_DECLARATOR:
777 parent->u.type_declarator.type = TYPEDEC_NESTED;
778 parent->u.type_declarator.u.nested.type_declarator = node;
780 case NODE_STRUCT_OR_VARIANT_DECLARATION:
781 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
784 _bt_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
786 case NODE_TYPEALIAS_TARGET:
787 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
789 case NODE_TYPEALIAS_ALIAS:
790 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
804 case NODE_FLOATING_POINT:
807 case NODE_CTF_EXPRESSION:
808 case NODE_TYPE_SPECIFIER:
809 case NODE_TYPE_SPECIFIER_LIST:
811 case NODE_ENUMERATOR:
812 case NODE_UNARY_EXPRESSION:
817 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
826 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
827 * create the link declared by the input, -ENOENT if node or parent is NULL,
828 * -EINVAL if there is an internal structure problem.
830 static int set_parent_node(struct ctf_node *node,
831 struct ctf_node *parent)
833 if (!node || !parent)
836 /* Note: Linking to parent will be done only by an external visitor */
838 switch (node->type) {
840 printfn_fatal(node, "trying to reparent root node");
844 if (parent->type == NODE_ROOT) {
845 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
851 if (parent->type == NODE_ROOT) {
852 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
858 if (parent->type == NODE_ROOT) {
859 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
865 if (parent->type == NODE_ROOT) {
866 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
872 if (parent->type == NODE_ROOT) {
873 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
879 if (parent->type == NODE_ROOT) {
880 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.callsite);
886 case NODE_CTF_EXPRESSION:
887 return reparent_ctf_expression(node, parent);
888 case NODE_UNARY_EXPRESSION:
889 if (parent->type == NODE_TYPE_DECLARATOR)
890 parent->u.type_declarator.bitfield_len = node;
896 return reparent_typedef(node, parent);
897 case NODE_TYPEALIAS_TARGET:
898 if (parent->type == NODE_TYPEALIAS)
899 parent->u.typealias.target = node;
902 case NODE_TYPEALIAS_ALIAS:
903 if (parent->type == NODE_TYPEALIAS)
904 parent->u.typealias.alias = node;
908 return reparent_typealias(node, parent);
911 if (parent->type == NODE_TYPE_DECLARATOR) {
912 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
916 case NODE_TYPE_DECLARATOR:
917 return reparent_type_declarator(node, parent);
919 case NODE_TYPE_SPECIFIER_LIST:
920 return reparent_type_specifier_list(node, parent);
922 case NODE_TYPE_SPECIFIER:
923 return reparent_type_specifier(node, parent);
925 case NODE_FLOATING_POINT:
931 return -EINVAL; /* Dealt with internally within grammar */
933 case NODE_ENUMERATOR:
934 if (parent->type == NODE_ENUM) {
935 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
940 case NODE_STRUCT_OR_VARIANT_DECLARATION:
941 switch (parent->type) {
943 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
946 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
955 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
962 void yyerror(struct ctf_scanner *scanner, const char *str)
964 printfl_error(yyget_lineno(scanner->scanner),
965 "token \"%s\": %s\n",
966 yyget_text(scanner->scanner), str);
975 #define reparent_error(scanner, str) \
977 yyerror(scanner, YY_("reparent_error: " str)); \
981 static void free_strings(struct bt_list_head *list)
983 struct gc_string *gstr, *tmp;
985 bt_list_for_each_entry_safe(gstr, tmp, list, gc)
989 static struct ctf_ast *ctf_ast_alloc(void)
993 ast = malloc(sizeof(*ast));
996 memset(ast, 0, sizeof(*ast));
997 BT_INIT_LIST_HEAD(&ast->allocated_nodes);
998 ast->root.type = NODE_ROOT;
999 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
1000 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
1001 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
1002 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
1003 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
1004 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
1005 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
1006 BT_INIT_LIST_HEAD(&ast->root.u.root.callsite);
1010 static void ctf_ast_free(struct ctf_ast *ast)
1012 struct ctf_node *node, *tmp;
1014 bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
1019 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
1021 return yyparse(scanner);
1024 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
1026 struct ctf_scanner *scanner;
1029 yydebug = babeltrace_debug;
1031 scanner = malloc(sizeof(*scanner));
1034 memset(scanner, 0, sizeof(*scanner));
1036 ret = yylex_init_extra(scanner, &scanner->scanner);
1038 printf_fatal("yylex_init error");
1039 goto cleanup_scanner;
1041 /* Start processing new stream */
1042 yyrestart(input, scanner->scanner);
1044 scanner->ast = ctf_ast_alloc();
1047 init_scope(&scanner->root_scope, NULL);
1048 scanner->cs = &scanner->root_scope;
1049 BT_INIT_LIST_HEAD(&scanner->allocated_strings);
1052 fprintf(stdout, "Scanner input is a%s.\n",
1053 isatty(fileno(input)) ? "n interactive tty" :
1054 " noninteractive file");
1059 ret = yylex_destroy(scanner->scanner);
1061 printf_fatal("yylex_destroy error");
1067 void ctf_scanner_free(struct ctf_scanner *scanner)
1071 finalize_scope(&scanner->root_scope);
1072 free_strings(&scanner->allocated_strings);
1073 ctf_ast_free(scanner->ast);
1074 ret = yylex_destroy(scanner->scanner);
1076 printf_error("yylex_destroy error");
1085 %parse-param {struct ctf_scanner *scanner}
1086 %lex-param {struct ctf_scanner *scanner}
1088 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
1089 * vs struct { int :value; } (unnamed bit-field). The default is to
1090 * shift, so whenever we encounter an enumeration, we are doing the
1091 * proper thing (shift). It is illegal to declare an enumeration
1092 * "bit-field", so it is OK if this situation ends up in a parsing
1097 %token INTEGER_LITERAL STRING_LITERAL CHARACTER_LITERAL 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 TOK_ALIGN
1098 %token <gs> IDENTIFIER ID_TYPE
1103 unsigned long long ull;
1105 struct gc_string *gs;
1109 %type <gs> STRING_LITERAL CHARACTER_LITERAL
1113 %type <ull> INTEGER_LITERAL
1114 %type <n> postfix_expression unary_expression unary_expression_or_range
1116 %type <n> declaration
1117 %type <n> event_declaration
1118 %type <n> stream_declaration
1119 %type <n> env_declaration
1120 %type <n> trace_declaration
1121 %type <n> clock_declaration
1122 %type <n> callsite_declaration
1123 %type <n> integer_declaration_specifiers
1124 %type <n> declaration_specifiers
1125 %type <n> alias_declaration_specifiers
1127 %type <n> type_declarator_list
1128 %type <n> integer_type_specifier
1129 %type <n> type_specifier
1130 %type <n> struct_type_specifier
1131 %type <n> variant_type_specifier
1132 %type <n> enum_type_specifier
1133 %type <n> struct_or_variant_declaration_list
1134 %type <n> struct_or_variant_declaration
1135 %type <n> struct_or_variant_declarator_list
1136 %type <n> struct_or_variant_declarator
1137 %type <n> enumerator_list
1138 %type <n> enumerator
1139 %type <n> abstract_declarator_list
1140 %type <n> abstract_declarator
1141 %type <n> direct_abstract_declarator
1142 %type <n> alias_abstract_declarator_list
1143 %type <n> alias_abstract_declarator
1144 %type <n> direct_alias_abstract_declarator
1145 %type <n> declarator
1146 %type <n> direct_declarator
1147 %type <n> type_declarator
1148 %type <n> direct_type_declarator
1150 %type <n> ctf_assignment_expression_list
1151 %type <n> ctf_assignment_expression
1158 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
1159 reparent_error(scanner, "error reparenting to root");
1163 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
1164 reparent_error(scanner, "error reparenting to root");
1226 /* 2: Phrase structure grammar */
1231 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1232 $$->u.unary_expression.type = UNARY_STRING;
1233 $$->u.unary_expression.u.string = yylval.gs->s;
1237 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1238 $$->u.unary_expression.type = UNARY_STRING;
1239 $$->u.unary_expression.u.string = yylval.gs->s;
1243 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1244 $$->u.unary_expression.type = UNARY_STRING;
1245 $$->u.unary_expression.u.string = yylval.gs->s;
1249 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1250 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1251 $$->u.unary_expression.u.unsigned_constant = $1;
1255 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1256 $$->u.unary_expression.type = UNARY_STRING;
1257 $$->u.unary_expression.u.string = $1->s;
1261 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1262 $$->u.unary_expression.type = UNARY_STRING;
1263 $$->u.unary_expression.u.string = $1->s;
1265 | LPAREN unary_expression RPAREN
1269 | postfix_expression LSBRAC unary_expression RSBRAC
1271 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1272 $$->u.unary_expression.type = UNARY_SBRAC;
1273 $$->u.unary_expression.u.sbrac_exp = $3;
1274 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1275 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1277 | postfix_expression DOT IDENTIFIER
1279 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1280 $$->u.unary_expression.type = UNARY_STRING;
1281 $$->u.unary_expression.u.string = yylval.gs->s;
1282 $$->u.unary_expression.link = UNARY_DOTLINK;
1283 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1284 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1286 | postfix_expression DOT ID_TYPE
1288 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1289 $$->u.unary_expression.type = UNARY_STRING;
1290 $$->u.unary_expression.u.string = yylval.gs->s;
1291 $$->u.unary_expression.link = UNARY_DOTLINK;
1292 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1293 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1295 | postfix_expression RARROW IDENTIFIER
1297 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1298 $$->u.unary_expression.type = UNARY_STRING;
1299 $$->u.unary_expression.u.string = yylval.gs->s;
1300 $$->u.unary_expression.link = UNARY_ARROWLINK;
1301 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1302 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1304 | postfix_expression RARROW ID_TYPE
1306 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1307 $$->u.unary_expression.type = UNARY_STRING;
1308 $$->u.unary_expression.u.string = yylval.gs->s;
1309 $$->u.unary_expression.link = UNARY_ARROWLINK;
1310 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1311 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1318 | PLUS postfix_expression
1321 if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
1322 && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
1323 reparent_error(scanner, "expecting numeric constant");
1326 | MINUS postfix_expression
1329 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1330 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1331 $$->u.unary_expression.u.signed_constant =
1332 -($$->u.unary_expression.u.unsigned_constant);
1333 } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1334 $$->u.unary_expression.u.signed_constant =
1335 -($$->u.unary_expression.u.signed_constant);
1337 reparent_error(scanner, "expecting numeric constant");
1342 unary_expression_or_range:
1343 unary_expression DOTDOTDOT unary_expression
1346 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1347 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1353 /* 2.2: Declarations */
1356 declaration_specifiers SEMICOLON
1360 | stream_declaration
1368 | callsite_declaration
1370 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1372 struct ctf_node *list;
1374 $$ = make_node(scanner, NODE_TYPEDEF);
1375 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1376 $$->u._typedef.type_specifier_list = list;
1377 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1378 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1379 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1381 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1383 struct ctf_node *list;
1385 $$ = make_node(scanner, NODE_TYPEDEF);
1386 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1387 $$->u._typedef.type_specifier_list = list;
1388 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1389 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1391 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1393 struct ctf_node *list;
1395 $$ = make_node(scanner, NODE_TYPEDEF);
1396 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1397 $$->u._typedef.type_specifier_list = list;
1398 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1399 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1401 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1403 struct ctf_node *list;
1405 $$ = make_node(scanner, NODE_TYPEALIAS);
1406 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1407 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1409 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1410 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1411 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1412 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1414 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1415 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1416 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1417 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1422 event_declaration_begin event_declaration_end
1424 $$ = make_node(scanner, NODE_EVENT);
1426 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1428 $$ = make_node(scanner, NODE_EVENT);
1429 if (set_parent_node($2, $$))
1430 reparent_error(scanner, "event_declaration");
1434 event_declaration_begin:
1436 { push_scope(scanner); }
1439 event_declaration_end:
1441 { pop_scope(scanner); }
1446 stream_declaration_begin stream_declaration_end
1448 $$ = make_node(scanner, NODE_STREAM);
1450 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1452 $$ = make_node(scanner, NODE_STREAM);
1453 if (set_parent_node($2, $$))
1454 reparent_error(scanner, "stream_declaration");
1458 stream_declaration_begin:
1460 { push_scope(scanner); }
1463 stream_declaration_end:
1465 { pop_scope(scanner); }
1469 env_declaration_begin env_declaration_end
1471 $$ = make_node(scanner, NODE_ENV);
1473 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1475 $$ = make_node(scanner, NODE_ENV);
1476 if (set_parent_node($2, $$))
1477 reparent_error(scanner, "env declaration");
1481 env_declaration_begin:
1483 { push_scope(scanner); }
1486 env_declaration_end:
1488 { pop_scope(scanner); }
1492 trace_declaration_begin trace_declaration_end
1494 $$ = make_node(scanner, NODE_TRACE);
1496 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1498 $$ = make_node(scanner, NODE_TRACE);
1499 if (set_parent_node($2, $$))
1500 reparent_error(scanner, "trace_declaration");
1504 trace_declaration_begin:
1506 { push_scope(scanner); }
1509 trace_declaration_end:
1511 { pop_scope(scanner); }
1515 CLOCK clock_declaration_begin clock_declaration_end
1517 $$ = make_node(scanner, NODE_CLOCK);
1519 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1521 $$ = make_node(scanner, NODE_CLOCK);
1522 if (set_parent_node($3, $$))
1523 reparent_error(scanner, "trace_declaration");
1527 clock_declaration_begin:
1529 { push_scope(scanner); }
1532 clock_declaration_end:
1534 { pop_scope(scanner); }
1537 callsite_declaration:
1538 CALLSITE callsite_declaration_begin callsite_declaration_end
1540 $$ = make_node(scanner, NODE_CALLSITE);
1542 | CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1544 $$ = make_node(scanner, NODE_CALLSITE);
1545 if (set_parent_node($3, $$))
1546 reparent_error(scanner, "trace_declaration");
1550 callsite_declaration_begin:
1552 { push_scope(scanner); }
1555 callsite_declaration_end:
1557 { pop_scope(scanner); }
1560 integer_declaration_specifiers:
1563 struct ctf_node *node;
1565 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1566 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1567 node->u.type_specifier.type = TYPESPEC_CONST;
1568 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1570 | integer_type_specifier
1572 struct ctf_node *node;
1574 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1576 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1578 | integer_declaration_specifiers CONST
1580 struct ctf_node *node;
1583 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1584 node->u.type_specifier.type = TYPESPEC_CONST;
1585 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1587 | integer_declaration_specifiers integer_type_specifier
1590 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1594 declaration_specifiers:
1597 struct ctf_node *node;
1599 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1600 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1601 node->u.type_specifier.type = TYPESPEC_CONST;
1602 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1606 struct ctf_node *node;
1608 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1610 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1612 | declaration_specifiers CONST
1614 struct ctf_node *node;
1617 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1618 node->u.type_specifier.type = TYPESPEC_CONST;
1619 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1621 | declaration_specifiers type_specifier
1624 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1628 type_declarator_list:
1631 | type_declarator_list COMMA type_declarator
1634 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1638 integer_type_specifier:
1641 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1642 $$->u.type_specifier.type = TYPESPEC_CHAR;
1646 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1647 $$->u.type_specifier.type = TYPESPEC_SHORT;
1651 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1652 $$->u.type_specifier.type = TYPESPEC_INT;
1656 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1657 $$->u.type_specifier.type = TYPESPEC_LONG;
1661 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1662 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1666 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1667 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1671 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1672 $$->u.type_specifier.type = TYPESPEC_BOOL;
1676 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1677 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1678 $$->u.type_specifier.id_type = yylval.gs->s;
1680 | INTEGER LBRAC RBRAC
1682 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1683 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1684 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1686 | INTEGER LBRAC ctf_assignment_expression_list 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);
1691 if (set_parent_node($3, $$->u.type_specifier.node))
1692 reparent_error(scanner, "integer reparent error");
1699 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1700 $$->u.type_specifier.type = TYPESPEC_VOID;
1704 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1705 $$->u.type_specifier.type = TYPESPEC_CHAR;
1709 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1710 $$->u.type_specifier.type = TYPESPEC_SHORT;
1714 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1715 $$->u.type_specifier.type = TYPESPEC_INT;
1719 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1720 $$->u.type_specifier.type = TYPESPEC_LONG;
1724 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1725 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1729 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1730 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1734 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1735 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1739 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1740 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1744 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1745 $$->u.type_specifier.type = TYPESPEC_BOOL;
1749 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1750 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1754 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1755 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1759 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1760 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1761 $$->u.type_specifier.id_type = yylval.gs->s;
1763 | FLOATING_POINT LBRAC RBRAC
1765 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1766 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1767 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1769 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1771 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1772 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1773 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1774 if (set_parent_node($3, $$->u.type_specifier.node))
1775 reparent_error(scanner, "floating point reparent error");
1777 | INTEGER LBRAC RBRAC
1779 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1780 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1781 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1783 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1785 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1786 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1787 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1788 if (set_parent_node($3, $$->u.type_specifier.node))
1789 reparent_error(scanner, "integer reparent error");
1793 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1794 $$->u.type_specifier.type = TYPESPEC_STRING;
1795 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1797 | STRING LBRAC RBRAC
1799 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1800 $$->u.type_specifier.type = TYPESPEC_STRING;
1801 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1803 | STRING LBRAC ctf_assignment_expression_list RBRAC
1805 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1806 $$->u.type_specifier.type = TYPESPEC_STRING;
1807 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1808 if (set_parent_node($3, $$->u.type_specifier.node))
1809 reparent_error(scanner, "string reparent error");
1811 | ENUM enum_type_specifier
1813 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1814 $$->u.type_specifier.type = TYPESPEC_ENUM;
1815 $$->u.type_specifier.node = $2;
1817 | VARIANT variant_type_specifier
1819 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1820 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1821 $$->u.type_specifier.node = $2;
1823 | STRUCT struct_type_specifier
1825 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1826 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1827 $$->u.type_specifier.node = $2;
1831 struct_type_specifier:
1832 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1834 $$ = make_node(scanner, NODE_STRUCT);
1835 $$->u._struct.has_body = 1;
1836 if ($2 && set_parent_node($2, $$))
1837 reparent_error(scanner, "struct reparent error");
1839 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1841 $$ = make_node(scanner, NODE_STRUCT);
1842 $$->u._struct.has_body = 1;
1843 $$->u._struct.name = $1->s;
1844 if ($3 && set_parent_node($3, $$))
1845 reparent_error(scanner, "struct reparent error");
1847 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1849 $$ = make_node(scanner, NODE_STRUCT);
1850 $$->u._struct.has_body = 1;
1851 $$->u._struct.name = $1->s;
1852 if ($3 && set_parent_node($3, $$))
1853 reparent_error(scanner, "struct reparent error");
1857 $$ = make_node(scanner, NODE_STRUCT);
1858 $$->u._struct.has_body = 0;
1859 $$->u._struct.name = $1->s;
1863 $$ = make_node(scanner, NODE_STRUCT);
1864 $$->u._struct.has_body = 0;
1865 $$->u._struct.name = $1->s;
1867 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1869 $$ = make_node(scanner, NODE_STRUCT);
1870 $$->u._struct.has_body = 1;
1871 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1872 if ($2 && set_parent_node($2, $$))
1873 reparent_error(scanner, "struct reparent error");
1875 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1877 $$ = make_node(scanner, NODE_STRUCT);
1878 $$->u._struct.has_body = 1;
1879 $$->u._struct.name = $1->s;
1880 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1881 if ($3 && set_parent_node($3, $$))
1882 reparent_error(scanner, "struct reparent error");
1884 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1886 $$ = make_node(scanner, NODE_STRUCT);
1887 $$->u._struct.has_body = 1;
1888 $$->u._struct.name = $1->s;
1889 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1890 if ($3 && set_parent_node($3, $$))
1891 reparent_error(scanner, "struct reparent error");
1895 struct_declaration_begin:
1897 { push_scope(scanner); }
1900 struct_declaration_end:
1902 { pop_scope(scanner); }
1905 variant_type_specifier:
1906 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1908 $$ = make_node(scanner, NODE_VARIANT);
1909 $$->u.variant.has_body = 1;
1910 if ($2 && set_parent_node($2, $$))
1911 reparent_error(scanner, "variant reparent error");
1913 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1915 $$ = make_node(scanner, NODE_VARIANT);
1916 $$->u.variant.has_body = 1;
1917 $$->u.variant.choice = $2->s;
1918 if ($5 && set_parent_node($5, $$))
1919 reparent_error(scanner, "variant reparent error");
1921 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1923 $$ = make_node(scanner, NODE_VARIANT);
1924 $$->u.variant.has_body = 1;
1925 $$->u.variant.choice = $2->s;
1926 if ($5 && set_parent_node($5, $$))
1927 reparent_error(scanner, "variant reparent error");
1929 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1931 $$ = make_node(scanner, NODE_VARIANT);
1932 $$->u.variant.has_body = 1;
1933 $$->u.variant.name = $1->s;
1934 if ($3 && set_parent_node($3, $$))
1935 reparent_error(scanner, "variant reparent error");
1937 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1939 $$ = make_node(scanner, NODE_VARIANT);
1940 $$->u.variant.has_body = 1;
1941 $$->u.variant.name = $1->s;
1942 $$->u.variant.choice = $3->s;
1943 if ($6 && set_parent_node($6, $$))
1944 reparent_error(scanner, "variant reparent error");
1946 | IDENTIFIER LT IDENTIFIER GT
1948 $$ = make_node(scanner, NODE_VARIANT);
1949 $$->u.variant.has_body = 0;
1950 $$->u.variant.name = $1->s;
1951 $$->u.variant.choice = $3->s;
1953 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1955 $$ = make_node(scanner, NODE_VARIANT);
1956 $$->u.variant.has_body = 1;
1957 $$->u.variant.name = $1->s;
1958 $$->u.variant.choice = $3->s;
1959 if ($6 && set_parent_node($6, $$))
1960 reparent_error(scanner, "variant reparent error");
1962 | IDENTIFIER LT ID_TYPE GT
1964 $$ = make_node(scanner, NODE_VARIANT);
1965 $$->u.variant.has_body = 0;
1966 $$->u.variant.name = $1->s;
1967 $$->u.variant.choice = $3->s;
1969 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1971 $$ = make_node(scanner, NODE_VARIANT);
1972 $$->u.variant.has_body = 1;
1973 $$->u.variant.name = $1->s;
1974 if ($3 && set_parent_node($3, $$))
1975 reparent_error(scanner, "variant reparent error");
1977 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1979 $$ = make_node(scanner, NODE_VARIANT);
1980 $$->u.variant.has_body = 1;
1981 $$->u.variant.name = $1->s;
1982 $$->u.variant.choice = $3->s;
1983 if ($6 && set_parent_node($6, $$))
1984 reparent_error(scanner, "variant reparent error");
1986 | ID_TYPE LT IDENTIFIER GT
1988 $$ = make_node(scanner, NODE_VARIANT);
1989 $$->u.variant.has_body = 0;
1990 $$->u.variant.name = $1->s;
1991 $$->u.variant.choice = $3->s;
1993 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1995 $$ = make_node(scanner, NODE_VARIANT);
1996 $$->u.variant.has_body = 1;
1997 $$->u.variant.name = $1->s;
1998 $$->u.variant.choice = $3->s;
1999 if ($6 && set_parent_node($6, $$))
2000 reparent_error(scanner, "variant reparent error");
2002 | ID_TYPE LT ID_TYPE GT
2004 $$ = make_node(scanner, NODE_VARIANT);
2005 $$->u.variant.has_body = 0;
2006 $$->u.variant.name = $1->s;
2007 $$->u.variant.choice = $3->s;
2011 variant_declaration_begin:
2013 { push_scope(scanner); }
2016 variant_declaration_end:
2018 { pop_scope(scanner); }
2021 enum_type_specifier:
2022 LBRAC enumerator_list RBRAC
2024 $$ = make_node(scanner, NODE_ENUM);
2025 $$->u._enum.has_body = 1;
2026 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2028 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
2030 $$ = make_node(scanner, NODE_ENUM);
2031 $$->u._enum.has_body = 1;
2032 ($$)->u._enum.container_type = $2;
2033 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2035 | IDENTIFIER LBRAC enumerator_list RBRAC
2037 $$ = make_node(scanner, NODE_ENUM);
2038 $$->u._enum.has_body = 1;
2039 $$->u._enum.enum_id = $1->s;
2040 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2042 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
2044 $$ = make_node(scanner, NODE_ENUM);
2045 $$->u._enum.has_body = 1;
2046 $$->u._enum.enum_id = $1->s;
2047 ($$)->u._enum.container_type = $3;
2048 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2050 | ID_TYPE LBRAC enumerator_list RBRAC
2052 $$ = make_node(scanner, NODE_ENUM);
2053 $$->u._enum.has_body = 1;
2054 $$->u._enum.enum_id = $1->s;
2055 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2057 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
2059 $$ = make_node(scanner, NODE_ENUM);
2060 $$->u._enum.has_body = 1;
2061 $$->u._enum.enum_id = $1->s;
2062 ($$)->u._enum.container_type = $3;
2063 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2065 | LBRAC enumerator_list COMMA RBRAC
2067 $$ = make_node(scanner, NODE_ENUM);
2068 $$->u._enum.has_body = 1;
2069 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2071 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2073 $$ = make_node(scanner, NODE_ENUM);
2074 $$->u._enum.has_body = 1;
2075 ($$)->u._enum.container_type = $2;
2076 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2078 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
2080 $$ = make_node(scanner, NODE_ENUM);
2081 $$->u._enum.has_body = 1;
2082 $$->u._enum.enum_id = $1->s;
2083 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2085 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2087 $$ = make_node(scanner, NODE_ENUM);
2088 $$->u._enum.has_body = 1;
2089 $$->u._enum.enum_id = $1->s;
2090 ($$)->u._enum.container_type = $3;
2091 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2095 $$ = make_node(scanner, NODE_ENUM);
2096 $$->u._enum.has_body = 0;
2097 $$->u._enum.enum_id = $1->s;
2099 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
2101 $$ = make_node(scanner, NODE_ENUM);
2102 $$->u._enum.has_body = 1;
2103 $$->u._enum.enum_id = $1->s;
2104 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2106 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2108 $$ = make_node(scanner, NODE_ENUM);
2109 $$->u._enum.has_body = 1;
2110 $$->u._enum.enum_id = $1->s;
2111 ($$)->u._enum.container_type = $3;
2112 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2116 $$ = make_node(scanner, NODE_ENUM);
2117 $$->u._enum.has_body = 0;
2118 $$->u._enum.enum_id = $1->s;
2122 struct_or_variant_declaration_list:
2125 | struct_or_variant_declaration_list struct_or_variant_declaration
2129 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2132 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
2137 struct_or_variant_declaration:
2138 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
2140 struct ctf_node *list;
2142 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2143 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2144 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
2145 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2146 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
2148 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2150 struct ctf_node *list;
2152 $$ = make_node(scanner, NODE_TYPEDEF);
2153 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2154 $$->u._typedef.type_specifier_list = list;
2155 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2156 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2157 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2159 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2161 struct ctf_node *list;
2163 $$ = make_node(scanner, NODE_TYPEDEF);
2164 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2165 $$->u._typedef.type_specifier_list = list;
2166 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2167 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2169 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
2171 struct ctf_node *list;
2173 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2174 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2175 $$ = make_node(scanner, NODE_TYPEDEF);
2176 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2177 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2179 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
2181 struct ctf_node *list;
2183 $$ = make_node(scanner, NODE_TYPEALIAS);
2184 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2185 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2187 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2188 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2189 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2190 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2192 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2193 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2194 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2195 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2199 alias_declaration_specifiers:
2202 struct ctf_node *node;
2204 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2205 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2206 node->u.type_specifier.type = TYPESPEC_CONST;
2207 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2211 struct ctf_node *node;
2213 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2215 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2219 struct ctf_node *node;
2221 add_type(scanner, $1);
2222 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2223 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2224 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2225 node->u.type_specifier.id_type = yylval.gs->s;
2226 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2228 | alias_declaration_specifiers CONST
2230 struct ctf_node *node;
2233 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2234 node->u.type_specifier.type = TYPESPEC_CONST;
2235 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2237 | alias_declaration_specifiers type_specifier
2240 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2242 | alias_declaration_specifiers IDENTIFIER
2244 struct ctf_node *node;
2246 add_type(scanner, $2);
2248 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2249 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2250 node->u.type_specifier.id_type = yylval.gs->s;
2251 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2255 struct_or_variant_declarator_list:
2256 struct_or_variant_declarator
2258 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2261 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2265 struct_or_variant_declarator:
2268 | COLON unary_expression
2270 | declarator COLON unary_expression
2273 if (set_parent_node($3, $1))
2274 reparent_error(scanner, "struct_or_variant_declarator");
2281 | enumerator_list COMMA enumerator
2284 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2291 $$ = make_node(scanner, NODE_ENUMERATOR);
2292 $$->u.enumerator.id = $1->s;
2296 $$ = make_node(scanner, NODE_ENUMERATOR);
2297 $$->u.enumerator.id = $1->s;
2301 $$ = make_node(scanner, NODE_ENUMERATOR);
2302 $$->u.enumerator.id = $1->s;
2306 $$ = make_node(scanner, NODE_ENUMERATOR);
2307 $$->u.enumerator.id = $1->s;
2309 | IDENTIFIER EQUAL unary_expression_or_range
2311 $$ = make_node(scanner, NODE_ENUMERATOR);
2312 $$->u.enumerator.id = $1->s;
2313 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2315 | ID_TYPE EQUAL unary_expression_or_range
2317 $$ = make_node(scanner, NODE_ENUMERATOR);
2318 $$->u.enumerator.id = $1->s;
2319 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2321 | keywords EQUAL unary_expression_or_range
2323 $$ = make_node(scanner, NODE_ENUMERATOR);
2324 $$->u.enumerator.id = $1->s;
2325 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2327 | STRING_LITERAL EQUAL unary_expression_or_range
2329 $$ = make_node(scanner, NODE_ENUMERATOR);
2330 $$->u.enumerator.id = $1->s;
2331 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2335 abstract_declarator_list:
2338 | abstract_declarator_list COMMA abstract_declarator
2341 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2345 abstract_declarator:
2346 direct_abstract_declarator
2348 | pointer direct_abstract_declarator
2351 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2355 direct_abstract_declarator:
2358 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2359 $$->u.type_declarator.type = TYPEDEC_ID;
2364 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2365 $$->u.type_declarator.type = TYPEDEC_ID;
2366 $$->u.type_declarator.u.id = $1->s;
2368 | LPAREN abstract_declarator RPAREN
2370 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2371 $$->u.type_declarator.type = TYPEDEC_NESTED;
2372 $$->u.type_declarator.u.nested.type_declarator = $2;
2374 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2376 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2377 $$->u.type_declarator.type = TYPEDEC_NESTED;
2378 $$->u.type_declarator.u.nested.type_declarator = $1;
2379 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2380 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2382 | direct_abstract_declarator LSBRAC RSBRAC
2384 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2385 $$->u.type_declarator.type = TYPEDEC_NESTED;
2386 $$->u.type_declarator.u.nested.type_declarator = $1;
2387 $$->u.type_declarator.u.nested.abstract_array = 1;
2391 alias_abstract_declarator_list:
2392 alias_abstract_declarator
2394 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2397 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2401 alias_abstract_declarator:
2402 direct_alias_abstract_declarator
2404 | pointer direct_alias_abstract_declarator
2407 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2411 direct_alias_abstract_declarator:
2414 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2415 $$->u.type_declarator.type = TYPEDEC_ID;
2418 | LPAREN alias_abstract_declarator RPAREN
2420 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2421 $$->u.type_declarator.type = TYPEDEC_NESTED;
2422 $$->u.type_declarator.u.nested.type_declarator = $2;
2424 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2426 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2427 $$->u.type_declarator.type = TYPEDEC_NESTED;
2428 $$->u.type_declarator.u.nested.type_declarator = $1;
2429 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2430 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2432 | direct_alias_abstract_declarator LSBRAC RSBRAC
2434 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2435 $$->u.type_declarator.type = TYPEDEC_NESTED;
2436 $$->u.type_declarator.u.nested.type_declarator = $1;
2437 $$->u.type_declarator.u.nested.abstract_array = 1;
2444 | pointer direct_declarator
2447 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2454 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2455 $$->u.type_declarator.type = TYPEDEC_ID;
2456 $$->u.type_declarator.u.id = $1->s;
2458 | LPAREN declarator RPAREN
2460 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2461 $$->u.type_declarator.type = TYPEDEC_NESTED;
2462 $$->u.type_declarator.u.nested.type_declarator = $2;
2464 | direct_declarator LSBRAC unary_expression RSBRAC
2466 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2467 $$->u.type_declarator.type = TYPEDEC_NESTED;
2468 $$->u.type_declarator.u.nested.type_declarator = $1;
2469 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2470 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2475 direct_type_declarator
2477 | pointer direct_type_declarator
2480 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2484 direct_type_declarator:
2487 add_type(scanner, $1);
2488 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2489 $$->u.type_declarator.type = TYPEDEC_ID;
2490 $$->u.type_declarator.u.id = $1->s;
2492 | LPAREN type_declarator RPAREN
2494 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2495 $$->u.type_declarator.type = TYPEDEC_NESTED;
2496 $$->u.type_declarator.u.nested.type_declarator = $2;
2498 | direct_type_declarator LSBRAC unary_expression RSBRAC
2500 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2501 $$->u.type_declarator.type = TYPEDEC_NESTED;
2502 $$->u.type_declarator.u.nested.type_declarator = $1;
2503 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2504 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2511 $$ = make_node(scanner, NODE_POINTER);
2515 $$ = make_node(scanner, NODE_POINTER);
2516 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2518 | STAR type_qualifier_list pointer
2520 $$ = make_node(scanner, NODE_POINTER);
2521 $$->u.pointer.const_qualifier = 1;
2522 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2526 type_qualifier_list:
2527 /* pointer assumes only const type qualifier */
2529 | type_qualifier_list CONST
2532 /* 2.3: CTF-specific declarations */
2534 ctf_assignment_expression_list:
2535 ctf_assignment_expression SEMICOLON
2537 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2540 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2544 ctf_assignment_expression:
2545 unary_expression EQUAL unary_expression
2548 * Because we have left and right, cannot use
2551 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2552 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2553 if ($1->u.unary_expression.type != UNARY_STRING)
2554 reparent_error(scanner, "ctf_assignment_expression left expects string");
2555 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2557 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2560 * Because we have left and right, cannot use
2563 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2564 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2565 if ($1->u.unary_expression.type != UNARY_STRING)
2566 reparent_error(scanner, "ctf_assignment_expression left expects string");
2567 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2569 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2571 struct ctf_node *list;
2573 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2574 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2575 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2576 $$ = make_node(scanner, NODE_TYPEDEF);
2577 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2578 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2580 | TYPEDEF declaration_specifiers type_declarator_list
2582 struct ctf_node *list;
2584 $$ = make_node(scanner, NODE_TYPEDEF);
2585 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2586 $$->u._typedef.type_specifier_list = list;
2587 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2588 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2590 | declaration_specifiers TYPEDEF type_declarator_list
2592 struct ctf_node *list;
2594 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2595 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2596 $$ = make_node(scanner, NODE_TYPEDEF);
2597 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2598 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2600 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2602 struct ctf_node *list;
2604 $$ = make_node(scanner, NODE_TYPEALIAS);
2605 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2606 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2608 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2609 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2610 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2611 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2613 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2614 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2615 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2616 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);