3 * SPDX-License-Identifier: MIT
5 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 * Common Trace Format Metadata Grammar.
10 #define BT_LOG_OUTPUT_LEVEL ctf_plugin_metadata_log_level
11 #define BT_LOG_TAG "PLUGIN/CTF/META/PARSER"
23 #include "common/list.h"
24 #include "common/assert.h"
29 #include "parser-wrap.h"
31 /* Join two lists, put "add" at the end of "head". */
33 _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
35 /* Do nothing if the list which gets added is empty. */
36 if (add != add->next) {
37 add->next->prev = head->prev;
38 add->prev->next = head;
39 head->prev->next = add->next;
40 head->prev = add->prev;
45 int yylex(union YYSTYPE *yyval, yyscan_t yyscanner);
47 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
49 int yylex_destroy(yyscan_t yyscanner);
51 void yyrestart(FILE * in_str, yyscan_t yyscanner);
53 int yyget_lineno(yyscan_t yyscanner);
55 char *yyget_text(yyscan_t yyscanner);
57 static const char *node_type_to_str[] = {
58 #define ENTRY(S) [S] = #S,
59 FOREACH_CTF_NODES(ENTRY)
64 * Static node for out of memory errors. Only "type" is used. lineno is
65 * always left at 0. The rest of the node content can be overwritten,
68 static struct ctf_node error_node = {
73 const char *node_type(struct ctf_node *node)
75 if (node->type < NR_NODE_TYPES)
76 return node_type_to_str[node->type];
81 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
83 lvalp->s = objstack_alloc(scanner->objstack, strlen(src) + 1);
84 strcpy(lvalp->s, src);
88 int str_check(size_t str_len, size_t offset, size_t len)
91 if (offset + len < offset)
93 if (offset + len > str_len)
99 int bt_isodigit(int c)
117 int parse_base_sequence(const char *src, size_t len, size_t pos,
118 char *buffer, size_t *buf_len, int base)
120 const size_t max_char = 3;
123 while (!str_check(len, pos, 1) && nr_char < max_char) {
128 buffer[nr_char++] = c;
131 } else if (base == 16) {
133 buffer[nr_char++] = c;
138 /* Unsupported base */
142 BT_ASSERT_DBG(nr_char > 0);
143 buffer[nr_char] = '\0';
149 int import_basic_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
150 size_t len, const char *src, char delim)
152 size_t pos = 0, dpos = 0;
154 if (str_check(len, pos, 1))
156 if (src[pos++] != delim)
159 while (src[pos] != delim) {
162 if (str_check(len, pos, 1))
166 if (str_check(len, pos, 1))
216 if (parse_base_sequence(src, len, pos - 1,
217 oct_buffer, &oct_len, 8))
219 c = strtoul(&oct_buffer[0], NULL, 8);
228 if (parse_base_sequence(src, len, pos,
229 hex_buffer, &hex_len, 16))
231 c = strtoul(&hex_buffer[0], NULL, 16);
239 if (str_check(len, dpos, 1))
241 lvalp->s[dpos++] = c;
244 if (str_check(len, dpos, 1))
246 lvalp->s[dpos++] = '\0';
248 if (str_check(len, pos, 1))
250 if (src[pos++] != delim)
253 if (str_check(len, pos, 1))
255 if (src[pos] != '\0')
260 int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
261 const char *src, char delim)
265 len = strlen(src) + 1;
266 lvalp->s = objstack_alloc(scanner->objstack, len);
268 // TODO: import wide string
269 _BT_LOGE_APPEND_CAUSE_LINENO(yyget_lineno(scanner),
270 "wide characters are not supported as of this version: "
271 "scanner-addr=%p", scanner);
274 return import_basic_string(scanner, lvalp, len, src, delim);
278 static void init_scope(struct ctf_scanner_scope *scope,
279 struct ctf_scanner_scope *parent)
281 scope->parent = parent;
282 scope->classes = g_hash_table_new_full(g_str_hash, g_str_equal,
286 static void finalize_scope(struct ctf_scanner_scope *scope)
288 g_hash_table_destroy(scope->classes);
291 static void push_scope(struct ctf_scanner *scanner)
293 struct ctf_scanner_scope *ns;
295 BT_LOGT("Pushing scope: scanner-addr=%p", scanner);
296 ns = malloc(sizeof(struct ctf_scanner_scope));
297 init_scope(ns, scanner->cs);
301 static void pop_scope(struct ctf_scanner *scanner)
303 struct ctf_scanner_scope *os;
305 BT_LOGT("Popping scope: scanner-addr=%p", scanner);
307 scanner->cs = os->parent;
312 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
316 ret = GPOINTER_TO_INT(g_hash_table_lookup(s->classes, id));
317 BT_LOGT("Looked up type: scanner-addr=%p, id=\"%s\", ret=%d",
323 int is_type(struct ctf_scanner *scanner, const char *id)
325 struct ctf_scanner_scope *it;
328 for (it = scanner->cs; it; it = it->parent) {
329 if (lookup_type(it, id)) {
334 BT_LOGT("Found if ID is type: scanner-addr=%p, id=\"%s\", ret=%d",
339 static void add_type(struct ctf_scanner *scanner, char *id)
341 BT_LOGT("Adding type: scanner-addr=%p, id=\"%s\"",
343 if (lookup_type(scanner->cs, id))
345 g_hash_table_insert(scanner->cs->classes, id, id);
348 static struct ctf_node *make_node(struct ctf_scanner *scanner,
351 struct ctf_node *node;
353 node = objstack_alloc(scanner->objstack, sizeof(*node));
355 _BT_LOGE_APPEND_CAUSE_LINENO(yyget_lineno(scanner->scanner),
356 "failed to allocate one stack entry: "
357 "scanner-addr=%p", scanner);
361 node->lineno = yyget_lineno(scanner->scanner);
362 BT_INIT_LIST_HEAD(&node->tmp_head);
363 bt_list_add(&node->siblings, &node->tmp_head);
367 node->type = NODE_ERROR;
368 BT_LOGE("Trying to create root node: scanner-addr=%p",
372 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
375 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
378 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
381 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
384 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
387 BT_INIT_LIST_HEAD(&node->u.callsite.declaration_list);
389 case NODE_CTF_EXPRESSION:
390 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
391 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
393 case NODE_UNARY_EXPRESSION:
396 BT_INIT_LIST_HEAD(&node->u.field_class_def.field_class_declarators);
398 case NODE_TYPEALIAS_TARGET:
399 BT_INIT_LIST_HEAD(&node->u.field_class_alias_target.field_class_declarators);
401 case NODE_TYPEALIAS_ALIAS:
402 BT_INIT_LIST_HEAD(&node->u.field_class_alias_name.field_class_declarators);
406 case NODE_TYPE_SPECIFIER:
408 case NODE_TYPE_SPECIFIER_LIST:
409 BT_INIT_LIST_HEAD(&node->u.field_class_specifier_list.head);
413 case NODE_TYPE_DECLARATOR:
414 BT_INIT_LIST_HEAD(&node->u.field_class_declarator.pointers);
416 case NODE_FLOATING_POINT:
417 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
420 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
423 BT_INIT_LIST_HEAD(&node->u.string.expressions);
425 case NODE_ENUMERATOR:
426 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
429 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
431 case NODE_STRUCT_OR_VARIANT_DECLARATION:
432 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.field_class_declarators);
435 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
438 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
439 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
443 node->type = NODE_ERROR;
444 BT_LOGE("Unknown node type: scanner-addr=%p, node-type=%d",
452 static int reparent_ctf_expression(struct ctf_node *node,
453 struct ctf_node *parent)
455 switch (parent->type) {
457 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
460 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
463 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
466 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
469 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
472 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
474 case NODE_FLOATING_POINT:
475 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
478 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
481 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
485 case NODE_CTF_EXPRESSION:
487 case NODE_TYPEALIAS_TARGET:
488 case NODE_TYPEALIAS_ALIAS:
490 case NODE_TYPE_SPECIFIER:
491 case NODE_TYPE_SPECIFIER_LIST:
493 case NODE_TYPE_DECLARATOR:
494 case NODE_ENUMERATOR:
496 case NODE_STRUCT_OR_VARIANT_DECLARATION:
499 case NODE_UNARY_EXPRESSION:
504 BT_LOGE("Unknown node type: node-type=%d", parent->type);
510 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
512 switch (parent->type) {
514 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
517 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
520 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
523 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
526 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
529 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
532 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
535 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
538 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
541 case NODE_FLOATING_POINT:
544 case NODE_CTF_EXPRESSION:
546 case NODE_TYPEALIAS_TARGET:
547 case NODE_TYPEALIAS_ALIAS:
549 case NODE_TYPE_SPECIFIER:
550 case NODE_TYPE_SPECIFIER_LIST:
552 case NODE_TYPE_DECLARATOR:
553 case NODE_ENUMERATOR:
555 case NODE_STRUCT_OR_VARIANT_DECLARATION:
556 case NODE_UNARY_EXPRESSION:
561 BT_LOGE("Unknown node type: node-type=%d", parent->type);
567 static int reparent_field_class_alias(struct ctf_node *node, struct ctf_node *parent)
569 switch (parent->type) {
571 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
574 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
577 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
580 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
583 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
586 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
589 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
592 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
595 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
598 case NODE_FLOATING_POINT:
601 case NODE_CTF_EXPRESSION:
603 case NODE_TYPEALIAS_TARGET:
604 case NODE_TYPEALIAS_ALIAS:
606 case NODE_TYPE_SPECIFIER:
607 case NODE_TYPE_SPECIFIER_LIST:
609 case NODE_TYPE_DECLARATOR:
610 case NODE_ENUMERATOR:
612 case NODE_STRUCT_OR_VARIANT_DECLARATION:
613 case NODE_UNARY_EXPRESSION:
618 BT_LOGE("Unknown node type: node-type=%d", parent->type);
624 static int reparent_field_class_specifier(struct ctf_node *node,
625 struct ctf_node *parent)
627 switch (parent->type) {
628 case NODE_TYPE_SPECIFIER_LIST:
629 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_specifier_list.head);
632 case NODE_TYPE_SPECIFIER:
642 case NODE_TYPEALIAS_TARGET:
643 case NODE_TYPEALIAS_ALIAS:
644 case NODE_TYPE_DECLARATOR:
646 case NODE_STRUCT_OR_VARIANT_DECLARATION:
648 case NODE_FLOATING_POINT:
651 case NODE_CTF_EXPRESSION:
653 case NODE_ENUMERATOR:
654 case NODE_UNARY_EXPRESSION:
659 BT_LOGE("Unknown node type: node-type=%d", parent->type);
665 static int reparent_field_class_specifier_list(struct ctf_node *node,
666 struct ctf_node *parent)
668 switch (parent->type) {
670 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
673 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
676 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
679 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
682 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
685 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
688 bt_list_add_tail(&node->siblings, &parent->u.callsite.declaration_list);
691 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
694 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
697 parent->u.field_class_def.field_class_specifier_list = node;
699 case NODE_TYPEALIAS_TARGET:
700 parent->u.field_class_alias_target.field_class_specifier_list = node;
702 case NODE_TYPEALIAS_ALIAS:
703 parent->u.field_class_alias_name.field_class_specifier_list = node;
706 parent->u._enum.container_field_class = node;
708 case NODE_STRUCT_OR_VARIANT_DECLARATION:
709 parent->u.struct_or_variant_declaration.field_class_specifier_list = node;
711 case NODE_TYPE_DECLARATOR:
712 case NODE_TYPE_SPECIFIER:
714 case NODE_FLOATING_POINT:
717 case NODE_CTF_EXPRESSION:
719 case NODE_ENUMERATOR:
720 case NODE_UNARY_EXPRESSION:
725 BT_LOGE("Unknown node type: node-type=%d", parent->type);
731 static int reparent_field_class_declarator(struct ctf_node *node,
732 struct ctf_node *parent)
734 switch (parent->type) {
735 case NODE_TYPE_DECLARATOR:
736 parent->u.field_class_declarator.type = TYPEDEC_NESTED;
737 parent->u.field_class_declarator.u.nested.field_class_declarator = node;
739 case NODE_STRUCT_OR_VARIANT_DECLARATION:
740 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.field_class_declarators);
743 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_def.field_class_declarators);
745 case NODE_TYPEALIAS_TARGET:
746 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_alias_target.field_class_declarators);
748 case NODE_TYPEALIAS_ALIAS:
749 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_alias_name.field_class_declarators);
763 case NODE_FLOATING_POINT:
766 case NODE_CTF_EXPRESSION:
767 case NODE_TYPE_SPECIFIER:
768 case NODE_TYPE_SPECIFIER_LIST:
770 case NODE_ENUMERATOR:
771 case NODE_UNARY_EXPRESSION:
776 BT_LOGE("Unknown node type: node-type=%d", parent->type);
785 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
786 * create the link declared by the input, -ENOENT if node or parent is NULL,
787 * -EINVAL if there is an internal structure problem.
789 static int set_parent_node(struct ctf_node *node,
790 struct ctf_node *parent)
792 if (!node || !parent)
795 /* Note: Linking to parent will be done only by an external visitor */
797 switch (node->type) {
799 BT_LOGE_STR("Trying to reparent root node.");
803 if (parent->type == NODE_ROOT) {
804 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
810 if (parent->type == NODE_ROOT) {
811 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
817 if (parent->type == NODE_ROOT) {
818 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
824 if (parent->type == NODE_ROOT) {
825 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
831 if (parent->type == NODE_ROOT) {
832 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
838 if (parent->type == NODE_ROOT) {
839 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.callsite);
845 case NODE_CTF_EXPRESSION:
846 return reparent_ctf_expression(node, parent);
847 case NODE_UNARY_EXPRESSION:
848 if (parent->type == NODE_TYPE_DECLARATOR)
849 parent->u.field_class_declarator.bitfield_len = node;
855 return reparent_typedef(node, parent);
856 case NODE_TYPEALIAS_TARGET:
857 if (parent->type == NODE_TYPEALIAS)
858 parent->u.field_class_alias.target = node;
862 case NODE_TYPEALIAS_ALIAS:
863 if (parent->type == NODE_TYPEALIAS)
864 parent->u.field_class_alias.alias = node;
869 return reparent_field_class_alias(node, parent);
872 if (parent->type == NODE_TYPE_DECLARATOR) {
873 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_declarator.pointers);
877 case NODE_TYPE_DECLARATOR:
878 return reparent_field_class_declarator(node, parent);
880 case NODE_TYPE_SPECIFIER_LIST:
881 return reparent_field_class_specifier_list(node, parent);
883 case NODE_TYPE_SPECIFIER:
884 return reparent_field_class_specifier(node, parent);
886 case NODE_FLOATING_POINT:
892 return -EINVAL; /* Dealt with internally within grammar */
894 case NODE_ENUMERATOR:
895 if (parent->type == NODE_ENUM) {
896 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
901 case NODE_STRUCT_OR_VARIANT_DECLARATION:
902 switch (parent->type) {
904 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
907 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
916 BT_LOGE("Unknown node type: node-type=%d", parent->type);
923 void yyerror(struct ctf_scanner *scanner, yyscan_t yyscanner, const char *str)
925 _BT_LOGE_APPEND_CAUSE_LINENO(yyget_lineno(scanner->scanner),
926 "%s: token=\"%s\"", str, yyget_text(scanner->scanner));
929 #define reparent_error(scanner, str) \
931 yyerror(scanner, scanner->scanner, YY_("reparent_error: " str)); \
935 static struct ctf_ast *ctf_ast_alloc(struct ctf_scanner *scanner)
939 ast = objstack_alloc(scanner->objstack, sizeof(*ast));
942 ast->root.type = NODE_ROOT;
943 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
944 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
945 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
946 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
947 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
948 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
949 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
950 BT_INIT_LIST_HEAD(&ast->root.u.root.callsite);
954 int ctf_scanner_append_ast(struct ctf_scanner *scanner, FILE *input)
956 /* Start processing new stream */
957 yyrestart(input, scanner->scanner);
958 return yyparse(scanner, scanner->scanner);
961 struct ctf_scanner *ctf_scanner_alloc(void)
963 struct ctf_scanner *scanner;
966 scanner = malloc(sizeof(*scanner));
969 memset(scanner, 0, sizeof(*scanner));
970 ret = yylex_init_extra(scanner, &scanner->scanner);
972 BT_LOGE("yylex_init_extra() failed: ret=%d", ret);
973 goto cleanup_scanner;
975 scanner->objstack = objstack_create();
976 if (!scanner->objstack)
978 scanner->ast = ctf_ast_alloc(scanner);
980 goto cleanup_objstack;
981 init_scope(&scanner->root_scope, NULL);
982 scanner->cs = &scanner->root_scope;
987 objstack_destroy(scanner->objstack);
989 ret = yylex_destroy(scanner->scanner);
991 BT_LOGE("yylex_destroy() failed: scanner-addr=%p, ret=%d",
998 void ctf_scanner_free(struct ctf_scanner *scanner)
1005 struct ctf_scanner_scope *scope = scanner->cs;
1008 struct ctf_scanner_scope *parent = scope->parent;
1009 finalize_scope(scope);
1012 * The root scope is allocated within the ctf_scanner structure,
1013 * do doesn't need freeing. All others are allocated on their
1016 if (scope != &scanner->root_scope)
1022 objstack_destroy(scanner->objstack);
1023 ret = yylex_destroy(scanner->scanner);
1025 BT_LOGE("yylex_destroy() failed: scanner-addr=%p, ret=%d",
1031 * The bison-provided version of strlen (yystrlen) generates a benign
1032 * -Wnull-dereference warning. That version is used when building on cygwin,
1033 * for example, but you can also enable it by hand (to test) by removing the
1034 * preprocessor conditional around it.
1036 * Define yystrlen such that it will always use strlen. As far as we know,
1037 * strlen provided by all the platforms we use is reliable.
1039 #define yystrlen strlen
1044 * This ends up in parser.h and makes sure those who want to include it pass
1045 * through parser-wrap.h.
1048 #ifndef ALLOW_INCLUDE_PARSER_H
1049 # error "Don't include parser.h directly, include parser-wrap.h instead."
1055 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src);
1058 int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src, char delim);
1064 %parse-param {struct ctf_scanner *scanner}
1065 %parse-param {yyscan_t yyscanner}
1066 %lex-param {yyscan_t yyscanner}
1068 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
1069 * vs struct { int :value; } (unnamed bit-field). The default is to
1070 * shift, so whenever we encounter an enumeration, we are doing the
1071 * proper thing (shift). It is illegal to declare an enumeration
1072 * "bit-field", so it is OK if this situation ends up in a parsing
1077 %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
1078 %token <s> IDENTIFIER ID_TYPE
1083 unsigned long long ull;
1089 %type <s> CTF_STRING_LITERAL CTF_CHARACTER_LITERAL
1093 %type <ull> CTF_INTEGER_LITERAL
1094 %type <n> postfix_expression unary_expression unary_expression_or_range
1096 %type <n> declaration
1097 %type <n> event_declaration
1098 %type <n> stream_declaration
1099 %type <n> env_declaration
1100 %type <n> trace_declaration
1101 %type <n> clock_declaration
1102 %type <n> callsite_declaration
1103 %type <n> integer_declaration_specifiers
1104 %type <n> declaration_specifiers
1105 %type <n> alias_declaration_specifiers
1107 %type <n> field_class_declarator_list
1108 %type <n> integer_field_class_specifier
1109 %type <n> field_class_specifier
1110 %type <n> struct_class_specifier
1111 %type <n> variant_field_class_specifier
1112 %type <n> enum_field_class_specifier
1113 %type <n> struct_or_variant_declaration_list
1114 %type <n> struct_or_variant_declaration
1115 %type <n> struct_or_variant_declarator_list
1116 %type <n> struct_or_variant_declarator
1117 %type <n> enumerator_list
1118 %type <n> enumerator
1119 %type <n> abstract_declarator_list
1120 %type <n> abstract_declarator
1121 %type <n> direct_abstract_declarator
1122 %type <n> alias_abstract_declarator_list
1123 %type <n> alias_abstract_declarator
1124 %type <n> direct_alias_abstract_declarator
1125 %type <n> declarator
1126 %type <n> direct_declarator
1127 %type <n> field_class_declarator
1128 %type <n> direct_field_class_declarator
1130 %type <n> ctf_assignment_expression_list
1131 %type <n> ctf_assignment_expression
1138 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
1139 reparent_error(scanner, "error reparenting to root");
1143 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
1144 reparent_error(scanner, "error reparenting to root");
1173 | CTF_FLOATING_POINT
1206 /* 2: Phrase structure grammar */
1211 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1212 $$->u.unary_expression.type = UNARY_STRING;
1213 $$->u.unary_expression.u.string = yylval.s;
1217 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1218 $$->u.unary_expression.type = UNARY_STRING;
1219 $$->u.unary_expression.u.string = yylval.s;
1223 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1224 $$->u.unary_expression.type = UNARY_STRING;
1225 $$->u.unary_expression.u.string = yylval.s;
1227 | CTF_INTEGER_LITERAL
1229 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1230 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1231 $$->u.unary_expression.u.unsigned_constant = $1;
1233 | CTF_STRING_LITERAL
1235 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1236 $$->u.unary_expression.type = UNARY_STRING;
1237 $$->u.unary_expression.u.string = $1;
1239 | CTF_CHARACTER_LITERAL
1241 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1242 $$->u.unary_expression.type = UNARY_STRING;
1243 $$->u.unary_expression.u.string = $1;
1245 | CTF_LPAREN unary_expression CTF_RPAREN
1249 | postfix_expression CTF_LSBRAC unary_expression CTF_RSBRAC
1251 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1252 $$->u.unary_expression.type = UNARY_SBRAC;
1253 $$->u.unary_expression.u.sbrac_exp = $3;
1254 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1255 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1257 | postfix_expression CTF_DOT IDENTIFIER
1259 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1260 $$->u.unary_expression.type = UNARY_STRING;
1261 $$->u.unary_expression.u.string = yylval.s;
1262 $$->u.unary_expression.link = UNARY_DOTLINK;
1263 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1264 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1266 | postfix_expression CTF_DOT ID_TYPE
1268 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1269 $$->u.unary_expression.type = UNARY_STRING;
1270 $$->u.unary_expression.u.string = yylval.s;
1271 $$->u.unary_expression.link = UNARY_DOTLINK;
1272 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1273 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1275 | postfix_expression CTF_DOT keywords
1277 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1278 $$->u.unary_expression.type = UNARY_STRING;
1279 $$->u.unary_expression.u.string = yylval.s;
1280 $$->u.unary_expression.link = UNARY_DOTLINK;
1281 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1282 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1284 | postfix_expression CTF_RARROW IDENTIFIER
1286 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1287 $$->u.unary_expression.type = UNARY_STRING;
1288 $$->u.unary_expression.u.string = yylval.s;
1289 $$->u.unary_expression.link = UNARY_ARROWLINK;
1290 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1291 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1293 | postfix_expression CTF_RARROW ID_TYPE
1295 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1296 $$->u.unary_expression.type = UNARY_STRING;
1297 $$->u.unary_expression.u.string = yylval.s;
1298 $$->u.unary_expression.link = UNARY_ARROWLINK;
1299 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1300 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1307 | CTF_PLUS postfix_expression
1310 if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
1311 && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
1312 reparent_error(scanner, "expecting numeric constant");
1315 | CTF_MINUS postfix_expression
1318 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1319 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1320 $$->u.unary_expression.u.signed_constant =
1321 -($$->u.unary_expression.u.unsigned_constant);
1322 } else if ($$->u.unary_expression.type == UNARY_SIGNED_CONSTANT) {
1323 $$->u.unary_expression.u.signed_constant =
1324 -($$->u.unary_expression.u.signed_constant);
1326 reparent_error(scanner, "expecting numeric constant");
1331 unary_expression_or_range:
1332 unary_expression CTF_DOTDOTDOT unary_expression
1335 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1336 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1342 /* 2.2: Declarations */
1345 declaration_specifiers CTF_SEMICOLON
1349 | stream_declaration
1357 | callsite_declaration
1359 | declaration_specifiers CTF_TYPEDEF declaration_specifiers field_class_declarator_list CTF_SEMICOLON
1361 struct ctf_node *list;
1363 $$ = make_node(scanner, NODE_TYPEDEF);
1364 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1365 $$->u.field_class_def.field_class_specifier_list = list;
1366 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1367 _bt_list_splice_tail(&($3)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1368 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
1370 | CTF_TYPEDEF declaration_specifiers field_class_declarator_list CTF_SEMICOLON
1372 struct ctf_node *list;
1374 $$ = make_node(scanner, NODE_TYPEDEF);
1375 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1376 $$->u.field_class_def.field_class_specifier_list = list;
1377 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1378 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
1380 | declaration_specifiers CTF_TYPEDEF field_class_declarator_list CTF_SEMICOLON
1382 struct ctf_node *list;
1384 $$ = make_node(scanner, NODE_TYPEDEF);
1385 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1386 $$->u.field_class_def.field_class_specifier_list = list;
1387 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1388 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
1390 | CTF_TYPEALIAS declaration_specifiers abstract_declarator_list CTF_TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list CTF_SEMICOLON
1392 struct ctf_node *list;
1394 $$ = make_node(scanner, NODE_TYPEALIAS);
1395 $$->u.field_class_alias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1396 $$->u.field_class_alias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1398 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1399 $$->u.field_class_alias.target->u.field_class_alias_target.field_class_specifier_list = list;
1400 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1401 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_alias.target->u.field_class_alias_target.field_class_declarators);
1403 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1404 $$->u.field_class_alias.alias->u.field_class_alias_name.field_class_specifier_list = list;
1405 _bt_list_splice_tail(&($5)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1406 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.field_class_alias.alias->u.field_class_alias_name.field_class_declarators);
1411 event_declaration_begin event_declaration_end
1413 $$ = make_node(scanner, NODE_EVENT);
1415 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1417 $$ = make_node(scanner, NODE_EVENT);
1418 if (set_parent_node($2, $$))
1419 reparent_error(scanner, "event_declaration");
1423 event_declaration_begin:
1425 { push_scope(scanner); }
1428 event_declaration_end:
1429 CTF_RBRAC CTF_SEMICOLON
1430 { pop_scope(scanner); }
1435 stream_declaration_begin stream_declaration_end
1437 $$ = make_node(scanner, NODE_STREAM);
1439 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1441 $$ = make_node(scanner, NODE_STREAM);
1442 if (set_parent_node($2, $$))
1443 reparent_error(scanner, "stream_declaration");
1447 stream_declaration_begin:
1448 CTF_STREAM CTF_LBRAC
1449 { push_scope(scanner); }
1452 stream_declaration_end:
1453 CTF_RBRAC CTF_SEMICOLON
1454 { pop_scope(scanner); }
1458 env_declaration_begin env_declaration_end
1460 $$ = make_node(scanner, NODE_ENV);
1462 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1464 $$ = make_node(scanner, NODE_ENV);
1465 if (set_parent_node($2, $$))
1466 reparent_error(scanner, "env declaration");
1470 env_declaration_begin:
1472 { push_scope(scanner); }
1475 env_declaration_end:
1476 CTF_RBRAC CTF_SEMICOLON
1477 { pop_scope(scanner); }
1481 trace_declaration_begin trace_declaration_end
1483 $$ = make_node(scanner, NODE_TRACE);
1485 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1487 $$ = make_node(scanner, NODE_TRACE);
1488 if (set_parent_node($2, $$))
1489 reparent_error(scanner, "trace_declaration");
1493 trace_declaration_begin:
1495 { push_scope(scanner); }
1498 trace_declaration_end:
1499 CTF_RBRAC CTF_SEMICOLON
1500 { pop_scope(scanner); }
1504 CTF_CLOCK clock_declaration_begin clock_declaration_end
1506 $$ = make_node(scanner, NODE_CLOCK);
1508 | CTF_CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1510 $$ = make_node(scanner, NODE_CLOCK);
1511 if (set_parent_node($3, $$))
1512 reparent_error(scanner, "trace_declaration");
1516 clock_declaration_begin:
1518 { push_scope(scanner); }
1521 clock_declaration_end:
1522 CTF_RBRAC CTF_SEMICOLON
1523 { pop_scope(scanner); }
1526 callsite_declaration:
1527 CTF_CALLSITE callsite_declaration_begin callsite_declaration_end
1529 $$ = make_node(scanner, NODE_CALLSITE);
1531 | CTF_CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1533 $$ = make_node(scanner, NODE_CALLSITE);
1534 if (set_parent_node($3, $$))
1535 reparent_error(scanner, "trace_declaration");
1539 callsite_declaration_begin:
1541 { push_scope(scanner); }
1544 callsite_declaration_end:
1545 CTF_RBRAC CTF_SEMICOLON
1546 { pop_scope(scanner); }
1549 integer_declaration_specifiers:
1552 struct ctf_node *node;
1554 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1555 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1556 node->u.field_class_specifier.type = TYPESPEC_CONST;
1557 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1559 | integer_field_class_specifier
1561 struct ctf_node *node;
1563 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1565 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1567 | integer_declaration_specifiers CTF_CONST
1569 struct ctf_node *node;
1572 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1573 node->u.field_class_specifier.type = TYPESPEC_CONST;
1574 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1576 | integer_declaration_specifiers integer_field_class_specifier
1579 bt_list_add_tail(&($2)->siblings, &($$)->u.field_class_specifier_list.head);
1583 declaration_specifiers:
1586 struct ctf_node *node;
1588 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1589 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1590 node->u.field_class_specifier.type = TYPESPEC_CONST;
1591 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1593 | field_class_specifier
1595 struct ctf_node *node;
1597 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1599 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1601 | declaration_specifiers CTF_CONST
1603 struct ctf_node *node;
1606 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1607 node->u.field_class_specifier.type = TYPESPEC_CONST;
1608 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1610 | declaration_specifiers field_class_specifier
1613 bt_list_add_tail(&($2)->siblings, &($$)->u.field_class_specifier_list.head);
1617 field_class_declarator_list:
1618 field_class_declarator
1620 | field_class_declarator_list CTF_COMMA field_class_declarator
1623 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1627 integer_field_class_specifier:
1630 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1631 $$->u.field_class_specifier.type = TYPESPEC_CHAR;
1635 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1636 $$->u.field_class_specifier.type = TYPESPEC_SHORT;
1640 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1641 $$->u.field_class_specifier.type = TYPESPEC_INT;
1645 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1646 $$->u.field_class_specifier.type = TYPESPEC_LONG;
1650 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1651 $$->u.field_class_specifier.type = TYPESPEC_SIGNED;
1655 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1656 $$->u.field_class_specifier.type = TYPESPEC_UNSIGNED;
1660 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1661 $$->u.field_class_specifier.type = TYPESPEC_BOOL;
1665 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1666 $$->u.field_class_specifier.type = TYPESPEC_ID_TYPE;
1667 $$->u.field_class_specifier.id_type = yylval.s;
1669 | CTF_INTEGER CTF_LBRAC CTF_RBRAC
1671 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1672 $$->u.field_class_specifier.type = TYPESPEC_INTEGER;
1673 $$->u.field_class_specifier.node = make_node(scanner, NODE_INTEGER);
1675 | CTF_INTEGER CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1677 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1678 $$->u.field_class_specifier.type = TYPESPEC_INTEGER;
1679 $$->u.field_class_specifier.node = make_node(scanner, NODE_INTEGER);
1680 if (set_parent_node($3, $$->u.field_class_specifier.node))
1681 reparent_error(scanner, "integer reparent error");
1685 field_class_specifier:
1688 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1689 $$->u.field_class_specifier.type = TYPESPEC_VOID;
1693 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1694 $$->u.field_class_specifier.type = TYPESPEC_CHAR;
1698 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1699 $$->u.field_class_specifier.type = TYPESPEC_SHORT;
1703 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1704 $$->u.field_class_specifier.type = TYPESPEC_INT;
1708 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1709 $$->u.field_class_specifier.type = TYPESPEC_LONG;
1713 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1714 $$->u.field_class_specifier.type = TYPESPEC_FLOAT;
1718 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1719 $$->u.field_class_specifier.type = TYPESPEC_DOUBLE;
1723 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1724 $$->u.field_class_specifier.type = TYPESPEC_SIGNED;
1728 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1729 $$->u.field_class_specifier.type = TYPESPEC_UNSIGNED;
1733 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1734 $$->u.field_class_specifier.type = TYPESPEC_BOOL;
1738 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1739 $$->u.field_class_specifier.type = TYPESPEC_COMPLEX;
1743 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1744 $$->u.field_class_specifier.type = TYPESPEC_IMAGINARY;
1748 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1749 $$->u.field_class_specifier.type = TYPESPEC_ID_TYPE;
1750 $$->u.field_class_specifier.id_type = yylval.s;
1752 | CTF_FLOATING_POINT CTF_LBRAC CTF_RBRAC
1754 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1755 $$->u.field_class_specifier.type = TYPESPEC_FLOATING_POINT;
1756 $$->u.field_class_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1758 | CTF_FLOATING_POINT CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1760 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1761 $$->u.field_class_specifier.type = TYPESPEC_FLOATING_POINT;
1762 $$->u.field_class_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1763 if (set_parent_node($3, $$->u.field_class_specifier.node))
1764 reparent_error(scanner, "floating point reparent error");
1766 | CTF_INTEGER CTF_LBRAC CTF_RBRAC
1768 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1769 $$->u.field_class_specifier.type = TYPESPEC_INTEGER;
1770 $$->u.field_class_specifier.node = make_node(scanner, NODE_INTEGER);
1772 | CTF_INTEGER CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1774 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1775 $$->u.field_class_specifier.type = TYPESPEC_INTEGER;
1776 $$->u.field_class_specifier.node = make_node(scanner, NODE_INTEGER);
1777 if (set_parent_node($3, $$->u.field_class_specifier.node))
1778 reparent_error(scanner, "integer reparent error");
1782 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1783 $$->u.field_class_specifier.type = TYPESPEC_STRING;
1784 $$->u.field_class_specifier.node = make_node(scanner, NODE_STRING);
1786 | CTF_STRING CTF_LBRAC CTF_RBRAC
1788 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1789 $$->u.field_class_specifier.type = TYPESPEC_STRING;
1790 $$->u.field_class_specifier.node = make_node(scanner, NODE_STRING);
1792 | CTF_STRING CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1794 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1795 $$->u.field_class_specifier.type = TYPESPEC_STRING;
1796 $$->u.field_class_specifier.node = make_node(scanner, NODE_STRING);
1797 if (set_parent_node($3, $$->u.field_class_specifier.node))
1798 reparent_error(scanner, "string reparent error");
1800 | CTF_ENUM enum_field_class_specifier
1802 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1803 $$->u.field_class_specifier.type = TYPESPEC_ENUM;
1804 $$->u.field_class_specifier.node = $2;
1806 | CTF_VARIANT variant_field_class_specifier
1808 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1809 $$->u.field_class_specifier.type = TYPESPEC_VARIANT;
1810 $$->u.field_class_specifier.node = $2;
1812 | CTF_STRUCT struct_class_specifier
1814 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1815 $$->u.field_class_specifier.type = TYPESPEC_STRUCT;
1816 $$->u.field_class_specifier.node = $2;
1820 struct_class_specifier:
1821 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1823 $$ = make_node(scanner, NODE_STRUCT);
1824 $$->u._struct.has_body = 1;
1825 if ($2 && set_parent_node($2, $$))
1826 reparent_error(scanner, "struct reparent error");
1828 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1830 $$ = make_node(scanner, NODE_STRUCT);
1831 $$->u._struct.has_body = 1;
1832 $$->u._struct.name = $1;
1833 if ($3 && set_parent_node($3, $$))
1834 reparent_error(scanner, "struct reparent error");
1836 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1838 $$ = make_node(scanner, NODE_STRUCT);
1839 $$->u._struct.has_body = 1;
1840 $$->u._struct.name = $1;
1841 if ($3 && set_parent_node($3, $$))
1842 reparent_error(scanner, "struct reparent error");
1846 $$ = make_node(scanner, NODE_STRUCT);
1847 $$->u._struct.has_body = 0;
1848 $$->u._struct.name = $1;
1852 $$ = make_node(scanner, NODE_STRUCT);
1853 $$->u._struct.has_body = 0;
1854 $$->u._struct.name = $1;
1856 | 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 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1861 if ($2 && set_parent_node($2, $$))
1862 reparent_error(scanner, "struct reparent error");
1864 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end CTF_TOK_ALIGN CTF_LPAREN unary_expression CTF_RPAREN
1866 $$ = make_node(scanner, NODE_STRUCT);
1867 $$->u._struct.has_body = 1;
1868 $$->u._struct.name = $1;
1869 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1870 if ($3 && set_parent_node($3, $$))
1871 reparent_error(scanner, "struct reparent error");
1873 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end CTF_TOK_ALIGN CTF_LPAREN unary_expression CTF_RPAREN
1875 $$ = make_node(scanner, NODE_STRUCT);
1876 $$->u._struct.has_body = 1;
1877 $$->u._struct.name = $1;
1878 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1879 if ($3 && set_parent_node($3, $$))
1880 reparent_error(scanner, "struct reparent error");
1884 struct_declaration_begin:
1886 { push_scope(scanner); }
1889 struct_declaration_end:
1891 { pop_scope(scanner); }
1894 variant_field_class_specifier:
1895 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1897 $$ = make_node(scanner, NODE_VARIANT);
1898 $$->u.variant.has_body = 1;
1899 if ($2 && set_parent_node($2, $$))
1900 reparent_error(scanner, "variant reparent error");
1902 | CTF_LT IDENTIFIER CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1904 $$ = make_node(scanner, NODE_VARIANT);
1905 $$->u.variant.has_body = 1;
1906 $$->u.variant.choice = $2;
1907 if ($5 && set_parent_node($5, $$))
1908 reparent_error(scanner, "variant reparent error");
1910 | CTF_LT ID_TYPE CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1912 $$ = make_node(scanner, NODE_VARIANT);
1913 $$->u.variant.has_body = 1;
1914 $$->u.variant.choice = $2;
1915 if ($5 && set_parent_node($5, $$))
1916 reparent_error(scanner, "variant reparent error");
1918 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1920 $$ = make_node(scanner, NODE_VARIANT);
1921 $$->u.variant.has_body = 1;
1922 $$->u.variant.name = $1;
1923 if ($3 && set_parent_node($3, $$))
1924 reparent_error(scanner, "variant reparent error");
1926 | IDENTIFIER CTF_LT IDENTIFIER CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1928 $$ = make_node(scanner, NODE_VARIANT);
1929 $$->u.variant.has_body = 1;
1930 $$->u.variant.name = $1;
1931 $$->u.variant.choice = $3;
1932 if ($6 && set_parent_node($6, $$))
1933 reparent_error(scanner, "variant reparent error");
1935 | IDENTIFIER CTF_LT IDENTIFIER CTF_GT
1937 $$ = make_node(scanner, NODE_VARIANT);
1938 $$->u.variant.has_body = 0;
1939 $$->u.variant.name = $1;
1940 $$->u.variant.choice = $3;
1942 | IDENTIFIER CTF_LT ID_TYPE CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1944 $$ = make_node(scanner, NODE_VARIANT);
1945 $$->u.variant.has_body = 1;
1946 $$->u.variant.name = $1;
1947 $$->u.variant.choice = $3;
1948 if ($6 && set_parent_node($6, $$))
1949 reparent_error(scanner, "variant reparent error");
1951 | IDENTIFIER CTF_LT ID_TYPE CTF_GT
1953 $$ = make_node(scanner, NODE_VARIANT);
1954 $$->u.variant.has_body = 0;
1955 $$->u.variant.name = $1;
1956 $$->u.variant.choice = $3;
1958 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1960 $$ = make_node(scanner, NODE_VARIANT);
1961 $$->u.variant.has_body = 1;
1962 $$->u.variant.name = $1;
1963 if ($3 && set_parent_node($3, $$))
1964 reparent_error(scanner, "variant reparent error");
1966 | ID_TYPE CTF_LT IDENTIFIER CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1968 $$ = make_node(scanner, NODE_VARIANT);
1969 $$->u.variant.has_body = 1;
1970 $$->u.variant.name = $1;
1971 $$->u.variant.choice = $3;
1972 if ($6 && set_parent_node($6, $$))
1973 reparent_error(scanner, "variant reparent error");
1975 | ID_TYPE CTF_LT IDENTIFIER CTF_GT
1977 $$ = make_node(scanner, NODE_VARIANT);
1978 $$->u.variant.has_body = 0;
1979 $$->u.variant.name = $1;
1980 $$->u.variant.choice = $3;
1982 | ID_TYPE CTF_LT ID_TYPE CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1984 $$ = make_node(scanner, NODE_VARIANT);
1985 $$->u.variant.has_body = 1;
1986 $$->u.variant.name = $1;
1987 $$->u.variant.choice = $3;
1988 if ($6 && set_parent_node($6, $$))
1989 reparent_error(scanner, "variant reparent error");
1991 | ID_TYPE CTF_LT ID_TYPE CTF_GT
1993 $$ = make_node(scanner, NODE_VARIANT);
1994 $$->u.variant.has_body = 0;
1995 $$->u.variant.name = $1;
1996 $$->u.variant.choice = $3;
2000 variant_declaration_begin:
2002 { push_scope(scanner); }
2005 variant_declaration_end:
2007 { pop_scope(scanner); }
2010 enum_field_class_specifier:
2011 CTF_LBRAC enumerator_list CTF_RBRAC
2013 $$ = make_node(scanner, NODE_ENUM);
2014 $$->u._enum.has_body = 1;
2015 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2017 | CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_RBRAC
2019 $$ = make_node(scanner, NODE_ENUM);
2020 $$->u._enum.has_body = 1;
2021 ($$)->u._enum.container_field_class = $2;
2022 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2024 | IDENTIFIER 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 | IDENTIFIER 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 | ID_TYPE CTF_LBRAC enumerator_list CTF_RBRAC
2041 $$ = make_node(scanner, NODE_ENUM);
2042 $$->u._enum.has_body = 1;
2043 $$->u._enum.enum_id = $1;
2044 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2046 | ID_TYPE CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_RBRAC
2048 $$ = make_node(scanner, NODE_ENUM);
2049 $$->u._enum.has_body = 1;
2050 $$->u._enum.enum_id = $1;
2051 ($$)->u._enum.container_field_class = $3;
2052 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2054 | CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2056 $$ = make_node(scanner, NODE_ENUM);
2057 $$->u._enum.has_body = 1;
2058 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2060 | CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2062 $$ = make_node(scanner, NODE_ENUM);
2063 $$->u._enum.has_body = 1;
2064 ($$)->u._enum.container_field_class = $2;
2065 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2067 | IDENTIFIER CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2069 $$ = make_node(scanner, NODE_ENUM);
2070 $$->u._enum.has_body = 1;
2071 $$->u._enum.enum_id = $1;
2072 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2074 | IDENTIFIER CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2076 $$ = make_node(scanner, NODE_ENUM);
2077 $$->u._enum.has_body = 1;
2078 $$->u._enum.enum_id = $1;
2079 ($$)->u._enum.container_field_class = $3;
2080 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2084 $$ = make_node(scanner, NODE_ENUM);
2085 $$->u._enum.has_body = 0;
2086 $$->u._enum.enum_id = $1;
2088 | ID_TYPE CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2090 $$ = make_node(scanner, NODE_ENUM);
2091 $$->u._enum.has_body = 1;
2092 $$->u._enum.enum_id = $1;
2093 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2095 | ID_TYPE CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2097 $$ = make_node(scanner, NODE_ENUM);
2098 $$->u._enum.has_body = 1;
2099 $$->u._enum.enum_id = $1;
2100 ($$)->u._enum.container_field_class = $3;
2101 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2105 $$ = make_node(scanner, NODE_ENUM);
2106 $$->u._enum.has_body = 0;
2107 $$->u._enum.enum_id = $1;
2111 struct_or_variant_declaration_list:
2114 | struct_or_variant_declaration_list struct_or_variant_declaration
2118 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2121 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
2126 struct_or_variant_declaration:
2127 declaration_specifiers struct_or_variant_declarator_list CTF_SEMICOLON
2129 struct ctf_node *list;
2131 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2132 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2133 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
2134 ($$)->u.struct_or_variant_declaration.field_class_specifier_list = list;
2135 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.field_class_declarators);
2137 | declaration_specifiers CTF_TYPEDEF declaration_specifiers field_class_declarator_list CTF_SEMICOLON
2139 struct ctf_node *list;
2141 $$ = make_node(scanner, NODE_TYPEDEF);
2142 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2143 $$->u.field_class_def.field_class_specifier_list = list;
2144 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2145 _bt_list_splice_tail(&($3)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2146 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2148 | CTF_TYPEDEF declaration_specifiers field_class_declarator_list CTF_SEMICOLON
2150 struct ctf_node *list;
2152 $$ = make_node(scanner, NODE_TYPEDEF);
2153 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2154 $$->u.field_class_def.field_class_specifier_list = list;
2155 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2156 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2158 | declaration_specifiers CTF_TYPEDEF field_class_declarator_list CTF_SEMICOLON
2160 struct ctf_node *list;
2162 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2163 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2164 $$ = make_node(scanner, NODE_TYPEDEF);
2165 ($$)->u.struct_or_variant_declaration.field_class_specifier_list = list;
2166 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2168 | CTF_TYPEALIAS declaration_specifiers abstract_declarator_list CTF_TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list CTF_SEMICOLON
2170 struct ctf_node *list;
2172 $$ = make_node(scanner, NODE_TYPEALIAS);
2173 $$->u.field_class_alias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2174 $$->u.field_class_alias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2176 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2177 $$->u.field_class_alias.target->u.field_class_alias_target.field_class_specifier_list = list;
2178 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2179 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_alias.target->u.field_class_alias_target.field_class_declarators);
2181 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2182 $$->u.field_class_alias.alias->u.field_class_alias_name.field_class_specifier_list = list;
2183 _bt_list_splice_tail(&($5)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2184 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.field_class_alias.alias->u.field_class_alias_name.field_class_declarators);
2188 alias_declaration_specifiers:
2191 struct ctf_node *node;
2193 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2194 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2195 node->u.field_class_specifier.type = TYPESPEC_CONST;
2196 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2198 | field_class_specifier
2200 struct ctf_node *node;
2202 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2204 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2208 struct ctf_node *node;
2210 add_type(scanner, $1);
2211 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2212 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2213 node->u.field_class_specifier.type = TYPESPEC_ID_TYPE;
2214 node->u.field_class_specifier.id_type = yylval.s;
2215 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2217 | alias_declaration_specifiers CTF_CONST
2219 struct ctf_node *node;
2222 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2223 node->u.field_class_specifier.type = TYPESPEC_CONST;
2224 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2226 | alias_declaration_specifiers field_class_specifier
2229 bt_list_add_tail(&($2)->siblings, &($$)->u.field_class_specifier_list.head);
2231 | alias_declaration_specifiers IDENTIFIER
2233 struct ctf_node *node;
2235 add_type(scanner, $2);
2237 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2238 node->u.field_class_specifier.type = TYPESPEC_ID_TYPE;
2239 node->u.field_class_specifier.id_type = yylval.s;
2240 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2244 struct_or_variant_declarator_list:
2245 struct_or_variant_declarator
2247 | struct_or_variant_declarator_list CTF_COMMA struct_or_variant_declarator
2250 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2254 struct_or_variant_declarator:
2257 | CTF_COLON unary_expression
2259 | declarator CTF_COLON unary_expression
2262 if (set_parent_node($3, $1))
2263 reparent_error(scanner, "struct_or_variant_declarator");
2270 | enumerator_list CTF_COMMA enumerator
2273 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2280 $$ = make_node(scanner, NODE_ENUMERATOR);
2281 $$->u.enumerator.id = $1;
2285 $$ = make_node(scanner, NODE_ENUMERATOR);
2286 $$->u.enumerator.id = $1;
2290 $$ = make_node(scanner, NODE_ENUMERATOR);
2291 $$->u.enumerator.id = $1;
2293 | CTF_STRING_LITERAL
2295 $$ = make_node(scanner, NODE_ENUMERATOR);
2296 $$->u.enumerator.id = $1;
2298 | IDENTIFIER CTF_EQUAL unary_expression_or_range
2300 $$ = make_node(scanner, NODE_ENUMERATOR);
2301 $$->u.enumerator.id = $1;
2302 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2304 | ID_TYPE CTF_EQUAL unary_expression_or_range
2306 $$ = make_node(scanner, NODE_ENUMERATOR);
2307 $$->u.enumerator.id = $1;
2308 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2310 | keywords CTF_EQUAL unary_expression_or_range
2312 $$ = make_node(scanner, NODE_ENUMERATOR);
2313 $$->u.enumerator.id = $1;
2314 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2316 | CTF_STRING_LITERAL CTF_EQUAL unary_expression_or_range
2318 $$ = make_node(scanner, NODE_ENUMERATOR);
2319 $$->u.enumerator.id = $1;
2320 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2324 abstract_declarator_list:
2327 | abstract_declarator_list CTF_COMMA abstract_declarator
2330 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2334 abstract_declarator:
2335 direct_abstract_declarator
2337 | pointer direct_abstract_declarator
2340 bt_list_splice(&($1)->tmp_head, &($$)->u.field_class_declarator.pointers);
2344 direct_abstract_declarator:
2347 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2348 $$->u.field_class_declarator.type = TYPEDEC_ID;
2353 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2354 $$->u.field_class_declarator.type = TYPEDEC_ID;
2355 $$->u.field_class_declarator.u.id = $1;
2357 | CTF_LPAREN abstract_declarator CTF_RPAREN
2359 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2360 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2361 $$->u.field_class_declarator.u.nested.field_class_declarator = $2;
2363 | direct_abstract_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2365 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2366 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2367 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2368 BT_INIT_LIST_HEAD(&($$)->u.field_class_declarator.u.nested.length);
2369 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_declarator.u.nested.length);
2371 | direct_abstract_declarator CTF_LSBRAC CTF_RSBRAC
2373 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2374 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2375 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2376 $$->u.field_class_declarator.u.nested.abstract_array = 1;
2380 alias_abstract_declarator_list:
2381 alias_abstract_declarator
2383 | alias_abstract_declarator_list CTF_COMMA alias_abstract_declarator
2386 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2390 alias_abstract_declarator:
2391 direct_alias_abstract_declarator
2393 | pointer direct_alias_abstract_declarator
2396 bt_list_splice(&($1)->tmp_head, &($$)->u.field_class_declarator.pointers);
2400 direct_alias_abstract_declarator:
2403 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2404 $$->u.field_class_declarator.type = TYPEDEC_ID;
2407 | CTF_LPAREN alias_abstract_declarator CTF_RPAREN
2409 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2410 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2411 $$->u.field_class_declarator.u.nested.field_class_declarator = $2;
2413 | direct_alias_abstract_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2415 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2416 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2417 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2418 BT_INIT_LIST_HEAD(&($$)->u.field_class_declarator.u.nested.length);
2419 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_declarator.u.nested.length);
2421 | direct_alias_abstract_declarator CTF_LSBRAC CTF_RSBRAC
2423 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2424 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2425 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2426 $$->u.field_class_declarator.u.nested.abstract_array = 1;
2433 | pointer direct_declarator
2436 bt_list_splice(&($1)->tmp_head, &($$)->u.field_class_declarator.pointers);
2443 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2444 $$->u.field_class_declarator.type = TYPEDEC_ID;
2445 $$->u.field_class_declarator.u.id = $1;
2447 | CTF_LPAREN declarator CTF_RPAREN
2449 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2450 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2451 $$->u.field_class_declarator.u.nested.field_class_declarator = $2;
2453 | direct_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2455 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2456 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2457 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2458 BT_INIT_LIST_HEAD(&($$)->u.field_class_declarator.u.nested.length);
2459 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_declarator.u.nested.length);
2463 field_class_declarator:
2464 direct_field_class_declarator
2466 | pointer direct_field_class_declarator
2469 bt_list_splice(&($1)->tmp_head, &($$)->u.field_class_declarator.pointers);
2473 direct_field_class_declarator:
2476 add_type(scanner, $1);
2477 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2478 $$->u.field_class_declarator.type = TYPEDEC_ID;
2479 $$->u.field_class_declarator.u.id = $1;
2481 | CTF_LPAREN field_class_declarator CTF_RPAREN
2483 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2484 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2485 $$->u.field_class_declarator.u.nested.field_class_declarator = $2;
2487 | direct_field_class_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2489 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2490 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2491 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2492 BT_INIT_LIST_HEAD(&($$)->u.field_class_declarator.u.nested.length);
2493 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_declarator.u.nested.length);
2500 $$ = make_node(scanner, NODE_POINTER);
2504 $$ = make_node(scanner, NODE_POINTER);
2505 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2507 | CTF_STAR type_qualifier_list pointer
2509 $$ = make_node(scanner, NODE_POINTER);
2510 $$->u.pointer.const_qualifier = 1;
2511 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2515 type_qualifier_list:
2516 /* pointer assumes only const type qualifier */
2518 | type_qualifier_list CTF_CONST
2521 /* 2.3: CTF-specific declarations */
2523 ctf_assignment_expression_list:
2524 ctf_assignment_expression CTF_SEMICOLON
2526 | ctf_assignment_expression_list ctf_assignment_expression CTF_SEMICOLON
2529 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2533 ctf_assignment_expression:
2534 unary_expression CTF_EQUAL unary_expression
2537 * Because we have left and right, cannot use
2540 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2541 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2542 if ($1->u.unary_expression.type != UNARY_STRING)
2543 reparent_error(scanner, "ctf_assignment_expression left expects string");
2544 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2546 | unary_expression CTF_TYPEASSIGN declaration_specifiers /* Only allow struct */
2549 * Because we have left and right, cannot use
2552 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2553 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2554 if ($1->u.unary_expression.type != UNARY_STRING)
2555 reparent_error(scanner, "ctf_assignment_expression left expects string");
2556 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2558 | declaration_specifiers CTF_TYPEDEF declaration_specifiers field_class_declarator_list
2560 struct ctf_node *list;
2562 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2563 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2564 _bt_list_splice_tail(&($3)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2565 $$ = make_node(scanner, NODE_TYPEDEF);
2566 ($$)->u.struct_or_variant_declaration.field_class_specifier_list = list;
2567 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2569 | CTF_TYPEDEF declaration_specifiers field_class_declarator_list
2571 struct ctf_node *list;
2573 $$ = make_node(scanner, NODE_TYPEDEF);
2574 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2575 $$->u.field_class_def.field_class_specifier_list = list;
2576 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2577 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2579 | declaration_specifiers CTF_TYPEDEF field_class_declarator_list
2581 struct ctf_node *list;
2583 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2584 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2585 $$ = make_node(scanner, NODE_TYPEDEF);
2586 ($$)->u.struct_or_variant_declaration.field_class_specifier_list = list;
2587 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2589 | CTF_TYPEALIAS declaration_specifiers abstract_declarator_list CTF_TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2591 struct ctf_node *list;
2593 $$ = make_node(scanner, NODE_TYPEALIAS);
2594 $$->u.field_class_alias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2595 $$->u.field_class_alias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2597 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2598 $$->u.field_class_alias.target->u.field_class_alias_target.field_class_specifier_list = list;
2599 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2600 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_alias.target->u.field_class_alias_target.field_class_declarators);
2602 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2603 $$->u.field_class_alias.alias->u.field_class_alias_name.field_class_specifier_list = list;
2604 _bt_list_splice_tail(&($5)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2605 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.field_class_alias.alias->u.field_class_alias_name.field_class_declarators);