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 <babeltrace2/list-internal.h>
41 #include <babeltrace2/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->classes = 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->classes);
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->classes, 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->classes, 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.field_class_def.field_class_declarators);
423 case NODE_TYPEALIAS_TARGET:
424 BT_INIT_LIST_HEAD(&node->u.field_class_alias_target.field_class_declarators);
426 case NODE_TYPEALIAS_ALIAS:
427 BT_INIT_LIST_HEAD(&node->u.field_class_alias_name.field_class_declarators);
431 case NODE_TYPE_SPECIFIER:
433 case NODE_TYPE_SPECIFIER_LIST:
434 BT_INIT_LIST_HEAD(&node->u.field_class_specifier_list.head);
438 case NODE_TYPE_DECLARATOR:
439 BT_INIT_LIST_HEAD(&node->u.field_class_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.field_class_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_field_class_alias(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_field_class_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.field_class_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_field_class_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.field_class_def.field_class_specifier_list = node;
724 case NODE_TYPEALIAS_TARGET:
725 parent->u.field_class_alias_target.field_class_specifier_list = node;
727 case NODE_TYPEALIAS_ALIAS:
728 parent->u.field_class_alias_name.field_class_specifier_list = node;
731 parent->u._enum.container_field_class = node;
733 case NODE_STRUCT_OR_VARIANT_DECLARATION:
734 parent->u.struct_or_variant_declaration.field_class_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_field_class_declarator(struct ctf_node *node,
757 struct ctf_node *parent)
759 switch (parent->type) {
760 case NODE_TYPE_DECLARATOR:
761 parent->u.field_class_declarator.type = TYPEDEC_NESTED;
762 parent->u.field_class_declarator.u.nested.field_class_declarator = node;
764 case NODE_STRUCT_OR_VARIANT_DECLARATION:
765 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.field_class_declarators);
768 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_def.field_class_declarators);
770 case NODE_TYPEALIAS_TARGET:
771 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_alias_target.field_class_declarators);
773 case NODE_TYPEALIAS_ALIAS:
774 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_alias_name.field_class_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.field_class_declarator.bitfield_len = node;
880 return reparent_typedef(node, parent);
881 case NODE_TYPEALIAS_TARGET:
882 if (parent->type == NODE_TYPEALIAS)
883 parent->u.field_class_alias.target = node;
887 case NODE_TYPEALIAS_ALIAS:
888 if (parent->type == NODE_TYPEALIAS)
889 parent->u.field_class_alias.alias = node;
894 return reparent_field_class_alias(node, parent);
897 if (parent->type == NODE_TYPE_DECLARATOR) {
898 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_declarator.pointers);
902 case NODE_TYPE_DECLARATOR:
903 return reparent_field_class_declarator(node, parent);
905 case NODE_TYPE_SPECIFIER_LIST:
906 return reparent_field_class_specifier_list(node, parent);
908 case NODE_TYPE_SPECIFIER:
909 return reparent_field_class_specifier(node, parent);
911 case NODE_FLOATING_POINT:
917 return -EINVAL; /* Dealt with internally within grammar */
919 case NODE_ENUMERATOR:
920 if (parent->type == NODE_ENUM) {
921 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
926 case NODE_STRUCT_OR_VARIANT_DECLARATION:
927 switch (parent->type) {
929 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
932 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
941 BT_LOGE("Unknown node type: node-type=%d", parent->type);
948 void yyerror(struct ctf_scanner *scanner, yyscan_t yyscanner, const char *str)
950 _BT_LOGE_LINENO(yyget_lineno(scanner->scanner),
951 "%s: token=\"%s\"", str, yyget_text(scanner->scanner));
960 #define reparent_error(scanner, str) \
962 yyerror(scanner, scanner->scanner, YY_("reparent_error: " str)); \
966 static struct ctf_ast *ctf_ast_alloc(struct ctf_scanner *scanner)
970 ast = objstack_alloc(scanner->objstack, sizeof(*ast));
973 ast->root.type = NODE_ROOT;
974 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
975 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
976 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
977 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
978 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
979 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
980 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
981 BT_INIT_LIST_HEAD(&ast->root.u.root.callsite);
985 int ctf_scanner_append_ast(struct ctf_scanner *scanner, FILE *input)
987 /* Start processing new stream */
988 yyrestart(input, scanner->scanner);
989 return yyparse(scanner, scanner->scanner);
992 struct ctf_scanner *ctf_scanner_alloc(void)
994 struct ctf_scanner *scanner;
997 scanner = malloc(sizeof(*scanner));
1000 memset(scanner, 0, sizeof(*scanner));
1001 ret = yylex_init_extra(scanner, &scanner->scanner);
1003 BT_LOGE("yylex_init_extra() failed: ret=%d", ret);
1004 goto cleanup_scanner;
1006 scanner->objstack = objstack_create();
1007 if (!scanner->objstack)
1009 scanner->ast = ctf_ast_alloc(scanner);
1011 goto cleanup_objstack;
1012 init_scope(&scanner->root_scope, NULL);
1013 scanner->cs = &scanner->root_scope;
1018 objstack_destroy(scanner->objstack);
1020 ret = yylex_destroy(scanner->scanner);
1022 BT_LOGE("yylex_destroy() failed: scanner-addr=%p, ret=%d",
1029 void ctf_scanner_free(struct ctf_scanner *scanner)
1035 finalize_scope(&scanner->root_scope);
1036 objstack_destroy(scanner->objstack);
1037 ret = yylex_destroy(scanner->scanner);
1039 BT_LOGE("yylex_destroy() failed: scanner-addr=%p, ret=%d",
1049 %parse-param {struct ctf_scanner *scanner}
1050 %parse-param {yyscan_t yyscanner}
1051 %lex-param {yyscan_t yyscanner}
1053 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
1054 * vs struct { int :value; } (unnamed bit-field). The default is to
1055 * shift, so whenever we encounter an enumeration, we are doing the
1056 * proper thing (shift). It is illegal to declare an enumeration
1057 * "bit-field", so it is OK if this situation ends up in a parsing
1062 %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
1063 %token <s> IDENTIFIER ID_TYPE
1068 unsigned long long ull;
1074 %type <s> CTF_STRING_LITERAL CTF_CHARACTER_LITERAL
1078 %type <ull> CTF_INTEGER_LITERAL
1079 %type <n> postfix_expression unary_expression unary_expression_or_range
1081 %type <n> declaration
1082 %type <n> event_declaration
1083 %type <n> stream_declaration
1084 %type <n> env_declaration
1085 %type <n> trace_declaration
1086 %type <n> clock_declaration
1087 %type <n> callsite_declaration
1088 %type <n> integer_declaration_specifiers
1089 %type <n> declaration_specifiers
1090 %type <n> alias_declaration_specifiers
1092 %type <n> field_class_declarator_list
1093 %type <n> integer_field_class_specifier
1094 %type <n> field_class_specifier
1095 %type <n> struct_class_specifier
1096 %type <n> variant_field_class_specifier
1097 %type <n> enum_field_class_specifier
1098 %type <n> struct_or_variant_declaration_list
1099 %type <n> struct_or_variant_declaration
1100 %type <n> struct_or_variant_declarator_list
1101 %type <n> struct_or_variant_declarator
1102 %type <n> enumerator_list
1103 %type <n> enumerator
1104 %type <n> abstract_declarator_list
1105 %type <n> abstract_declarator
1106 %type <n> direct_abstract_declarator
1107 %type <n> alias_abstract_declarator_list
1108 %type <n> alias_abstract_declarator
1109 %type <n> direct_alias_abstract_declarator
1110 %type <n> declarator
1111 %type <n> direct_declarator
1112 %type <n> field_class_declarator
1113 %type <n> direct_field_class_declarator
1115 %type <n> ctf_assignment_expression_list
1116 %type <n> ctf_assignment_expression
1123 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
1124 reparent_error(scanner, "error reparenting to root");
1128 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
1129 reparent_error(scanner, "error reparenting to root");
1158 | CTF_FLOATING_POINT
1191 /* 2: Phrase structure grammar */
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_STRING;
1210 $$->u.unary_expression.u.string = yylval.s;
1212 | CTF_INTEGER_LITERAL
1214 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1215 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1216 $$->u.unary_expression.u.unsigned_constant = $1;
1218 | CTF_STRING_LITERAL
1220 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1221 $$->u.unary_expression.type = UNARY_STRING;
1222 $$->u.unary_expression.u.string = $1;
1224 | CTF_CHARACTER_LITERAL
1226 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1227 $$->u.unary_expression.type = UNARY_STRING;
1228 $$->u.unary_expression.u.string = $1;
1230 | CTF_LPAREN unary_expression CTF_RPAREN
1234 | postfix_expression CTF_LSBRAC unary_expression CTF_RSBRAC
1236 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1237 $$->u.unary_expression.type = UNARY_SBRAC;
1238 $$->u.unary_expression.u.sbrac_exp = $3;
1239 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1240 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1242 | postfix_expression CTF_DOT IDENTIFIER
1244 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1245 $$->u.unary_expression.type = UNARY_STRING;
1246 $$->u.unary_expression.u.string = yylval.s;
1247 $$->u.unary_expression.link = UNARY_DOTLINK;
1248 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1249 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1251 | postfix_expression CTF_DOT ID_TYPE
1253 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1254 $$->u.unary_expression.type = UNARY_STRING;
1255 $$->u.unary_expression.u.string = yylval.s;
1256 $$->u.unary_expression.link = UNARY_DOTLINK;
1257 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1258 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1260 | postfix_expression CTF_DOT keywords
1262 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1263 $$->u.unary_expression.type = UNARY_STRING;
1264 $$->u.unary_expression.u.string = yylval.s;
1265 $$->u.unary_expression.link = UNARY_DOTLINK;
1266 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1267 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1269 | postfix_expression CTF_RARROW IDENTIFIER
1271 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1272 $$->u.unary_expression.type = UNARY_STRING;
1273 $$->u.unary_expression.u.string = yylval.s;
1274 $$->u.unary_expression.link = UNARY_ARROWLINK;
1275 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1276 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1278 | postfix_expression CTF_RARROW ID_TYPE
1280 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1281 $$->u.unary_expression.type = UNARY_STRING;
1282 $$->u.unary_expression.u.string = yylval.s;
1283 $$->u.unary_expression.link = UNARY_ARROWLINK;
1284 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1285 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1292 | CTF_PLUS postfix_expression
1295 if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
1296 && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
1297 reparent_error(scanner, "expecting numeric constant");
1300 | CTF_MINUS postfix_expression
1303 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1304 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1305 $$->u.unary_expression.u.signed_constant =
1306 -($$->u.unary_expression.u.unsigned_constant);
1307 } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1308 $$->u.unary_expression.u.signed_constant =
1309 -($$->u.unary_expression.u.signed_constant);
1311 reparent_error(scanner, "expecting numeric constant");
1316 unary_expression_or_range:
1317 unary_expression CTF_DOTDOTDOT unary_expression
1320 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1321 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1327 /* 2.2: Declarations */
1330 declaration_specifiers CTF_SEMICOLON
1334 | stream_declaration
1342 | callsite_declaration
1344 | declaration_specifiers CTF_TYPEDEF declaration_specifiers field_class_declarator_list CTF_SEMICOLON
1346 struct ctf_node *list;
1348 $$ = make_node(scanner, NODE_TYPEDEF);
1349 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1350 $$->u.field_class_def.field_class_specifier_list = list;
1351 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1352 _bt_list_splice_tail(&($3)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1353 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
1355 | CTF_TYPEDEF declaration_specifiers field_class_declarator_list CTF_SEMICOLON
1357 struct ctf_node *list;
1359 $$ = make_node(scanner, NODE_TYPEDEF);
1360 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1361 $$->u.field_class_def.field_class_specifier_list = list;
1362 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1363 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
1365 | declaration_specifiers CTF_TYPEDEF field_class_declarator_list CTF_SEMICOLON
1367 struct ctf_node *list;
1369 $$ = make_node(scanner, NODE_TYPEDEF);
1370 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1371 $$->u.field_class_def.field_class_specifier_list = list;
1372 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1373 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
1375 | CTF_TYPEALIAS declaration_specifiers abstract_declarator_list CTF_TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list CTF_SEMICOLON
1377 struct ctf_node *list;
1379 $$ = make_node(scanner, NODE_TYPEALIAS);
1380 $$->u.field_class_alias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1381 $$->u.field_class_alias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1383 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1384 $$->u.field_class_alias.target->u.field_class_alias_target.field_class_specifier_list = list;
1385 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1386 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_alias.target->u.field_class_alias_target.field_class_declarators);
1388 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1389 $$->u.field_class_alias.alias->u.field_class_alias_name.field_class_specifier_list = list;
1390 _bt_list_splice_tail(&($5)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1391 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.field_class_alias.alias->u.field_class_alias_name.field_class_declarators);
1396 event_declaration_begin event_declaration_end
1398 $$ = make_node(scanner, NODE_EVENT);
1400 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1402 $$ = make_node(scanner, NODE_EVENT);
1403 if (set_parent_node($2, $$))
1404 reparent_error(scanner, "event_declaration");
1408 event_declaration_begin:
1410 { push_scope(scanner); }
1413 event_declaration_end:
1414 CTF_RBRAC CTF_SEMICOLON
1415 { pop_scope(scanner); }
1420 stream_declaration_begin stream_declaration_end
1422 $$ = make_node(scanner, NODE_STREAM);
1424 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1426 $$ = make_node(scanner, NODE_STREAM);
1427 if (set_parent_node($2, $$))
1428 reparent_error(scanner, "stream_declaration");
1432 stream_declaration_begin:
1433 CTF_STREAM CTF_LBRAC
1434 { push_scope(scanner); }
1437 stream_declaration_end:
1438 CTF_RBRAC CTF_SEMICOLON
1439 { pop_scope(scanner); }
1443 env_declaration_begin env_declaration_end
1445 $$ = make_node(scanner, NODE_ENV);
1447 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1449 $$ = make_node(scanner, NODE_ENV);
1450 if (set_parent_node($2, $$))
1451 reparent_error(scanner, "env declaration");
1455 env_declaration_begin:
1457 { push_scope(scanner); }
1460 env_declaration_end:
1461 CTF_RBRAC CTF_SEMICOLON
1462 { pop_scope(scanner); }
1466 trace_declaration_begin trace_declaration_end
1468 $$ = make_node(scanner, NODE_TRACE);
1470 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1472 $$ = make_node(scanner, NODE_TRACE);
1473 if (set_parent_node($2, $$))
1474 reparent_error(scanner, "trace_declaration");
1478 trace_declaration_begin:
1480 { push_scope(scanner); }
1483 trace_declaration_end:
1484 CTF_RBRAC CTF_SEMICOLON
1485 { pop_scope(scanner); }
1489 CTF_CLOCK clock_declaration_begin clock_declaration_end
1491 $$ = make_node(scanner, NODE_CLOCK);
1493 | CTF_CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1495 $$ = make_node(scanner, NODE_CLOCK);
1496 if (set_parent_node($3, $$))
1497 reparent_error(scanner, "trace_declaration");
1501 clock_declaration_begin:
1503 { push_scope(scanner); }
1506 clock_declaration_end:
1507 CTF_RBRAC CTF_SEMICOLON
1508 { pop_scope(scanner); }
1511 callsite_declaration:
1512 CTF_CALLSITE callsite_declaration_begin callsite_declaration_end
1514 $$ = make_node(scanner, NODE_CALLSITE);
1516 | CTF_CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1518 $$ = make_node(scanner, NODE_CALLSITE);
1519 if (set_parent_node($3, $$))
1520 reparent_error(scanner, "trace_declaration");
1524 callsite_declaration_begin:
1526 { push_scope(scanner); }
1529 callsite_declaration_end:
1530 CTF_RBRAC CTF_SEMICOLON
1531 { pop_scope(scanner); }
1534 integer_declaration_specifiers:
1537 struct ctf_node *node;
1539 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1540 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1541 node->u.field_class_specifier.type = TYPESPEC_CONST;
1542 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1544 | integer_field_class_specifier
1546 struct ctf_node *node;
1548 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1550 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1552 | integer_declaration_specifiers CTF_CONST
1554 struct ctf_node *node;
1557 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1558 node->u.field_class_specifier.type = TYPESPEC_CONST;
1559 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1561 | integer_declaration_specifiers integer_field_class_specifier
1564 bt_list_add_tail(&($2)->siblings, &($$)->u.field_class_specifier_list.head);
1568 declaration_specifiers:
1571 struct ctf_node *node;
1573 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1574 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1575 node->u.field_class_specifier.type = TYPESPEC_CONST;
1576 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1578 | field_class_specifier
1580 struct ctf_node *node;
1582 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1584 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1586 | declaration_specifiers CTF_CONST
1588 struct ctf_node *node;
1591 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1592 node->u.field_class_specifier.type = TYPESPEC_CONST;
1593 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1595 | declaration_specifiers field_class_specifier
1598 bt_list_add_tail(&($2)->siblings, &($$)->u.field_class_specifier_list.head);
1602 field_class_declarator_list:
1603 field_class_declarator
1605 | field_class_declarator_list CTF_COMMA field_class_declarator
1608 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1612 integer_field_class_specifier:
1615 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1616 $$->u.field_class_specifier.type = TYPESPEC_CHAR;
1620 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1621 $$->u.field_class_specifier.type = TYPESPEC_SHORT;
1625 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1626 $$->u.field_class_specifier.type = TYPESPEC_INT;
1630 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1631 $$->u.field_class_specifier.type = TYPESPEC_LONG;
1635 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1636 $$->u.field_class_specifier.type = TYPESPEC_SIGNED;
1640 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1641 $$->u.field_class_specifier.type = TYPESPEC_UNSIGNED;
1645 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1646 $$->u.field_class_specifier.type = TYPESPEC_BOOL;
1650 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1651 $$->u.field_class_specifier.type = TYPESPEC_ID_TYPE;
1652 $$->u.field_class_specifier.id_type = yylval.s;
1654 | CTF_INTEGER CTF_LBRAC CTF_RBRAC
1656 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1657 $$->u.field_class_specifier.type = TYPESPEC_INTEGER;
1658 $$->u.field_class_specifier.node = make_node(scanner, NODE_INTEGER);
1660 | CTF_INTEGER CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1662 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1663 $$->u.field_class_specifier.type = TYPESPEC_INTEGER;
1664 $$->u.field_class_specifier.node = make_node(scanner, NODE_INTEGER);
1665 if (set_parent_node($3, $$->u.field_class_specifier.node))
1666 reparent_error(scanner, "integer reparent error");
1670 field_class_specifier:
1673 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1674 $$->u.field_class_specifier.type = TYPESPEC_VOID;
1678 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1679 $$->u.field_class_specifier.type = TYPESPEC_CHAR;
1683 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1684 $$->u.field_class_specifier.type = TYPESPEC_SHORT;
1688 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1689 $$->u.field_class_specifier.type = TYPESPEC_INT;
1693 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1694 $$->u.field_class_specifier.type = TYPESPEC_LONG;
1698 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1699 $$->u.field_class_specifier.type = TYPESPEC_FLOAT;
1703 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1704 $$->u.field_class_specifier.type = TYPESPEC_DOUBLE;
1708 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1709 $$->u.field_class_specifier.type = TYPESPEC_SIGNED;
1713 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1714 $$->u.field_class_specifier.type = TYPESPEC_UNSIGNED;
1718 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1719 $$->u.field_class_specifier.type = TYPESPEC_BOOL;
1723 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1724 $$->u.field_class_specifier.type = TYPESPEC_COMPLEX;
1728 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1729 $$->u.field_class_specifier.type = TYPESPEC_IMAGINARY;
1733 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1734 $$->u.field_class_specifier.type = TYPESPEC_ID_TYPE;
1735 $$->u.field_class_specifier.id_type = yylval.s;
1737 | CTF_FLOATING_POINT CTF_LBRAC CTF_RBRAC
1739 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1740 $$->u.field_class_specifier.type = TYPESPEC_FLOATING_POINT;
1741 $$->u.field_class_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1743 | CTF_FLOATING_POINT CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1745 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1746 $$->u.field_class_specifier.type = TYPESPEC_FLOATING_POINT;
1747 $$->u.field_class_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1748 if (set_parent_node($3, $$->u.field_class_specifier.node))
1749 reparent_error(scanner, "floating point reparent error");
1751 | CTF_INTEGER CTF_LBRAC CTF_RBRAC
1753 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1754 $$->u.field_class_specifier.type = TYPESPEC_INTEGER;
1755 $$->u.field_class_specifier.node = make_node(scanner, NODE_INTEGER);
1757 | CTF_INTEGER CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1759 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1760 $$->u.field_class_specifier.type = TYPESPEC_INTEGER;
1761 $$->u.field_class_specifier.node = make_node(scanner, NODE_INTEGER);
1762 if (set_parent_node($3, $$->u.field_class_specifier.node))
1763 reparent_error(scanner, "integer reparent error");
1767 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1768 $$->u.field_class_specifier.type = TYPESPEC_STRING;
1769 $$->u.field_class_specifier.node = make_node(scanner, NODE_STRING);
1771 | CTF_STRING CTF_LBRAC CTF_RBRAC
1773 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1774 $$->u.field_class_specifier.type = TYPESPEC_STRING;
1775 $$->u.field_class_specifier.node = make_node(scanner, NODE_STRING);
1777 | CTF_STRING CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1779 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1780 $$->u.field_class_specifier.type = TYPESPEC_STRING;
1781 $$->u.field_class_specifier.node = make_node(scanner, NODE_STRING);
1782 if (set_parent_node($3, $$->u.field_class_specifier.node))
1783 reparent_error(scanner, "string reparent error");
1785 | CTF_ENUM enum_field_class_specifier
1787 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1788 $$->u.field_class_specifier.type = TYPESPEC_ENUM;
1789 $$->u.field_class_specifier.node = $2;
1791 | CTF_VARIANT variant_field_class_specifier
1793 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1794 $$->u.field_class_specifier.type = TYPESPEC_VARIANT;
1795 $$->u.field_class_specifier.node = $2;
1797 | CTF_STRUCT struct_class_specifier
1799 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1800 $$->u.field_class_specifier.type = TYPESPEC_STRUCT;
1801 $$->u.field_class_specifier.node = $2;
1805 struct_class_specifier:
1806 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1808 $$ = make_node(scanner, NODE_STRUCT);
1809 $$->u._struct.has_body = 1;
1810 if ($2 && set_parent_node($2, $$))
1811 reparent_error(scanner, "struct reparent error");
1813 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1815 $$ = make_node(scanner, NODE_STRUCT);
1816 $$->u._struct.has_body = 1;
1817 $$->u._struct.name = $1;
1818 if ($3 && set_parent_node($3, $$))
1819 reparent_error(scanner, "struct reparent error");
1821 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1823 $$ = make_node(scanner, NODE_STRUCT);
1824 $$->u._struct.has_body = 1;
1825 $$->u._struct.name = $1;
1826 if ($3 && set_parent_node($3, $$))
1827 reparent_error(scanner, "struct reparent error");
1831 $$ = make_node(scanner, NODE_STRUCT);
1832 $$->u._struct.has_body = 0;
1833 $$->u._struct.name = $1;
1837 $$ = make_node(scanner, NODE_STRUCT);
1838 $$->u._struct.has_body = 0;
1839 $$->u._struct.name = $1;
1841 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end CTF_TOK_ALIGN CTF_LPAREN unary_expression CTF_RPAREN
1843 $$ = make_node(scanner, NODE_STRUCT);
1844 $$->u._struct.has_body = 1;
1845 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1846 if ($2 && set_parent_node($2, $$))
1847 reparent_error(scanner, "struct reparent error");
1849 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end CTF_TOK_ALIGN CTF_LPAREN unary_expression CTF_RPAREN
1851 $$ = make_node(scanner, NODE_STRUCT);
1852 $$->u._struct.has_body = 1;
1853 $$->u._struct.name = $1;
1854 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1855 if ($3 && set_parent_node($3, $$))
1856 reparent_error(scanner, "struct reparent error");
1858 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end CTF_TOK_ALIGN CTF_LPAREN unary_expression CTF_RPAREN
1860 $$ = make_node(scanner, NODE_STRUCT);
1861 $$->u._struct.has_body = 1;
1862 $$->u._struct.name = $1;
1863 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1864 if ($3 && set_parent_node($3, $$))
1865 reparent_error(scanner, "struct reparent error");
1869 struct_declaration_begin:
1871 { push_scope(scanner); }
1874 struct_declaration_end:
1876 { pop_scope(scanner); }
1879 variant_field_class_specifier:
1880 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1882 $$ = make_node(scanner, NODE_VARIANT);
1883 $$->u.variant.has_body = 1;
1884 if ($2 && set_parent_node($2, $$))
1885 reparent_error(scanner, "variant reparent error");
1887 | CTF_LT IDENTIFIER CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1889 $$ = make_node(scanner, NODE_VARIANT);
1890 $$->u.variant.has_body = 1;
1891 $$->u.variant.choice = $2;
1892 if ($5 && set_parent_node($5, $$))
1893 reparent_error(scanner, "variant reparent error");
1895 | CTF_LT ID_TYPE CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1897 $$ = make_node(scanner, NODE_VARIANT);
1898 $$->u.variant.has_body = 1;
1899 $$->u.variant.choice = $2;
1900 if ($5 && set_parent_node($5, $$))
1901 reparent_error(scanner, "variant reparent error");
1903 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1905 $$ = make_node(scanner, NODE_VARIANT);
1906 $$->u.variant.has_body = 1;
1907 $$->u.variant.name = $1;
1908 if ($3 && set_parent_node($3, $$))
1909 reparent_error(scanner, "variant reparent error");
1911 | IDENTIFIER CTF_LT IDENTIFIER CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1913 $$ = make_node(scanner, NODE_VARIANT);
1914 $$->u.variant.has_body = 1;
1915 $$->u.variant.name = $1;
1916 $$->u.variant.choice = $3;
1917 if ($6 && set_parent_node($6, $$))
1918 reparent_error(scanner, "variant reparent error");
1920 | IDENTIFIER CTF_LT IDENTIFIER CTF_GT
1922 $$ = make_node(scanner, NODE_VARIANT);
1923 $$->u.variant.has_body = 0;
1924 $$->u.variant.name = $1;
1925 $$->u.variant.choice = $3;
1927 | IDENTIFIER CTF_LT ID_TYPE CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1929 $$ = make_node(scanner, NODE_VARIANT);
1930 $$->u.variant.has_body = 1;
1931 $$->u.variant.name = $1;
1932 $$->u.variant.choice = $3;
1933 if ($6 && set_parent_node($6, $$))
1934 reparent_error(scanner, "variant reparent error");
1936 | IDENTIFIER CTF_LT ID_TYPE CTF_GT
1938 $$ = make_node(scanner, NODE_VARIANT);
1939 $$->u.variant.has_body = 0;
1940 $$->u.variant.name = $1;
1941 $$->u.variant.choice = $3;
1943 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1945 $$ = make_node(scanner, NODE_VARIANT);
1946 $$->u.variant.has_body = 1;
1947 $$->u.variant.name = $1;
1948 if ($3 && set_parent_node($3, $$))
1949 reparent_error(scanner, "variant reparent error");
1951 | ID_TYPE CTF_LT IDENTIFIER CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1953 $$ = make_node(scanner, NODE_VARIANT);
1954 $$->u.variant.has_body = 1;
1955 $$->u.variant.name = $1;
1956 $$->u.variant.choice = $3;
1957 if ($6 && set_parent_node($6, $$))
1958 reparent_error(scanner, "variant reparent error");
1960 | ID_TYPE CTF_LT IDENTIFIER CTF_GT
1962 $$ = make_node(scanner, NODE_VARIANT);
1963 $$->u.variant.has_body = 0;
1964 $$->u.variant.name = $1;
1965 $$->u.variant.choice = $3;
1967 | ID_TYPE CTF_LT ID_TYPE CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1969 $$ = make_node(scanner, NODE_VARIANT);
1970 $$->u.variant.has_body = 1;
1971 $$->u.variant.name = $1;
1972 $$->u.variant.choice = $3;
1973 if ($6 && set_parent_node($6, $$))
1974 reparent_error(scanner, "variant reparent error");
1976 | ID_TYPE CTF_LT ID_TYPE CTF_GT
1978 $$ = make_node(scanner, NODE_VARIANT);
1979 $$->u.variant.has_body = 0;
1980 $$->u.variant.name = $1;
1981 $$->u.variant.choice = $3;
1985 variant_declaration_begin:
1987 { push_scope(scanner); }
1990 variant_declaration_end:
1992 { pop_scope(scanner); }
1995 enum_field_class_specifier:
1996 CTF_LBRAC enumerator_list CTF_RBRAC
1998 $$ = make_node(scanner, NODE_ENUM);
1999 $$->u._enum.has_body = 1;
2000 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2002 | CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_RBRAC
2004 $$ = make_node(scanner, NODE_ENUM);
2005 $$->u._enum.has_body = 1;
2006 ($$)->u._enum.container_field_class = $2;
2007 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2009 | IDENTIFIER CTF_LBRAC enumerator_list CTF_RBRAC
2011 $$ = make_node(scanner, NODE_ENUM);
2012 $$->u._enum.has_body = 1;
2013 $$->u._enum.enum_id = $1;
2014 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2016 | IDENTIFIER CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_RBRAC
2018 $$ = make_node(scanner, NODE_ENUM);
2019 $$->u._enum.has_body = 1;
2020 $$->u._enum.enum_id = $1;
2021 ($$)->u._enum.container_field_class = $3;
2022 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2024 | ID_TYPE CTF_LBRAC enumerator_list CTF_RBRAC
2026 $$ = make_node(scanner, NODE_ENUM);
2027 $$->u._enum.has_body = 1;
2028 $$->u._enum.enum_id = $1;
2029 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2031 | ID_TYPE CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_RBRAC
2033 $$ = make_node(scanner, NODE_ENUM);
2034 $$->u._enum.has_body = 1;
2035 $$->u._enum.enum_id = $1;
2036 ($$)->u._enum.container_field_class = $3;
2037 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2039 | CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2041 $$ = make_node(scanner, NODE_ENUM);
2042 $$->u._enum.has_body = 1;
2043 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2045 | CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2047 $$ = make_node(scanner, NODE_ENUM);
2048 $$->u._enum.has_body = 1;
2049 ($$)->u._enum.container_field_class = $2;
2050 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2052 | IDENTIFIER CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2054 $$ = make_node(scanner, NODE_ENUM);
2055 $$->u._enum.has_body = 1;
2056 $$->u._enum.enum_id = $1;
2057 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2059 | IDENTIFIER CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2061 $$ = make_node(scanner, NODE_ENUM);
2062 $$->u._enum.has_body = 1;
2063 $$->u._enum.enum_id = $1;
2064 ($$)->u._enum.container_field_class = $3;
2065 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2069 $$ = make_node(scanner, NODE_ENUM);
2070 $$->u._enum.has_body = 0;
2071 $$->u._enum.enum_id = $1;
2073 | ID_TYPE CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2075 $$ = make_node(scanner, NODE_ENUM);
2076 $$->u._enum.has_body = 1;
2077 $$->u._enum.enum_id = $1;
2078 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2080 | ID_TYPE CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2082 $$ = make_node(scanner, NODE_ENUM);
2083 $$->u._enum.has_body = 1;
2084 $$->u._enum.enum_id = $1;
2085 ($$)->u._enum.container_field_class = $3;
2086 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2090 $$ = make_node(scanner, NODE_ENUM);
2091 $$->u._enum.has_body = 0;
2092 $$->u._enum.enum_id = $1;
2096 struct_or_variant_declaration_list:
2099 | struct_or_variant_declaration_list struct_or_variant_declaration
2103 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2106 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
2111 struct_or_variant_declaration:
2112 declaration_specifiers struct_or_variant_declarator_list CTF_SEMICOLON
2114 struct ctf_node *list;
2116 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2117 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2118 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
2119 ($$)->u.struct_or_variant_declaration.field_class_specifier_list = list;
2120 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.field_class_declarators);
2122 | declaration_specifiers CTF_TYPEDEF declaration_specifiers field_class_declarator_list CTF_SEMICOLON
2124 struct ctf_node *list;
2126 $$ = make_node(scanner, NODE_TYPEDEF);
2127 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2128 $$->u.field_class_def.field_class_specifier_list = list;
2129 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2130 _bt_list_splice_tail(&($3)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2131 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2133 | CTF_TYPEDEF declaration_specifiers field_class_declarator_list CTF_SEMICOLON
2135 struct ctf_node *list;
2137 $$ = make_node(scanner, NODE_TYPEDEF);
2138 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2139 $$->u.field_class_def.field_class_specifier_list = list;
2140 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2141 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2143 | declaration_specifiers CTF_TYPEDEF field_class_declarator_list CTF_SEMICOLON
2145 struct ctf_node *list;
2147 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2148 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2149 $$ = make_node(scanner, NODE_TYPEDEF);
2150 ($$)->u.struct_or_variant_declaration.field_class_specifier_list = list;
2151 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2153 | CTF_TYPEALIAS declaration_specifiers abstract_declarator_list CTF_TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list CTF_SEMICOLON
2155 struct ctf_node *list;
2157 $$ = make_node(scanner, NODE_TYPEALIAS);
2158 $$->u.field_class_alias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2159 $$->u.field_class_alias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2161 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2162 $$->u.field_class_alias.target->u.field_class_alias_target.field_class_specifier_list = list;
2163 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2164 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_alias.target->u.field_class_alias_target.field_class_declarators);
2166 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2167 $$->u.field_class_alias.alias->u.field_class_alias_name.field_class_specifier_list = list;
2168 _bt_list_splice_tail(&($5)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2169 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.field_class_alias.alias->u.field_class_alias_name.field_class_declarators);
2173 alias_declaration_specifiers:
2176 struct ctf_node *node;
2178 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2179 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2180 node->u.field_class_specifier.type = TYPESPEC_CONST;
2181 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2183 | field_class_specifier
2185 struct ctf_node *node;
2187 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2189 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2193 struct ctf_node *node;
2195 add_type(scanner, $1);
2196 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2197 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2198 node->u.field_class_specifier.type = TYPESPEC_ID_TYPE;
2199 node->u.field_class_specifier.id_type = yylval.s;
2200 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2202 | alias_declaration_specifiers CTF_CONST
2204 struct ctf_node *node;
2207 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2208 node->u.field_class_specifier.type = TYPESPEC_CONST;
2209 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2211 | alias_declaration_specifiers field_class_specifier
2214 bt_list_add_tail(&($2)->siblings, &($$)->u.field_class_specifier_list.head);
2216 | alias_declaration_specifiers IDENTIFIER
2218 struct ctf_node *node;
2220 add_type(scanner, $2);
2222 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2223 node->u.field_class_specifier.type = TYPESPEC_ID_TYPE;
2224 node->u.field_class_specifier.id_type = yylval.s;
2225 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2229 struct_or_variant_declarator_list:
2230 struct_or_variant_declarator
2232 | struct_or_variant_declarator_list CTF_COMMA struct_or_variant_declarator
2235 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2239 struct_or_variant_declarator:
2242 | CTF_COLON unary_expression
2244 | declarator CTF_COLON unary_expression
2247 if (set_parent_node($3, $1))
2248 reparent_error(scanner, "struct_or_variant_declarator");
2255 | enumerator_list CTF_COMMA enumerator
2258 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2265 $$ = make_node(scanner, NODE_ENUMERATOR);
2266 $$->u.enumerator.id = $1;
2270 $$ = make_node(scanner, NODE_ENUMERATOR);
2271 $$->u.enumerator.id = $1;
2275 $$ = make_node(scanner, NODE_ENUMERATOR);
2276 $$->u.enumerator.id = $1;
2278 | CTF_STRING_LITERAL
2280 $$ = make_node(scanner, NODE_ENUMERATOR);
2281 $$->u.enumerator.id = $1;
2283 | IDENTIFIER CTF_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 | ID_TYPE CTF_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 | keywords CTF_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);
2301 | CTF_STRING_LITERAL CTF_EQUAL unary_expression_or_range
2303 $$ = make_node(scanner, NODE_ENUMERATOR);
2304 $$->u.enumerator.id = $1;
2305 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2309 abstract_declarator_list:
2312 | abstract_declarator_list CTF_COMMA abstract_declarator
2315 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2319 abstract_declarator:
2320 direct_abstract_declarator
2322 | pointer direct_abstract_declarator
2325 bt_list_splice(&($1)->tmp_head, &($$)->u.field_class_declarator.pointers);
2329 direct_abstract_declarator:
2332 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2333 $$->u.field_class_declarator.type = TYPEDEC_ID;
2338 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2339 $$->u.field_class_declarator.type = TYPEDEC_ID;
2340 $$->u.field_class_declarator.u.id = $1;
2342 | CTF_LPAREN abstract_declarator CTF_RPAREN
2344 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2345 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2346 $$->u.field_class_declarator.u.nested.field_class_declarator = $2;
2348 | direct_abstract_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2350 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2351 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2352 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2353 BT_INIT_LIST_HEAD(&($$)->u.field_class_declarator.u.nested.length);
2354 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_declarator.u.nested.length);
2356 | direct_abstract_declarator CTF_LSBRAC CTF_RSBRAC
2358 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2359 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2360 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2361 $$->u.field_class_declarator.u.nested.abstract_array = 1;
2365 alias_abstract_declarator_list:
2366 alias_abstract_declarator
2368 | alias_abstract_declarator_list CTF_COMMA alias_abstract_declarator
2371 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2375 alias_abstract_declarator:
2376 direct_alias_abstract_declarator
2378 | pointer direct_alias_abstract_declarator
2381 bt_list_splice(&($1)->tmp_head, &($$)->u.field_class_declarator.pointers);
2385 direct_alias_abstract_declarator:
2388 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2389 $$->u.field_class_declarator.type = TYPEDEC_ID;
2392 | CTF_LPAREN alias_abstract_declarator CTF_RPAREN
2394 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2395 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2396 $$->u.field_class_declarator.u.nested.field_class_declarator = $2;
2398 | direct_alias_abstract_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2400 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2401 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2402 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2403 BT_INIT_LIST_HEAD(&($$)->u.field_class_declarator.u.nested.length);
2404 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_declarator.u.nested.length);
2406 | direct_alias_abstract_declarator CTF_LSBRAC CTF_RSBRAC
2408 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2409 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2410 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2411 $$->u.field_class_declarator.u.nested.abstract_array = 1;
2418 | pointer direct_declarator
2421 bt_list_splice(&($1)->tmp_head, &($$)->u.field_class_declarator.pointers);
2428 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2429 $$->u.field_class_declarator.type = TYPEDEC_ID;
2430 $$->u.field_class_declarator.u.id = $1;
2432 | CTF_LPAREN declarator CTF_RPAREN
2434 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2435 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2436 $$->u.field_class_declarator.u.nested.field_class_declarator = $2;
2438 | direct_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2440 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2441 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2442 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2443 BT_INIT_LIST_HEAD(&($$)->u.field_class_declarator.u.nested.length);
2444 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_declarator.u.nested.length);
2448 field_class_declarator:
2449 direct_field_class_declarator
2451 | pointer direct_field_class_declarator
2454 bt_list_splice(&($1)->tmp_head, &($$)->u.field_class_declarator.pointers);
2458 direct_field_class_declarator:
2461 add_type(scanner, $1);
2462 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2463 $$->u.field_class_declarator.type = TYPEDEC_ID;
2464 $$->u.field_class_declarator.u.id = $1;
2466 | CTF_LPAREN field_class_declarator CTF_RPAREN
2468 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2469 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2470 $$->u.field_class_declarator.u.nested.field_class_declarator = $2;
2472 | direct_field_class_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2474 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2475 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2476 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2477 BT_INIT_LIST_HEAD(&($$)->u.field_class_declarator.u.nested.length);
2478 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_declarator.u.nested.length);
2485 $$ = make_node(scanner, NODE_POINTER);
2489 $$ = make_node(scanner, NODE_POINTER);
2490 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2492 | CTF_STAR type_qualifier_list pointer
2494 $$ = make_node(scanner, NODE_POINTER);
2495 $$->u.pointer.const_qualifier = 1;
2496 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2500 type_qualifier_list:
2501 /* pointer assumes only const type qualifier */
2503 | type_qualifier_list CTF_CONST
2506 /* 2.3: CTF-specific declarations */
2508 ctf_assignment_expression_list:
2509 ctf_assignment_expression CTF_SEMICOLON
2511 | ctf_assignment_expression_list ctf_assignment_expression CTF_SEMICOLON
2514 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2518 ctf_assignment_expression:
2519 unary_expression CTF_EQUAL unary_expression
2522 * Because we have left and right, cannot use
2525 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2526 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2527 if ($1->u.unary_expression.type != UNARY_STRING)
2528 reparent_error(scanner, "ctf_assignment_expression left expects string");
2529 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2531 | unary_expression CTF_TYPEASSIGN declaration_specifiers /* Only allow struct */
2534 * Because we have left and right, cannot use
2537 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2538 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2539 if ($1->u.unary_expression.type != UNARY_STRING)
2540 reparent_error(scanner, "ctf_assignment_expression left expects string");
2541 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2543 | declaration_specifiers CTF_TYPEDEF declaration_specifiers field_class_declarator_list
2545 struct ctf_node *list;
2547 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2548 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2549 _bt_list_splice_tail(&($3)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2550 $$ = make_node(scanner, NODE_TYPEDEF);
2551 ($$)->u.struct_or_variant_declaration.field_class_specifier_list = list;
2552 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2554 | CTF_TYPEDEF declaration_specifiers field_class_declarator_list
2556 struct ctf_node *list;
2558 $$ = make_node(scanner, NODE_TYPEDEF);
2559 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2560 $$->u.field_class_def.field_class_specifier_list = list;
2561 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2562 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2564 | declaration_specifiers CTF_TYPEDEF field_class_declarator_list
2566 struct ctf_node *list;
2568 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2569 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2570 $$ = make_node(scanner, NODE_TYPEDEF);
2571 ($$)->u.struct_or_variant_declaration.field_class_specifier_list = list;
2572 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2574 | CTF_TYPEALIAS declaration_specifiers abstract_declarator_list CTF_TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2576 struct ctf_node *list;
2578 $$ = make_node(scanner, NODE_TYPEALIAS);
2579 $$->u.field_class_alias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2580 $$->u.field_class_alias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2582 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2583 $$->u.field_class_alias.target->u.field_class_alias_target.field_class_specifier_list = list;
2584 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2585 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_alias.target->u.field_class_alias_target.field_class_declarators);
2587 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2588 $$->u.field_class_alias.alias->u.field_class_alias_name.field_class_specifier_list = list;
2589 _bt_list_splice_tail(&($5)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2590 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.field_class_alias.alias->u.field_class_alias_name.field_class_declarators);