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_OUTPUT_LEVEL ctf_plugin_metadata_log_level
29 #define BT_LOG_TAG "PLUGIN/CTF/META/PARSER"
41 #include "common/list.h"
42 #include "common/assert.h"
47 #include "parser-wrap.h"
49 /* Join two lists, put "add" at the end of "head". */
51 _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
53 /* Do nothing if the list which gets added is empty. */
54 if (add != add->next) {
55 add->next->prev = head->prev;
56 add->prev->next = head;
57 head->prev->next = add->next;
58 head->prev = add->prev;
63 int yylex(union YYSTYPE *yyval, yyscan_t yyscanner);
65 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
67 int yylex_destroy(yyscan_t yyscanner);
69 void yyrestart(FILE * in_str, yyscan_t yyscanner);
71 int yyget_lineno(yyscan_t yyscanner);
73 char *yyget_text(yyscan_t yyscanner);
75 static const char *node_type_to_str[] = {
76 #define ENTRY(S) [S] = #S,
77 FOREACH_CTF_NODES(ENTRY)
82 * Static node for out of memory errors. Only "type" is used. lineno is
83 * always left at 0. The rest of the node content can be overwritten,
86 static struct ctf_node error_node = {
91 const char *node_type(struct ctf_node *node)
93 if (node->type < NR_NODE_TYPES)
94 return node_type_to_str[node->type];
99 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
101 lvalp->s = objstack_alloc(scanner->objstack, strlen(src) + 1);
102 strcpy(lvalp->s, src);
106 int str_check(size_t str_len, size_t offset, size_t len)
109 if (offset + len < offset)
111 if (offset + len > str_len)
117 int bt_isodigit(int c)
135 int parse_base_sequence(const char *src, size_t len, size_t pos,
136 char *buffer, size_t *buf_len, int base)
138 const size_t max_char = 3;
141 while (!str_check(len, pos, 1) && nr_char < max_char) {
146 buffer[nr_char++] = c;
149 } else if (base == 16) {
151 buffer[nr_char++] = c;
156 /* Unsupported base */
160 BT_ASSERT_DBG(nr_char > 0);
161 buffer[nr_char] = '\0';
167 int import_basic_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
168 size_t len, const char *src, char delim)
170 size_t pos = 0, dpos = 0;
172 if (str_check(len, pos, 1))
174 if (src[pos++] != delim)
177 while (src[pos] != delim) {
180 if (str_check(len, pos, 1))
184 if (str_check(len, pos, 1))
234 if (parse_base_sequence(src, len, pos - 1,
235 oct_buffer, &oct_len, 8))
237 c = strtoul(&oct_buffer[0], NULL, 8);
246 if (parse_base_sequence(src, len, pos,
247 hex_buffer, &hex_len, 16))
249 c = strtoul(&hex_buffer[0], NULL, 16);
257 if (str_check(len, dpos, 1))
259 lvalp->s[dpos++] = c;
262 if (str_check(len, dpos, 1))
264 lvalp->s[dpos++] = '\0';
266 if (str_check(len, pos, 1))
268 if (src[pos++] != delim)
271 if (str_check(len, pos, 1))
273 if (src[pos] != '\0')
278 int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
279 const char *src, char delim)
283 len = strlen(src) + 1;
284 lvalp->s = objstack_alloc(scanner->objstack, len);
286 // TODO: import wide string
287 _BT_LOGE_LINENO(yyget_lineno(scanner),
288 "wide characters are not supported as of this version: "
289 "scanner-addr=%p", scanner);
292 return import_basic_string(scanner, lvalp, len, src, delim);
296 static void init_scope(struct ctf_scanner_scope *scope,
297 struct ctf_scanner_scope *parent)
299 scope->parent = parent;
300 scope->classes = g_hash_table_new_full(g_str_hash, g_str_equal,
304 static void finalize_scope(struct ctf_scanner_scope *scope)
306 g_hash_table_destroy(scope->classes);
309 static void push_scope(struct ctf_scanner *scanner)
311 struct ctf_scanner_scope *ns;
313 BT_LOGT("Pushing scope: scanner-addr=%p", scanner);
314 ns = malloc(sizeof(struct ctf_scanner_scope));
315 init_scope(ns, scanner->cs);
319 static void pop_scope(struct ctf_scanner *scanner)
321 struct ctf_scanner_scope *os;
323 BT_LOGT("Popping scope: scanner-addr=%p", scanner);
325 scanner->cs = os->parent;
330 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
334 ret = GPOINTER_TO_INT(g_hash_table_lookup(s->classes, id));
335 BT_LOGT("Looked up type: scanner-addr=%p, id=\"%s\", ret=%d",
341 int is_type(struct ctf_scanner *scanner, const char *id)
343 struct ctf_scanner_scope *it;
346 for (it = scanner->cs; it; it = it->parent) {
347 if (lookup_type(it, id)) {
352 BT_LOGT("Found if ID is type: scanner-addr=%p, id=\"%s\", ret=%d",
357 static void add_type(struct ctf_scanner *scanner, char *id)
359 BT_LOGT("Adding type: scanner-addr=%p, id=\"%s\"",
361 if (lookup_type(scanner->cs, id))
363 g_hash_table_insert(scanner->cs->classes, id, id);
366 static struct ctf_node *make_node(struct ctf_scanner *scanner,
369 struct ctf_node *node;
371 node = objstack_alloc(scanner->objstack, sizeof(*node));
373 _BT_LOGE_LINENO(yyget_lineno(scanner->scanner),
374 "failed to allocate one stack entry: "
375 "scanner-addr=%p", scanner);
379 node->lineno = yyget_lineno(scanner->scanner);
380 BT_INIT_LIST_HEAD(&node->tmp_head);
381 bt_list_add(&node->siblings, &node->tmp_head);
385 node->type = NODE_ERROR;
386 BT_LOGE("Trying to create root node: scanner-addr=%p",
390 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
393 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
396 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
399 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
402 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
405 BT_INIT_LIST_HEAD(&node->u.callsite.declaration_list);
407 case NODE_CTF_EXPRESSION:
408 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
409 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
411 case NODE_UNARY_EXPRESSION:
414 BT_INIT_LIST_HEAD(&node->u.field_class_def.field_class_declarators);
416 case NODE_TYPEALIAS_TARGET:
417 BT_INIT_LIST_HEAD(&node->u.field_class_alias_target.field_class_declarators);
419 case NODE_TYPEALIAS_ALIAS:
420 BT_INIT_LIST_HEAD(&node->u.field_class_alias_name.field_class_declarators);
424 case NODE_TYPE_SPECIFIER:
426 case NODE_TYPE_SPECIFIER_LIST:
427 BT_INIT_LIST_HEAD(&node->u.field_class_specifier_list.head);
431 case NODE_TYPE_DECLARATOR:
432 BT_INIT_LIST_HEAD(&node->u.field_class_declarator.pointers);
434 case NODE_FLOATING_POINT:
435 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
438 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
441 BT_INIT_LIST_HEAD(&node->u.string.expressions);
443 case NODE_ENUMERATOR:
444 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
447 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
449 case NODE_STRUCT_OR_VARIANT_DECLARATION:
450 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.field_class_declarators);
453 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
456 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
457 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
461 node->type = NODE_ERROR;
462 BT_LOGE("Unknown node type: scanner-addr=%p, node-type=%d",
470 static int reparent_ctf_expression(struct ctf_node *node,
471 struct ctf_node *parent)
473 switch (parent->type) {
475 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
478 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
481 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
484 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
487 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
490 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
492 case NODE_FLOATING_POINT:
493 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
496 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
499 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
503 case NODE_CTF_EXPRESSION:
505 case NODE_TYPEALIAS_TARGET:
506 case NODE_TYPEALIAS_ALIAS:
508 case NODE_TYPE_SPECIFIER:
509 case NODE_TYPE_SPECIFIER_LIST:
511 case NODE_TYPE_DECLARATOR:
512 case NODE_ENUMERATOR:
514 case NODE_STRUCT_OR_VARIANT_DECLARATION:
517 case NODE_UNARY_EXPRESSION:
522 BT_LOGE("Unknown node type: node-type=%d", parent->type);
528 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
530 switch (parent->type) {
532 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
535 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
538 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
541 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
544 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
547 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
550 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
553 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
556 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
559 case NODE_FLOATING_POINT:
562 case NODE_CTF_EXPRESSION:
564 case NODE_TYPEALIAS_TARGET:
565 case NODE_TYPEALIAS_ALIAS:
567 case NODE_TYPE_SPECIFIER:
568 case NODE_TYPE_SPECIFIER_LIST:
570 case NODE_TYPE_DECLARATOR:
571 case NODE_ENUMERATOR:
573 case NODE_STRUCT_OR_VARIANT_DECLARATION:
574 case NODE_UNARY_EXPRESSION:
579 BT_LOGE("Unknown node type: node-type=%d", parent->type);
585 static int reparent_field_class_alias(struct ctf_node *node, struct ctf_node *parent)
587 switch (parent->type) {
589 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
592 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
595 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
598 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
601 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
604 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
607 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
610 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
613 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
616 case NODE_FLOATING_POINT:
619 case NODE_CTF_EXPRESSION:
621 case NODE_TYPEALIAS_TARGET:
622 case NODE_TYPEALIAS_ALIAS:
624 case NODE_TYPE_SPECIFIER:
625 case NODE_TYPE_SPECIFIER_LIST:
627 case NODE_TYPE_DECLARATOR:
628 case NODE_ENUMERATOR:
630 case NODE_STRUCT_OR_VARIANT_DECLARATION:
631 case NODE_UNARY_EXPRESSION:
636 BT_LOGE("Unknown node type: node-type=%d", parent->type);
642 static int reparent_field_class_specifier(struct ctf_node *node,
643 struct ctf_node *parent)
645 switch (parent->type) {
646 case NODE_TYPE_SPECIFIER_LIST:
647 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_specifier_list.head);
650 case NODE_TYPE_SPECIFIER:
660 case NODE_TYPEALIAS_TARGET:
661 case NODE_TYPEALIAS_ALIAS:
662 case NODE_TYPE_DECLARATOR:
664 case NODE_STRUCT_OR_VARIANT_DECLARATION:
666 case NODE_FLOATING_POINT:
669 case NODE_CTF_EXPRESSION:
671 case NODE_ENUMERATOR:
672 case NODE_UNARY_EXPRESSION:
677 BT_LOGE("Unknown node type: node-type=%d", parent->type);
683 static int reparent_field_class_specifier_list(struct ctf_node *node,
684 struct ctf_node *parent)
686 switch (parent->type) {
688 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
691 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
694 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
697 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
700 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
703 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
706 bt_list_add_tail(&node->siblings, &parent->u.callsite.declaration_list);
709 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
712 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
715 parent->u.field_class_def.field_class_specifier_list = node;
717 case NODE_TYPEALIAS_TARGET:
718 parent->u.field_class_alias_target.field_class_specifier_list = node;
720 case NODE_TYPEALIAS_ALIAS:
721 parent->u.field_class_alias_name.field_class_specifier_list = node;
724 parent->u._enum.container_field_class = node;
726 case NODE_STRUCT_OR_VARIANT_DECLARATION:
727 parent->u.struct_or_variant_declaration.field_class_specifier_list = node;
729 case NODE_TYPE_DECLARATOR:
730 case NODE_TYPE_SPECIFIER:
732 case NODE_FLOATING_POINT:
735 case NODE_CTF_EXPRESSION:
737 case NODE_ENUMERATOR:
738 case NODE_UNARY_EXPRESSION:
743 BT_LOGE("Unknown node type: node-type=%d", parent->type);
749 static int reparent_field_class_declarator(struct ctf_node *node,
750 struct ctf_node *parent)
752 switch (parent->type) {
753 case NODE_TYPE_DECLARATOR:
754 parent->u.field_class_declarator.type = TYPEDEC_NESTED;
755 parent->u.field_class_declarator.u.nested.field_class_declarator = node;
757 case NODE_STRUCT_OR_VARIANT_DECLARATION:
758 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.field_class_declarators);
761 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_def.field_class_declarators);
763 case NODE_TYPEALIAS_TARGET:
764 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_alias_target.field_class_declarators);
766 case NODE_TYPEALIAS_ALIAS:
767 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_alias_name.field_class_declarators);
781 case NODE_FLOATING_POINT:
784 case NODE_CTF_EXPRESSION:
785 case NODE_TYPE_SPECIFIER:
786 case NODE_TYPE_SPECIFIER_LIST:
788 case NODE_ENUMERATOR:
789 case NODE_UNARY_EXPRESSION:
794 BT_LOGE("Unknown node type: node-type=%d", parent->type);
803 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
804 * create the link declared by the input, -ENOENT if node or parent is NULL,
805 * -EINVAL if there is an internal structure problem.
807 static int set_parent_node(struct ctf_node *node,
808 struct ctf_node *parent)
810 if (!node || !parent)
813 /* Note: Linking to parent will be done only by an external visitor */
815 switch (node->type) {
817 BT_LOGE_STR("Trying to reparent root node.");
821 if (parent->type == NODE_ROOT) {
822 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
828 if (parent->type == NODE_ROOT) {
829 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
835 if (parent->type == NODE_ROOT) {
836 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
842 if (parent->type == NODE_ROOT) {
843 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
849 if (parent->type == NODE_ROOT) {
850 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
856 if (parent->type == NODE_ROOT) {
857 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.callsite);
863 case NODE_CTF_EXPRESSION:
864 return reparent_ctf_expression(node, parent);
865 case NODE_UNARY_EXPRESSION:
866 if (parent->type == NODE_TYPE_DECLARATOR)
867 parent->u.field_class_declarator.bitfield_len = node;
873 return reparent_typedef(node, parent);
874 case NODE_TYPEALIAS_TARGET:
875 if (parent->type == NODE_TYPEALIAS)
876 parent->u.field_class_alias.target = node;
880 case NODE_TYPEALIAS_ALIAS:
881 if (parent->type == NODE_TYPEALIAS)
882 parent->u.field_class_alias.alias = node;
887 return reparent_field_class_alias(node, parent);
890 if (parent->type == NODE_TYPE_DECLARATOR) {
891 _bt_list_splice_tail(&node->tmp_head, &parent->u.field_class_declarator.pointers);
895 case NODE_TYPE_DECLARATOR:
896 return reparent_field_class_declarator(node, parent);
898 case NODE_TYPE_SPECIFIER_LIST:
899 return reparent_field_class_specifier_list(node, parent);
901 case NODE_TYPE_SPECIFIER:
902 return reparent_field_class_specifier(node, parent);
904 case NODE_FLOATING_POINT:
910 return -EINVAL; /* Dealt with internally within grammar */
912 case NODE_ENUMERATOR:
913 if (parent->type == NODE_ENUM) {
914 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
919 case NODE_STRUCT_OR_VARIANT_DECLARATION:
920 switch (parent->type) {
922 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
925 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
934 BT_LOGE("Unknown node type: node-type=%d", parent->type);
941 void yyerror(struct ctf_scanner *scanner, yyscan_t yyscanner, const char *str)
943 _BT_LOGE_LINENO(yyget_lineno(scanner->scanner),
944 "%s: token=\"%s\"", str, yyget_text(scanner->scanner));
947 #define reparent_error(scanner, str) \
949 yyerror(scanner, scanner->scanner, YY_("reparent_error: " str)); \
953 static struct ctf_ast *ctf_ast_alloc(struct ctf_scanner *scanner)
957 ast = objstack_alloc(scanner->objstack, sizeof(*ast));
960 ast->root.type = NODE_ROOT;
961 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
962 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
963 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
964 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
965 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
966 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
967 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
968 BT_INIT_LIST_HEAD(&ast->root.u.root.callsite);
972 int ctf_scanner_append_ast(struct ctf_scanner *scanner, FILE *input)
974 /* Start processing new stream */
975 yyrestart(input, scanner->scanner);
976 return yyparse(scanner, scanner->scanner);
979 struct ctf_scanner *ctf_scanner_alloc(void)
981 struct ctf_scanner *scanner;
984 scanner = malloc(sizeof(*scanner));
987 memset(scanner, 0, sizeof(*scanner));
988 ret = yylex_init_extra(scanner, &scanner->scanner);
990 BT_LOGE("yylex_init_extra() failed: ret=%d", ret);
991 goto cleanup_scanner;
993 scanner->objstack = objstack_create();
994 if (!scanner->objstack)
996 scanner->ast = ctf_ast_alloc(scanner);
998 goto cleanup_objstack;
999 init_scope(&scanner->root_scope, NULL);
1000 scanner->cs = &scanner->root_scope;
1005 objstack_destroy(scanner->objstack);
1007 ret = yylex_destroy(scanner->scanner);
1009 BT_LOGE("yylex_destroy() failed: scanner-addr=%p, ret=%d",
1016 void ctf_scanner_free(struct ctf_scanner *scanner)
1022 finalize_scope(&scanner->root_scope);
1023 objstack_destroy(scanner->objstack);
1024 ret = yylex_destroy(scanner->scanner);
1026 BT_LOGE("yylex_destroy() failed: scanner-addr=%p, ret=%d",
1032 * The bison-provided version of strlen (yystrlen) generates a benign
1033 * -Wnull-dereference warning. That version is used when building on cygwin,
1034 * for example, but you can also enable it by hand (to test) by removing the
1035 * preprocessor conditional around it.
1037 * Define yystrlen such that it will always use strlen. As far as we know,
1038 * strlen provided by all the platforms we use is reliable.
1040 #define yystrlen strlen
1045 * This ends up in parser.h and makes sure those who want to include it pass
1046 * through parser-wrap.h.
1049 #ifndef ALLOW_INCLUDE_PARSER_H
1050 # error "Don't include parser.h directly, include parser-wrap.h instead."
1056 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src);
1059 int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src, char delim);
1065 %parse-param {struct ctf_scanner *scanner}
1066 %parse-param {yyscan_t yyscanner}
1067 %lex-param {yyscan_t yyscanner}
1069 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
1070 * vs struct { int :value; } (unnamed bit-field). The default is to
1071 * shift, so whenever we encounter an enumeration, we are doing the
1072 * proper thing (shift). It is illegal to declare an enumeration
1073 * "bit-field", so it is OK if this situation ends up in a parsing
1078 %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
1079 %token <s> IDENTIFIER ID_TYPE
1084 unsigned long long ull;
1090 %type <s> CTF_STRING_LITERAL CTF_CHARACTER_LITERAL
1094 %type <ull> CTF_INTEGER_LITERAL
1095 %type <n> postfix_expression unary_expression unary_expression_or_range
1097 %type <n> declaration
1098 %type <n> event_declaration
1099 %type <n> stream_declaration
1100 %type <n> env_declaration
1101 %type <n> trace_declaration
1102 %type <n> clock_declaration
1103 %type <n> callsite_declaration
1104 %type <n> integer_declaration_specifiers
1105 %type <n> declaration_specifiers
1106 %type <n> alias_declaration_specifiers
1108 %type <n> field_class_declarator_list
1109 %type <n> integer_field_class_specifier
1110 %type <n> field_class_specifier
1111 %type <n> struct_class_specifier
1112 %type <n> variant_field_class_specifier
1113 %type <n> enum_field_class_specifier
1114 %type <n> struct_or_variant_declaration_list
1115 %type <n> struct_or_variant_declaration
1116 %type <n> struct_or_variant_declarator_list
1117 %type <n> struct_or_variant_declarator
1118 %type <n> enumerator_list
1119 %type <n> enumerator
1120 %type <n> abstract_declarator_list
1121 %type <n> abstract_declarator
1122 %type <n> direct_abstract_declarator
1123 %type <n> alias_abstract_declarator_list
1124 %type <n> alias_abstract_declarator
1125 %type <n> direct_alias_abstract_declarator
1126 %type <n> declarator
1127 %type <n> direct_declarator
1128 %type <n> field_class_declarator
1129 %type <n> direct_field_class_declarator
1131 %type <n> ctf_assignment_expression_list
1132 %type <n> ctf_assignment_expression
1139 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
1140 reparent_error(scanner, "error reparenting to root");
1144 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
1145 reparent_error(scanner, "error reparenting to root");
1174 | CTF_FLOATING_POINT
1207 /* 2: Phrase structure grammar */
1212 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1213 $$->u.unary_expression.type = UNARY_STRING;
1214 $$->u.unary_expression.u.string = yylval.s;
1218 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1219 $$->u.unary_expression.type = UNARY_STRING;
1220 $$->u.unary_expression.u.string = yylval.s;
1224 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1225 $$->u.unary_expression.type = UNARY_STRING;
1226 $$->u.unary_expression.u.string = yylval.s;
1228 | CTF_INTEGER_LITERAL
1230 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1231 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1232 $$->u.unary_expression.u.unsigned_constant = $1;
1234 | CTF_STRING_LITERAL
1236 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1237 $$->u.unary_expression.type = UNARY_STRING;
1238 $$->u.unary_expression.u.string = $1;
1240 | CTF_CHARACTER_LITERAL
1242 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1243 $$->u.unary_expression.type = UNARY_STRING;
1244 $$->u.unary_expression.u.string = $1;
1246 | CTF_LPAREN unary_expression CTF_RPAREN
1250 | postfix_expression CTF_LSBRAC unary_expression CTF_RSBRAC
1252 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1253 $$->u.unary_expression.type = UNARY_SBRAC;
1254 $$->u.unary_expression.u.sbrac_exp = $3;
1255 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1256 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1258 | postfix_expression CTF_DOT IDENTIFIER
1260 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1261 $$->u.unary_expression.type = UNARY_STRING;
1262 $$->u.unary_expression.u.string = yylval.s;
1263 $$->u.unary_expression.link = UNARY_DOTLINK;
1264 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1265 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1267 | postfix_expression CTF_DOT ID_TYPE
1269 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1270 $$->u.unary_expression.type = UNARY_STRING;
1271 $$->u.unary_expression.u.string = yylval.s;
1272 $$->u.unary_expression.link = UNARY_DOTLINK;
1273 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1274 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1276 | postfix_expression CTF_DOT keywords
1278 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1279 $$->u.unary_expression.type = UNARY_STRING;
1280 $$->u.unary_expression.u.string = yylval.s;
1281 $$->u.unary_expression.link = UNARY_DOTLINK;
1282 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1283 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1285 | postfix_expression CTF_RARROW IDENTIFIER
1287 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1288 $$->u.unary_expression.type = UNARY_STRING;
1289 $$->u.unary_expression.u.string = yylval.s;
1290 $$->u.unary_expression.link = UNARY_ARROWLINK;
1291 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1292 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1294 | postfix_expression CTF_RARROW ID_TYPE
1296 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1297 $$->u.unary_expression.type = UNARY_STRING;
1298 $$->u.unary_expression.u.string = yylval.s;
1299 $$->u.unary_expression.link = UNARY_ARROWLINK;
1300 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1301 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1308 | CTF_PLUS postfix_expression
1311 if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
1312 && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
1313 reparent_error(scanner, "expecting numeric constant");
1316 | CTF_MINUS postfix_expression
1319 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1320 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1321 $$->u.unary_expression.u.signed_constant =
1322 -($$->u.unary_expression.u.unsigned_constant);
1323 } else if ($$->u.unary_expression.type == UNARY_SIGNED_CONSTANT) {
1324 $$->u.unary_expression.u.signed_constant =
1325 -($$->u.unary_expression.u.signed_constant);
1327 reparent_error(scanner, "expecting numeric constant");
1332 unary_expression_or_range:
1333 unary_expression CTF_DOTDOTDOT unary_expression
1336 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1337 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1343 /* 2.2: Declarations */
1346 declaration_specifiers CTF_SEMICOLON
1350 | stream_declaration
1358 | callsite_declaration
1360 | declaration_specifiers CTF_TYPEDEF declaration_specifiers field_class_declarator_list CTF_SEMICOLON
1362 struct ctf_node *list;
1364 $$ = make_node(scanner, NODE_TYPEDEF);
1365 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1366 $$->u.field_class_def.field_class_specifier_list = list;
1367 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1368 _bt_list_splice_tail(&($3)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1369 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
1371 | CTF_TYPEDEF declaration_specifiers field_class_declarator_list CTF_SEMICOLON
1373 struct ctf_node *list;
1375 $$ = make_node(scanner, NODE_TYPEDEF);
1376 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1377 $$->u.field_class_def.field_class_specifier_list = list;
1378 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1379 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
1381 | declaration_specifiers CTF_TYPEDEF field_class_declarator_list CTF_SEMICOLON
1383 struct ctf_node *list;
1385 $$ = make_node(scanner, NODE_TYPEDEF);
1386 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1387 $$->u.field_class_def.field_class_specifier_list = list;
1388 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1389 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
1391 | CTF_TYPEALIAS declaration_specifiers abstract_declarator_list CTF_TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list CTF_SEMICOLON
1393 struct ctf_node *list;
1395 $$ = make_node(scanner, NODE_TYPEALIAS);
1396 $$->u.field_class_alias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1397 $$->u.field_class_alias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1399 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1400 $$->u.field_class_alias.target->u.field_class_alias_target.field_class_specifier_list = list;
1401 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1402 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_alias.target->u.field_class_alias_target.field_class_declarators);
1404 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1405 $$->u.field_class_alias.alias->u.field_class_alias_name.field_class_specifier_list = list;
1406 _bt_list_splice_tail(&($5)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
1407 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.field_class_alias.alias->u.field_class_alias_name.field_class_declarators);
1412 event_declaration_begin event_declaration_end
1414 $$ = make_node(scanner, NODE_EVENT);
1416 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1418 $$ = make_node(scanner, NODE_EVENT);
1419 if (set_parent_node($2, $$))
1420 reparent_error(scanner, "event_declaration");
1424 event_declaration_begin:
1426 { push_scope(scanner); }
1429 event_declaration_end:
1430 CTF_RBRAC CTF_SEMICOLON
1431 { pop_scope(scanner); }
1436 stream_declaration_begin stream_declaration_end
1438 $$ = make_node(scanner, NODE_STREAM);
1440 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1442 $$ = make_node(scanner, NODE_STREAM);
1443 if (set_parent_node($2, $$))
1444 reparent_error(scanner, "stream_declaration");
1448 stream_declaration_begin:
1449 CTF_STREAM CTF_LBRAC
1450 { push_scope(scanner); }
1453 stream_declaration_end:
1454 CTF_RBRAC CTF_SEMICOLON
1455 { pop_scope(scanner); }
1459 env_declaration_begin env_declaration_end
1461 $$ = make_node(scanner, NODE_ENV);
1463 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1465 $$ = make_node(scanner, NODE_ENV);
1466 if (set_parent_node($2, $$))
1467 reparent_error(scanner, "env declaration");
1471 env_declaration_begin:
1473 { push_scope(scanner); }
1476 env_declaration_end:
1477 CTF_RBRAC CTF_SEMICOLON
1478 { pop_scope(scanner); }
1482 trace_declaration_begin trace_declaration_end
1484 $$ = make_node(scanner, NODE_TRACE);
1486 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1488 $$ = make_node(scanner, NODE_TRACE);
1489 if (set_parent_node($2, $$))
1490 reparent_error(scanner, "trace_declaration");
1494 trace_declaration_begin:
1496 { push_scope(scanner); }
1499 trace_declaration_end:
1500 CTF_RBRAC CTF_SEMICOLON
1501 { pop_scope(scanner); }
1505 CTF_CLOCK clock_declaration_begin clock_declaration_end
1507 $$ = make_node(scanner, NODE_CLOCK);
1509 | CTF_CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1511 $$ = make_node(scanner, NODE_CLOCK);
1512 if (set_parent_node($3, $$))
1513 reparent_error(scanner, "trace_declaration");
1517 clock_declaration_begin:
1519 { push_scope(scanner); }
1522 clock_declaration_end:
1523 CTF_RBRAC CTF_SEMICOLON
1524 { pop_scope(scanner); }
1527 callsite_declaration:
1528 CTF_CALLSITE callsite_declaration_begin callsite_declaration_end
1530 $$ = make_node(scanner, NODE_CALLSITE);
1532 | CTF_CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1534 $$ = make_node(scanner, NODE_CALLSITE);
1535 if (set_parent_node($3, $$))
1536 reparent_error(scanner, "trace_declaration");
1540 callsite_declaration_begin:
1542 { push_scope(scanner); }
1545 callsite_declaration_end:
1546 CTF_RBRAC CTF_SEMICOLON
1547 { pop_scope(scanner); }
1550 integer_declaration_specifiers:
1553 struct ctf_node *node;
1555 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1556 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1557 node->u.field_class_specifier.type = TYPESPEC_CONST;
1558 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1560 | integer_field_class_specifier
1562 struct ctf_node *node;
1564 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1566 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1568 | integer_declaration_specifiers CTF_CONST
1570 struct ctf_node *node;
1573 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1574 node->u.field_class_specifier.type = TYPESPEC_CONST;
1575 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1577 | integer_declaration_specifiers integer_field_class_specifier
1580 bt_list_add_tail(&($2)->siblings, &($$)->u.field_class_specifier_list.head);
1584 declaration_specifiers:
1587 struct ctf_node *node;
1589 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1590 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1591 node->u.field_class_specifier.type = TYPESPEC_CONST;
1592 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1594 | field_class_specifier
1596 struct ctf_node *node;
1598 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1600 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1602 | declaration_specifiers CTF_CONST
1604 struct ctf_node *node;
1607 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1608 node->u.field_class_specifier.type = TYPESPEC_CONST;
1609 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
1611 | declaration_specifiers field_class_specifier
1614 bt_list_add_tail(&($2)->siblings, &($$)->u.field_class_specifier_list.head);
1618 field_class_declarator_list:
1619 field_class_declarator
1621 | field_class_declarator_list CTF_COMMA field_class_declarator
1624 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1628 integer_field_class_specifier:
1631 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1632 $$->u.field_class_specifier.type = TYPESPEC_CHAR;
1636 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1637 $$->u.field_class_specifier.type = TYPESPEC_SHORT;
1641 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1642 $$->u.field_class_specifier.type = TYPESPEC_INT;
1646 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1647 $$->u.field_class_specifier.type = TYPESPEC_LONG;
1651 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1652 $$->u.field_class_specifier.type = TYPESPEC_SIGNED;
1656 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1657 $$->u.field_class_specifier.type = TYPESPEC_UNSIGNED;
1661 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1662 $$->u.field_class_specifier.type = TYPESPEC_BOOL;
1666 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1667 $$->u.field_class_specifier.type = TYPESPEC_ID_TYPE;
1668 $$->u.field_class_specifier.id_type = yylval.s;
1670 | CTF_INTEGER CTF_LBRAC CTF_RBRAC
1672 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1673 $$->u.field_class_specifier.type = TYPESPEC_INTEGER;
1674 $$->u.field_class_specifier.node = make_node(scanner, NODE_INTEGER);
1676 | CTF_INTEGER CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1678 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1679 $$->u.field_class_specifier.type = TYPESPEC_INTEGER;
1680 $$->u.field_class_specifier.node = make_node(scanner, NODE_INTEGER);
1681 if (set_parent_node($3, $$->u.field_class_specifier.node))
1682 reparent_error(scanner, "integer reparent error");
1686 field_class_specifier:
1689 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1690 $$->u.field_class_specifier.type = TYPESPEC_VOID;
1694 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1695 $$->u.field_class_specifier.type = TYPESPEC_CHAR;
1699 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1700 $$->u.field_class_specifier.type = TYPESPEC_SHORT;
1704 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1705 $$->u.field_class_specifier.type = TYPESPEC_INT;
1709 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1710 $$->u.field_class_specifier.type = TYPESPEC_LONG;
1714 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1715 $$->u.field_class_specifier.type = TYPESPEC_FLOAT;
1719 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1720 $$->u.field_class_specifier.type = TYPESPEC_DOUBLE;
1724 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1725 $$->u.field_class_specifier.type = TYPESPEC_SIGNED;
1729 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1730 $$->u.field_class_specifier.type = TYPESPEC_UNSIGNED;
1734 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1735 $$->u.field_class_specifier.type = TYPESPEC_BOOL;
1739 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1740 $$->u.field_class_specifier.type = TYPESPEC_COMPLEX;
1744 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1745 $$->u.field_class_specifier.type = TYPESPEC_IMAGINARY;
1749 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1750 $$->u.field_class_specifier.type = TYPESPEC_ID_TYPE;
1751 $$->u.field_class_specifier.id_type = yylval.s;
1753 | CTF_FLOATING_POINT CTF_LBRAC CTF_RBRAC
1755 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1756 $$->u.field_class_specifier.type = TYPESPEC_FLOATING_POINT;
1757 $$->u.field_class_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1759 | CTF_FLOATING_POINT CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1761 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1762 $$->u.field_class_specifier.type = TYPESPEC_FLOATING_POINT;
1763 $$->u.field_class_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1764 if (set_parent_node($3, $$->u.field_class_specifier.node))
1765 reparent_error(scanner, "floating point reparent error");
1767 | CTF_INTEGER CTF_LBRAC CTF_RBRAC
1769 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1770 $$->u.field_class_specifier.type = TYPESPEC_INTEGER;
1771 $$->u.field_class_specifier.node = make_node(scanner, NODE_INTEGER);
1773 | CTF_INTEGER CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1775 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1776 $$->u.field_class_specifier.type = TYPESPEC_INTEGER;
1777 $$->u.field_class_specifier.node = make_node(scanner, NODE_INTEGER);
1778 if (set_parent_node($3, $$->u.field_class_specifier.node))
1779 reparent_error(scanner, "integer reparent error");
1783 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1784 $$->u.field_class_specifier.type = TYPESPEC_STRING;
1785 $$->u.field_class_specifier.node = make_node(scanner, NODE_STRING);
1787 | CTF_STRING CTF_LBRAC CTF_RBRAC
1789 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1790 $$->u.field_class_specifier.type = TYPESPEC_STRING;
1791 $$->u.field_class_specifier.node = make_node(scanner, NODE_STRING);
1793 | CTF_STRING CTF_LBRAC ctf_assignment_expression_list CTF_RBRAC
1795 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1796 $$->u.field_class_specifier.type = TYPESPEC_STRING;
1797 $$->u.field_class_specifier.node = make_node(scanner, NODE_STRING);
1798 if (set_parent_node($3, $$->u.field_class_specifier.node))
1799 reparent_error(scanner, "string reparent error");
1801 | CTF_ENUM enum_field_class_specifier
1803 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1804 $$->u.field_class_specifier.type = TYPESPEC_ENUM;
1805 $$->u.field_class_specifier.node = $2;
1807 | CTF_VARIANT variant_field_class_specifier
1809 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1810 $$->u.field_class_specifier.type = TYPESPEC_VARIANT;
1811 $$->u.field_class_specifier.node = $2;
1813 | CTF_STRUCT struct_class_specifier
1815 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1816 $$->u.field_class_specifier.type = TYPESPEC_STRUCT;
1817 $$->u.field_class_specifier.node = $2;
1821 struct_class_specifier:
1822 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1824 $$ = make_node(scanner, NODE_STRUCT);
1825 $$->u._struct.has_body = 1;
1826 if ($2 && set_parent_node($2, $$))
1827 reparent_error(scanner, "struct reparent error");
1829 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1831 $$ = make_node(scanner, NODE_STRUCT);
1832 $$->u._struct.has_body = 1;
1833 $$->u._struct.name = $1;
1834 if ($3 && set_parent_node($3, $$))
1835 reparent_error(scanner, "struct reparent error");
1837 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1839 $$ = make_node(scanner, NODE_STRUCT);
1840 $$->u._struct.has_body = 1;
1841 $$->u._struct.name = $1;
1842 if ($3 && set_parent_node($3, $$))
1843 reparent_error(scanner, "struct reparent error");
1847 $$ = make_node(scanner, NODE_STRUCT);
1848 $$->u._struct.has_body = 0;
1849 $$->u._struct.name = $1;
1853 $$ = make_node(scanner, NODE_STRUCT);
1854 $$->u._struct.has_body = 0;
1855 $$->u._struct.name = $1;
1857 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end CTF_TOK_ALIGN CTF_LPAREN unary_expression CTF_RPAREN
1859 $$ = make_node(scanner, NODE_STRUCT);
1860 $$->u._struct.has_body = 1;
1861 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1862 if ($2 && set_parent_node($2, $$))
1863 reparent_error(scanner, "struct reparent error");
1865 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end CTF_TOK_ALIGN CTF_LPAREN unary_expression CTF_RPAREN
1867 $$ = make_node(scanner, NODE_STRUCT);
1868 $$->u._struct.has_body = 1;
1869 $$->u._struct.name = $1;
1870 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1871 if ($3 && set_parent_node($3, $$))
1872 reparent_error(scanner, "struct reparent error");
1874 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end CTF_TOK_ALIGN CTF_LPAREN unary_expression CTF_RPAREN
1876 $$ = make_node(scanner, NODE_STRUCT);
1877 $$->u._struct.has_body = 1;
1878 $$->u._struct.name = $1;
1879 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1880 if ($3 && set_parent_node($3, $$))
1881 reparent_error(scanner, "struct reparent error");
1885 struct_declaration_begin:
1887 { push_scope(scanner); }
1890 struct_declaration_end:
1892 { pop_scope(scanner); }
1895 variant_field_class_specifier:
1896 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1898 $$ = make_node(scanner, NODE_VARIANT);
1899 $$->u.variant.has_body = 1;
1900 if ($2 && set_parent_node($2, $$))
1901 reparent_error(scanner, "variant reparent error");
1903 | CTF_LT IDENTIFIER CTF_GT 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.choice = $2;
1908 if ($5 && set_parent_node($5, $$))
1909 reparent_error(scanner, "variant reparent error");
1911 | CTF_LT ID_TYPE 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.choice = $2;
1916 if ($5 && set_parent_node($5, $$))
1917 reparent_error(scanner, "variant reparent error");
1919 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1921 $$ = make_node(scanner, NODE_VARIANT);
1922 $$->u.variant.has_body = 1;
1923 $$->u.variant.name = $1;
1924 if ($3 && set_parent_node($3, $$))
1925 reparent_error(scanner, "variant reparent error");
1927 | IDENTIFIER CTF_LT IDENTIFIER 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 IDENTIFIER 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 | IDENTIFIER CTF_LT ID_TYPE CTF_GT 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 $$->u.variant.choice = $3;
1949 if ($6 && set_parent_node($6, $$))
1950 reparent_error(scanner, "variant reparent error");
1952 | IDENTIFIER CTF_LT ID_TYPE CTF_GT
1954 $$ = make_node(scanner, NODE_VARIANT);
1955 $$->u.variant.has_body = 0;
1956 $$->u.variant.name = $1;
1957 $$->u.variant.choice = $3;
1959 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1961 $$ = make_node(scanner, NODE_VARIANT);
1962 $$->u.variant.has_body = 1;
1963 $$->u.variant.name = $1;
1964 if ($3 && set_parent_node($3, $$))
1965 reparent_error(scanner, "variant reparent error");
1967 | ID_TYPE CTF_LT IDENTIFIER 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 IDENTIFIER CTF_GT
1978 $$ = make_node(scanner, NODE_VARIANT);
1979 $$->u.variant.has_body = 0;
1980 $$->u.variant.name = $1;
1981 $$->u.variant.choice = $3;
1983 | ID_TYPE CTF_LT ID_TYPE CTF_GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1985 $$ = make_node(scanner, NODE_VARIANT);
1986 $$->u.variant.has_body = 1;
1987 $$->u.variant.name = $1;
1988 $$->u.variant.choice = $3;
1989 if ($6 && set_parent_node($6, $$))
1990 reparent_error(scanner, "variant reparent error");
1992 | ID_TYPE CTF_LT ID_TYPE CTF_GT
1994 $$ = make_node(scanner, NODE_VARIANT);
1995 $$->u.variant.has_body = 0;
1996 $$->u.variant.name = $1;
1997 $$->u.variant.choice = $3;
2001 variant_declaration_begin:
2003 { push_scope(scanner); }
2006 variant_declaration_end:
2008 { pop_scope(scanner); }
2011 enum_field_class_specifier:
2012 CTF_LBRAC enumerator_list CTF_RBRAC
2014 $$ = make_node(scanner, NODE_ENUM);
2015 $$->u._enum.has_body = 1;
2016 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2018 | CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_RBRAC
2020 $$ = make_node(scanner, NODE_ENUM);
2021 $$->u._enum.has_body = 1;
2022 ($$)->u._enum.container_field_class = $2;
2023 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2025 | IDENTIFIER CTF_LBRAC enumerator_list CTF_RBRAC
2027 $$ = make_node(scanner, NODE_ENUM);
2028 $$->u._enum.has_body = 1;
2029 $$->u._enum.enum_id = $1;
2030 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2032 | IDENTIFIER CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_RBRAC
2034 $$ = make_node(scanner, NODE_ENUM);
2035 $$->u._enum.has_body = 1;
2036 $$->u._enum.enum_id = $1;
2037 ($$)->u._enum.container_field_class = $3;
2038 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2040 | ID_TYPE CTF_LBRAC enumerator_list CTF_RBRAC
2042 $$ = make_node(scanner, NODE_ENUM);
2043 $$->u._enum.has_body = 1;
2044 $$->u._enum.enum_id = $1;
2045 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2047 | ID_TYPE CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_RBRAC
2049 $$ = make_node(scanner, NODE_ENUM);
2050 $$->u._enum.has_body = 1;
2051 $$->u._enum.enum_id = $1;
2052 ($$)->u._enum.container_field_class = $3;
2053 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2055 | CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2057 $$ = make_node(scanner, NODE_ENUM);
2058 $$->u._enum.has_body = 1;
2059 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2061 | CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2063 $$ = make_node(scanner, NODE_ENUM);
2064 $$->u._enum.has_body = 1;
2065 ($$)->u._enum.container_field_class = $2;
2066 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2068 | IDENTIFIER CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2070 $$ = make_node(scanner, NODE_ENUM);
2071 $$->u._enum.has_body = 1;
2072 $$->u._enum.enum_id = $1;
2073 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2075 | IDENTIFIER CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2077 $$ = make_node(scanner, NODE_ENUM);
2078 $$->u._enum.has_body = 1;
2079 $$->u._enum.enum_id = $1;
2080 ($$)->u._enum.container_field_class = $3;
2081 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2085 $$ = make_node(scanner, NODE_ENUM);
2086 $$->u._enum.has_body = 0;
2087 $$->u._enum.enum_id = $1;
2089 | ID_TYPE CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2091 $$ = make_node(scanner, NODE_ENUM);
2092 $$->u._enum.has_body = 1;
2093 $$->u._enum.enum_id = $1;
2094 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2096 | ID_TYPE CTF_COLON integer_declaration_specifiers CTF_LBRAC enumerator_list CTF_COMMA CTF_RBRAC
2098 $$ = make_node(scanner, NODE_ENUM);
2099 $$->u._enum.has_body = 1;
2100 $$->u._enum.enum_id = $1;
2101 ($$)->u._enum.container_field_class = $3;
2102 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2106 $$ = make_node(scanner, NODE_ENUM);
2107 $$->u._enum.has_body = 0;
2108 $$->u._enum.enum_id = $1;
2112 struct_or_variant_declaration_list:
2115 | struct_or_variant_declaration_list struct_or_variant_declaration
2119 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2122 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
2127 struct_or_variant_declaration:
2128 declaration_specifiers struct_or_variant_declarator_list CTF_SEMICOLON
2130 struct ctf_node *list;
2132 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2133 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2134 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
2135 ($$)->u.struct_or_variant_declaration.field_class_specifier_list = list;
2136 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.field_class_declarators);
2138 | declaration_specifiers CTF_TYPEDEF declaration_specifiers field_class_declarator_list CTF_SEMICOLON
2140 struct ctf_node *list;
2142 $$ = make_node(scanner, NODE_TYPEDEF);
2143 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2144 $$->u.field_class_def.field_class_specifier_list = list;
2145 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2146 _bt_list_splice_tail(&($3)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2147 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2149 | CTF_TYPEDEF declaration_specifiers field_class_declarator_list CTF_SEMICOLON
2151 struct ctf_node *list;
2153 $$ = make_node(scanner, NODE_TYPEDEF);
2154 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2155 $$->u.field_class_def.field_class_specifier_list = list;
2156 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2157 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2159 | declaration_specifiers CTF_TYPEDEF field_class_declarator_list CTF_SEMICOLON
2161 struct ctf_node *list;
2163 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2164 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2165 $$ = make_node(scanner, NODE_TYPEDEF);
2166 ($$)->u.struct_or_variant_declaration.field_class_specifier_list = list;
2167 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2169 | CTF_TYPEALIAS declaration_specifiers abstract_declarator_list CTF_TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list CTF_SEMICOLON
2171 struct ctf_node *list;
2173 $$ = make_node(scanner, NODE_TYPEALIAS);
2174 $$->u.field_class_alias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2175 $$->u.field_class_alias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2177 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2178 $$->u.field_class_alias.target->u.field_class_alias_target.field_class_specifier_list = list;
2179 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2180 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_alias.target->u.field_class_alias_target.field_class_declarators);
2182 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2183 $$->u.field_class_alias.alias->u.field_class_alias_name.field_class_specifier_list = list;
2184 _bt_list_splice_tail(&($5)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2185 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.field_class_alias.alias->u.field_class_alias_name.field_class_declarators);
2189 alias_declaration_specifiers:
2192 struct ctf_node *node;
2194 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2195 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2196 node->u.field_class_specifier.type = TYPESPEC_CONST;
2197 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2199 | field_class_specifier
2201 struct ctf_node *node;
2203 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2205 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2209 struct ctf_node *node;
2211 add_type(scanner, $1);
2212 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2213 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2214 node->u.field_class_specifier.type = TYPESPEC_ID_TYPE;
2215 node->u.field_class_specifier.id_type = yylval.s;
2216 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2218 | alias_declaration_specifiers CTF_CONST
2220 struct ctf_node *node;
2223 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2224 node->u.field_class_specifier.type = TYPESPEC_CONST;
2225 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2227 | alias_declaration_specifiers field_class_specifier
2230 bt_list_add_tail(&($2)->siblings, &($$)->u.field_class_specifier_list.head);
2232 | alias_declaration_specifiers IDENTIFIER
2234 struct ctf_node *node;
2236 add_type(scanner, $2);
2238 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2239 node->u.field_class_specifier.type = TYPESPEC_ID_TYPE;
2240 node->u.field_class_specifier.id_type = yylval.s;
2241 bt_list_add_tail(&node->siblings, &($$)->u.field_class_specifier_list.head);
2245 struct_or_variant_declarator_list:
2246 struct_or_variant_declarator
2248 | struct_or_variant_declarator_list CTF_COMMA struct_or_variant_declarator
2251 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2255 struct_or_variant_declarator:
2258 | CTF_COLON unary_expression
2260 | declarator CTF_COLON unary_expression
2263 if (set_parent_node($3, $1))
2264 reparent_error(scanner, "struct_or_variant_declarator");
2271 | enumerator_list CTF_COMMA enumerator
2274 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2281 $$ = make_node(scanner, NODE_ENUMERATOR);
2282 $$->u.enumerator.id = $1;
2286 $$ = make_node(scanner, NODE_ENUMERATOR);
2287 $$->u.enumerator.id = $1;
2291 $$ = make_node(scanner, NODE_ENUMERATOR);
2292 $$->u.enumerator.id = $1;
2294 | CTF_STRING_LITERAL
2296 $$ = make_node(scanner, NODE_ENUMERATOR);
2297 $$->u.enumerator.id = $1;
2299 | IDENTIFIER CTF_EQUAL unary_expression_or_range
2301 $$ = make_node(scanner, NODE_ENUMERATOR);
2302 $$->u.enumerator.id = $1;
2303 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2305 | ID_TYPE CTF_EQUAL unary_expression_or_range
2307 $$ = make_node(scanner, NODE_ENUMERATOR);
2308 $$->u.enumerator.id = $1;
2309 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2311 | keywords CTF_EQUAL unary_expression_or_range
2313 $$ = make_node(scanner, NODE_ENUMERATOR);
2314 $$->u.enumerator.id = $1;
2315 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2317 | CTF_STRING_LITERAL CTF_EQUAL unary_expression_or_range
2319 $$ = make_node(scanner, NODE_ENUMERATOR);
2320 $$->u.enumerator.id = $1;
2321 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2325 abstract_declarator_list:
2328 | abstract_declarator_list CTF_COMMA abstract_declarator
2331 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2335 abstract_declarator:
2336 direct_abstract_declarator
2338 | pointer direct_abstract_declarator
2341 bt_list_splice(&($1)->tmp_head, &($$)->u.field_class_declarator.pointers);
2345 direct_abstract_declarator:
2348 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2349 $$->u.field_class_declarator.type = TYPEDEC_ID;
2354 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2355 $$->u.field_class_declarator.type = TYPEDEC_ID;
2356 $$->u.field_class_declarator.u.id = $1;
2358 | CTF_LPAREN abstract_declarator CTF_RPAREN
2360 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2361 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2362 $$->u.field_class_declarator.u.nested.field_class_declarator = $2;
2364 | direct_abstract_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2366 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2367 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2368 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2369 BT_INIT_LIST_HEAD(&($$)->u.field_class_declarator.u.nested.length);
2370 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_declarator.u.nested.length);
2372 | direct_abstract_declarator CTF_LSBRAC CTF_RSBRAC
2374 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2375 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2376 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2377 $$->u.field_class_declarator.u.nested.abstract_array = 1;
2381 alias_abstract_declarator_list:
2382 alias_abstract_declarator
2384 | alias_abstract_declarator_list CTF_COMMA alias_abstract_declarator
2387 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2391 alias_abstract_declarator:
2392 direct_alias_abstract_declarator
2394 | pointer direct_alias_abstract_declarator
2397 bt_list_splice(&($1)->tmp_head, &($$)->u.field_class_declarator.pointers);
2401 direct_alias_abstract_declarator:
2404 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2405 $$->u.field_class_declarator.type = TYPEDEC_ID;
2408 | CTF_LPAREN alias_abstract_declarator CTF_RPAREN
2410 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2411 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2412 $$->u.field_class_declarator.u.nested.field_class_declarator = $2;
2414 | direct_alias_abstract_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2416 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2417 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2418 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2419 BT_INIT_LIST_HEAD(&($$)->u.field_class_declarator.u.nested.length);
2420 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_declarator.u.nested.length);
2422 | direct_alias_abstract_declarator CTF_LSBRAC CTF_RSBRAC
2424 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2425 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2426 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2427 $$->u.field_class_declarator.u.nested.abstract_array = 1;
2434 | pointer direct_declarator
2437 bt_list_splice(&($1)->tmp_head, &($$)->u.field_class_declarator.pointers);
2444 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2445 $$->u.field_class_declarator.type = TYPEDEC_ID;
2446 $$->u.field_class_declarator.u.id = $1;
2448 | CTF_LPAREN declarator CTF_RPAREN
2450 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2451 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2452 $$->u.field_class_declarator.u.nested.field_class_declarator = $2;
2454 | direct_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2456 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2457 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2458 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2459 BT_INIT_LIST_HEAD(&($$)->u.field_class_declarator.u.nested.length);
2460 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_declarator.u.nested.length);
2464 field_class_declarator:
2465 direct_field_class_declarator
2467 | pointer direct_field_class_declarator
2470 bt_list_splice(&($1)->tmp_head, &($$)->u.field_class_declarator.pointers);
2474 direct_field_class_declarator:
2477 add_type(scanner, $1);
2478 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2479 $$->u.field_class_declarator.type = TYPEDEC_ID;
2480 $$->u.field_class_declarator.u.id = $1;
2482 | CTF_LPAREN field_class_declarator CTF_RPAREN
2484 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2485 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2486 $$->u.field_class_declarator.u.nested.field_class_declarator = $2;
2488 | direct_field_class_declarator CTF_LSBRAC unary_expression CTF_RSBRAC
2490 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2491 $$->u.field_class_declarator.type = TYPEDEC_NESTED;
2492 $$->u.field_class_declarator.u.nested.field_class_declarator = $1;
2493 BT_INIT_LIST_HEAD(&($$)->u.field_class_declarator.u.nested.length);
2494 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_declarator.u.nested.length);
2501 $$ = make_node(scanner, NODE_POINTER);
2505 $$ = make_node(scanner, NODE_POINTER);
2506 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2508 | CTF_STAR type_qualifier_list pointer
2510 $$ = make_node(scanner, NODE_POINTER);
2511 $$->u.pointer.const_qualifier = 1;
2512 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2516 type_qualifier_list:
2517 /* pointer assumes only const type qualifier */
2519 | type_qualifier_list CTF_CONST
2522 /* 2.3: CTF-specific declarations */
2524 ctf_assignment_expression_list:
2525 ctf_assignment_expression CTF_SEMICOLON
2527 | ctf_assignment_expression_list ctf_assignment_expression CTF_SEMICOLON
2530 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2534 ctf_assignment_expression:
2535 unary_expression CTF_EQUAL unary_expression
2538 * Because we have left and right, cannot use
2541 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2542 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2543 if ($1->u.unary_expression.type != UNARY_STRING)
2544 reparent_error(scanner, "ctf_assignment_expression left expects string");
2545 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2547 | unary_expression CTF_TYPEASSIGN declaration_specifiers /* Only allow struct */
2550 * Because we have left and right, cannot use
2553 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2554 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2555 if ($1->u.unary_expression.type != UNARY_STRING)
2556 reparent_error(scanner, "ctf_assignment_expression left expects string");
2557 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2559 | declaration_specifiers CTF_TYPEDEF declaration_specifiers field_class_declarator_list
2561 struct ctf_node *list;
2563 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2564 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2565 _bt_list_splice_tail(&($3)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2566 $$ = make_node(scanner, NODE_TYPEDEF);
2567 ($$)->u.struct_or_variant_declaration.field_class_specifier_list = list;
2568 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2570 | CTF_TYPEDEF declaration_specifiers field_class_declarator_list
2572 struct ctf_node *list;
2574 $$ = make_node(scanner, NODE_TYPEDEF);
2575 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2576 $$->u.field_class_def.field_class_specifier_list = list;
2577 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2578 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2580 | declaration_specifiers CTF_TYPEDEF field_class_declarator_list
2582 struct ctf_node *list;
2584 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2585 _bt_list_splice_tail(&($1)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2586 $$ = make_node(scanner, NODE_TYPEDEF);
2587 ($$)->u.struct_or_variant_declaration.field_class_specifier_list = list;
2588 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_def.field_class_declarators);
2590 | CTF_TYPEALIAS declaration_specifiers abstract_declarator_list CTF_TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2592 struct ctf_node *list;
2594 $$ = make_node(scanner, NODE_TYPEALIAS);
2595 $$->u.field_class_alias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2596 $$->u.field_class_alias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2598 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2599 $$->u.field_class_alias.target->u.field_class_alias_target.field_class_specifier_list = list;
2600 _bt_list_splice_tail(&($2)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2601 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.field_class_alias.target->u.field_class_alias_target.field_class_declarators);
2603 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2604 $$->u.field_class_alias.alias->u.field_class_alias_name.field_class_specifier_list = list;
2605 _bt_list_splice_tail(&($5)->u.field_class_specifier_list.head, &list->u.field_class_specifier_list.head);
2606 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.field_class_alias.alias->u.field_class_alias_name.field_class_declarators);