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
28 #define BT_LOG_TAG "PLUGIN-CTF-METADATA-PARSER"
40 #include <babeltrace/list-internal.h>
41 #include <babeltrace/assert-internal.h>
47 #if BT_LOG_ENABLED_VERBOSE
49 # define YYFPRINTF(_stream, _fmt, args...) BT_LOGV(_fmt, ## args)
54 /* Join two lists, put "add" at the end of "head". */
56 _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
58 /* Do nothing if the list which gets added is empty. */
59 if (add != add->next) {
60 add->next->prev = head->prev;
61 add->prev->next = head;
62 head->prev->next = add->next;
63 head->prev = add->prev;
68 int yyparse(struct ctf_scanner *scanner, yyscan_t yyscanner);
70 int yylex(union YYSTYPE *yyval, yyscan_t yyscanner);
72 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
74 int yylex_destroy(yyscan_t yyscanner);
76 void yyrestart(FILE * in_str, yyscan_t yyscanner);
78 int yyget_lineno(yyscan_t yyscanner);
80 char *yyget_text(yyscan_t yyscanner);
82 static const char *node_type_to_str[] = {
83 #define ENTRY(S) [S] = #S,
84 FOREACH_CTF_NODES(ENTRY)
89 * Static node for out of memory errors. Only "type" is used. lineno is
90 * always left at 0. The rest of the node content can be overwritten,
93 static struct ctf_node error_node = {
98 const char *node_type(struct ctf_node *node)
100 if (node->type < NR_NODE_TYPES)
101 return node_type_to_str[node->type];
106 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
108 lvalp->s = objstack_alloc(scanner->objstack, strlen(src) + 1);
109 strcpy(lvalp->s, src);
113 int str_check(size_t str_len, size_t offset, size_t len)
116 if (offset + len < offset)
118 if (offset + len > str_len)
124 int bt_isodigit(int c)
142 int parse_base_sequence(const char *src, size_t len, size_t pos,
143 char *buffer, size_t *buf_len, int base)
145 const size_t max_char = 3;
148 while (!str_check(len, pos, 1) && nr_char < max_char) {
153 buffer[nr_char++] = c;
156 } else if (base == 16) {
158 buffer[nr_char++] = c;
163 /* Unsupported base */
167 BT_ASSERT(nr_char > 0);
168 buffer[nr_char] = '\0';
174 int import_basic_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
175 size_t len, const char *src, char delim)
177 size_t pos = 0, dpos = 0;
179 if (str_check(len, pos, 1))
181 if (src[pos++] != delim)
184 while (src[pos] != delim) {
187 if (str_check(len, pos, 1))
191 if (str_check(len, pos, 1))
241 if (parse_base_sequence(src, len, pos - 1,
242 oct_buffer, &oct_len, 8))
244 c = strtoul(&oct_buffer[0], NULL, 8);
253 if (parse_base_sequence(src, len, pos,
254 hex_buffer, &hex_len, 16))
256 c = strtoul(&hex_buffer[0], NULL, 16);
264 if (str_check(len, dpos, 1))
266 lvalp->s[dpos++] = c;
269 if (str_check(len, dpos, 1))
271 lvalp->s[dpos++] = '\0';
273 if (str_check(len, pos, 1))
275 if (src[pos++] != delim)
278 if (str_check(len, pos, 1))
280 if (src[pos] != '\0')
285 int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
286 const char *src, char delim)
290 len = strlen(src) + 1;
291 lvalp->s = objstack_alloc(scanner->objstack, len);
293 // TODO: import wide string
294 _BT_LOGE_LINENO(yyget_lineno(scanner),
295 "wide characters are not supported as of this version: "
296 "scanner-addr=%p", scanner);
299 return import_basic_string(scanner, lvalp, len, src, delim);
303 static void init_scope(struct ctf_scanner_scope *scope,
304 struct ctf_scanner_scope *parent)
306 scope->parent = parent;
307 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
311 static void finalize_scope(struct ctf_scanner_scope *scope)
313 g_hash_table_destroy(scope->types);
316 static void push_scope(struct ctf_scanner *scanner)
318 struct ctf_scanner_scope *ns;
320 BT_LOGV("Pushing scope: scanner-addr=%p", scanner);
321 ns = malloc(sizeof(struct ctf_scanner_scope));
322 init_scope(ns, scanner->cs);
326 static void pop_scope(struct ctf_scanner *scanner)
328 struct ctf_scanner_scope *os;
330 BT_LOGV("Popping scope: scanner-addr=%p", scanner);
332 scanner->cs = os->parent;
337 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
341 ret = GPOINTER_TO_INT(g_hash_table_lookup(s->types, id));
342 BT_LOGV("Looked up type: scanner-addr=%p, id=\"%s\", ret=%d",
348 int is_type(struct ctf_scanner *scanner, const char *id)
350 struct ctf_scanner_scope *it;
353 for (it = scanner->cs; it != NULL; it = it->parent) {
354 if (lookup_type(it, id)) {
359 BT_LOGV("Found if ID is type: scanner-addr=%p, id=\"%s\", ret=%d",
364 static void add_type(struct ctf_scanner *scanner, char *id)
366 BT_LOGV("Adding type: scanner-addr=%p, id=\"%s\"",
368 if (lookup_type(scanner->cs, id))
370 g_hash_table_insert(scanner->cs->types, id, id);
373 static struct ctf_node *make_node(struct ctf_scanner *scanner,
376 struct ctf_node *node;
378 node = objstack_alloc(scanner->objstack, sizeof(*node));
380 _BT_LOGE_LINENO(yyget_lineno(scanner->scanner),
381 "failed to allocate one stack entry: "
382 "scanner-addr=%p", scanner);
386 node->lineno = yyget_lineno(scanner->scanner);
387 BT_INIT_LIST_HEAD(&node->tmp_head);
388 bt_list_add(&node->siblings, &node->tmp_head);
392 node->type = NODE_ERROR;
393 BT_LOGE("Trying to create root node: scanner-addr=%p",
397 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
400 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
403 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
406 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
409 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
412 BT_INIT_LIST_HEAD(&node->u.callsite.declaration_list);
414 case NODE_CTF_EXPRESSION:
415 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
416 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
418 case NODE_UNARY_EXPRESSION:
421 BT_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
423 case NODE_TYPEALIAS_TARGET:
424 BT_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
426 case NODE_TYPEALIAS_ALIAS:
427 BT_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
431 case NODE_TYPE_SPECIFIER:
433 case NODE_TYPE_SPECIFIER_LIST:
434 BT_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
438 case NODE_TYPE_DECLARATOR:
439 BT_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
441 case NODE_FLOATING_POINT:
442 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
445 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
448 BT_INIT_LIST_HEAD(&node->u.string.expressions);
450 case NODE_ENUMERATOR:
451 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
454 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
456 case NODE_STRUCT_OR_VARIANT_DECLARATION:
457 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
460 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
463 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
464 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
468 node->type = NODE_ERROR;
469 BT_LOGE("Unknown node type: scanner-addr=%p, node-type=%d",
477 static int reparent_ctf_expression(struct ctf_node *node,
478 struct ctf_node *parent)
480 switch (parent->type) {
482 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
485 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
488 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
491 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
494 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
497 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
499 case NODE_FLOATING_POINT:
500 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
503 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
506 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
510 case NODE_CTF_EXPRESSION:
512 case NODE_TYPEALIAS_TARGET:
513 case NODE_TYPEALIAS_ALIAS:
515 case NODE_TYPE_SPECIFIER:
516 case NODE_TYPE_SPECIFIER_LIST:
518 case NODE_TYPE_DECLARATOR:
519 case NODE_ENUMERATOR:
521 case NODE_STRUCT_OR_VARIANT_DECLARATION:
524 case NODE_UNARY_EXPRESSION:
529 BT_LOGE("Unknown node type: node-type=%d", parent->type);
535 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
537 switch (parent->type) {
539 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
542 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
545 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
548 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
551 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
554 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
557 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
560 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
563 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
566 case NODE_FLOATING_POINT:
569 case NODE_CTF_EXPRESSION:
571 case NODE_TYPEALIAS_TARGET:
572 case NODE_TYPEALIAS_ALIAS:
574 case NODE_TYPE_SPECIFIER:
575 case NODE_TYPE_SPECIFIER_LIST:
577 case NODE_TYPE_DECLARATOR:
578 case NODE_ENUMERATOR:
580 case NODE_STRUCT_OR_VARIANT_DECLARATION:
581 case NODE_UNARY_EXPRESSION:
586 BT_LOGE("Unknown node type: node-type=%d", parent->type);
592 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
594 switch (parent->type) {
596 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
599 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
602 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
605 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
608 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
611 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
614 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
617 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
620 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
623 case NODE_FLOATING_POINT:
626 case NODE_CTF_EXPRESSION:
628 case NODE_TYPEALIAS_TARGET:
629 case NODE_TYPEALIAS_ALIAS:
631 case NODE_TYPE_SPECIFIER:
632 case NODE_TYPE_SPECIFIER_LIST:
634 case NODE_TYPE_DECLARATOR:
635 case NODE_ENUMERATOR:
637 case NODE_STRUCT_OR_VARIANT_DECLARATION:
638 case NODE_UNARY_EXPRESSION:
643 BT_LOGE("Unknown node type: node-type=%d", parent->type);
649 static int reparent_type_specifier(struct ctf_node *node,
650 struct ctf_node *parent)
652 switch (parent->type) {
653 case NODE_TYPE_SPECIFIER_LIST:
654 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
657 case NODE_TYPE_SPECIFIER:
667 case NODE_TYPEALIAS_TARGET:
668 case NODE_TYPEALIAS_ALIAS:
669 case NODE_TYPE_DECLARATOR:
671 case NODE_STRUCT_OR_VARIANT_DECLARATION:
673 case NODE_FLOATING_POINT:
676 case NODE_CTF_EXPRESSION:
678 case NODE_ENUMERATOR:
679 case NODE_UNARY_EXPRESSION:
684 BT_LOGE("Unknown node type: node-type=%d", parent->type);
690 static int reparent_type_specifier_list(struct ctf_node *node,
691 struct ctf_node *parent)
693 switch (parent->type) {
695 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
698 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
701 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
704 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
707 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
710 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
713 bt_list_add_tail(&node->siblings, &parent->u.callsite.declaration_list);
716 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
719 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
722 parent->u._typedef.type_specifier_list = node;
724 case NODE_TYPEALIAS_TARGET:
725 parent->u.typealias_target.type_specifier_list = node;
727 case NODE_TYPEALIAS_ALIAS:
728 parent->u.typealias_alias.type_specifier_list = node;
731 parent->u._enum.container_type = node;
733 case NODE_STRUCT_OR_VARIANT_DECLARATION:
734 parent->u.struct_or_variant_declaration.type_specifier_list = node;
736 case NODE_TYPE_DECLARATOR:
737 case NODE_TYPE_SPECIFIER:
739 case NODE_FLOATING_POINT:
742 case NODE_CTF_EXPRESSION:
744 case NODE_ENUMERATOR:
745 case NODE_UNARY_EXPRESSION:
750 BT_LOGE("Unknown node type: node-type=%d", parent->type);
756 static int reparent_type_declarator(struct ctf_node *node,
757 struct ctf_node *parent)
759 switch (parent->type) {
760 case NODE_TYPE_DECLARATOR:
761 parent->u.type_declarator.type = TYPEDEC_NESTED;
762 parent->u.type_declarator.u.nested.type_declarator = node;
764 case NODE_STRUCT_OR_VARIANT_DECLARATION:
765 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
768 _bt_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
770 case NODE_TYPEALIAS_TARGET:
771 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
773 case NODE_TYPEALIAS_ALIAS:
774 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
788 case NODE_FLOATING_POINT:
791 case NODE_CTF_EXPRESSION:
792 case NODE_TYPE_SPECIFIER:
793 case NODE_TYPE_SPECIFIER_LIST:
795 case NODE_ENUMERATOR:
796 case NODE_UNARY_EXPRESSION:
801 BT_LOGE("Unknown node type: node-type=%d", parent->type);
810 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
811 * create the link declared by the input, -ENOENT if node or parent is NULL,
812 * -EINVAL if there is an internal structure problem.
814 static int set_parent_node(struct ctf_node *node,
815 struct ctf_node *parent)
817 if (!node || !parent)
820 /* Note: Linking to parent will be done only by an external visitor */
822 switch (node->type) {
824 BT_LOGE_STR("Trying to reparent root node.");
828 if (parent->type == NODE_ROOT) {
829 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
835 if (parent->type == NODE_ROOT) {
836 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
842 if (parent->type == NODE_ROOT) {
843 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
849 if (parent->type == NODE_ROOT) {
850 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
856 if (parent->type == NODE_ROOT) {
857 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
863 if (parent->type == NODE_ROOT) {
864 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.callsite);
870 case NODE_CTF_EXPRESSION:
871 return reparent_ctf_expression(node, parent);
872 case NODE_UNARY_EXPRESSION:
873 if (parent->type == NODE_TYPE_DECLARATOR)
874 parent->u.type_declarator.bitfield_len = node;
880 return reparent_typedef(node, parent);
881 case NODE_TYPEALIAS_TARGET:
882 if (parent->type == NODE_TYPEALIAS)
883 parent->u.typealias.target = node;
886 case NODE_TYPEALIAS_ALIAS:
887 if (parent->type == NODE_TYPEALIAS)
888 parent->u.typealias.alias = node;
892 return reparent_typealias(node, parent);
895 if (parent->type == NODE_TYPE_DECLARATOR) {
896 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
900 case NODE_TYPE_DECLARATOR:
901 return reparent_type_declarator(node, parent);
903 case NODE_TYPE_SPECIFIER_LIST:
904 return reparent_type_specifier_list(node, parent);
906 case NODE_TYPE_SPECIFIER:
907 return reparent_type_specifier(node, parent);
909 case NODE_FLOATING_POINT:
915 return -EINVAL; /* Dealt with internally within grammar */
917 case NODE_ENUMERATOR:
918 if (parent->type == NODE_ENUM) {
919 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
924 case NODE_STRUCT_OR_VARIANT_DECLARATION:
925 switch (parent->type) {
927 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
930 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
939 BT_LOGE("Unknown node type: node-type=%d", parent->type);
946 void yyerror(struct ctf_scanner *scanner, yyscan_t yyscanner, const char *str)
948 _BT_LOGE_LINENO(yyget_lineno(scanner->scanner),
949 "%s: token=\"%s\"", str, yyget_text(scanner->scanner));
958 #define reparent_error(scanner, str) \
960 yyerror(scanner, scanner->scanner, YY_("reparent_error: " str)); \
964 static struct ctf_ast *ctf_ast_alloc(struct ctf_scanner *scanner)
968 ast = objstack_alloc(scanner->objstack, sizeof(*ast));
971 ast->root.type = NODE_ROOT;
972 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
973 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
974 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
975 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
976 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
977 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
978 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
979 BT_INIT_LIST_HEAD(&ast->root.u.root.callsite);
983 int ctf_scanner_append_ast(struct ctf_scanner *scanner, FILE *input)
985 /* Start processing new stream */
986 yyrestart(input, scanner->scanner);
987 return yyparse(scanner, scanner->scanner);
990 struct ctf_scanner *ctf_scanner_alloc(void)
992 struct ctf_scanner *scanner;
995 scanner = malloc(sizeof(*scanner));
998 memset(scanner, 0, sizeof(*scanner));
999 ret = yylex_init_extra(scanner, &scanner->scanner);
1001 BT_LOGE("yylex_init_extra() failed: ret=%d", ret);
1002 goto cleanup_scanner;
1004 scanner->objstack = objstack_create();
1005 if (!scanner->objstack)
1007 scanner->ast = ctf_ast_alloc(scanner);
1009 goto cleanup_objstack;
1010 init_scope(&scanner->root_scope, NULL);
1011 scanner->cs = &scanner->root_scope;
1016 objstack_destroy(scanner->objstack);
1018 ret = yylex_destroy(scanner->scanner);
1020 BT_LOGE("yylex_destroy() failed: scanner-addr=%p, ret=%d",
1027 void ctf_scanner_free(struct ctf_scanner *scanner)
1033 finalize_scope(&scanner->root_scope);
1034 objstack_destroy(scanner->objstack);
1035 ret = yylex_destroy(scanner->scanner);
1037 BT_LOGE("yylex_destroy() failed: scanner-addr=%p, ret=%d",
1047 %parse-param {struct ctf_scanner *scanner}
1048 %parse-param {yyscan_t yyscanner}
1049 %lex-param {yyscan_t yyscanner}
1051 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
1052 * vs struct { int :value; } (unnamed bit-field). The default is to
1053 * shift, so whenever we encounter an enumeration, we are doing the
1054 * proper thing (shift). It is illegal to declare an enumeration
1055 * "bit-field", so it is OK if this situation ends up in a parsing
1060 %token CTF_INTEGER_LITERAL CTF_STRING_LITERAL CTF_CHARACTER_LITERAL CTF_LSBRAC CTF_RSBRAC CTF_LPAREN CTF_RPAREN CTF_LBRAC CTF_RBRAC CTF_RARROW CTF_STAR CTF_PLUS CTF_MINUS CTF_LT CTF_GT CTF_TYPEASSIGN CTF_COLON CTF_SEMICOLON CTF_DOTDOTDOT CTF_DOT CTF_EQUAL CTF_COMMA CTF_CONST CTF_CHAR CTF_DOUBLE CTF_ENUM CTF_ENV CTF_EVENT CTF_FLOATING_POINT CTF_FLOAT CTF_INTEGER CTF_INT CTF_LONG CTF_SHORT CTF_SIGNED CTF_STREAM CTF_STRING CTF_STRUCT CTF_TRACE CTF_CALLSITE CTF_CLOCK CTF_TYPEALIAS CTF_TYPEDEF CTF_UNSIGNED CTF_VARIANT CTF_VOID CTF_BOOL CTF_COMPLEX CTF_IMAGINARY CTF_TOK_ALIGN
1061 %token <s> IDENTIFIER ID_TYPE
1066 unsigned long long ull;
1072 %type <s> CTF_STRING_LITERAL CTF_CHARACTER_LITERAL
1076 %type <ull> CTF_INTEGER_LITERAL
1077 %type <n> postfix_expression unary_expression unary_expression_or_range
1079 %type <n> declaration
1080 %type <n> event_declaration
1081 %type <n> stream_declaration
1082 %type <n> env_declaration
1083 %type <n> trace_declaration
1084 %type <n> clock_declaration
1085 %type <n> callsite_declaration
1086 %type <n> integer_declaration_specifiers
1087 %type <n> declaration_specifiers
1088 %type <n> alias_declaration_specifiers
1090 %type <n> type_declarator_list
1091 %type <n> integer_type_specifier
1092 %type <n> type_specifier
1093 %type <n> struct_type_specifier
1094 %type <n> variant_type_specifier
1095 %type <n> enum_type_specifier
1096 %type <n> struct_or_variant_declaration_list
1097 %type <n> struct_or_variant_declaration
1098 %type <n> struct_or_variant_declarator_list
1099 %type <n> struct_or_variant_declarator
1100 %type <n> enumerator_list
1101 %type <n> enumerator
1102 %type <n> abstract_declarator_list
1103 %type <n> abstract_declarator
1104 %type <n> direct_abstract_declarator
1105 %type <n> alias_abstract_declarator_list
1106 %type <n> alias_abstract_declarator
1107 %type <n> direct_alias_abstract_declarator
1108 %type <n> declarator
1109 %type <n> direct_declarator
1110 %type <n> type_declarator
1111 %type <n> direct_type_declarator
1113 %type <n> ctf_assignment_expression_list
1114 %type <n> ctf_assignment_expression
1121 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
1122 reparent_error(scanner, "error reparenting to root");
1126 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
1127 reparent_error(scanner, "error reparenting to root");
1156 | CTF_FLOATING_POINT
1189 /* 2: Phrase structure grammar */
1194 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1195 $$->u.unary_expression.type = UNARY_STRING;
1196 $$->u.unary_expression.u.string = yylval.s;
1200 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1201 $$->u.unary_expression.type = UNARY_STRING;
1202 $$->u.unary_expression.u.string = yylval.s;
1206 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1207 $$->u.unary_expression.type = UNARY_STRING;
1208 $$->u.unary_expression.u.string = yylval.s;
1210 | CTF_INTEGER_LITERAL
1212 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1213 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1214 $$->u.unary_expression.u.unsigned_constant = $1;
1216 | CTF_STRING_LITERAL
1218 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1219 $$->u.unary_expression.type = UNARY_STRING;
1220 $$->u.unary_expression.u.string = $1;
1222 | CTF_CHARACTER_LITERAL
1224 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1225 $$->u.unary_expression.type = UNARY_STRING;
1226 $$->u.unary_expression.u.string = $1;
1228 | CTF_LPAREN unary_expression CTF_RPAREN
1232 | postfix_expression CTF_LSBRAC unary_expression CTF_RSBRAC
1234 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1235 $$->u.unary_expression.type = UNARY_SBRAC;
1236 $$->u.unary_expression.u.sbrac_exp = $3;
1237 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1238 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1240 | postfix_expression CTF_DOT IDENTIFIER
1242 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1243 $$->u.unary_expression.type = UNARY_STRING;
1244 $$->u.unary_expression.u.string = yylval.s;
1245 $$->u.unary_expression.link = UNARY_DOTLINK;
1246 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1247 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1249 | postfix_expression CTF_DOT ID_TYPE
1251 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1252 $$->u.unary_expression.type = UNARY_STRING;
1253 $$->u.unary_expression.u.string = yylval.s;
1254 $$->u.unary_expression.link = UNARY_DOTLINK;
1255 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1256 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1258 | postfix_expression CTF_DOT keywords
1260 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1261 $$->u.unary_expression.type = UNARY_STRING;
1262 $$->u.unary_expression.u.string = yylval.s;
1263 $$->u.unary_expression.link = UNARY_DOTLINK;
1264 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1265 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1267 | postfix_expression CTF_RARROW IDENTIFIER
1269 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1270 $$->u.unary_expression.type = UNARY_STRING;
1271 $$->u.unary_expression.u.string = yylval.s;
1272 $$->u.unary_expression.link = UNARY_ARROWLINK;
1273 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1274 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1276 | postfix_expression CTF_RARROW ID_TYPE
1278 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1279 $$->u.unary_expression.type = UNARY_STRING;
1280 $$->u.unary_expression.u.string = yylval.s;
1281 $$->u.unary_expression.link = UNARY_ARROWLINK;
1282 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1283 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1290 | CTF_PLUS postfix_expression
1293 if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
1294 && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
1295 reparent_error(scanner, "expecting numeric constant");
1298 | CTF_MINUS postfix_expression
1301 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1302 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1303 $$->u.unary_expression.u.signed_constant =
1304 -($$->u.unary_expression.u.unsigned_constant);
1305 } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1306 $$->u.unary_expression.u.signed_constant =
1307 -($$->u.unary_expression.u.signed_constant);
1309 reparent_error(scanner, "expecting numeric constant");
1314 unary_expression_or_range:
1315 unary_expression CTF_DOTDOTDOT unary_expression
1318 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1319 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1325 /* 2.2: Declarations */
1328 declaration_specifiers CTF_SEMICOLON
1332 | stream_declaration
1340 | callsite_declaration
1342 | declaration_specifiers CTF_TYPEDEF declaration_specifiers type_declarator_list CTF_SEMICOLON
1344 struct ctf_node *list;
1346 $$ = make_node(scanner, NODE_TYPEDEF);
1347 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1348 $$->u._typedef.type_specifier_list = list;
1349 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1350 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1351 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1353 | CTF_TYPEDEF declaration_specifiers type_declarator_list CTF_SEMICOLON
1355 struct ctf_node *list;
1357 $$ = make_node(scanner, NODE_TYPEDEF);
1358 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1359 $$->u._typedef.type_specifier_list = list;
1360 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1361 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1363 | declaration_specifiers CTF_TYPEDEF type_declarator_list CTF_SEMICOLON
1365 struct ctf_node *list;
1367 $$ = make_node(scanner, NODE_TYPEDEF);
1368 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1369 $$->u._typedef.type_specifier_list = list;
1370 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1371 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1373 | CTF_TYPEALIAS declaration_specifiers abstract_declarator_list CTF_TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list CTF_SEMICOLON
1375 struct ctf_node *list;
1377 $$ = make_node(scanner, NODE_TYPEALIAS);
1378 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1379 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1381 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1382 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1383 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1384 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1386 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1387 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1388 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1389 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1394 event_declaration_begin event_declaration_end
1396 $$ = make_node(scanner, NODE_EVENT);
1398 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1400 $$ = make_node(scanner, NODE_EVENT);
1401 if (set_parent_node($2, $$))
1402 reparent_error(scanner, "event_declaration");
1406 event_declaration_begin:
1408 { push_scope(scanner); }
1411 event_declaration_end:
1412 CTF_RBRAC CTF_SEMICOLON
1413 { pop_scope(scanner); }
1418 stream_declaration_begin stream_declaration_end
1420 $$ = make_node(scanner, NODE_STREAM);
1422 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1424 $$ = make_node(scanner, NODE_STREAM);
1425 if (set_parent_node($2, $$))
1426 reparent_error(scanner, "stream_declaration");
1430 stream_declaration_begin:
1431 CTF_STREAM CTF_LBRAC
1432 { push_scope(scanner); }
1435 stream_declaration_end:
1436 CTF_RBRAC CTF_SEMICOLON
1437 { pop_scope(scanner); }
1441 env_declaration_begin env_declaration_end
1443 $$ = make_node(scanner, NODE_ENV);
1445 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1447 $$ = make_node(scanner, NODE_ENV);
1448 if (set_parent_node($2, $$))
1449 reparent_error(scanner, "env declaration");
1453 env_declaration_begin:
1455 { push_scope(scanner); }
1458 env_declaration_end:
1459 CTF_RBRAC CTF_SEMICOLON
1460 { pop_scope(scanner); }
1464 trace_declaration_begin trace_declaration_end
1466 $$ = make_node(scanner, NODE_TRACE);
1468 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1470 $$ = make_node(scanner, NODE_TRACE);
1471 if (set_parent_node($2, $$))
1472 reparent_error(scanner, "trace_declaration");
1476 trace_declaration_begin:
1478 { push_scope(scanner); }
1481 trace_declaration_end:
1482 CTF_RBRAC CTF_SEMICOLON
1483 { pop_scope(scanner); }
1487 CTF_CLOCK clock_declaration_begin clock_declaration_end
1489 $$ = make_node(scanner, NODE_CLOCK);
1491 | CTF_CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1493 $$ = make_node(scanner, NODE_CLOCK);
1494 if (set_parent_node($3, $$))
1495 reparent_error(scanner, "trace_declaration");
1499 clock_declaration_begin:
1501 { push_scope(scanner); }
1504 clock_declaration_end:
1505 CTF_RBRAC CTF_SEMICOLON
1506 { pop_scope(scanner); }
1509 callsite_declaration:
1510 CTF_CALLSITE callsite_declaration_begin callsite_declaration_end
1512 $$ = make_node(scanner, NODE_CALLSITE);
1514 | CTF_CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1516 $$ = make_node(scanner, NODE_CALLSITE);
1517 if (set_parent_node($3, $$))
1518 reparent_error(scanner, "trace_declaration");
1522 callsite_declaration_begin:
1524 { push_scope(scanner); }
1527 callsite_declaration_end:
1528 CTF_RBRAC CTF_SEMICOLON
1529 { pop_scope(scanner); }
1532 integer_declaration_specifiers:
1535 struct ctf_node *node;
1537 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1538 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1539 node->u.type_specifier.type = TYPESPEC_CONST;
1540 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1542 | integer_type_specifier
1544 struct ctf_node *node;
1546 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1548 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1550 | integer_declaration_specifiers CTF_CONST
1552 struct ctf_node *node;
1555 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1556 node->u.type_specifier.type = TYPESPEC_CONST;
1557 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1559 | integer_declaration_specifiers integer_type_specifier
1562 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1566 declaration_specifiers:
1569 struct ctf_node *node;
1571 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1572 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1573 node->u.type_specifier.type = TYPESPEC_CONST;
1574 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1578 struct ctf_node *node;
1580 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1582 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1584 | declaration_specifiers CTF_CONST
1586 struct ctf_node *node;
1589 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1590 node->u.type_specifier.type = TYPESPEC_CONST;
1591 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1593 | declaration_specifiers type_specifier
1596 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1600 type_declarator_list:
1603 | type_declarator_list CTF_COMMA type_declarator
1606 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1610 integer_type_specifier:
1613 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1614 $$->u.type_specifier.type = TYPESPEC_CHAR;
1618 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1619 $$->u.type_specifier.type = TYPESPEC_SHORT;
1623 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1624 $$->u.type_specifier.type = TYPESPEC_INT;
1628 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1629 $$->u.type_specifier.type = TYPESPEC_LONG;
1633 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1634 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1638 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1639 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1643 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1644 $$->u.type_specifier.type = TYPESPEC_BOOL;
1648 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1649 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1650 $$->u.type_specifier.id_type = yylval.s;
1652 | CTF_INTEGER CTF_LBRAC CTF_RBRAC
1654 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1655 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1656 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1658 | CTF_INTEGER CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1660 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1661 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1662 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1663 if (set_parent_node($3, $$->u.type_specifier.node))
1664 reparent_error(scanner, "integer reparent error");
1671 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1672 $$->u.type_specifier.type = TYPESPEC_VOID;
1676 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1677 $$->u.type_specifier.type = TYPESPEC_CHAR;
1681 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1682 $$->u.type_specifier.type = TYPESPEC_SHORT;
1686 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1687 $$->u.type_specifier.type = TYPESPEC_INT;
1691 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1692 $$->u.type_specifier.type = TYPESPEC_LONG;
1696 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1697 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1701 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1702 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1706 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1707 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1711 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1712 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1716 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1717 $$->u.type_specifier.type = TYPESPEC_BOOL;
1721 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1722 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1726 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1727 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1731 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1732 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1733 $$->u.type_specifier.id_type = yylval.s;
1735 | CTF_FLOATING_POINT CTF_LBRAC CTF_RBRAC
1737 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1738 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1739 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1741 | CTF_FLOATING_POINT CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1743 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1744 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1745 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1746 if (set_parent_node($3, $$->u.type_specifier.node))
1747 reparent_error(scanner, "floating point reparent error");
1749 | CTF_INTEGER CTF_LBRAC CTF_RBRAC
1751 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1752 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1753 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1755 | CTF_INTEGER CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1757 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1758 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1759 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1760 if (set_parent_node($3, $$->u.type_specifier.node))
1761 reparent_error(scanner, "integer reparent error");
1765 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1766 $$->u.type_specifier.type = TYPESPEC_STRING;
1767 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1769 | CTF_STRING CTF_LBRAC CTF_RBRAC
1771 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1772 $$->u.type_specifier.type = TYPESPEC_STRING;
1773 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1775 | CTF_STRING CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1777 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1778 $$->u.type_specifier.type = TYPESPEC_STRING;
1779 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1780 if (set_parent_node($3, $$->u.type_specifier.node))
1781 reparent_error(scanner, "string reparent error");
1783 | CTF_ENUM enum_type_specifier
1785 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1786 $$->u.type_specifier.type = TYPESPEC_ENUM;
1787 $$->u.type_specifier.node = $2;
1789 | CTF_VARIANT variant_type_specifier
1791 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1792 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1793 $$->u.type_specifier.node = $2;
1795 | CTF_STRUCT struct_type_specifier
1797 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1798 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1799 $$->u.type_specifier.node = $2;
1803 struct_type_specifier:
1804 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1806 $$ = make_node(scanner, NODE_STRUCT);
1807 $$->u._struct.has_body = 1;
1808 if ($2 && set_parent_node($2, $$))
1809 reparent_error(scanner, "struct reparent error");
1811 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1813 $$ = make_node(scanner, NODE_STRUCT);
1814 $$->u._struct.has_body = 1;
1815 $$->u._struct.name = $1;
1816 if ($3 && set_parent_node($3, $$))
1817 reparent_error(scanner, "struct reparent error");
1819 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1821 $$ = make_node(scanner, NODE_STRUCT);
1822 $$->u._struct.has_body = 1;
1823 $$->u._struct.name = $1;
1824 if ($3 && set_parent_node($3, $$))
1825 reparent_error(scanner, "struct reparent error");
1829 $$ = make_node(scanner, NODE_STRUCT);
1830 $$->u._struct.has_body = 0;
1831 $$->u._struct.name = $1;
1835 $$ = make_node(scanner, NODE_STRUCT);
1836 $$->u._struct.has_body = 0;
1837 $$->u._struct.name = $1;
1839 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end CTF_TOK_ALIGN CTF_LPAREN unary_expression CTF_RPAREN
1841 $$ = make_node(scanner, NODE_STRUCT);
1842 $$->u._struct.has_body = 1;
1843 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1844 if ($2 && set_parent_node($2, $$))
1845 reparent_error(scanner, "struct reparent error");
1847 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end CTF_TOK_ALIGN CTF_LPAREN unary_expression CTF_RPAREN
1849 $$ = make_node(scanner, NODE_STRUCT);
1850 $$->u._struct.has_body = 1;
1851 $$->u._struct.name = $1;
1852 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1853 if ($3 && set_parent_node($3, $$))
1854 reparent_error(scanner, "struct reparent error");
1856 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end CTF_TOK_ALIGN CTF_LPAREN unary_expression CTF_RPAREN
1858 $$ = make_node(scanner, NODE_STRUCT);
1859 $$->u._struct.has_body = 1;
1860 $$->u._struct.name = $1;
1861 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1862 if ($3 && set_parent_node($3, $$))
1863 reparent_error(scanner, "struct reparent error");
1867 struct_declaration_begin:
1869 { push_scope(scanner); }
1872 struct_declaration_end:
1874 { pop_scope(scanner); }
1877 variant_type_specifier:
1878 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1880 $$ = make_node(scanner, NODE_VARIANT);
1881 $$->u.variant.has_body = 1;
1882 if ($2 && set_parent_node($2, $$))
1883 reparent_error(scanner, "variant reparent error");
1885 | CTF_LT IDENTIFIER CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1887 $$ = make_node(scanner, NODE_VARIANT);
1888 $$->u.variant.has_body = 1;
1889 $$->u.variant.choice = $2;
1890 if ($5 && set_parent_node($5, $$))
1891 reparent_error(scanner, "variant reparent error");
1893 | CTF_LT ID_TYPE CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1895 $$ = make_node(scanner, NODE_VARIANT);
1896 $$->u.variant.has_body = 1;
1897 $$->u.variant.choice = $2;
1898 if ($5 && set_parent_node($5, $$))
1899 reparent_error(scanner, "variant reparent error");
1901 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1903 $$ = make_node(scanner, NODE_VARIANT);
1904 $$->u.variant.has_body = 1;
1905 $$->u.variant.name = $1;
1906 if ($3 && set_parent_node($3, $$))
1907 reparent_error(scanner, "variant reparent error");
1909 | IDENTIFIER CTF_LT IDENTIFIER CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1911 $$ = make_node(scanner, NODE_VARIANT);
1912 $$->u.variant.has_body = 1;
1913 $$->u.variant.name = $1;
1914 $$->u.variant.choice = $3;
1915 if ($6 && set_parent_node($6, $$))
1916 reparent_error(scanner, "variant reparent error");
1918 | IDENTIFIER CTF_LT IDENTIFIER CTF_GT
1920 $$ = make_node(scanner, NODE_VARIANT);
1921 $$->u.variant.has_body = 0;
1922 $$->u.variant.name = $1;
1923 $$->u.variant.choice = $3;
1925 | IDENTIFIER CTF_LT ID_TYPE CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1927 $$ = make_node(scanner, NODE_VARIANT);
1928 $$->u.variant.has_body = 1;
1929 $$->u.variant.name = $1;
1930 $$->u.variant.choice = $3;
1931 if ($6 && set_parent_node($6, $$))
1932 reparent_error(scanner, "variant reparent error");
1934 | IDENTIFIER CTF_LT ID_TYPE CTF_GT
1936 $$ = make_node(scanner, NODE_VARIANT);
1937 $$->u.variant.has_body = 0;
1938 $$->u.variant.name = $1;
1939 $$->u.variant.choice = $3;
1941 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1943 $$ = make_node(scanner, NODE_VARIANT);
1944 $$->u.variant.has_body = 1;
1945 $$->u.variant.name = $1;
1946 if ($3 && set_parent_node($3, $$))
1947 reparent_error(scanner, "variant reparent error");
1949 | ID_TYPE CTF_LT IDENTIFIER CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1951 $$ = make_node(scanner, NODE_VARIANT);
1952 $$->u.variant.has_body = 1;
1953 $$->u.variant.name = $1;
1954 $$->u.variant.choice = $3;
1955 if ($6 && set_parent_node($6, $$))
1956 reparent_error(scanner, "variant reparent error");
1958 | ID_TYPE CTF_LT IDENTIFIER CTF_GT
1960 $$ = make_node(scanner, NODE_VARIANT);
1961 $$->u.variant.has_body = 0;
1962 $$->u.variant.name = $1;
1963 $$->u.variant.choice = $3;
1965 | ID_TYPE CTF_LT ID_TYPE CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1967 $$ = make_node(scanner, NODE_VARIANT);
1968 $$->u.variant.has_body = 1;
1969 $$->u.variant.name = $1;
1970 $$->u.variant.choice = $3;
1971 if ($6 && set_parent_node($6, $$))
1972 reparent_error(scanner, "variant reparent error");
1974 | ID_TYPE CTF_LT ID_TYPE CTF_GT
1976 $$ = make_node(scanner, NODE_VARIANT);
1977 $$->u.variant.has_body = 0;
1978 $$->u.variant.name = $1;
1979 $$->u.variant.choice = $3;
1983 variant_declaration_begin:
1985 { push_scope(scanner); }
1988 variant_declaration_end:
1990 { pop_scope(scanner); }
1993 enum_type_specifier:
1994 CTF_LBRAC enumerator_list CTF_RBRAC
1996 $$ = make_node(scanner, NODE_ENUM);
1997 $$->u._enum.has_body = 1;
1998 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2000 | CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_RBRAC
2002 $$ = make_node(scanner, NODE_ENUM);
2003 $$->u._enum.has_body = 1;
2004 ($$)->u._enum.container_type = $2;
2005 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2007 | IDENTIFIER CTF_LBRAC enumerator_list CTF_RBRAC
2009 $$ = make_node(scanner, NODE_ENUM);
2010 $$->u._enum.has_body = 1;
2011 $$->u._enum.enum_id = $1;
2012 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2014 | IDENTIFIER CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_RBRAC
2016 $$ = make_node(scanner, NODE_ENUM);
2017 $$->u._enum.has_body = 1;
2018 $$->u._enum.enum_id = $1;
2019 ($$)->u._enum.container_type = $3;
2020 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2022 | ID_TYPE CTF_LBRAC enumerator_list CTF_RBRAC
2024 $$ = make_node(scanner, NODE_ENUM);
2025 $$->u._enum.has_body = 1;
2026 $$->u._enum.enum_id = $1;
2027 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2029 | ID_TYPE CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_RBRAC
2031 $$ = make_node(scanner, NODE_ENUM);
2032 $$->u._enum.has_body = 1;
2033 $$->u._enum.enum_id = $1;
2034 ($$)->u._enum.container_type = $3;
2035 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2037 | CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2039 $$ = make_node(scanner, NODE_ENUM);
2040 $$->u._enum.has_body = 1;
2041 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2043 | CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2045 $$ = make_node(scanner, NODE_ENUM);
2046 $$->u._enum.has_body = 1;
2047 ($$)->u._enum.container_type = $2;
2048 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2050 | IDENTIFIER CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2052 $$ = make_node(scanner, NODE_ENUM);
2053 $$->u._enum.has_body = 1;
2054 $$->u._enum.enum_id = $1;
2055 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2057 | IDENTIFIER CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2059 $$ = make_node(scanner, NODE_ENUM);
2060 $$->u._enum.has_body = 1;
2061 $$->u._enum.enum_id = $1;
2062 ($$)->u._enum.container_type = $3;
2063 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2067 $$ = make_node(scanner, NODE_ENUM);
2068 $$->u._enum.has_body = 0;
2069 $$->u._enum.enum_id = $1;
2071 | ID_TYPE CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2073 $$ = make_node(scanner, NODE_ENUM);
2074 $$->u._enum.has_body = 1;
2075 $$->u._enum.enum_id = $1;
2076 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2078 | ID_TYPE CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2080 $$ = make_node(scanner, NODE_ENUM);
2081 $$->u._enum.has_body = 1;
2082 $$->u._enum.enum_id = $1;
2083 ($$)->u._enum.container_type = $3;
2084 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2088 $$ = make_node(scanner, NODE_ENUM);
2089 $$->u._enum.has_body = 0;
2090 $$->u._enum.enum_id = $1;
2094 struct_or_variant_declaration_list:
2097 | struct_or_variant_declaration_list struct_or_variant_declaration
2101 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2104 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
2109 struct_or_variant_declaration:
2110 declaration_specifiers struct_or_variant_declarator_list CTF_SEMICOLON
2112 struct ctf_node *list;
2114 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2115 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2116 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
2117 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2118 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
2120 | declaration_specifiers CTF_TYPEDEF declaration_specifiers type_declarator_list CTF_SEMICOLON
2122 struct ctf_node *list;
2124 $$ = make_node(scanner, NODE_TYPEDEF);
2125 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2126 $$->u._typedef.type_specifier_list = list;
2127 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2128 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2129 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2131 | CTF_TYPEDEF declaration_specifiers type_declarator_list CTF_SEMICOLON
2133 struct ctf_node *list;
2135 $$ = make_node(scanner, NODE_TYPEDEF);
2136 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2137 $$->u._typedef.type_specifier_list = list;
2138 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2139 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2141 | declaration_specifiers CTF_TYPEDEF type_declarator_list CTF_SEMICOLON
2143 struct ctf_node *list;
2145 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2146 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2147 $$ = make_node(scanner, NODE_TYPEDEF);
2148 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2149 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2151 | CTF_TYPEALIAS declaration_specifiers abstract_declarator_list CTF_TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list CTF_SEMICOLON
2153 struct ctf_node *list;
2155 $$ = make_node(scanner, NODE_TYPEALIAS);
2156 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2157 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2159 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2160 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2161 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2162 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2164 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2165 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2166 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2167 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2171 alias_declaration_specifiers:
2174 struct ctf_node *node;
2176 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2177 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2178 node->u.type_specifier.type = TYPESPEC_CONST;
2179 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2183 struct ctf_node *node;
2185 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2187 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2191 struct ctf_node *node;
2193 add_type(scanner, $1);
2194 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2195 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2196 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2197 node->u.type_specifier.id_type = yylval.s;
2198 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2200 | alias_declaration_specifiers CTF_CONST
2202 struct ctf_node *node;
2205 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2206 node->u.type_specifier.type = TYPESPEC_CONST;
2207 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2209 | alias_declaration_specifiers type_specifier
2212 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2214 | alias_declaration_specifiers IDENTIFIER
2216 struct ctf_node *node;
2218 add_type(scanner, $2);
2220 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2221 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2222 node->u.type_specifier.id_type = yylval.s;
2223 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2227 struct_or_variant_declarator_list:
2228 struct_or_variant_declarator
2230 | struct_or_variant_declarator_list CTF_COMMA struct_or_variant_declarator
2233 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2237 struct_or_variant_declarator:
2240 | CTF_COLON unary_expression
2242 | declarator CTF_COLON unary_expression
2245 if (set_parent_node($3, $1))
2246 reparent_error(scanner, "struct_or_variant_declarator");
2253 | enumerator_list CTF_COMMA enumerator
2256 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2263 $$ = make_node(scanner, NODE_ENUMERATOR);
2264 $$->u.enumerator.id = $1;
2268 $$ = make_node(scanner, NODE_ENUMERATOR);
2269 $$->u.enumerator.id = $1;
2273 $$ = make_node(scanner, NODE_ENUMERATOR);
2274 $$->u.enumerator.id = $1;
2276 | CTF_STRING_LITERAL
2278 $$ = make_node(scanner, NODE_ENUMERATOR);
2279 $$->u.enumerator.id = $1;
2281 | IDENTIFIER CTF_EQUAL unary_expression_or_range
2283 $$ = make_node(scanner, NODE_ENUMERATOR);
2284 $$->u.enumerator.id = $1;
2285 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2287 | ID_TYPE CTF_EQUAL unary_expression_or_range
2289 $$ = make_node(scanner, NODE_ENUMERATOR);
2290 $$->u.enumerator.id = $1;
2291 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2293 | keywords CTF_EQUAL unary_expression_or_range
2295 $$ = make_node(scanner, NODE_ENUMERATOR);
2296 $$->u.enumerator.id = $1;
2297 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2299 | CTF_STRING_LITERAL CTF_EQUAL unary_expression_or_range
2301 $$ = make_node(scanner, NODE_ENUMERATOR);
2302 $$->u.enumerator.id = $1;
2303 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2307 abstract_declarator_list:
2310 | abstract_declarator_list CTF_COMMA abstract_declarator
2313 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2317 abstract_declarator:
2318 direct_abstract_declarator
2320 | pointer direct_abstract_declarator
2323 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2327 direct_abstract_declarator:
2330 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2331 $$->u.type_declarator.type = TYPEDEC_ID;
2336 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2337 $$->u.type_declarator.type = TYPEDEC_ID;
2338 $$->u.type_declarator.u.id = $1;
2340 | CTF_LPAREN abstract_declarator CTF_RPAREN
2342 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2343 $$->u.type_declarator.type = TYPEDEC_NESTED;
2344 $$->u.type_declarator.u.nested.type_declarator = $2;
2346 | direct_abstract_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2348 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2349 $$->u.type_declarator.type = TYPEDEC_NESTED;
2350 $$->u.type_declarator.u.nested.type_declarator = $1;
2351 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2352 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2354 | direct_abstract_declarator CTF_LSBRAC CTF_RSBRAC
2356 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2357 $$->u.type_declarator.type = TYPEDEC_NESTED;
2358 $$->u.type_declarator.u.nested.type_declarator = $1;
2359 $$->u.type_declarator.u.nested.abstract_array = 1;
2363 alias_abstract_declarator_list:
2364 alias_abstract_declarator
2366 | alias_abstract_declarator_list CTF_COMMA alias_abstract_declarator
2369 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2373 alias_abstract_declarator:
2374 direct_alias_abstract_declarator
2376 | pointer direct_alias_abstract_declarator
2379 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2383 direct_alias_abstract_declarator:
2386 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2387 $$->u.type_declarator.type = TYPEDEC_ID;
2390 | CTF_LPAREN alias_abstract_declarator CTF_RPAREN
2392 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2393 $$->u.type_declarator.type = TYPEDEC_NESTED;
2394 $$->u.type_declarator.u.nested.type_declarator = $2;
2396 | direct_alias_abstract_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2398 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2399 $$->u.type_declarator.type = TYPEDEC_NESTED;
2400 $$->u.type_declarator.u.nested.type_declarator = $1;
2401 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2402 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2404 | direct_alias_abstract_declarator CTF_LSBRAC CTF_RSBRAC
2406 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2407 $$->u.type_declarator.type = TYPEDEC_NESTED;
2408 $$->u.type_declarator.u.nested.type_declarator = $1;
2409 $$->u.type_declarator.u.nested.abstract_array = 1;
2416 | pointer direct_declarator
2419 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2426 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2427 $$->u.type_declarator.type = TYPEDEC_ID;
2428 $$->u.type_declarator.u.id = $1;
2430 | CTF_LPAREN declarator CTF_RPAREN
2432 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2433 $$->u.type_declarator.type = TYPEDEC_NESTED;
2434 $$->u.type_declarator.u.nested.type_declarator = $2;
2436 | direct_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2438 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2439 $$->u.type_declarator.type = TYPEDEC_NESTED;
2440 $$->u.type_declarator.u.nested.type_declarator = $1;
2441 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2442 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2447 direct_type_declarator
2449 | pointer direct_type_declarator
2452 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2456 direct_type_declarator:
2459 add_type(scanner, $1);
2460 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2461 $$->u.type_declarator.type = TYPEDEC_ID;
2462 $$->u.type_declarator.u.id = $1;
2464 | CTF_LPAREN type_declarator CTF_RPAREN
2466 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2467 $$->u.type_declarator.type = TYPEDEC_NESTED;
2468 $$->u.type_declarator.u.nested.type_declarator = $2;
2470 | direct_type_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2472 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2473 $$->u.type_declarator.type = TYPEDEC_NESTED;
2474 $$->u.type_declarator.u.nested.type_declarator = $1;
2475 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2476 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2483 $$ = make_node(scanner, NODE_POINTER);
2487 $$ = make_node(scanner, NODE_POINTER);
2488 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2490 | CTF_STAR type_qualifier_list pointer
2492 $$ = make_node(scanner, NODE_POINTER);
2493 $$->u.pointer.const_qualifier = 1;
2494 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2498 type_qualifier_list:
2499 /* pointer assumes only const type qualifier */
2501 | type_qualifier_list CTF_CONST
2504 /* 2.3: CTF-specific declarations */
2506 ctf_assignment_expression_list:
2507 ctf_assignment_expression CTF_SEMICOLON
2509 | ctf_assignment_expression_list ctf_assignment_expression CTF_SEMICOLON
2512 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2516 ctf_assignment_expression:
2517 unary_expression CTF_EQUAL unary_expression
2520 * Because we have left and right, cannot use
2523 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2524 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2525 if ($1->u.unary_expression.type != UNARY_STRING)
2526 reparent_error(scanner, "ctf_assignment_expression left expects string");
2527 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2529 | unary_expression CTF_TYPEASSIGN declaration_specifiers /* Only allow struct */
2532 * Because we have left and right, cannot use
2535 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2536 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2537 if ($1->u.unary_expression.type != UNARY_STRING)
2538 reparent_error(scanner, "ctf_assignment_expression left expects string");
2539 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2541 | declaration_specifiers CTF_TYPEDEF declaration_specifiers type_declarator_list
2543 struct ctf_node *list;
2545 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2546 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2547 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2548 $$ = make_node(scanner, NODE_TYPEDEF);
2549 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2550 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2552 | CTF_TYPEDEF declaration_specifiers type_declarator_list
2554 struct ctf_node *list;
2556 $$ = make_node(scanner, NODE_TYPEDEF);
2557 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2558 $$->u._typedef.type_specifier_list = list;
2559 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2560 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2562 | declaration_specifiers CTF_TYPEDEF type_declarator_list
2564 struct ctf_node *list;
2566 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2567 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2568 $$ = make_node(scanner, NODE_TYPEDEF);
2569 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2570 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2572 | CTF_TYPEALIAS declaration_specifiers abstract_declarator_list CTF_TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2574 struct ctf_node *list;
2576 $$ = make_node(scanner, NODE_TYPEALIAS);
2577 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2578 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2580 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2581 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2582 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2583 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2585 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2586 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2587 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2588 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);