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 const char *node_type(struct ctf_node *node)
89 if (node->type < NR_NODE_TYPES)
90 return node_type_to_str[node->type];
95 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
98 struct gc_string *gstr;
101 /* TODO: could be faster with find first bit or glib Gstring */
102 /* sizeof long to account for malloc header (int or long ?) */
103 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
106 gstr = malloc(alloclen);
107 bt_list_add(&gstr->gc, &scanner->allocated_strings);
108 gstr->alloclen = alloclen;
113 * note: never use gc_string_append on a string that has external references.
114 * gsrc will be garbage collected immediately, and gstr might be.
115 * Should only be used to append characters to a string literal or constant.
118 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
119 struct gc_string *gstr,
120 struct gc_string *gsrc)
122 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
125 /* TODO: could be faster with find first bit or glib Gstring */
126 /* sizeof long to account for malloc header (int or long ?) */
127 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
130 if (alloclen > gstr->alloclen) {
131 struct gc_string *newgstr;
133 newgstr = gc_string_alloc(scanner, newlen);
134 strcpy(newgstr->s, gstr->s);
135 strcat(newgstr->s, gsrc->s);
136 bt_list_del(&gstr->gc);
140 strcat(gstr->s, gsrc->s);
142 bt_list_del(&gsrc->gc);
147 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
149 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
150 strcpy(lvalp->gs->s, src);
154 int str_check(size_t str_len, size_t offset, size_t len)
157 if (offset + len < offset)
159 if (offset + len > str_len)
165 int import_basic_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
166 size_t len, const char *src, char delim)
168 size_t pos = 0, dpos = 0;
170 if (str_check(len, pos, 1))
172 if (src[pos++] != delim)
175 while (src[pos] != delim) {
178 if (str_check(len, pos, 1))
182 if (str_check(len, pos, 1))
227 if (str_check(len, pos, oct_len))
229 if (!isdigit((int) src[pos]) || !isdigit((int) src[pos+1]) || !isdigit((int) src[pos+2]))
231 char oct_buffer[4] = { src[pos], src[pos+1], src[pos+2], '\0' };
232 c = strtoul(&oct_buffer[0], NULL, 8);
240 if (str_check(len, pos, hex_len))
242 if (!isxdigit((int) src[pos]) || !isxdigit((int) src[pos+1]))
244 char hex_buffer[3] = { src[pos], src[pos+1], '\0' };
245 c = strtoul(&hex_buffer[0], NULL, 16);
253 if (str_check(len, dpos, 1))
255 lvalp->gs->s[dpos++] = c;
258 if (str_check(len, dpos, 1))
260 lvalp->gs->s[dpos++] = '\0';
262 if (str_check(len, pos, 1))
264 if (src[pos++] != delim)
267 if (str_check(len, pos, 1))
269 if (src[pos] != '\0')
274 int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
275 const char *src, char delim)
279 len = strlen(src) + 1;
280 lvalp->gs = gc_string_alloc(scanner, len);
282 // TODO: import wide string
283 printfl_error(yyget_lineno(scanner),
284 "Wide string not supported yet.");
287 return import_basic_string(scanner, lvalp, len, src, delim);
291 static void init_scope(struct ctf_scanner_scope *scope,
292 struct ctf_scanner_scope *parent)
294 scope->parent = parent;
295 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
299 static void finalize_scope(struct ctf_scanner_scope *scope)
301 g_hash_table_destroy(scope->types);
304 static void push_scope(struct ctf_scanner *scanner)
306 struct ctf_scanner_scope *ns;
308 printf_debug("push scope\n");
309 ns = malloc(sizeof(struct ctf_scanner_scope));
310 init_scope(ns, scanner->cs);
314 static void pop_scope(struct ctf_scanner *scanner)
316 struct ctf_scanner_scope *os;
318 printf_debug("pop scope\n");
320 scanner->cs = os->parent;
325 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
329 ret = (int) (long) g_hash_table_lookup(s->types, id);
330 printf_debug("lookup %p %s %d\n", s, id, ret);
335 int is_type(struct ctf_scanner *scanner, const char *id)
337 struct ctf_scanner_scope *it;
340 for (it = scanner->cs; it != NULL; it = it->parent) {
341 if (lookup_type(it, id)) {
346 printf_debug("is type %s %d\n", id, ret);
350 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
352 printf_debug("add type %s\n", id->s);
353 if (lookup_type(scanner->cs, id->s))
355 g_hash_table_insert(scanner->cs->types, id->s, id->s);
358 static struct ctf_node *make_node(struct ctf_scanner *scanner,
361 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
362 struct ctf_node *node;
364 node = malloc(sizeof(*node));
367 memset(node, 0, sizeof(*node));
369 node->lineno = yyget_lineno(scanner->scanner);
370 BT_INIT_LIST_HEAD(&node->tmp_head);
371 bt_list_add(&node->gc, &ast->allocated_nodes);
372 bt_list_add(&node->siblings, &node->tmp_head);
376 printfn_fatal(node, "trying to create root node");
380 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
383 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
386 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
389 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
392 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
395 BT_INIT_LIST_HEAD(&node->u.callsite.declaration_list);
398 case NODE_CTF_EXPRESSION:
399 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
400 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
402 case NODE_UNARY_EXPRESSION:
406 BT_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
408 case NODE_TYPEALIAS_TARGET:
409 BT_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
411 case NODE_TYPEALIAS_ALIAS:
412 BT_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
417 case NODE_TYPE_SPECIFIER:
419 case NODE_TYPE_SPECIFIER_LIST:
420 BT_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
424 case NODE_TYPE_DECLARATOR:
425 BT_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
428 case NODE_FLOATING_POINT:
429 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
432 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
435 BT_INIT_LIST_HEAD(&node->u.string.expressions);
437 case NODE_ENUMERATOR:
438 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
441 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
443 case NODE_STRUCT_OR_VARIANT_DECLARATION:
444 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
447 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
450 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
451 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
456 printfn_fatal(node, "unknown node type '%d'", (int) type);
463 static int reparent_ctf_expression(struct ctf_node *node,
464 struct ctf_node *parent)
466 switch (parent->type) {
468 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
471 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
474 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
477 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
480 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
483 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
485 case NODE_FLOATING_POINT:
486 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
489 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
492 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
496 case NODE_CTF_EXPRESSION:
498 case NODE_TYPEALIAS_TARGET:
499 case NODE_TYPEALIAS_ALIAS:
501 case NODE_TYPE_SPECIFIER:
502 case NODE_TYPE_SPECIFIER_LIST:
504 case NODE_TYPE_DECLARATOR:
505 case NODE_ENUMERATOR:
507 case NODE_STRUCT_OR_VARIANT_DECLARATION:
510 case NODE_UNARY_EXPRESSION:
515 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
521 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
523 switch (parent->type) {
525 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
528 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
531 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
534 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
537 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
540 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
543 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
546 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
549 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
552 case NODE_FLOATING_POINT:
555 case NODE_CTF_EXPRESSION:
557 case NODE_TYPEALIAS_TARGET:
558 case NODE_TYPEALIAS_ALIAS:
560 case NODE_TYPE_SPECIFIER:
561 case NODE_TYPE_SPECIFIER_LIST:
563 case NODE_TYPE_DECLARATOR:
564 case NODE_ENUMERATOR:
566 case NODE_STRUCT_OR_VARIANT_DECLARATION:
567 case NODE_UNARY_EXPRESSION:
572 printfn_fatal(node, "unknown node type %d", parent->type);
578 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
580 switch (parent->type) {
582 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
585 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
588 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
591 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
594 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
597 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
600 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
603 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
606 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
609 case NODE_FLOATING_POINT:
612 case NODE_CTF_EXPRESSION:
614 case NODE_TYPEALIAS_TARGET:
615 case NODE_TYPEALIAS_ALIAS:
617 case NODE_TYPE_SPECIFIER:
618 case NODE_TYPE_SPECIFIER_LIST:
620 case NODE_TYPE_DECLARATOR:
621 case NODE_ENUMERATOR:
623 case NODE_STRUCT_OR_VARIANT_DECLARATION:
624 case NODE_UNARY_EXPRESSION:
629 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
635 static int reparent_type_specifier(struct ctf_node *node,
636 struct ctf_node *parent)
638 switch (parent->type) {
639 case NODE_TYPE_SPECIFIER_LIST:
640 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
643 case NODE_TYPE_SPECIFIER:
653 case NODE_TYPEALIAS_TARGET:
654 case NODE_TYPEALIAS_ALIAS:
655 case NODE_TYPE_DECLARATOR:
657 case NODE_STRUCT_OR_VARIANT_DECLARATION:
659 case NODE_FLOATING_POINT:
662 case NODE_CTF_EXPRESSION:
664 case NODE_ENUMERATOR:
665 case NODE_UNARY_EXPRESSION:
670 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
676 static int reparent_type_specifier_list(struct ctf_node *node,
677 struct ctf_node *parent)
679 switch (parent->type) {
681 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
684 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
687 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
690 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
693 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
696 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
699 bt_list_add_tail(&node->siblings, &parent->u.callsite.declaration_list);
702 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
705 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
708 parent->u._typedef.type_specifier_list = node;
710 case NODE_TYPEALIAS_TARGET:
711 parent->u.typealias_target.type_specifier_list = node;
713 case NODE_TYPEALIAS_ALIAS:
714 parent->u.typealias_alias.type_specifier_list = node;
717 parent->u._enum.container_type = node;
719 case NODE_STRUCT_OR_VARIANT_DECLARATION:
720 parent->u.struct_or_variant_declaration.type_specifier_list = node;
722 case NODE_TYPE_DECLARATOR:
723 case NODE_TYPE_SPECIFIER:
725 case NODE_FLOATING_POINT:
728 case NODE_CTF_EXPRESSION:
730 case NODE_ENUMERATOR:
731 case NODE_UNARY_EXPRESSION:
736 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
742 static int reparent_type_declarator(struct ctf_node *node,
743 struct ctf_node *parent)
745 switch (parent->type) {
746 case NODE_TYPE_DECLARATOR:
747 parent->u.type_declarator.type = TYPEDEC_NESTED;
748 parent->u.type_declarator.u.nested.type_declarator = node;
750 case NODE_STRUCT_OR_VARIANT_DECLARATION:
751 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
754 _bt_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
756 case NODE_TYPEALIAS_TARGET:
757 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
759 case NODE_TYPEALIAS_ALIAS:
760 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
774 case NODE_FLOATING_POINT:
777 case NODE_CTF_EXPRESSION:
778 case NODE_TYPE_SPECIFIER:
779 case NODE_TYPE_SPECIFIER_LIST:
781 case NODE_ENUMERATOR:
782 case NODE_UNARY_EXPRESSION:
787 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
796 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
797 * create the link declared by the input, -ENOENT if node or parent is NULL,
798 * -EINVAL if there is an internal structure problem.
800 static int set_parent_node(struct ctf_node *node,
801 struct ctf_node *parent)
803 if (!node || !parent)
806 /* Note: Linking to parent will be done only by an external visitor */
808 switch (node->type) {
810 printfn_fatal(node, "trying to reparent root node");
814 if (parent->type == NODE_ROOT) {
815 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
821 if (parent->type == NODE_ROOT) {
822 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
828 if (parent->type == NODE_ROOT) {
829 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
835 if (parent->type == NODE_ROOT) {
836 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
842 if (parent->type == NODE_ROOT) {
843 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
849 if (parent->type == NODE_ROOT) {
850 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.callsite);
856 case NODE_CTF_EXPRESSION:
857 return reparent_ctf_expression(node, parent);
858 case NODE_UNARY_EXPRESSION:
859 if (parent->type == NODE_TYPE_DECLARATOR)
860 parent->u.type_declarator.bitfield_len = node;
866 return reparent_typedef(node, parent);
867 case NODE_TYPEALIAS_TARGET:
868 if (parent->type == NODE_TYPEALIAS)
869 parent->u.typealias.target = node;
872 case NODE_TYPEALIAS_ALIAS:
873 if (parent->type == NODE_TYPEALIAS)
874 parent->u.typealias.alias = node;
878 return reparent_typealias(node, parent);
881 if (parent->type == NODE_TYPE_DECLARATOR) {
882 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
886 case NODE_TYPE_DECLARATOR:
887 return reparent_type_declarator(node, parent);
889 case NODE_TYPE_SPECIFIER_LIST:
890 return reparent_type_specifier_list(node, parent);
892 case NODE_TYPE_SPECIFIER:
893 return reparent_type_specifier(node, parent);
895 case NODE_FLOATING_POINT:
901 return -EINVAL; /* Dealt with internally within grammar */
903 case NODE_ENUMERATOR:
904 if (parent->type == NODE_ENUM) {
905 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
910 case NODE_STRUCT_OR_VARIANT_DECLARATION:
911 switch (parent->type) {
913 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
916 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
925 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
932 void yyerror(struct ctf_scanner *scanner, const char *str)
934 printfl_error(yyget_lineno(scanner->scanner),
935 "token \"%s\": %s\n",
936 yyget_text(scanner->scanner), str);
945 #define reparent_error(scanner, str) \
947 yyerror(scanner, YY_("reparent_error: " str)); \
951 static void free_strings(struct bt_list_head *list)
953 struct gc_string *gstr, *tmp;
955 bt_list_for_each_entry_safe(gstr, tmp, list, gc)
959 static struct ctf_ast *ctf_ast_alloc(void)
963 ast = malloc(sizeof(*ast));
966 memset(ast, 0, sizeof(*ast));
967 BT_INIT_LIST_HEAD(&ast->allocated_nodes);
968 ast->root.type = NODE_ROOT;
969 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
970 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
971 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
972 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
973 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
974 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
975 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
976 BT_INIT_LIST_HEAD(&ast->root.u.root.callsite);
980 static void ctf_ast_free(struct ctf_ast *ast)
982 struct ctf_node *node, *tmp;
984 bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
989 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
991 return yyparse(scanner);
994 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
996 struct ctf_scanner *scanner;
999 yydebug = babeltrace_debug;
1001 scanner = malloc(sizeof(*scanner));
1004 memset(scanner, 0, sizeof(*scanner));
1006 ret = yylex_init_extra(scanner, &scanner->scanner);
1008 printf_fatal("yylex_init error");
1009 goto cleanup_scanner;
1011 /* Start processing new stream */
1012 yyrestart(input, scanner->scanner);
1014 scanner->ast = ctf_ast_alloc();
1017 init_scope(&scanner->root_scope, NULL);
1018 scanner->cs = &scanner->root_scope;
1019 BT_INIT_LIST_HEAD(&scanner->allocated_strings);
1022 fprintf(stdout, "Scanner input is a%s.\n",
1023 isatty(fileno(input)) ? "n interactive tty" :
1024 " noninteractive file");
1029 ret = yylex_destroy(scanner->scanner);
1031 printf_fatal("yylex_destroy error");
1037 void ctf_scanner_free(struct ctf_scanner *scanner)
1041 finalize_scope(&scanner->root_scope);
1042 free_strings(&scanner->allocated_strings);
1043 ctf_ast_free(scanner->ast);
1044 ret = yylex_destroy(scanner->scanner);
1046 printf_error("yylex_destroy error");
1055 %parse-param {struct ctf_scanner *scanner}
1056 %lex-param {struct ctf_scanner *scanner}
1058 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
1059 * vs struct { int :value; } (unnamed bit-field). The default is to
1060 * shift, so whenever we encounter an enumeration, we are doing the
1061 * proper thing (shift). It is illegal to declare an enumeration
1062 * "bit-field", so it is OK if this situation ends up in a parsing
1067 %token 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 DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT TOK_ALIGN
1068 %token <gs> IDENTIFIER ID_TYPE
1074 struct gc_string *gs;
1078 %type <gs> STRING_LITERAL CHARACTER_LITERAL
1082 %type <n> postfix_expression unary_expression unary_expression_or_range
1084 %type <n> declaration
1085 %type <n> event_declaration
1086 %type <n> stream_declaration
1087 %type <n> env_declaration
1088 %type <n> trace_declaration
1089 %type <n> clock_declaration
1090 %type <n> callsite_declaration
1091 %type <n> integer_declaration_specifiers
1092 %type <n> declaration_specifiers
1093 %type <n> alias_declaration_specifiers
1095 %type <n> type_declarator_list
1096 %type <n> integer_type_specifier
1097 %type <n> type_specifier
1098 %type <n> struct_type_specifier
1099 %type <n> variant_type_specifier
1100 %type <n> enum_type_specifier
1101 %type <n> struct_or_variant_declaration_list
1102 %type <n> struct_or_variant_declaration
1103 %type <n> struct_or_variant_declarator_list
1104 %type <n> struct_or_variant_declarator
1105 %type <n> enumerator_list
1106 %type <n> enumerator
1107 %type <n> abstract_declarator_list
1108 %type <n> abstract_declarator
1109 %type <n> direct_abstract_declarator
1110 %type <n> alias_abstract_declarator_list
1111 %type <n> alias_abstract_declarator
1112 %type <n> direct_alias_abstract_declarator
1113 %type <n> declarator
1114 %type <n> direct_declarator
1115 %type <n> type_declarator
1116 %type <n> direct_type_declarator
1118 %type <n> ctf_assignment_expression_list
1119 %type <n> ctf_assignment_expression
1126 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
1127 reparent_error(scanner, "error reparenting to root");
1131 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
1132 reparent_error(scanner, "error reparenting to root");
1194 /* 2: Phrase structure grammar */
1199 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1200 $$->u.unary_expression.type = UNARY_STRING;
1201 $$->u.unary_expression.u.string = yylval.gs->s;
1205 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1206 $$->u.unary_expression.type = UNARY_STRING;
1207 $$->u.unary_expression.u.string = yylval.gs->s;
1211 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1212 $$->u.unary_expression.type = UNARY_STRING;
1213 $$->u.unary_expression.u.string = yylval.gs->s;
1217 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1218 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1219 sscanf(yylval.gs->s, "%" PRIu64,
1220 &$$->u.unary_expression.u.unsigned_constant);
1224 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1225 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1226 sscanf(yylval.gs->s, "0%" PRIo64,
1227 &$$->u.unary_expression.u.unsigned_constant);
1229 | HEXADECIMAL_CONSTANT
1231 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1232 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1233 sscanf(yylval.gs->s, "0x%" PRIx64,
1234 &$$->u.unary_expression.u.unsigned_constant);
1238 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1239 $$->u.unary_expression.type = UNARY_STRING;
1240 $$->u.unary_expression.u.string = $1->s;
1244 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1245 $$->u.unary_expression.type = UNARY_STRING;
1246 $$->u.unary_expression.u.string = $1->s;
1248 | LPAREN unary_expression RPAREN
1250 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1251 $$->u.unary_expression.type = UNARY_NESTED;
1252 $$->u.unary_expression.u.nested_exp = $2;
1254 | postfix_expression LSBRAC unary_expression RSBRAC
1256 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1257 $$->u.unary_expression.type = UNARY_SBRAC;
1258 $$->u.unary_expression.u.sbrac_exp = $3;
1259 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1260 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1262 | postfix_expression DOT IDENTIFIER
1264 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1265 $$->u.unary_expression.type = UNARY_STRING;
1266 $$->u.unary_expression.u.string = yylval.gs->s;
1267 $$->u.unary_expression.link = UNARY_DOTLINK;
1268 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1269 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1271 | postfix_expression DOT ID_TYPE
1273 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1274 $$->u.unary_expression.type = UNARY_STRING;
1275 $$->u.unary_expression.u.string = yylval.gs->s;
1276 $$->u.unary_expression.link = UNARY_DOTLINK;
1277 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1278 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1280 | postfix_expression RARROW IDENTIFIER
1282 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1283 $$->u.unary_expression.type = UNARY_STRING;
1284 $$->u.unary_expression.u.string = yylval.gs->s;
1285 $$->u.unary_expression.link = UNARY_ARROWLINK;
1286 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1287 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1289 | postfix_expression RARROW ID_TYPE
1291 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1292 $$->u.unary_expression.type = UNARY_STRING;
1293 $$->u.unary_expression.u.string = yylval.gs->s;
1294 $$->u.unary_expression.link = UNARY_ARROWLINK;
1295 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1296 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1303 | PLUS postfix_expression
1306 if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
1307 && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
1308 reparent_error(scanner, "expecting numeric constant");
1311 | MINUS postfix_expression
1314 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1315 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1316 $$->u.unary_expression.u.signed_constant =
1317 -($$->u.unary_expression.u.unsigned_constant);
1318 } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1319 $$->u.unary_expression.u.signed_constant =
1320 -($$->u.unary_expression.u.signed_constant);
1322 reparent_error(scanner, "expecting numeric constant");
1327 unary_expression_or_range:
1328 unary_expression DOTDOTDOT unary_expression
1331 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1332 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1338 /* 2.2: Declarations */
1341 declaration_specifiers SEMICOLON
1345 | stream_declaration
1353 | callsite_declaration
1355 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1357 struct ctf_node *list;
1359 $$ = make_node(scanner, NODE_TYPEDEF);
1360 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1361 $$->u._typedef.type_specifier_list = list;
1362 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1363 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1364 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1366 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1368 struct ctf_node *list;
1370 $$ = make_node(scanner, NODE_TYPEDEF);
1371 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1372 $$->u._typedef.type_specifier_list = list;
1373 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1374 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1376 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1378 struct ctf_node *list;
1380 $$ = make_node(scanner, NODE_TYPEDEF);
1381 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1382 $$->u._typedef.type_specifier_list = list;
1383 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1384 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1386 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1388 struct ctf_node *list;
1390 $$ = make_node(scanner, NODE_TYPEALIAS);
1391 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1392 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1394 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1395 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1396 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1397 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1399 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1400 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1401 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1402 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1407 event_declaration_begin event_declaration_end
1409 $$ = make_node(scanner, NODE_EVENT);
1411 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1413 $$ = make_node(scanner, NODE_EVENT);
1414 if (set_parent_node($2, $$))
1415 reparent_error(scanner, "event_declaration");
1419 event_declaration_begin:
1421 { push_scope(scanner); }
1424 event_declaration_end:
1426 { pop_scope(scanner); }
1431 stream_declaration_begin stream_declaration_end
1433 $$ = make_node(scanner, NODE_STREAM);
1435 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1437 $$ = make_node(scanner, NODE_STREAM);
1438 if (set_parent_node($2, $$))
1439 reparent_error(scanner, "stream_declaration");
1443 stream_declaration_begin:
1445 { push_scope(scanner); }
1448 stream_declaration_end:
1450 { pop_scope(scanner); }
1454 env_declaration_begin env_declaration_end
1456 $$ = make_node(scanner, NODE_ENV);
1458 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1460 $$ = make_node(scanner, NODE_ENV);
1461 if (set_parent_node($2, $$))
1462 reparent_error(scanner, "env declaration");
1466 env_declaration_begin:
1468 { push_scope(scanner); }
1471 env_declaration_end:
1473 { pop_scope(scanner); }
1477 trace_declaration_begin trace_declaration_end
1479 $$ = make_node(scanner, NODE_TRACE);
1481 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1483 $$ = make_node(scanner, NODE_TRACE);
1484 if (set_parent_node($2, $$))
1485 reparent_error(scanner, "trace_declaration");
1489 trace_declaration_begin:
1491 { push_scope(scanner); }
1494 trace_declaration_end:
1496 { pop_scope(scanner); }
1500 CLOCK clock_declaration_begin clock_declaration_end
1502 $$ = make_node(scanner, NODE_CLOCK);
1504 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1506 $$ = make_node(scanner, NODE_CLOCK);
1507 if (set_parent_node($3, $$))
1508 reparent_error(scanner, "trace_declaration");
1512 clock_declaration_begin:
1514 { push_scope(scanner); }
1517 clock_declaration_end:
1519 { pop_scope(scanner); }
1522 callsite_declaration:
1523 CALLSITE callsite_declaration_begin callsite_declaration_end
1525 $$ = make_node(scanner, NODE_CALLSITE);
1527 | CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1529 $$ = make_node(scanner, NODE_CALLSITE);
1530 if (set_parent_node($3, $$))
1531 reparent_error(scanner, "trace_declaration");
1535 callsite_declaration_begin:
1537 { push_scope(scanner); }
1540 callsite_declaration_end:
1542 { pop_scope(scanner); }
1545 integer_declaration_specifiers:
1548 struct ctf_node *node;
1550 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1551 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1552 node->u.type_specifier.type = TYPESPEC_CONST;
1553 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1555 | integer_type_specifier
1557 struct ctf_node *node;
1559 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1561 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1563 | integer_declaration_specifiers CONST
1565 struct ctf_node *node;
1568 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1569 node->u.type_specifier.type = TYPESPEC_CONST;
1570 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1572 | integer_declaration_specifiers integer_type_specifier
1575 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1579 declaration_specifiers:
1582 struct ctf_node *node;
1584 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1585 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1586 node->u.type_specifier.type = TYPESPEC_CONST;
1587 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1591 struct ctf_node *node;
1593 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1595 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1597 | declaration_specifiers CONST
1599 struct ctf_node *node;
1602 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1603 node->u.type_specifier.type = TYPESPEC_CONST;
1604 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1606 | declaration_specifiers type_specifier
1609 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1613 type_declarator_list:
1616 | type_declarator_list COMMA type_declarator
1619 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1623 integer_type_specifier:
1626 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1627 $$->u.type_specifier.type = TYPESPEC_CHAR;
1631 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1632 $$->u.type_specifier.type = TYPESPEC_SHORT;
1636 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1637 $$->u.type_specifier.type = TYPESPEC_INT;
1641 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1642 $$->u.type_specifier.type = TYPESPEC_LONG;
1646 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1647 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1651 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1652 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1656 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1657 $$->u.type_specifier.type = TYPESPEC_BOOL;
1661 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1662 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1663 $$->u.type_specifier.id_type = yylval.gs->s;
1665 | INTEGER LBRAC RBRAC
1667 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1668 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1669 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1671 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1673 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1674 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1675 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1676 if (set_parent_node($3, $$->u.type_specifier.node))
1677 reparent_error(scanner, "integer reparent error");
1684 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1685 $$->u.type_specifier.type = TYPESPEC_VOID;
1689 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1690 $$->u.type_specifier.type = TYPESPEC_CHAR;
1694 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1695 $$->u.type_specifier.type = TYPESPEC_SHORT;
1699 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1700 $$->u.type_specifier.type = TYPESPEC_INT;
1704 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1705 $$->u.type_specifier.type = TYPESPEC_LONG;
1709 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1710 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1714 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1715 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1719 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1720 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1724 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1725 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1729 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1730 $$->u.type_specifier.type = TYPESPEC_BOOL;
1734 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1735 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1739 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1740 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1744 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1745 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1746 $$->u.type_specifier.id_type = yylval.gs->s;
1748 | FLOATING_POINT LBRAC RBRAC
1750 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1751 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1752 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1754 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1756 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1757 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1758 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1759 if (set_parent_node($3, $$->u.type_specifier.node))
1760 reparent_error(scanner, "floating point reparent error");
1762 | INTEGER LBRAC RBRAC
1764 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1765 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1766 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1768 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1770 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1771 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1772 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1773 if (set_parent_node($3, $$->u.type_specifier.node))
1774 reparent_error(scanner, "integer reparent error");
1778 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1779 $$->u.type_specifier.type = TYPESPEC_STRING;
1780 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1782 | STRING LBRAC RBRAC
1784 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1785 $$->u.type_specifier.type = TYPESPEC_STRING;
1786 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1788 | STRING LBRAC ctf_assignment_expression_list RBRAC
1790 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1791 $$->u.type_specifier.type = TYPESPEC_STRING;
1792 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1793 if (set_parent_node($3, $$->u.type_specifier.node))
1794 reparent_error(scanner, "string reparent error");
1796 | ENUM enum_type_specifier
1798 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1799 $$->u.type_specifier.type = TYPESPEC_ENUM;
1800 $$->u.type_specifier.node = $2;
1802 | VARIANT variant_type_specifier
1804 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1805 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1806 $$->u.type_specifier.node = $2;
1808 | STRUCT struct_type_specifier
1810 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1811 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1812 $$->u.type_specifier.node = $2;
1816 struct_type_specifier:
1817 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1819 $$ = make_node(scanner, NODE_STRUCT);
1820 $$->u._struct.has_body = 1;
1821 if ($2 && set_parent_node($2, $$))
1822 reparent_error(scanner, "struct reparent error");
1824 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1826 $$ = make_node(scanner, NODE_STRUCT);
1827 $$->u._struct.has_body = 1;
1828 $$->u._struct.name = $1->s;
1829 if ($3 && set_parent_node($3, $$))
1830 reparent_error(scanner, "struct reparent error");
1832 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1834 $$ = make_node(scanner, NODE_STRUCT);
1835 $$->u._struct.has_body = 1;
1836 $$->u._struct.name = $1->s;
1837 if ($3 && set_parent_node($3, $$))
1838 reparent_error(scanner, "struct reparent error");
1842 $$ = make_node(scanner, NODE_STRUCT);
1843 $$->u._struct.has_body = 0;
1844 $$->u._struct.name = $1->s;
1848 $$ = make_node(scanner, NODE_STRUCT);
1849 $$->u._struct.has_body = 0;
1850 $$->u._struct.name = $1->s;
1852 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1854 $$ = make_node(scanner, NODE_STRUCT);
1855 $$->u._struct.has_body = 1;
1856 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1857 if ($2 && set_parent_node($2, $$))
1858 reparent_error(scanner, "struct reparent error");
1860 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1862 $$ = make_node(scanner, NODE_STRUCT);
1863 $$->u._struct.has_body = 1;
1864 $$->u._struct.name = $1->s;
1865 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1866 if ($3 && set_parent_node($3, $$))
1867 reparent_error(scanner, "struct reparent error");
1869 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1871 $$ = make_node(scanner, NODE_STRUCT);
1872 $$->u._struct.has_body = 1;
1873 $$->u._struct.name = $1->s;
1874 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1875 if ($3 && set_parent_node($3, $$))
1876 reparent_error(scanner, "struct reparent error");
1880 struct_declaration_begin:
1882 { push_scope(scanner); }
1885 struct_declaration_end:
1887 { pop_scope(scanner); }
1890 variant_type_specifier:
1891 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1893 $$ = make_node(scanner, NODE_VARIANT);
1894 $$->u.variant.has_body = 1;
1895 if ($2 && set_parent_node($2, $$))
1896 reparent_error(scanner, "variant reparent error");
1898 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1900 $$ = make_node(scanner, NODE_VARIANT);
1901 $$->u.variant.has_body = 1;
1902 $$->u.variant.choice = $2->s;
1903 if ($5 && set_parent_node($5, $$))
1904 reparent_error(scanner, "variant reparent error");
1906 | 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.choice = $2->s;
1911 if ($5 && set_parent_node($5, $$))
1912 reparent_error(scanner, "variant reparent error");
1914 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1916 $$ = make_node(scanner, NODE_VARIANT);
1917 $$->u.variant.has_body = 1;
1918 $$->u.variant.name = $1->s;
1919 if ($3 && set_parent_node($3, $$))
1920 reparent_error(scanner, "variant reparent error");
1922 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1924 $$ = make_node(scanner, NODE_VARIANT);
1925 $$->u.variant.has_body = 1;
1926 $$->u.variant.name = $1->s;
1927 $$->u.variant.choice = $3->s;
1928 if ($6 && set_parent_node($6, $$))
1929 reparent_error(scanner, "variant reparent error");
1931 | IDENTIFIER LT IDENTIFIER GT
1933 $$ = make_node(scanner, NODE_VARIANT);
1934 $$->u.variant.has_body = 0;
1935 $$->u.variant.name = $1->s;
1936 $$->u.variant.choice = $3->s;
1938 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1940 $$ = make_node(scanner, NODE_VARIANT);
1941 $$->u.variant.has_body = 1;
1942 $$->u.variant.name = $1->s;
1943 $$->u.variant.choice = $3->s;
1944 if ($6 && set_parent_node($6, $$))
1945 reparent_error(scanner, "variant reparent error");
1947 | IDENTIFIER LT ID_TYPE GT
1949 $$ = make_node(scanner, NODE_VARIANT);
1950 $$->u.variant.has_body = 0;
1951 $$->u.variant.name = $1->s;
1952 $$->u.variant.choice = $3->s;
1954 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1956 $$ = make_node(scanner, NODE_VARIANT);
1957 $$->u.variant.has_body = 1;
1958 $$->u.variant.name = $1->s;
1959 if ($3 && set_parent_node($3, $$))
1960 reparent_error(scanner, "variant reparent error");
1962 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1964 $$ = make_node(scanner, NODE_VARIANT);
1965 $$->u.variant.has_body = 1;
1966 $$->u.variant.name = $1->s;
1967 $$->u.variant.choice = $3->s;
1968 if ($6 && set_parent_node($6, $$))
1969 reparent_error(scanner, "variant reparent error");
1971 | ID_TYPE LT IDENTIFIER GT
1973 $$ = make_node(scanner, NODE_VARIANT);
1974 $$->u.variant.has_body = 0;
1975 $$->u.variant.name = $1->s;
1976 $$->u.variant.choice = $3->s;
1978 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1980 $$ = make_node(scanner, NODE_VARIANT);
1981 $$->u.variant.has_body = 1;
1982 $$->u.variant.name = $1->s;
1983 $$->u.variant.choice = $3->s;
1984 if ($6 && set_parent_node($6, $$))
1985 reparent_error(scanner, "variant reparent error");
1987 | ID_TYPE LT ID_TYPE GT
1989 $$ = make_node(scanner, NODE_VARIANT);
1990 $$->u.variant.has_body = 0;
1991 $$->u.variant.name = $1->s;
1992 $$->u.variant.choice = $3->s;
1996 variant_declaration_begin:
1998 { push_scope(scanner); }
2001 variant_declaration_end:
2003 { pop_scope(scanner); }
2006 enum_type_specifier:
2007 LBRAC enumerator_list RBRAC
2009 $$ = make_node(scanner, NODE_ENUM);
2010 $$->u._enum.has_body = 1;
2011 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2013 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
2015 $$ = make_node(scanner, NODE_ENUM);
2016 $$->u._enum.has_body = 1;
2017 ($$)->u._enum.container_type = $2;
2018 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2020 | IDENTIFIER LBRAC enumerator_list RBRAC
2022 $$ = make_node(scanner, NODE_ENUM);
2023 $$->u._enum.has_body = 1;
2024 $$->u._enum.enum_id = $1->s;
2025 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2027 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
2029 $$ = make_node(scanner, NODE_ENUM);
2030 $$->u._enum.has_body = 1;
2031 $$->u._enum.enum_id = $1->s;
2032 ($$)->u._enum.container_type = $3;
2033 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2035 | ID_TYPE 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 | ID_TYPE 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 | LBRAC enumerator_list COMMA RBRAC
2052 $$ = make_node(scanner, NODE_ENUM);
2053 $$->u._enum.has_body = 1;
2054 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2056 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2058 $$ = make_node(scanner, NODE_ENUM);
2059 $$->u._enum.has_body = 1;
2060 ($$)->u._enum.container_type = $2;
2061 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2063 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
2065 $$ = make_node(scanner, NODE_ENUM);
2066 $$->u._enum.has_body = 1;
2067 $$->u._enum.enum_id = $1->s;
2068 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2070 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2072 $$ = make_node(scanner, NODE_ENUM);
2073 $$->u._enum.has_body = 1;
2074 $$->u._enum.enum_id = $1->s;
2075 ($$)->u._enum.container_type = $3;
2076 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2080 $$ = make_node(scanner, NODE_ENUM);
2081 $$->u._enum.has_body = 0;
2082 $$->u._enum.enum_id = $1->s;
2084 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
2086 $$ = make_node(scanner, NODE_ENUM);
2087 $$->u._enum.has_body = 1;
2088 $$->u._enum.enum_id = $1->s;
2089 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2091 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2093 $$ = make_node(scanner, NODE_ENUM);
2094 $$->u._enum.has_body = 1;
2095 $$->u._enum.enum_id = $1->s;
2096 ($$)->u._enum.container_type = $3;
2097 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2101 $$ = make_node(scanner, NODE_ENUM);
2102 $$->u._enum.has_body = 0;
2103 $$->u._enum.enum_id = $1->s;
2107 struct_or_variant_declaration_list:
2110 | struct_or_variant_declaration_list struct_or_variant_declaration
2114 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2117 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
2122 struct_or_variant_declaration:
2123 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
2125 struct ctf_node *list;
2127 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2128 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2129 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
2130 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2131 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
2133 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2135 struct ctf_node *list;
2137 $$ = make_node(scanner, NODE_TYPEDEF);
2138 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2139 $$->u._typedef.type_specifier_list = list;
2140 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2141 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2142 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2144 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2146 struct ctf_node *list;
2148 $$ = make_node(scanner, NODE_TYPEDEF);
2149 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2150 $$->u._typedef.type_specifier_list = list;
2151 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2152 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2154 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
2156 struct ctf_node *list;
2158 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2159 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2160 $$ = make_node(scanner, NODE_TYPEDEF);
2161 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2162 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2164 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
2166 struct ctf_node *list;
2168 $$ = make_node(scanner, NODE_TYPEALIAS);
2169 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2170 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2172 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2173 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2174 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2175 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2177 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2178 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2179 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2180 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2184 alias_declaration_specifiers:
2187 struct ctf_node *node;
2189 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2190 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2191 node->u.type_specifier.type = TYPESPEC_CONST;
2192 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2196 struct ctf_node *node;
2198 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2200 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2204 struct ctf_node *node;
2206 add_type(scanner, $1);
2207 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2208 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2209 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2210 node->u.type_specifier.id_type = yylval.gs->s;
2211 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2213 | alias_declaration_specifiers CONST
2215 struct ctf_node *node;
2218 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2219 node->u.type_specifier.type = TYPESPEC_CONST;
2220 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2222 | alias_declaration_specifiers type_specifier
2225 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2227 | alias_declaration_specifiers IDENTIFIER
2229 struct ctf_node *node;
2231 add_type(scanner, $2);
2233 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2234 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2235 node->u.type_specifier.id_type = yylval.gs->s;
2236 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2240 struct_or_variant_declarator_list:
2241 struct_or_variant_declarator
2243 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2246 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2250 struct_or_variant_declarator:
2253 | COLON unary_expression
2255 | declarator COLON unary_expression
2258 if (set_parent_node($3, $1))
2259 reparent_error(scanner, "struct_or_variant_declarator");
2266 | enumerator_list COMMA enumerator
2269 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2276 $$ = make_node(scanner, NODE_ENUMERATOR);
2277 $$->u.enumerator.id = $1->s;
2281 $$ = make_node(scanner, NODE_ENUMERATOR);
2282 $$->u.enumerator.id = $1->s;
2286 $$ = make_node(scanner, NODE_ENUMERATOR);
2287 $$->u.enumerator.id = $1->s;
2291 $$ = make_node(scanner, NODE_ENUMERATOR);
2292 $$->u.enumerator.id = $1->s;
2294 | IDENTIFIER EQUAL unary_expression_or_range
2296 $$ = make_node(scanner, NODE_ENUMERATOR);
2297 $$->u.enumerator.id = $1->s;
2298 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2300 | ID_TYPE EQUAL unary_expression_or_range
2302 $$ = make_node(scanner, NODE_ENUMERATOR);
2303 $$->u.enumerator.id = $1->s;
2304 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2306 | keywords EQUAL unary_expression_or_range
2308 $$ = make_node(scanner, NODE_ENUMERATOR);
2309 $$->u.enumerator.id = $1->s;
2310 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2312 | STRING_LITERAL EQUAL unary_expression_or_range
2314 $$ = make_node(scanner, NODE_ENUMERATOR);
2315 $$->u.enumerator.id = $1->s;
2316 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2320 abstract_declarator_list:
2323 | abstract_declarator_list COMMA abstract_declarator
2326 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2330 abstract_declarator:
2331 direct_abstract_declarator
2333 | pointer direct_abstract_declarator
2336 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2340 direct_abstract_declarator:
2343 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2344 $$->u.type_declarator.type = TYPEDEC_ID;
2349 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2350 $$->u.type_declarator.type = TYPEDEC_ID;
2351 $$->u.type_declarator.u.id = $1->s;
2353 | LPAREN abstract_declarator RPAREN
2355 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2356 $$->u.type_declarator.type = TYPEDEC_NESTED;
2357 $$->u.type_declarator.u.nested.type_declarator = $2;
2359 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2361 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2362 $$->u.type_declarator.type = TYPEDEC_NESTED;
2363 $$->u.type_declarator.u.nested.type_declarator = $1;
2364 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2365 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2367 | direct_abstract_declarator LSBRAC RSBRAC
2369 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2370 $$->u.type_declarator.type = TYPEDEC_NESTED;
2371 $$->u.type_declarator.u.nested.type_declarator = $1;
2372 $$->u.type_declarator.u.nested.abstract_array = 1;
2376 alias_abstract_declarator_list:
2377 alias_abstract_declarator
2379 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2382 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2386 alias_abstract_declarator:
2387 direct_alias_abstract_declarator
2389 | pointer direct_alias_abstract_declarator
2392 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2396 direct_alias_abstract_declarator:
2399 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2400 $$->u.type_declarator.type = TYPEDEC_ID;
2403 | LPAREN alias_abstract_declarator RPAREN
2405 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2406 $$->u.type_declarator.type = TYPEDEC_NESTED;
2407 $$->u.type_declarator.u.nested.type_declarator = $2;
2409 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2411 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2412 $$->u.type_declarator.type = TYPEDEC_NESTED;
2413 $$->u.type_declarator.u.nested.type_declarator = $1;
2414 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2415 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2417 | direct_alias_abstract_declarator LSBRAC RSBRAC
2419 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2420 $$->u.type_declarator.type = TYPEDEC_NESTED;
2421 $$->u.type_declarator.u.nested.type_declarator = $1;
2422 $$->u.type_declarator.u.nested.abstract_array = 1;
2429 | pointer direct_declarator
2432 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2439 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2440 $$->u.type_declarator.type = TYPEDEC_ID;
2441 $$->u.type_declarator.u.id = $1->s;
2443 | LPAREN declarator RPAREN
2445 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2446 $$->u.type_declarator.type = TYPEDEC_NESTED;
2447 $$->u.type_declarator.u.nested.type_declarator = $2;
2449 | direct_declarator LSBRAC unary_expression RSBRAC
2451 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2452 $$->u.type_declarator.type = TYPEDEC_NESTED;
2453 $$->u.type_declarator.u.nested.type_declarator = $1;
2454 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2455 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2460 direct_type_declarator
2462 | pointer direct_type_declarator
2465 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2469 direct_type_declarator:
2472 add_type(scanner, $1);
2473 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2474 $$->u.type_declarator.type = TYPEDEC_ID;
2475 $$->u.type_declarator.u.id = $1->s;
2477 | LPAREN type_declarator RPAREN
2479 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2480 $$->u.type_declarator.type = TYPEDEC_NESTED;
2481 $$->u.type_declarator.u.nested.type_declarator = $2;
2483 | direct_type_declarator LSBRAC unary_expression RSBRAC
2485 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2486 $$->u.type_declarator.type = TYPEDEC_NESTED;
2487 $$->u.type_declarator.u.nested.type_declarator = $1;
2488 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2489 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2496 $$ = make_node(scanner, NODE_POINTER);
2500 $$ = make_node(scanner, NODE_POINTER);
2501 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2503 | STAR type_qualifier_list pointer
2505 $$ = make_node(scanner, NODE_POINTER);
2506 $$->u.pointer.const_qualifier = 1;
2507 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2511 type_qualifier_list:
2512 /* pointer assumes only const type qualifier */
2514 | type_qualifier_list CONST
2517 /* 2.3: CTF-specific declarations */
2519 ctf_assignment_expression_list:
2520 ctf_assignment_expression SEMICOLON
2522 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2525 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2529 ctf_assignment_expression:
2530 unary_expression EQUAL unary_expression
2533 * Because we have left and right, cannot use
2536 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2537 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2538 if ($1->u.unary_expression.type != UNARY_STRING)
2539 reparent_error(scanner, "ctf_assignment_expression left expects string");
2540 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2542 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2545 * Because we have left and right, cannot use
2548 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2549 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2550 if ($1->u.unary_expression.type != UNARY_STRING)
2551 reparent_error(scanner, "ctf_assignment_expression left expects string");
2552 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2554 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2556 struct ctf_node *list;
2558 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2559 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2560 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2561 $$ = make_node(scanner, NODE_TYPEDEF);
2562 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2563 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2565 | TYPEDEF declaration_specifiers type_declarator_list
2567 struct ctf_node *list;
2569 $$ = make_node(scanner, NODE_TYPEDEF);
2570 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2571 $$->u._typedef.type_specifier_list = list;
2572 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2573 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2575 | declaration_specifiers TYPEDEF type_declarator_list
2577 struct ctf_node *list;
2579 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2580 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2581 $$ = make_node(scanner, NODE_TYPEDEF);
2582 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2583 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2585 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2587 struct ctf_node *list;
2589 $$ = make_node(scanner, NODE_TYPEALIAS);
2590 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2591 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2593 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2594 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2595 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2596 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2598 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2599 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2600 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2601 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);