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"
47 /* Join two lists, put "add" at the end of "head". */
49 _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
51 /* Do nothing if the list which gets added is empty. */
52 if (add != add->next) {
53 add->next->prev = head->prev;
54 add->prev->next = head;
55 head->prev->next = add->next;
56 head->prev = add->prev;
61 int yyparse(struct ctf_scanner *scanner, yyscan_t yyscanner);
63 int yylex(union YYSTYPE *yyval, yyscan_t yyscanner);
65 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
67 int yylex_destroy(yyscan_t yyscanner);
69 void yyrestart(FILE * in_str, yyscan_t yyscanner);
71 int yyget_lineno(yyscan_t yyscanner);
73 char *yyget_text(yyscan_t yyscanner);
75 static const char *node_type_to_str[] = {
76 #define ENTRY(S) [S] = #S,
77 FOREACH_CTF_NODES(ENTRY)
82 * Static node for out of memory errors. Only "type" is used. lineno is
83 * always left at 0. The rest of the node content can be overwritten,
86 static struct ctf_node error_node = {
91 const char *node_type(struct ctf_node *node)
93 if (node->type < NR_NODE_TYPES)
94 return node_type_to_str[node->type];
99 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
101 lvalp->s = objstack_alloc(scanner->objstack, strlen(src) + 1);
102 strcpy(lvalp->s, src);
106 int str_check(size_t str_len, size_t offset, size_t len)
109 if (offset + len < offset)
111 if (offset + len > str_len)
117 int bt_isodigit(int c)
135 int parse_base_sequence(const char *src, size_t len, size_t pos,
136 char *buffer, size_t *buf_len, int base)
138 const size_t max_char = 3;
141 while (!str_check(len, pos, 1) && nr_char < max_char) {
146 buffer[nr_char++] = c;
149 } else if (base == 16) {
151 buffer[nr_char++] = c;
156 /* Unsupported base */
161 buffer[nr_char] = '\0';
167 int import_basic_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
168 size_t len, const char *src, char delim)
170 size_t pos = 0, dpos = 0;
172 if (str_check(len, pos, 1))
174 if (src[pos++] != delim)
177 while (src[pos] != delim) {
180 if (str_check(len, pos, 1))
184 if (str_check(len, pos, 1))
234 if (parse_base_sequence(src, len, pos - 1,
235 oct_buffer, &oct_len, 8))
237 c = strtoul(&oct_buffer[0], NULL, 8);
246 if (parse_base_sequence(src, len, pos,
247 hex_buffer, &hex_len, 16))
249 c = strtoul(&hex_buffer[0], NULL, 16);
257 if (str_check(len, dpos, 1))
259 lvalp->s[dpos++] = c;
262 if (str_check(len, dpos, 1))
264 lvalp->s[dpos++] = '\0';
266 if (str_check(len, pos, 1))
268 if (src[pos++] != delim)
271 if (str_check(len, pos, 1))
273 if (src[pos] != '\0')
278 int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
279 const char *src, char delim)
283 len = strlen(src) + 1;
284 lvalp->s = objstack_alloc(scanner->objstack, len);
286 // TODO: import wide string
287 printfl_error(yyget_lineno(scanner),
288 "Wide string not supported yet.");
291 return import_basic_string(scanner, lvalp, len, src, delim);
295 static void init_scope(struct ctf_scanner_scope *scope,
296 struct ctf_scanner_scope *parent)
298 scope->parent = parent;
299 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
303 static void finalize_scope(struct ctf_scanner_scope *scope)
305 g_hash_table_destroy(scope->types);
308 static void push_scope(struct ctf_scanner *scanner)
310 struct ctf_scanner_scope *ns;
312 printf_debug("push scope\n");
313 ns = malloc(sizeof(struct ctf_scanner_scope));
314 init_scope(ns, scanner->cs);
318 static void pop_scope(struct ctf_scanner *scanner)
320 struct ctf_scanner_scope *os;
322 printf_debug("pop scope\n");
324 scanner->cs = os->parent;
329 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
333 ret = (int) (long) g_hash_table_lookup(s->types, id);
334 printf_debug("lookup %p %s %d\n", s, id, ret);
339 int is_type(struct ctf_scanner *scanner, const char *id)
341 struct ctf_scanner_scope *it;
344 for (it = scanner->cs; it != NULL; it = it->parent) {
345 if (lookup_type(it, id)) {
350 printf_debug("is type %s %d\n", id, ret);
354 static void add_type(struct ctf_scanner *scanner, char *id)
356 printf_debug("add type %s\n", id);
357 if (lookup_type(scanner->cs, id))
359 g_hash_table_insert(scanner->cs->types, id, id);
362 static struct ctf_node *make_node(struct ctf_scanner *scanner,
365 struct ctf_node *node;
367 node = objstack_alloc(scanner->objstack, sizeof(*node));
369 printfl_fatal(yyget_lineno(scanner->scanner), "out of memory");
373 node->lineno = yyget_lineno(scanner->scanner);
374 BT_INIT_LIST_HEAD(&node->tmp_head);
375 bt_list_add(&node->siblings, &node->tmp_head);
379 node->type = NODE_ERROR;
380 printfn_fatal(node, "trying to create root node");
384 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
387 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
390 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
393 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
396 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
399 BT_INIT_LIST_HEAD(&node->u.callsite.declaration_list);
402 case NODE_CTF_EXPRESSION:
403 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
404 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
406 case NODE_UNARY_EXPRESSION:
410 BT_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
412 case NODE_TYPEALIAS_TARGET:
413 BT_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
415 case NODE_TYPEALIAS_ALIAS:
416 BT_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
421 case NODE_TYPE_SPECIFIER:
423 case NODE_TYPE_SPECIFIER_LIST:
424 BT_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
428 case NODE_TYPE_DECLARATOR:
429 BT_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
432 case NODE_FLOATING_POINT:
433 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
436 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
439 BT_INIT_LIST_HEAD(&node->u.string.expressions);
441 case NODE_ENUMERATOR:
442 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
445 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
447 case NODE_STRUCT_OR_VARIANT_DECLARATION:
448 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
451 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
454 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
455 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
460 node->type = NODE_ERROR;
461 printfn_fatal(node, "unknown node type '%d'", (int) type);
468 static int reparent_ctf_expression(struct ctf_node *node,
469 struct ctf_node *parent)
471 switch (parent->type) {
473 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
476 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
479 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
482 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
485 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
488 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
490 case NODE_FLOATING_POINT:
491 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
494 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
497 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
501 case NODE_CTF_EXPRESSION:
503 case NODE_TYPEALIAS_TARGET:
504 case NODE_TYPEALIAS_ALIAS:
506 case NODE_TYPE_SPECIFIER:
507 case NODE_TYPE_SPECIFIER_LIST:
509 case NODE_TYPE_DECLARATOR:
510 case NODE_ENUMERATOR:
512 case NODE_STRUCT_OR_VARIANT_DECLARATION:
515 case NODE_UNARY_EXPRESSION:
520 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
526 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
528 switch (parent->type) {
530 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
533 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
536 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
539 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
542 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
545 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
548 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
551 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
554 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
557 case NODE_FLOATING_POINT:
560 case NODE_CTF_EXPRESSION:
562 case NODE_TYPEALIAS_TARGET:
563 case NODE_TYPEALIAS_ALIAS:
565 case NODE_TYPE_SPECIFIER:
566 case NODE_TYPE_SPECIFIER_LIST:
568 case NODE_TYPE_DECLARATOR:
569 case NODE_ENUMERATOR:
571 case NODE_STRUCT_OR_VARIANT_DECLARATION:
572 case NODE_UNARY_EXPRESSION:
577 printfn_fatal(node, "unknown node type %d", parent->type);
583 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
585 switch (parent->type) {
587 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
590 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
593 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
596 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
599 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
602 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
605 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
608 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
611 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
614 case NODE_FLOATING_POINT:
617 case NODE_CTF_EXPRESSION:
619 case NODE_TYPEALIAS_TARGET:
620 case NODE_TYPEALIAS_ALIAS:
622 case NODE_TYPE_SPECIFIER:
623 case NODE_TYPE_SPECIFIER_LIST:
625 case NODE_TYPE_DECLARATOR:
626 case NODE_ENUMERATOR:
628 case NODE_STRUCT_OR_VARIANT_DECLARATION:
629 case NODE_UNARY_EXPRESSION:
634 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
640 static int reparent_type_specifier(struct ctf_node *node,
641 struct ctf_node *parent)
643 switch (parent->type) {
644 case NODE_TYPE_SPECIFIER_LIST:
645 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
648 case NODE_TYPE_SPECIFIER:
658 case NODE_TYPEALIAS_TARGET:
659 case NODE_TYPEALIAS_ALIAS:
660 case NODE_TYPE_DECLARATOR:
662 case NODE_STRUCT_OR_VARIANT_DECLARATION:
664 case NODE_FLOATING_POINT:
667 case NODE_CTF_EXPRESSION:
669 case NODE_ENUMERATOR:
670 case NODE_UNARY_EXPRESSION:
675 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
681 static int reparent_type_specifier_list(struct ctf_node *node,
682 struct ctf_node *parent)
684 switch (parent->type) {
686 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
689 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
692 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
695 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
698 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
701 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
704 bt_list_add_tail(&node->siblings, &parent->u.callsite.declaration_list);
707 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
710 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
713 parent->u._typedef.type_specifier_list = node;
715 case NODE_TYPEALIAS_TARGET:
716 parent->u.typealias_target.type_specifier_list = node;
718 case NODE_TYPEALIAS_ALIAS:
719 parent->u.typealias_alias.type_specifier_list = node;
722 parent->u._enum.container_type = node;
724 case NODE_STRUCT_OR_VARIANT_DECLARATION:
725 parent->u.struct_or_variant_declaration.type_specifier_list = node;
727 case NODE_TYPE_DECLARATOR:
728 case NODE_TYPE_SPECIFIER:
730 case NODE_FLOATING_POINT:
733 case NODE_CTF_EXPRESSION:
735 case NODE_ENUMERATOR:
736 case NODE_UNARY_EXPRESSION:
741 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
747 static int reparent_type_declarator(struct ctf_node *node,
748 struct ctf_node *parent)
750 switch (parent->type) {
751 case NODE_TYPE_DECLARATOR:
752 parent->u.type_declarator.type = TYPEDEC_NESTED;
753 parent->u.type_declarator.u.nested.type_declarator = node;
755 case NODE_STRUCT_OR_VARIANT_DECLARATION:
756 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
759 _bt_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
761 case NODE_TYPEALIAS_TARGET:
762 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
764 case NODE_TYPEALIAS_ALIAS:
765 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
779 case NODE_FLOATING_POINT:
782 case NODE_CTF_EXPRESSION:
783 case NODE_TYPE_SPECIFIER:
784 case NODE_TYPE_SPECIFIER_LIST:
786 case NODE_ENUMERATOR:
787 case NODE_UNARY_EXPRESSION:
792 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
801 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
802 * create the link declared by the input, -ENOENT if node or parent is NULL,
803 * -EINVAL if there is an internal structure problem.
805 static int set_parent_node(struct ctf_node *node,
806 struct ctf_node *parent)
808 if (!node || !parent)
811 /* Note: Linking to parent will be done only by an external visitor */
813 switch (node->type) {
815 printfn_fatal(node, "trying to reparent root node");
819 if (parent->type == NODE_ROOT) {
820 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
826 if (parent->type == NODE_ROOT) {
827 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
833 if (parent->type == NODE_ROOT) {
834 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
840 if (parent->type == NODE_ROOT) {
841 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
847 if (parent->type == NODE_ROOT) {
848 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
854 if (parent->type == NODE_ROOT) {
855 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.callsite);
861 case NODE_CTF_EXPRESSION:
862 return reparent_ctf_expression(node, parent);
863 case NODE_UNARY_EXPRESSION:
864 if (parent->type == NODE_TYPE_DECLARATOR)
865 parent->u.type_declarator.bitfield_len = node;
871 return reparent_typedef(node, parent);
872 case NODE_TYPEALIAS_TARGET:
873 if (parent->type == NODE_TYPEALIAS)
874 parent->u.typealias.target = node;
877 case NODE_TYPEALIAS_ALIAS:
878 if (parent->type == NODE_TYPEALIAS)
879 parent->u.typealias.alias = node;
883 return reparent_typealias(node, parent);
886 if (parent->type == NODE_TYPE_DECLARATOR) {
887 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
891 case NODE_TYPE_DECLARATOR:
892 return reparent_type_declarator(node, parent);
894 case NODE_TYPE_SPECIFIER_LIST:
895 return reparent_type_specifier_list(node, parent);
897 case NODE_TYPE_SPECIFIER:
898 return reparent_type_specifier(node, parent);
900 case NODE_FLOATING_POINT:
906 return -EINVAL; /* Dealt with internally within grammar */
908 case NODE_ENUMERATOR:
909 if (parent->type == NODE_ENUM) {
910 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
915 case NODE_STRUCT_OR_VARIANT_DECLARATION:
916 switch (parent->type) {
918 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
921 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
930 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
937 void yyerror(struct ctf_scanner *scanner, yyscan_t yyscanner, const char *str)
939 printfl_error(yyget_lineno(scanner->scanner),
940 "token \"%s\": %s\n",
941 yyget_text(scanner->scanner), str);
950 #define reparent_error(scanner, str) \
952 yyerror(scanner, scanner->scanner, YY_("reparent_error: " str)); \
956 static struct ctf_ast *ctf_ast_alloc(struct ctf_scanner *scanner)
960 ast = objstack_alloc(scanner->objstack, sizeof(*ast));
963 ast->root.type = NODE_ROOT;
964 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
965 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
966 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
967 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
968 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
969 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
970 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
971 BT_INIT_LIST_HEAD(&ast->root.u.root.callsite);
975 int ctf_scanner_append_ast(struct ctf_scanner *scanner, FILE *input)
977 /* Start processing new stream */
978 yyrestart(input, scanner->scanner);
980 fprintf(stdout, "Scanner input is a%s.\n",
981 isatty(fileno(input)) ? "n interactive tty" :
982 " noninteractive file");
983 return yyparse(scanner, scanner->scanner);
986 struct ctf_scanner *ctf_scanner_alloc(void)
988 struct ctf_scanner *scanner;
991 yydebug = babeltrace_debug;
993 scanner = malloc(sizeof(*scanner));
996 memset(scanner, 0, sizeof(*scanner));
997 ret = yylex_init_extra(scanner, &scanner->scanner);
999 printf_fatal("yylex_init error");
1000 goto cleanup_scanner;
1002 scanner->objstack = objstack_create();
1003 if (!scanner->objstack)
1005 scanner->ast = ctf_ast_alloc(scanner);
1007 goto cleanup_objstack;
1008 init_scope(&scanner->root_scope, NULL);
1009 scanner->cs = &scanner->root_scope;
1014 objstack_destroy(scanner->objstack);
1016 ret = yylex_destroy(scanner->scanner);
1018 printf_fatal("yylex_destroy error");
1024 void ctf_scanner_free(struct ctf_scanner *scanner)
1030 finalize_scope(&scanner->root_scope);
1031 objstack_destroy(scanner->objstack);
1032 ret = yylex_destroy(scanner->scanner);
1034 printf_error("yylex_destroy error");
1043 %parse-param {struct ctf_scanner *scanner}
1044 %parse-param {yyscan_t yyscanner}
1045 %lex-param {yyscan_t yyscanner}
1047 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
1048 * vs struct { int :value; } (unnamed bit-field). The default is to
1049 * shift, so whenever we encounter an enumeration, we are doing the
1050 * proper thing (shift). It is illegal to declare an enumeration
1051 * "bit-field", so it is OK if this situation ends up in a parsing
1056 %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
1057 %token <s> IDENTIFIER ID_TYPE
1062 unsigned long long ull;
1068 %type <s> STRING_LITERAL CHARACTER_LITERAL
1072 %type <ull> INTEGER_LITERAL
1073 %type <n> postfix_expression unary_expression unary_expression_or_range
1075 %type <n> declaration
1076 %type <n> event_declaration
1077 %type <n> stream_declaration
1078 %type <n> env_declaration
1079 %type <n> trace_declaration
1080 %type <n> clock_declaration
1081 %type <n> callsite_declaration
1082 %type <n> integer_declaration_specifiers
1083 %type <n> declaration_specifiers
1084 %type <n> alias_declaration_specifiers
1086 %type <n> type_declarator_list
1087 %type <n> integer_type_specifier
1088 %type <n> type_specifier
1089 %type <n> struct_type_specifier
1090 %type <n> variant_type_specifier
1091 %type <n> enum_type_specifier
1092 %type <n> struct_or_variant_declaration_list
1093 %type <n> struct_or_variant_declaration
1094 %type <n> struct_or_variant_declarator_list
1095 %type <n> struct_or_variant_declarator
1096 %type <n> enumerator_list
1097 %type <n> enumerator
1098 %type <n> abstract_declarator_list
1099 %type <n> abstract_declarator
1100 %type <n> direct_abstract_declarator
1101 %type <n> alias_abstract_declarator_list
1102 %type <n> alias_abstract_declarator
1103 %type <n> direct_alias_abstract_declarator
1104 %type <n> declarator
1105 %type <n> direct_declarator
1106 %type <n> type_declarator
1107 %type <n> direct_type_declarator
1109 %type <n> ctf_assignment_expression_list
1110 %type <n> ctf_assignment_expression
1117 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
1118 reparent_error(scanner, "error reparenting to root");
1122 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
1123 reparent_error(scanner, "error reparenting to root");
1185 /* 2: Phrase structure grammar */
1190 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1191 $$->u.unary_expression.type = UNARY_STRING;
1192 $$->u.unary_expression.u.string = yylval.s;
1196 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1197 $$->u.unary_expression.type = UNARY_STRING;
1198 $$->u.unary_expression.u.string = yylval.s;
1202 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1203 $$->u.unary_expression.type = UNARY_STRING;
1204 $$->u.unary_expression.u.string = yylval.s;
1208 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1209 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1210 $$->u.unary_expression.u.unsigned_constant = $1;
1214 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1215 $$->u.unary_expression.type = UNARY_STRING;
1216 $$->u.unary_expression.u.string = $1;
1220 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1221 $$->u.unary_expression.type = UNARY_STRING;
1222 $$->u.unary_expression.u.string = $1;
1224 | LPAREN unary_expression RPAREN
1228 | postfix_expression LSBRAC unary_expression RSBRAC
1230 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1231 $$->u.unary_expression.type = UNARY_SBRAC;
1232 $$->u.unary_expression.u.sbrac_exp = $3;
1233 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1234 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1236 | postfix_expression DOT IDENTIFIER
1238 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1239 $$->u.unary_expression.type = UNARY_STRING;
1240 $$->u.unary_expression.u.string = yylval.s;
1241 $$->u.unary_expression.link = UNARY_DOTLINK;
1242 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1243 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1245 | postfix_expression DOT ID_TYPE
1247 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1248 $$->u.unary_expression.type = UNARY_STRING;
1249 $$->u.unary_expression.u.string = yylval.s;
1250 $$->u.unary_expression.link = UNARY_DOTLINK;
1251 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1252 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1254 | postfix_expression DOT keywords
1256 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1257 $$->u.unary_expression.type = UNARY_STRING;
1258 $$->u.unary_expression.u.string = yylval.s;
1259 $$->u.unary_expression.link = UNARY_DOTLINK;
1260 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1261 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1263 | postfix_expression RARROW IDENTIFIER
1265 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1266 $$->u.unary_expression.type = UNARY_STRING;
1267 $$->u.unary_expression.u.string = yylval.s;
1268 $$->u.unary_expression.link = UNARY_ARROWLINK;
1269 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1270 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1272 | postfix_expression RARROW ID_TYPE
1274 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1275 $$->u.unary_expression.type = UNARY_STRING;
1276 $$->u.unary_expression.u.string = yylval.s;
1277 $$->u.unary_expression.link = UNARY_ARROWLINK;
1278 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1279 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1286 | PLUS postfix_expression
1289 if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
1290 && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
1291 reparent_error(scanner, "expecting numeric constant");
1294 | MINUS postfix_expression
1297 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1298 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1299 $$->u.unary_expression.u.signed_constant =
1300 -($$->u.unary_expression.u.unsigned_constant);
1301 } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1302 $$->u.unary_expression.u.signed_constant =
1303 -($$->u.unary_expression.u.signed_constant);
1305 reparent_error(scanner, "expecting numeric constant");
1310 unary_expression_or_range:
1311 unary_expression DOTDOTDOT unary_expression
1314 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1315 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1321 /* 2.2: Declarations */
1324 declaration_specifiers SEMICOLON
1328 | stream_declaration
1336 | callsite_declaration
1338 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1340 struct ctf_node *list;
1342 $$ = make_node(scanner, NODE_TYPEDEF);
1343 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1344 $$->u._typedef.type_specifier_list = list;
1345 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1346 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1347 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1349 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1351 struct ctf_node *list;
1353 $$ = make_node(scanner, NODE_TYPEDEF);
1354 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1355 $$->u._typedef.type_specifier_list = list;
1356 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1357 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1359 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1361 struct ctf_node *list;
1363 $$ = make_node(scanner, NODE_TYPEDEF);
1364 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1365 $$->u._typedef.type_specifier_list = list;
1366 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1367 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1369 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1371 struct ctf_node *list;
1373 $$ = make_node(scanner, NODE_TYPEALIAS);
1374 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1375 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1377 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1378 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1379 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1380 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1382 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1383 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1384 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1385 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1390 event_declaration_begin event_declaration_end
1392 $$ = make_node(scanner, NODE_EVENT);
1394 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1396 $$ = make_node(scanner, NODE_EVENT);
1397 if (set_parent_node($2, $$))
1398 reparent_error(scanner, "event_declaration");
1402 event_declaration_begin:
1404 { push_scope(scanner); }
1407 event_declaration_end:
1409 { pop_scope(scanner); }
1414 stream_declaration_begin stream_declaration_end
1416 $$ = make_node(scanner, NODE_STREAM);
1418 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1420 $$ = make_node(scanner, NODE_STREAM);
1421 if (set_parent_node($2, $$))
1422 reparent_error(scanner, "stream_declaration");
1426 stream_declaration_begin:
1428 { push_scope(scanner); }
1431 stream_declaration_end:
1433 { pop_scope(scanner); }
1437 env_declaration_begin env_declaration_end
1439 $$ = make_node(scanner, NODE_ENV);
1441 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1443 $$ = make_node(scanner, NODE_ENV);
1444 if (set_parent_node($2, $$))
1445 reparent_error(scanner, "env declaration");
1449 env_declaration_begin:
1451 { push_scope(scanner); }
1454 env_declaration_end:
1456 { pop_scope(scanner); }
1460 trace_declaration_begin trace_declaration_end
1462 $$ = make_node(scanner, NODE_TRACE);
1464 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1466 $$ = make_node(scanner, NODE_TRACE);
1467 if (set_parent_node($2, $$))
1468 reparent_error(scanner, "trace_declaration");
1472 trace_declaration_begin:
1474 { push_scope(scanner); }
1477 trace_declaration_end:
1479 { pop_scope(scanner); }
1483 CLOCK clock_declaration_begin clock_declaration_end
1485 $$ = make_node(scanner, NODE_CLOCK);
1487 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1489 $$ = make_node(scanner, NODE_CLOCK);
1490 if (set_parent_node($3, $$))
1491 reparent_error(scanner, "trace_declaration");
1495 clock_declaration_begin:
1497 { push_scope(scanner); }
1500 clock_declaration_end:
1502 { pop_scope(scanner); }
1505 callsite_declaration:
1506 CALLSITE callsite_declaration_begin callsite_declaration_end
1508 $$ = make_node(scanner, NODE_CALLSITE);
1510 | CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1512 $$ = make_node(scanner, NODE_CALLSITE);
1513 if (set_parent_node($3, $$))
1514 reparent_error(scanner, "trace_declaration");
1518 callsite_declaration_begin:
1520 { push_scope(scanner); }
1523 callsite_declaration_end:
1525 { pop_scope(scanner); }
1528 integer_declaration_specifiers:
1531 struct ctf_node *node;
1533 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1534 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1535 node->u.type_specifier.type = TYPESPEC_CONST;
1536 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1538 | integer_type_specifier
1540 struct ctf_node *node;
1542 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1544 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1546 | integer_declaration_specifiers CONST
1548 struct ctf_node *node;
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_declaration_specifiers integer_type_specifier
1558 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1562 declaration_specifiers:
1565 struct ctf_node *node;
1567 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
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);
1574 struct ctf_node *node;
1576 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1578 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1580 | declaration_specifiers CONST
1582 struct ctf_node *node;
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);
1589 | declaration_specifiers type_specifier
1592 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1596 type_declarator_list:
1599 | type_declarator_list COMMA type_declarator
1602 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1606 integer_type_specifier:
1609 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1610 $$->u.type_specifier.type = TYPESPEC_CHAR;
1614 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1615 $$->u.type_specifier.type = TYPESPEC_SHORT;
1619 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1620 $$->u.type_specifier.type = TYPESPEC_INT;
1624 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1625 $$->u.type_specifier.type = TYPESPEC_LONG;
1629 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1630 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1634 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1635 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1639 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1640 $$->u.type_specifier.type = TYPESPEC_BOOL;
1644 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1645 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1646 $$->u.type_specifier.id_type = yylval.s;
1648 | INTEGER LBRAC RBRAC
1650 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1651 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1652 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1654 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1656 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1657 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1658 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1659 if (set_parent_node($3, $$->u.type_specifier.node))
1660 reparent_error(scanner, "integer reparent error");
1667 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1668 $$->u.type_specifier.type = TYPESPEC_VOID;
1672 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1673 $$->u.type_specifier.type = TYPESPEC_CHAR;
1677 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1678 $$->u.type_specifier.type = TYPESPEC_SHORT;
1682 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1683 $$->u.type_specifier.type = TYPESPEC_INT;
1687 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1688 $$->u.type_specifier.type = TYPESPEC_LONG;
1692 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1693 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1697 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1698 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1702 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1703 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1707 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1708 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1712 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1713 $$->u.type_specifier.type = TYPESPEC_BOOL;
1717 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1718 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1722 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1723 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1727 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1728 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1729 $$->u.type_specifier.id_type = yylval.s;
1731 | FLOATING_POINT LBRAC RBRAC
1733 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1734 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1735 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1737 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1739 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1740 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1741 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1742 if (set_parent_node($3, $$->u.type_specifier.node))
1743 reparent_error(scanner, "floating point reparent error");
1745 | INTEGER LBRAC RBRAC
1747 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1748 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1749 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1751 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1753 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1754 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1755 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1756 if (set_parent_node($3, $$->u.type_specifier.node))
1757 reparent_error(scanner, "integer reparent error");
1761 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1762 $$->u.type_specifier.type = TYPESPEC_STRING;
1763 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1765 | STRING LBRAC RBRAC
1767 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1768 $$->u.type_specifier.type = TYPESPEC_STRING;
1769 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1771 | STRING LBRAC ctf_assignment_expression_list RBRAC
1773 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1774 $$->u.type_specifier.type = TYPESPEC_STRING;
1775 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1776 if (set_parent_node($3, $$->u.type_specifier.node))
1777 reparent_error(scanner, "string reparent error");
1779 | ENUM enum_type_specifier
1781 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1782 $$->u.type_specifier.type = TYPESPEC_ENUM;
1783 $$->u.type_specifier.node = $2;
1785 | VARIANT variant_type_specifier
1787 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1788 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1789 $$->u.type_specifier.node = $2;
1791 | STRUCT struct_type_specifier
1793 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1794 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1795 $$->u.type_specifier.node = $2;
1799 struct_type_specifier:
1800 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1802 $$ = make_node(scanner, NODE_STRUCT);
1803 $$->u._struct.has_body = 1;
1804 if ($2 && set_parent_node($2, $$))
1805 reparent_error(scanner, "struct reparent error");
1807 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1809 $$ = make_node(scanner, NODE_STRUCT);
1810 $$->u._struct.has_body = 1;
1811 $$->u._struct.name = $1;
1812 if ($3 && set_parent_node($3, $$))
1813 reparent_error(scanner, "struct reparent error");
1815 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1817 $$ = make_node(scanner, NODE_STRUCT);
1818 $$->u._struct.has_body = 1;
1819 $$->u._struct.name = $1;
1820 if ($3 && set_parent_node($3, $$))
1821 reparent_error(scanner, "struct reparent error");
1825 $$ = make_node(scanner, NODE_STRUCT);
1826 $$->u._struct.has_body = 0;
1827 $$->u._struct.name = $1;
1831 $$ = make_node(scanner, NODE_STRUCT);
1832 $$->u._struct.has_body = 0;
1833 $$->u._struct.name = $1;
1835 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1837 $$ = make_node(scanner, NODE_STRUCT);
1838 $$->u._struct.has_body = 1;
1839 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1840 if ($2 && set_parent_node($2, $$))
1841 reparent_error(scanner, "struct reparent error");
1843 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1845 $$ = make_node(scanner, NODE_STRUCT);
1846 $$->u._struct.has_body = 1;
1847 $$->u._struct.name = $1;
1848 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1849 if ($3 && set_parent_node($3, $$))
1850 reparent_error(scanner, "struct reparent error");
1852 | ID_TYPE 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 $$->u._struct.name = $1;
1857 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1858 if ($3 && set_parent_node($3, $$))
1859 reparent_error(scanner, "struct reparent error");
1863 struct_declaration_begin:
1865 { push_scope(scanner); }
1868 struct_declaration_end:
1870 { pop_scope(scanner); }
1873 variant_type_specifier:
1874 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1876 $$ = make_node(scanner, NODE_VARIANT);
1877 $$->u.variant.has_body = 1;
1878 if ($2 && set_parent_node($2, $$))
1879 reparent_error(scanner, "variant reparent error");
1881 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1883 $$ = make_node(scanner, NODE_VARIANT);
1884 $$->u.variant.has_body = 1;
1885 $$->u.variant.choice = $2;
1886 if ($5 && set_parent_node($5, $$))
1887 reparent_error(scanner, "variant reparent error");
1889 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1891 $$ = make_node(scanner, NODE_VARIANT);
1892 $$->u.variant.has_body = 1;
1893 $$->u.variant.choice = $2;
1894 if ($5 && set_parent_node($5, $$))
1895 reparent_error(scanner, "variant reparent error");
1897 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1899 $$ = make_node(scanner, NODE_VARIANT);
1900 $$->u.variant.has_body = 1;
1901 $$->u.variant.name = $1;
1902 if ($3 && set_parent_node($3, $$))
1903 reparent_error(scanner, "variant reparent error");
1905 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1907 $$ = make_node(scanner, NODE_VARIANT);
1908 $$->u.variant.has_body = 1;
1909 $$->u.variant.name = $1;
1910 $$->u.variant.choice = $3;
1911 if ($6 && set_parent_node($6, $$))
1912 reparent_error(scanner, "variant reparent error");
1914 | IDENTIFIER LT IDENTIFIER GT
1916 $$ = make_node(scanner, NODE_VARIANT);
1917 $$->u.variant.has_body = 0;
1918 $$->u.variant.name = $1;
1919 $$->u.variant.choice = $3;
1921 | IDENTIFIER 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.name = $1;
1926 $$->u.variant.choice = $3;
1927 if ($6 && set_parent_node($6, $$))
1928 reparent_error(scanner, "variant reparent error");
1930 | IDENTIFIER LT ID_TYPE GT
1932 $$ = make_node(scanner, NODE_VARIANT);
1933 $$->u.variant.has_body = 0;
1934 $$->u.variant.name = $1;
1935 $$->u.variant.choice = $3;
1937 | ID_TYPE 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;
1942 if ($3 && set_parent_node($3, $$))
1943 reparent_error(scanner, "variant reparent error");
1945 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1947 $$ = make_node(scanner, NODE_VARIANT);
1948 $$->u.variant.has_body = 1;
1949 $$->u.variant.name = $1;
1950 $$->u.variant.choice = $3;
1951 if ($6 && set_parent_node($6, $$))
1952 reparent_error(scanner, "variant reparent error");
1954 | ID_TYPE LT IDENTIFIER GT
1956 $$ = make_node(scanner, NODE_VARIANT);
1957 $$->u.variant.has_body = 0;
1958 $$->u.variant.name = $1;
1959 $$->u.variant.choice = $3;
1961 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1963 $$ = make_node(scanner, NODE_VARIANT);
1964 $$->u.variant.has_body = 1;
1965 $$->u.variant.name = $1;
1966 $$->u.variant.choice = $3;
1967 if ($6 && set_parent_node($6, $$))
1968 reparent_error(scanner, "variant reparent error");
1970 | ID_TYPE LT ID_TYPE GT
1972 $$ = make_node(scanner, NODE_VARIANT);
1973 $$->u.variant.has_body = 0;
1974 $$->u.variant.name = $1;
1975 $$->u.variant.choice = $3;
1979 variant_declaration_begin:
1981 { push_scope(scanner); }
1984 variant_declaration_end:
1986 { pop_scope(scanner); }
1989 enum_type_specifier:
1990 LBRAC enumerator_list RBRAC
1992 $$ = make_node(scanner, NODE_ENUM);
1993 $$->u._enum.has_body = 1;
1994 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1996 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1998 $$ = make_node(scanner, NODE_ENUM);
1999 $$->u._enum.has_body = 1;
2000 ($$)->u._enum.container_type = $2;
2001 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2003 | IDENTIFIER LBRAC enumerator_list RBRAC
2005 $$ = make_node(scanner, NODE_ENUM);
2006 $$->u._enum.has_body = 1;
2007 $$->u._enum.enum_id = $1;
2008 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2010 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
2012 $$ = make_node(scanner, NODE_ENUM);
2013 $$->u._enum.has_body = 1;
2014 $$->u._enum.enum_id = $1;
2015 ($$)->u._enum.container_type = $3;
2016 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2018 | ID_TYPE LBRAC enumerator_list RBRAC
2020 $$ = make_node(scanner, NODE_ENUM);
2021 $$->u._enum.has_body = 1;
2022 $$->u._enum.enum_id = $1;
2023 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2025 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
2027 $$ = make_node(scanner, NODE_ENUM);
2028 $$->u._enum.has_body = 1;
2029 $$->u._enum.enum_id = $1;
2030 ($$)->u._enum.container_type = $3;
2031 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2033 | LBRAC enumerator_list COMMA RBRAC
2035 $$ = make_node(scanner, NODE_ENUM);
2036 $$->u._enum.has_body = 1;
2037 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2039 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2041 $$ = make_node(scanner, NODE_ENUM);
2042 $$->u._enum.has_body = 1;
2043 ($$)->u._enum.container_type = $2;
2044 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2046 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
2048 $$ = make_node(scanner, NODE_ENUM);
2049 $$->u._enum.has_body = 1;
2050 $$->u._enum.enum_id = $1;
2051 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2053 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2055 $$ = make_node(scanner, NODE_ENUM);
2056 $$->u._enum.has_body = 1;
2057 $$->u._enum.enum_id = $1;
2058 ($$)->u._enum.container_type = $3;
2059 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2063 $$ = make_node(scanner, NODE_ENUM);
2064 $$->u._enum.has_body = 0;
2065 $$->u._enum.enum_id = $1;
2067 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
2069 $$ = make_node(scanner, NODE_ENUM);
2070 $$->u._enum.has_body = 1;
2071 $$->u._enum.enum_id = $1;
2072 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2074 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2076 $$ = make_node(scanner, NODE_ENUM);
2077 $$->u._enum.has_body = 1;
2078 $$->u._enum.enum_id = $1;
2079 ($$)->u._enum.container_type = $3;
2080 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2084 $$ = make_node(scanner, NODE_ENUM);
2085 $$->u._enum.has_body = 0;
2086 $$->u._enum.enum_id = $1;
2090 struct_or_variant_declaration_list:
2093 | struct_or_variant_declaration_list struct_or_variant_declaration
2097 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2100 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
2105 struct_or_variant_declaration:
2106 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
2108 struct ctf_node *list;
2110 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2111 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2112 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
2113 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2114 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
2116 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2118 struct ctf_node *list;
2120 $$ = make_node(scanner, NODE_TYPEDEF);
2121 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2122 $$->u._typedef.type_specifier_list = list;
2123 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2124 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2125 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2127 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2129 struct ctf_node *list;
2131 $$ = make_node(scanner, NODE_TYPEDEF);
2132 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2133 $$->u._typedef.type_specifier_list = list;
2134 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2135 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2137 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
2139 struct ctf_node *list;
2141 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2142 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2143 $$ = make_node(scanner, NODE_TYPEDEF);
2144 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2145 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2147 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
2149 struct ctf_node *list;
2151 $$ = make_node(scanner, NODE_TYPEALIAS);
2152 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2153 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2155 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2156 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2157 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2158 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2160 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2161 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2162 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2163 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2167 alias_declaration_specifiers:
2170 struct ctf_node *node;
2172 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2173 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2174 node->u.type_specifier.type = TYPESPEC_CONST;
2175 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2179 struct ctf_node *node;
2181 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2183 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2187 struct ctf_node *node;
2189 add_type(scanner, $1);
2190 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2191 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2192 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2193 node->u.type_specifier.id_type = yylval.s;
2194 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2196 | alias_declaration_specifiers CONST
2198 struct ctf_node *node;
2201 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2202 node->u.type_specifier.type = TYPESPEC_CONST;
2203 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2205 | alias_declaration_specifiers type_specifier
2208 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2210 | alias_declaration_specifiers IDENTIFIER
2212 struct ctf_node *node;
2214 add_type(scanner, $2);
2216 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2217 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2218 node->u.type_specifier.id_type = yylval.s;
2219 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2223 struct_or_variant_declarator_list:
2224 struct_or_variant_declarator
2226 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2229 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2233 struct_or_variant_declarator:
2236 | COLON unary_expression
2238 | declarator COLON unary_expression
2241 if (set_parent_node($3, $1))
2242 reparent_error(scanner, "struct_or_variant_declarator");
2249 | enumerator_list COMMA enumerator
2252 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2259 $$ = make_node(scanner, NODE_ENUMERATOR);
2260 $$->u.enumerator.id = $1;
2264 $$ = make_node(scanner, NODE_ENUMERATOR);
2265 $$->u.enumerator.id = $1;
2269 $$ = make_node(scanner, NODE_ENUMERATOR);
2270 $$->u.enumerator.id = $1;
2274 $$ = make_node(scanner, NODE_ENUMERATOR);
2275 $$->u.enumerator.id = $1;
2277 | IDENTIFIER EQUAL unary_expression_or_range
2279 $$ = make_node(scanner, NODE_ENUMERATOR);
2280 $$->u.enumerator.id = $1;
2281 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2283 | ID_TYPE EQUAL unary_expression_or_range
2285 $$ = make_node(scanner, NODE_ENUMERATOR);
2286 $$->u.enumerator.id = $1;
2287 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2289 | keywords EQUAL unary_expression_or_range
2291 $$ = make_node(scanner, NODE_ENUMERATOR);
2292 $$->u.enumerator.id = $1;
2293 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2295 | STRING_LITERAL EQUAL unary_expression_or_range
2297 $$ = make_node(scanner, NODE_ENUMERATOR);
2298 $$->u.enumerator.id = $1;
2299 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2303 abstract_declarator_list:
2306 | abstract_declarator_list COMMA abstract_declarator
2309 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2313 abstract_declarator:
2314 direct_abstract_declarator
2316 | pointer direct_abstract_declarator
2319 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2323 direct_abstract_declarator:
2326 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2327 $$->u.type_declarator.type = TYPEDEC_ID;
2332 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2333 $$->u.type_declarator.type = TYPEDEC_ID;
2334 $$->u.type_declarator.u.id = $1;
2336 | LPAREN abstract_declarator RPAREN
2338 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2339 $$->u.type_declarator.type = TYPEDEC_NESTED;
2340 $$->u.type_declarator.u.nested.type_declarator = $2;
2342 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2344 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2345 $$->u.type_declarator.type = TYPEDEC_NESTED;
2346 $$->u.type_declarator.u.nested.type_declarator = $1;
2347 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2348 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2350 | direct_abstract_declarator LSBRAC RSBRAC
2352 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2353 $$->u.type_declarator.type = TYPEDEC_NESTED;
2354 $$->u.type_declarator.u.nested.type_declarator = $1;
2355 $$->u.type_declarator.u.nested.abstract_array = 1;
2359 alias_abstract_declarator_list:
2360 alias_abstract_declarator
2362 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2365 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2369 alias_abstract_declarator:
2370 direct_alias_abstract_declarator
2372 | pointer direct_alias_abstract_declarator
2375 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2379 direct_alias_abstract_declarator:
2382 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2383 $$->u.type_declarator.type = TYPEDEC_ID;
2386 | LPAREN alias_abstract_declarator RPAREN
2388 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2389 $$->u.type_declarator.type = TYPEDEC_NESTED;
2390 $$->u.type_declarator.u.nested.type_declarator = $2;
2392 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2394 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2395 $$->u.type_declarator.type = TYPEDEC_NESTED;
2396 $$->u.type_declarator.u.nested.type_declarator = $1;
2397 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2398 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2400 | direct_alias_abstract_declarator LSBRAC RSBRAC
2402 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2403 $$->u.type_declarator.type = TYPEDEC_NESTED;
2404 $$->u.type_declarator.u.nested.type_declarator = $1;
2405 $$->u.type_declarator.u.nested.abstract_array = 1;
2412 | pointer direct_declarator
2415 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2422 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2423 $$->u.type_declarator.type = TYPEDEC_ID;
2424 $$->u.type_declarator.u.id = $1;
2426 | LPAREN declarator RPAREN
2428 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2429 $$->u.type_declarator.type = TYPEDEC_NESTED;
2430 $$->u.type_declarator.u.nested.type_declarator = $2;
2432 | direct_declarator LSBRAC unary_expression 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 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2438 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2443 direct_type_declarator
2445 | pointer direct_type_declarator
2448 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2452 direct_type_declarator:
2455 add_type(scanner, $1);
2456 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2457 $$->u.type_declarator.type = TYPEDEC_ID;
2458 $$->u.type_declarator.u.id = $1;
2460 | LPAREN type_declarator RPAREN
2462 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2463 $$->u.type_declarator.type = TYPEDEC_NESTED;
2464 $$->u.type_declarator.u.nested.type_declarator = $2;
2466 | direct_type_declarator LSBRAC unary_expression RSBRAC
2468 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2469 $$->u.type_declarator.type = TYPEDEC_NESTED;
2470 $$->u.type_declarator.u.nested.type_declarator = $1;
2471 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2472 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2479 $$ = make_node(scanner, NODE_POINTER);
2483 $$ = make_node(scanner, NODE_POINTER);
2484 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2486 | STAR type_qualifier_list pointer
2488 $$ = make_node(scanner, NODE_POINTER);
2489 $$->u.pointer.const_qualifier = 1;
2490 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2494 type_qualifier_list:
2495 /* pointer assumes only const type qualifier */
2497 | type_qualifier_list CONST
2500 /* 2.3: CTF-specific declarations */
2502 ctf_assignment_expression_list:
2503 ctf_assignment_expression SEMICOLON
2505 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2508 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2512 ctf_assignment_expression:
2513 unary_expression EQUAL unary_expression
2516 * Because we have left and right, cannot use
2519 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2520 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2521 if ($1->u.unary_expression.type != UNARY_STRING)
2522 reparent_error(scanner, "ctf_assignment_expression left expects string");
2523 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2525 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2528 * Because we have left and right, cannot use
2531 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2532 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2533 if ($1->u.unary_expression.type != UNARY_STRING)
2534 reparent_error(scanner, "ctf_assignment_expression left expects string");
2535 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2537 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2539 struct ctf_node *list;
2541 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2542 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2543 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2544 $$ = make_node(scanner, NODE_TYPEDEF);
2545 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2546 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2548 | TYPEDEF declaration_specifiers type_declarator_list
2550 struct ctf_node *list;
2552 $$ = make_node(scanner, NODE_TYPEDEF);
2553 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2554 $$->u._typedef.type_specifier_list = list;
2555 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2556 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2558 | declaration_specifiers TYPEDEF type_declarator_list
2560 struct ctf_node *list;
2562 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2563 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2564 $$ = make_node(scanner, NODE_TYPEDEF);
2565 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2566 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2568 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2570 struct ctf_node *list;
2572 $$ = make_node(scanner, NODE_TYPEALIAS);
2573 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2574 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2576 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2577 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2578 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2579 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2581 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2582 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2583 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2584 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);