5 * Common Trace Format Metadata Grammar.
7 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 #include <babeltrace/list.h>
38 #include <babeltrace/babeltrace-internal.h>
39 #include "ctf-scanner.h"
40 #include "ctf-parser.h"
46 /* Join two lists, put "add" at the end of "head". */
48 _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
50 /* Do nothing if the list which gets added is empty. */
51 if (add != add->next) {
52 add->next->prev = head->prev;
53 add->prev->next = head;
54 head->prev->next = add->next;
55 head->prev = add->prev;
60 int yyparse(struct ctf_scanner *scanner);
62 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
64 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
66 int yylex_destroy(yyscan_t yyscanner);
68 void yyrestart(FILE * in_str, yyscan_t scanner);
70 int yyget_lineno(yyscan_t yyscanner);
72 char *yyget_text(yyscan_t yyscanner);
75 struct bt_list_head gc;
80 static const char *node_type_to_str[] = {
81 #define ENTRY(S) [S] = #S,
82 FOREACH_CTF_NODES(ENTRY)
87 const char *node_type(struct ctf_node *node)
89 if (node->type < NR_NODE_TYPES)
90 return node_type_to_str[node->type];
95 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
98 struct gc_string *gstr;
101 /* TODO: could be faster with find first bit or glib Gstring */
102 /* sizeof long to account for malloc header (int or long ?) */
103 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
106 gstr = malloc(alloclen);
107 bt_list_add(&gstr->gc, &scanner->allocated_strings);
108 gstr->alloclen = alloclen;
112 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
114 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
115 strcpy(lvalp->gs->s, src);
119 int str_check(size_t str_len, size_t offset, size_t len)
122 if (offset + len < offset)
124 if (offset + len > str_len)
130 int import_basic_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
131 size_t len, const char *src, char delim)
133 size_t pos = 0, dpos = 0;
135 if (str_check(len, pos, 1))
137 if (src[pos++] != delim)
140 while (src[pos] != delim) {
143 if (str_check(len, pos, 1))
147 if (str_check(len, pos, 1))
192 if (str_check(len, pos, oct_len))
194 if (!isdigit((int) src[pos]) || !isdigit((int) src[pos+1]) || !isdigit((int) src[pos+2]))
196 char oct_buffer[4] = { src[pos], src[pos+1], src[pos+2], '\0' };
197 c = strtoul(&oct_buffer[0], NULL, 8);
205 if (str_check(len, pos, hex_len))
207 if (!isxdigit((int) src[pos]) || !isxdigit((int) src[pos+1]))
209 char hex_buffer[3] = { src[pos], src[pos+1], '\0' };
210 c = strtoul(&hex_buffer[0], NULL, 16);
218 if (str_check(len, dpos, 1))
220 lvalp->gs->s[dpos++] = c;
223 if (str_check(len, dpos, 1))
225 lvalp->gs->s[dpos++] = '\0';
227 if (str_check(len, pos, 1))
229 if (src[pos++] != delim)
232 if (str_check(len, pos, 1))
234 if (src[pos] != '\0')
239 int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
240 const char *src, char delim)
244 len = strlen(src) + 1;
245 lvalp->gs = gc_string_alloc(scanner, len);
247 // TODO: import wide string
248 printfl_error(yyget_lineno(scanner),
249 "Wide string not supported yet.");
252 return import_basic_string(scanner, lvalp, len, src, delim);
256 static void init_scope(struct ctf_scanner_scope *scope,
257 struct ctf_scanner_scope *parent)
259 scope->parent = parent;
260 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
264 static void finalize_scope(struct ctf_scanner_scope *scope)
266 g_hash_table_destroy(scope->types);
269 static void push_scope(struct ctf_scanner *scanner)
271 struct ctf_scanner_scope *ns;
273 printf_debug("push scope\n");
274 ns = malloc(sizeof(struct ctf_scanner_scope));
275 init_scope(ns, scanner->cs);
279 static void pop_scope(struct ctf_scanner *scanner)
281 struct ctf_scanner_scope *os;
283 printf_debug("pop scope\n");
285 scanner->cs = os->parent;
290 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
294 ret = (int) (long) g_hash_table_lookup(s->types, id);
295 printf_debug("lookup %p %s %d\n", s, id, ret);
300 int is_type(struct ctf_scanner *scanner, const char *id)
302 struct ctf_scanner_scope *it;
305 for (it = scanner->cs; it != NULL; it = it->parent) {
306 if (lookup_type(it, id)) {
311 printf_debug("is type %s %d\n", id, ret);
315 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
317 printf_debug("add type %s\n", id->s);
318 if (lookup_type(scanner->cs, id->s))
320 g_hash_table_insert(scanner->cs->types, id->s, id->s);
323 static struct ctf_node *make_node(struct ctf_scanner *scanner,
326 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
327 struct ctf_node *node;
329 node = malloc(sizeof(*node));
332 memset(node, 0, sizeof(*node));
334 node->lineno = yyget_lineno(scanner->scanner);
335 BT_INIT_LIST_HEAD(&node->tmp_head);
336 bt_list_add(&node->gc, &ast->allocated_nodes);
337 bt_list_add(&node->siblings, &node->tmp_head);
341 printfn_fatal(node, "trying to create root node");
345 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
348 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
351 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
354 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
357 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
360 BT_INIT_LIST_HEAD(&node->u.callsite.declaration_list);
363 case NODE_CTF_EXPRESSION:
364 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
365 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
367 case NODE_UNARY_EXPRESSION:
371 BT_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
373 case NODE_TYPEALIAS_TARGET:
374 BT_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
376 case NODE_TYPEALIAS_ALIAS:
377 BT_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
382 case NODE_TYPE_SPECIFIER:
384 case NODE_TYPE_SPECIFIER_LIST:
385 BT_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
389 case NODE_TYPE_DECLARATOR:
390 BT_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
393 case NODE_FLOATING_POINT:
394 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
397 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
400 BT_INIT_LIST_HEAD(&node->u.string.expressions);
402 case NODE_ENUMERATOR:
403 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
406 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
408 case NODE_STRUCT_OR_VARIANT_DECLARATION:
409 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
412 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
415 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
416 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
421 printfn_fatal(node, "unknown node type '%d'", (int) type);
428 static int reparent_ctf_expression(struct ctf_node *node,
429 struct ctf_node *parent)
431 switch (parent->type) {
433 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
436 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
439 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
442 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
445 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
448 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
450 case NODE_FLOATING_POINT:
451 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
454 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
457 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
461 case NODE_CTF_EXPRESSION:
463 case NODE_TYPEALIAS_TARGET:
464 case NODE_TYPEALIAS_ALIAS:
466 case NODE_TYPE_SPECIFIER:
467 case NODE_TYPE_SPECIFIER_LIST:
469 case NODE_TYPE_DECLARATOR:
470 case NODE_ENUMERATOR:
472 case NODE_STRUCT_OR_VARIANT_DECLARATION:
475 case NODE_UNARY_EXPRESSION:
480 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
486 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
488 switch (parent->type) {
490 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
493 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
496 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
499 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
502 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
505 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
508 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
511 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
514 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
517 case NODE_FLOATING_POINT:
520 case NODE_CTF_EXPRESSION:
522 case NODE_TYPEALIAS_TARGET:
523 case NODE_TYPEALIAS_ALIAS:
525 case NODE_TYPE_SPECIFIER:
526 case NODE_TYPE_SPECIFIER_LIST:
528 case NODE_TYPE_DECLARATOR:
529 case NODE_ENUMERATOR:
531 case NODE_STRUCT_OR_VARIANT_DECLARATION:
532 case NODE_UNARY_EXPRESSION:
537 printfn_fatal(node, "unknown node type %d", parent->type);
543 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
545 switch (parent->type) {
547 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
550 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
553 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
556 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
559 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
562 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
565 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
568 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
571 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
574 case NODE_FLOATING_POINT:
577 case NODE_CTF_EXPRESSION:
579 case NODE_TYPEALIAS_TARGET:
580 case NODE_TYPEALIAS_ALIAS:
582 case NODE_TYPE_SPECIFIER:
583 case NODE_TYPE_SPECIFIER_LIST:
585 case NODE_TYPE_DECLARATOR:
586 case NODE_ENUMERATOR:
588 case NODE_STRUCT_OR_VARIANT_DECLARATION:
589 case NODE_UNARY_EXPRESSION:
594 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
600 static int reparent_type_specifier(struct ctf_node *node,
601 struct ctf_node *parent)
603 switch (parent->type) {
604 case NODE_TYPE_SPECIFIER_LIST:
605 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
608 case NODE_TYPE_SPECIFIER:
618 case NODE_TYPEALIAS_TARGET:
619 case NODE_TYPEALIAS_ALIAS:
620 case NODE_TYPE_DECLARATOR:
622 case NODE_STRUCT_OR_VARIANT_DECLARATION:
624 case NODE_FLOATING_POINT:
627 case NODE_CTF_EXPRESSION:
629 case NODE_ENUMERATOR:
630 case NODE_UNARY_EXPRESSION:
635 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
641 static int reparent_type_specifier_list(struct ctf_node *node,
642 struct ctf_node *parent)
644 switch (parent->type) {
646 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
649 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
652 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
655 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
658 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
661 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
664 bt_list_add_tail(&node->siblings, &parent->u.callsite.declaration_list);
667 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
670 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
673 parent->u._typedef.type_specifier_list = node;
675 case NODE_TYPEALIAS_TARGET:
676 parent->u.typealias_target.type_specifier_list = node;
678 case NODE_TYPEALIAS_ALIAS:
679 parent->u.typealias_alias.type_specifier_list = node;
682 parent->u._enum.container_type = node;
684 case NODE_STRUCT_OR_VARIANT_DECLARATION:
685 parent->u.struct_or_variant_declaration.type_specifier_list = node;
687 case NODE_TYPE_DECLARATOR:
688 case NODE_TYPE_SPECIFIER:
690 case NODE_FLOATING_POINT:
693 case NODE_CTF_EXPRESSION:
695 case NODE_ENUMERATOR:
696 case NODE_UNARY_EXPRESSION:
701 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
707 static int reparent_type_declarator(struct ctf_node *node,
708 struct ctf_node *parent)
710 switch (parent->type) {
711 case NODE_TYPE_DECLARATOR:
712 parent->u.type_declarator.type = TYPEDEC_NESTED;
713 parent->u.type_declarator.u.nested.type_declarator = node;
715 case NODE_STRUCT_OR_VARIANT_DECLARATION:
716 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
719 _bt_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
721 case NODE_TYPEALIAS_TARGET:
722 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
724 case NODE_TYPEALIAS_ALIAS:
725 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
739 case NODE_FLOATING_POINT:
742 case NODE_CTF_EXPRESSION:
743 case NODE_TYPE_SPECIFIER:
744 case NODE_TYPE_SPECIFIER_LIST:
746 case NODE_ENUMERATOR:
747 case NODE_UNARY_EXPRESSION:
752 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
761 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
762 * create the link declared by the input, -ENOENT if node or parent is NULL,
763 * -EINVAL if there is an internal structure problem.
765 static int set_parent_node(struct ctf_node *node,
766 struct ctf_node *parent)
768 if (!node || !parent)
771 /* Note: Linking to parent will be done only by an external visitor */
773 switch (node->type) {
775 printfn_fatal(node, "trying to reparent root node");
779 if (parent->type == NODE_ROOT) {
780 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
786 if (parent->type == NODE_ROOT) {
787 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
793 if (parent->type == NODE_ROOT) {
794 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
800 if (parent->type == NODE_ROOT) {
801 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
807 if (parent->type == NODE_ROOT) {
808 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
814 if (parent->type == NODE_ROOT) {
815 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.callsite);
821 case NODE_CTF_EXPRESSION:
822 return reparent_ctf_expression(node, parent);
823 case NODE_UNARY_EXPRESSION:
824 if (parent->type == NODE_TYPE_DECLARATOR)
825 parent->u.type_declarator.bitfield_len = node;
831 return reparent_typedef(node, parent);
832 case NODE_TYPEALIAS_TARGET:
833 if (parent->type == NODE_TYPEALIAS)
834 parent->u.typealias.target = node;
837 case NODE_TYPEALIAS_ALIAS:
838 if (parent->type == NODE_TYPEALIAS)
839 parent->u.typealias.alias = node;
843 return reparent_typealias(node, parent);
846 if (parent->type == NODE_TYPE_DECLARATOR) {
847 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
851 case NODE_TYPE_DECLARATOR:
852 return reparent_type_declarator(node, parent);
854 case NODE_TYPE_SPECIFIER_LIST:
855 return reparent_type_specifier_list(node, parent);
857 case NODE_TYPE_SPECIFIER:
858 return reparent_type_specifier(node, parent);
860 case NODE_FLOATING_POINT:
866 return -EINVAL; /* Dealt with internally within grammar */
868 case NODE_ENUMERATOR:
869 if (parent->type == NODE_ENUM) {
870 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
875 case NODE_STRUCT_OR_VARIANT_DECLARATION:
876 switch (parent->type) {
878 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
881 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
890 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
897 void yyerror(struct ctf_scanner *scanner, const char *str)
899 printfl_error(yyget_lineno(scanner->scanner),
900 "token \"%s\": %s\n",
901 yyget_text(scanner->scanner), str);
910 #define reparent_error(scanner, str) \
912 yyerror(scanner, YY_("reparent_error: " str)); \
916 static void free_strings(struct bt_list_head *list)
918 struct gc_string *gstr, *tmp;
920 bt_list_for_each_entry_safe(gstr, tmp, list, gc)
924 static struct ctf_ast *ctf_ast_alloc(void)
928 ast = malloc(sizeof(*ast));
931 memset(ast, 0, sizeof(*ast));
932 BT_INIT_LIST_HEAD(&ast->allocated_nodes);
933 ast->root.type = NODE_ROOT;
934 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
935 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
936 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
937 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
938 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
939 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
940 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
941 BT_INIT_LIST_HEAD(&ast->root.u.root.callsite);
945 static void ctf_ast_free(struct ctf_ast *ast)
947 struct ctf_node *node, *tmp;
949 bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
954 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
956 return yyparse(scanner);
959 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
961 struct ctf_scanner *scanner;
964 yydebug = babeltrace_debug;
966 scanner = malloc(sizeof(*scanner));
969 memset(scanner, 0, sizeof(*scanner));
971 ret = yylex_init_extra(scanner, &scanner->scanner);
973 printf_fatal("yylex_init error");
974 goto cleanup_scanner;
976 /* Start processing new stream */
977 yyrestart(input, scanner->scanner);
979 scanner->ast = ctf_ast_alloc();
982 init_scope(&scanner->root_scope, NULL);
983 scanner->cs = &scanner->root_scope;
984 BT_INIT_LIST_HEAD(&scanner->allocated_strings);
987 fprintf(stdout, "Scanner input is a%s.\n",
988 isatty(fileno(input)) ? "n interactive tty" :
989 " noninteractive file");
994 ret = yylex_destroy(scanner->scanner);
996 printf_fatal("yylex_destroy error");
1002 void ctf_scanner_free(struct ctf_scanner *scanner)
1006 finalize_scope(&scanner->root_scope);
1007 free_strings(&scanner->allocated_strings);
1008 ctf_ast_free(scanner->ast);
1009 ret = yylex_destroy(scanner->scanner);
1011 printf_error("yylex_destroy error");
1020 %parse-param {struct ctf_scanner *scanner}
1021 %lex-param {struct ctf_scanner *scanner}
1023 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
1024 * vs struct { int :value; } (unnamed bit-field). The default is to
1025 * shift, so whenever we encounter an enumeration, we are doing the
1026 * proper thing (shift). It is illegal to declare an enumeration
1027 * "bit-field", so it is OK if this situation ends up in a parsing
1032 %token INTEGER_LITERAL STRING_LITERAL CHARACTER_LITERAL LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM ENV EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE CALLSITE CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY TOK_ALIGN
1033 %token <gs> IDENTIFIER ID_TYPE
1038 unsigned long long ull;
1040 struct gc_string *gs;
1044 %type <gs> STRING_LITERAL CHARACTER_LITERAL
1048 %type <ull> INTEGER_LITERAL
1049 %type <n> postfix_expression unary_expression unary_expression_or_range
1051 %type <n> declaration
1052 %type <n> event_declaration
1053 %type <n> stream_declaration
1054 %type <n> env_declaration
1055 %type <n> trace_declaration
1056 %type <n> clock_declaration
1057 %type <n> callsite_declaration
1058 %type <n> integer_declaration_specifiers
1059 %type <n> declaration_specifiers
1060 %type <n> alias_declaration_specifiers
1062 %type <n> type_declarator_list
1063 %type <n> integer_type_specifier
1064 %type <n> type_specifier
1065 %type <n> struct_type_specifier
1066 %type <n> variant_type_specifier
1067 %type <n> enum_type_specifier
1068 %type <n> struct_or_variant_declaration_list
1069 %type <n> struct_or_variant_declaration
1070 %type <n> struct_or_variant_declarator_list
1071 %type <n> struct_or_variant_declarator
1072 %type <n> enumerator_list
1073 %type <n> enumerator
1074 %type <n> abstract_declarator_list
1075 %type <n> abstract_declarator
1076 %type <n> direct_abstract_declarator
1077 %type <n> alias_abstract_declarator_list
1078 %type <n> alias_abstract_declarator
1079 %type <n> direct_alias_abstract_declarator
1080 %type <n> declarator
1081 %type <n> direct_declarator
1082 %type <n> type_declarator
1083 %type <n> direct_type_declarator
1085 %type <n> ctf_assignment_expression_list
1086 %type <n> ctf_assignment_expression
1093 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
1094 reparent_error(scanner, "error reparenting to root");
1098 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
1099 reparent_error(scanner, "error reparenting to root");
1161 /* 2: Phrase structure grammar */
1166 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1167 $$->u.unary_expression.type = UNARY_STRING;
1168 $$->u.unary_expression.u.string = yylval.gs->s;
1172 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1173 $$->u.unary_expression.type = UNARY_STRING;
1174 $$->u.unary_expression.u.string = yylval.gs->s;
1178 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1179 $$->u.unary_expression.type = UNARY_STRING;
1180 $$->u.unary_expression.u.string = yylval.gs->s;
1184 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1185 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1186 $$->u.unary_expression.u.unsigned_constant = $1;
1190 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1191 $$->u.unary_expression.type = UNARY_STRING;
1192 $$->u.unary_expression.u.string = $1->s;
1196 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1197 $$->u.unary_expression.type = UNARY_STRING;
1198 $$->u.unary_expression.u.string = $1->s;
1200 | LPAREN unary_expression RPAREN
1202 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1203 $$->u.unary_expression.type = UNARY_NESTED;
1204 $$->u.unary_expression.u.nested_exp = $2;
1206 | postfix_expression LSBRAC unary_expression RSBRAC
1208 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1209 $$->u.unary_expression.type = UNARY_SBRAC;
1210 $$->u.unary_expression.u.sbrac_exp = $3;
1211 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1212 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1214 | postfix_expression DOT IDENTIFIER
1216 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1217 $$->u.unary_expression.type = UNARY_STRING;
1218 $$->u.unary_expression.u.string = yylval.gs->s;
1219 $$->u.unary_expression.link = UNARY_DOTLINK;
1220 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1221 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1223 | postfix_expression DOT ID_TYPE
1225 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1226 $$->u.unary_expression.type = UNARY_STRING;
1227 $$->u.unary_expression.u.string = yylval.gs->s;
1228 $$->u.unary_expression.link = UNARY_DOTLINK;
1229 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1230 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1232 | postfix_expression RARROW IDENTIFIER
1234 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1235 $$->u.unary_expression.type = UNARY_STRING;
1236 $$->u.unary_expression.u.string = yylval.gs->s;
1237 $$->u.unary_expression.link = UNARY_ARROWLINK;
1238 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1239 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1241 | postfix_expression RARROW ID_TYPE
1243 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1244 $$->u.unary_expression.type = UNARY_STRING;
1245 $$->u.unary_expression.u.string = yylval.gs->s;
1246 $$->u.unary_expression.link = UNARY_ARROWLINK;
1247 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1248 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1255 | PLUS postfix_expression
1258 if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
1259 && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
1260 reparent_error(scanner, "expecting numeric constant");
1263 | MINUS postfix_expression
1266 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1267 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1268 $$->u.unary_expression.u.signed_constant =
1269 -($$->u.unary_expression.u.unsigned_constant);
1270 } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1271 $$->u.unary_expression.u.signed_constant =
1272 -($$->u.unary_expression.u.signed_constant);
1274 reparent_error(scanner, "expecting numeric constant");
1279 unary_expression_or_range:
1280 unary_expression DOTDOTDOT unary_expression
1283 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1284 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1290 /* 2.2: Declarations */
1293 declaration_specifiers SEMICOLON
1297 | stream_declaration
1305 | callsite_declaration
1307 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1309 struct ctf_node *list;
1311 $$ = make_node(scanner, NODE_TYPEDEF);
1312 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1313 $$->u._typedef.type_specifier_list = list;
1314 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1315 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1316 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1318 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1320 struct ctf_node *list;
1322 $$ = make_node(scanner, NODE_TYPEDEF);
1323 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1324 $$->u._typedef.type_specifier_list = list;
1325 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1326 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1328 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1330 struct ctf_node *list;
1332 $$ = make_node(scanner, NODE_TYPEDEF);
1333 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1334 $$->u._typedef.type_specifier_list = list;
1335 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1336 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1338 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1340 struct ctf_node *list;
1342 $$ = make_node(scanner, NODE_TYPEALIAS);
1343 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1344 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1346 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1347 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1348 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1349 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1351 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1352 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1353 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1354 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1359 event_declaration_begin event_declaration_end
1361 $$ = make_node(scanner, NODE_EVENT);
1363 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1365 $$ = make_node(scanner, NODE_EVENT);
1366 if (set_parent_node($2, $$))
1367 reparent_error(scanner, "event_declaration");
1371 event_declaration_begin:
1373 { push_scope(scanner); }
1376 event_declaration_end:
1378 { pop_scope(scanner); }
1383 stream_declaration_begin stream_declaration_end
1385 $$ = make_node(scanner, NODE_STREAM);
1387 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1389 $$ = make_node(scanner, NODE_STREAM);
1390 if (set_parent_node($2, $$))
1391 reparent_error(scanner, "stream_declaration");
1395 stream_declaration_begin:
1397 { push_scope(scanner); }
1400 stream_declaration_end:
1402 { pop_scope(scanner); }
1406 env_declaration_begin env_declaration_end
1408 $$ = make_node(scanner, NODE_ENV);
1410 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1412 $$ = make_node(scanner, NODE_ENV);
1413 if (set_parent_node($2, $$))
1414 reparent_error(scanner, "env declaration");
1418 env_declaration_begin:
1420 { push_scope(scanner); }
1423 env_declaration_end:
1425 { pop_scope(scanner); }
1429 trace_declaration_begin trace_declaration_end
1431 $$ = make_node(scanner, NODE_TRACE);
1433 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1435 $$ = make_node(scanner, NODE_TRACE);
1436 if (set_parent_node($2, $$))
1437 reparent_error(scanner, "trace_declaration");
1441 trace_declaration_begin:
1443 { push_scope(scanner); }
1446 trace_declaration_end:
1448 { pop_scope(scanner); }
1452 CLOCK clock_declaration_begin clock_declaration_end
1454 $$ = make_node(scanner, NODE_CLOCK);
1456 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1458 $$ = make_node(scanner, NODE_CLOCK);
1459 if (set_parent_node($3, $$))
1460 reparent_error(scanner, "trace_declaration");
1464 clock_declaration_begin:
1466 { push_scope(scanner); }
1469 clock_declaration_end:
1471 { pop_scope(scanner); }
1474 callsite_declaration:
1475 CALLSITE callsite_declaration_begin callsite_declaration_end
1477 $$ = make_node(scanner, NODE_CALLSITE);
1479 | CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1481 $$ = make_node(scanner, NODE_CALLSITE);
1482 if (set_parent_node($3, $$))
1483 reparent_error(scanner, "trace_declaration");
1487 callsite_declaration_begin:
1489 { push_scope(scanner); }
1492 callsite_declaration_end:
1494 { pop_scope(scanner); }
1497 integer_declaration_specifiers:
1500 struct ctf_node *node;
1502 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1503 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1504 node->u.type_specifier.type = TYPESPEC_CONST;
1505 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1507 | integer_type_specifier
1509 struct ctf_node *node;
1511 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1513 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1515 | integer_declaration_specifiers CONST
1517 struct ctf_node *node;
1520 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1521 node->u.type_specifier.type = TYPESPEC_CONST;
1522 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1524 | integer_declaration_specifiers integer_type_specifier
1527 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1531 declaration_specifiers:
1534 struct ctf_node *node;
1536 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1537 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1538 node->u.type_specifier.type = TYPESPEC_CONST;
1539 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1543 struct ctf_node *node;
1545 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1547 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1549 | declaration_specifiers CONST
1551 struct ctf_node *node;
1554 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1555 node->u.type_specifier.type = TYPESPEC_CONST;
1556 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1558 | declaration_specifiers type_specifier
1561 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1565 type_declarator_list:
1568 | type_declarator_list COMMA type_declarator
1571 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1575 integer_type_specifier:
1578 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1579 $$->u.type_specifier.type = TYPESPEC_CHAR;
1583 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1584 $$->u.type_specifier.type = TYPESPEC_SHORT;
1588 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1589 $$->u.type_specifier.type = TYPESPEC_INT;
1593 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1594 $$->u.type_specifier.type = TYPESPEC_LONG;
1598 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1599 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1603 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1604 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1608 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1609 $$->u.type_specifier.type = TYPESPEC_BOOL;
1613 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1614 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1615 $$->u.type_specifier.id_type = yylval.gs->s;
1617 | INTEGER LBRAC RBRAC
1619 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1620 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1621 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1623 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1625 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1626 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1627 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1628 if (set_parent_node($3, $$->u.type_specifier.node))
1629 reparent_error(scanner, "integer reparent error");
1636 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1637 $$->u.type_specifier.type = TYPESPEC_VOID;
1641 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1642 $$->u.type_specifier.type = TYPESPEC_CHAR;
1646 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1647 $$->u.type_specifier.type = TYPESPEC_SHORT;
1651 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1652 $$->u.type_specifier.type = TYPESPEC_INT;
1656 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1657 $$->u.type_specifier.type = TYPESPEC_LONG;
1661 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1662 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1666 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1667 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1671 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1672 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1676 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1677 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1681 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1682 $$->u.type_specifier.type = TYPESPEC_BOOL;
1686 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1687 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1691 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1692 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1696 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1697 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1698 $$->u.type_specifier.id_type = yylval.gs->s;
1700 | FLOATING_POINT LBRAC RBRAC
1702 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1703 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1704 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1706 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1708 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1709 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1710 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1711 if (set_parent_node($3, $$->u.type_specifier.node))
1712 reparent_error(scanner, "floating point reparent error");
1714 | INTEGER LBRAC RBRAC
1716 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1717 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1718 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1720 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1722 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1723 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1724 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1725 if (set_parent_node($3, $$->u.type_specifier.node))
1726 reparent_error(scanner, "integer reparent error");
1730 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1731 $$->u.type_specifier.type = TYPESPEC_STRING;
1732 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1734 | STRING LBRAC RBRAC
1736 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1737 $$->u.type_specifier.type = TYPESPEC_STRING;
1738 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1740 | STRING LBRAC ctf_assignment_expression_list RBRAC
1742 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1743 $$->u.type_specifier.type = TYPESPEC_STRING;
1744 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1745 if (set_parent_node($3, $$->u.type_specifier.node))
1746 reparent_error(scanner, "string reparent error");
1748 | ENUM enum_type_specifier
1750 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1751 $$->u.type_specifier.type = TYPESPEC_ENUM;
1752 $$->u.type_specifier.node = $2;
1754 | VARIANT variant_type_specifier
1756 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1757 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1758 $$->u.type_specifier.node = $2;
1760 | STRUCT struct_type_specifier
1762 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1763 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1764 $$->u.type_specifier.node = $2;
1768 struct_type_specifier:
1769 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1771 $$ = make_node(scanner, NODE_STRUCT);
1772 $$->u._struct.has_body = 1;
1773 if ($2 && set_parent_node($2, $$))
1774 reparent_error(scanner, "struct reparent error");
1776 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1778 $$ = make_node(scanner, NODE_STRUCT);
1779 $$->u._struct.has_body = 1;
1780 $$->u._struct.name = $1->s;
1781 if ($3 && set_parent_node($3, $$))
1782 reparent_error(scanner, "struct reparent error");
1784 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1786 $$ = make_node(scanner, NODE_STRUCT);
1787 $$->u._struct.has_body = 1;
1788 $$->u._struct.name = $1->s;
1789 if ($3 && set_parent_node($3, $$))
1790 reparent_error(scanner, "struct reparent error");
1794 $$ = make_node(scanner, NODE_STRUCT);
1795 $$->u._struct.has_body = 0;
1796 $$->u._struct.name = $1->s;
1800 $$ = make_node(scanner, NODE_STRUCT);
1801 $$->u._struct.has_body = 0;
1802 $$->u._struct.name = $1->s;
1804 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1806 $$ = make_node(scanner, NODE_STRUCT);
1807 $$->u._struct.has_body = 1;
1808 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1809 if ($2 && set_parent_node($2, $$))
1810 reparent_error(scanner, "struct reparent error");
1812 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1814 $$ = make_node(scanner, NODE_STRUCT);
1815 $$->u._struct.has_body = 1;
1816 $$->u._struct.name = $1->s;
1817 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1818 if ($3 && set_parent_node($3, $$))
1819 reparent_error(scanner, "struct reparent error");
1821 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1823 $$ = make_node(scanner, NODE_STRUCT);
1824 $$->u._struct.has_body = 1;
1825 $$->u._struct.name = $1->s;
1826 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1827 if ($3 && set_parent_node($3, $$))
1828 reparent_error(scanner, "struct reparent error");
1832 struct_declaration_begin:
1834 { push_scope(scanner); }
1837 struct_declaration_end:
1839 { pop_scope(scanner); }
1842 variant_type_specifier:
1843 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1845 $$ = make_node(scanner, NODE_VARIANT);
1846 $$->u.variant.has_body = 1;
1847 if ($2 && set_parent_node($2, $$))
1848 reparent_error(scanner, "variant reparent error");
1850 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1852 $$ = make_node(scanner, NODE_VARIANT);
1853 $$->u.variant.has_body = 1;
1854 $$->u.variant.choice = $2->s;
1855 if ($5 && set_parent_node($5, $$))
1856 reparent_error(scanner, "variant reparent error");
1858 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1860 $$ = make_node(scanner, NODE_VARIANT);
1861 $$->u.variant.has_body = 1;
1862 $$->u.variant.choice = $2->s;
1863 if ($5 && set_parent_node($5, $$))
1864 reparent_error(scanner, "variant reparent error");
1866 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1868 $$ = make_node(scanner, NODE_VARIANT);
1869 $$->u.variant.has_body = 1;
1870 $$->u.variant.name = $1->s;
1871 if ($3 && set_parent_node($3, $$))
1872 reparent_error(scanner, "variant reparent error");
1874 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1876 $$ = make_node(scanner, NODE_VARIANT);
1877 $$->u.variant.has_body = 1;
1878 $$->u.variant.name = $1->s;
1879 $$->u.variant.choice = $3->s;
1880 if ($6 && set_parent_node($6, $$))
1881 reparent_error(scanner, "variant reparent error");
1883 | IDENTIFIER LT IDENTIFIER GT
1885 $$ = make_node(scanner, NODE_VARIANT);
1886 $$->u.variant.has_body = 0;
1887 $$->u.variant.name = $1->s;
1888 $$->u.variant.choice = $3->s;
1890 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1892 $$ = make_node(scanner, NODE_VARIANT);
1893 $$->u.variant.has_body = 1;
1894 $$->u.variant.name = $1->s;
1895 $$->u.variant.choice = $3->s;
1896 if ($6 && set_parent_node($6, $$))
1897 reparent_error(scanner, "variant reparent error");
1899 | IDENTIFIER LT ID_TYPE GT
1901 $$ = make_node(scanner, NODE_VARIANT);
1902 $$->u.variant.has_body = 0;
1903 $$->u.variant.name = $1->s;
1904 $$->u.variant.choice = $3->s;
1906 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1908 $$ = make_node(scanner, NODE_VARIANT);
1909 $$->u.variant.has_body = 1;
1910 $$->u.variant.name = $1->s;
1911 if ($3 && set_parent_node($3, $$))
1912 reparent_error(scanner, "variant reparent error");
1914 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1916 $$ = make_node(scanner, NODE_VARIANT);
1917 $$->u.variant.has_body = 1;
1918 $$->u.variant.name = $1->s;
1919 $$->u.variant.choice = $3->s;
1920 if ($6 && set_parent_node($6, $$))
1921 reparent_error(scanner, "variant reparent error");
1923 | ID_TYPE LT IDENTIFIER GT
1925 $$ = make_node(scanner, NODE_VARIANT);
1926 $$->u.variant.has_body = 0;
1927 $$->u.variant.name = $1->s;
1928 $$->u.variant.choice = $3->s;
1930 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1932 $$ = make_node(scanner, NODE_VARIANT);
1933 $$->u.variant.has_body = 1;
1934 $$->u.variant.name = $1->s;
1935 $$->u.variant.choice = $3->s;
1936 if ($6 && set_parent_node($6, $$))
1937 reparent_error(scanner, "variant reparent error");
1939 | ID_TYPE LT ID_TYPE GT
1941 $$ = make_node(scanner, NODE_VARIANT);
1942 $$->u.variant.has_body = 0;
1943 $$->u.variant.name = $1->s;
1944 $$->u.variant.choice = $3->s;
1948 variant_declaration_begin:
1950 { push_scope(scanner); }
1953 variant_declaration_end:
1955 { pop_scope(scanner); }
1958 enum_type_specifier:
1959 LBRAC enumerator_list RBRAC
1961 $$ = make_node(scanner, NODE_ENUM);
1962 $$->u._enum.has_body = 1;
1963 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1965 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1967 $$ = make_node(scanner, NODE_ENUM);
1968 $$->u._enum.has_body = 1;
1969 ($$)->u._enum.container_type = $2;
1970 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1972 | IDENTIFIER LBRAC enumerator_list RBRAC
1974 $$ = make_node(scanner, NODE_ENUM);
1975 $$->u._enum.has_body = 1;
1976 $$->u._enum.enum_id = $1->s;
1977 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1979 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1981 $$ = make_node(scanner, NODE_ENUM);
1982 $$->u._enum.has_body = 1;
1983 $$->u._enum.enum_id = $1->s;
1984 ($$)->u._enum.container_type = $3;
1985 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1987 | ID_TYPE LBRAC enumerator_list RBRAC
1989 $$ = make_node(scanner, NODE_ENUM);
1990 $$->u._enum.has_body = 1;
1991 $$->u._enum.enum_id = $1->s;
1992 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1994 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1996 $$ = make_node(scanner, NODE_ENUM);
1997 $$->u._enum.has_body = 1;
1998 $$->u._enum.enum_id = $1->s;
1999 ($$)->u._enum.container_type = $3;
2000 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2002 | LBRAC enumerator_list COMMA RBRAC
2004 $$ = make_node(scanner, NODE_ENUM);
2005 $$->u._enum.has_body = 1;
2006 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
2008 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2010 $$ = make_node(scanner, NODE_ENUM);
2011 $$->u._enum.has_body = 1;
2012 ($$)->u._enum.container_type = $2;
2013 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
2015 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
2017 $$ = make_node(scanner, NODE_ENUM);
2018 $$->u._enum.has_body = 1;
2019 $$->u._enum.enum_id = $1->s;
2020 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2022 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2024 $$ = make_node(scanner, NODE_ENUM);
2025 $$->u._enum.has_body = 1;
2026 $$->u._enum.enum_id = $1->s;
2027 ($$)->u._enum.container_type = $3;
2028 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2032 $$ = make_node(scanner, NODE_ENUM);
2033 $$->u._enum.has_body = 0;
2034 $$->u._enum.enum_id = $1->s;
2036 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
2038 $$ = make_node(scanner, NODE_ENUM);
2039 $$->u._enum.has_body = 1;
2040 $$->u._enum.enum_id = $1->s;
2041 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2043 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2045 $$ = make_node(scanner, NODE_ENUM);
2046 $$->u._enum.has_body = 1;
2047 $$->u._enum.enum_id = $1->s;
2048 ($$)->u._enum.container_type = $3;
2049 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2053 $$ = make_node(scanner, NODE_ENUM);
2054 $$->u._enum.has_body = 0;
2055 $$->u._enum.enum_id = $1->s;
2059 struct_or_variant_declaration_list:
2062 | struct_or_variant_declaration_list struct_or_variant_declaration
2066 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2069 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
2074 struct_or_variant_declaration:
2075 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
2077 struct ctf_node *list;
2079 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2080 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2081 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
2082 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2083 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
2085 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2087 struct ctf_node *list;
2089 $$ = make_node(scanner, NODE_TYPEDEF);
2090 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2091 $$->u._typedef.type_specifier_list = list;
2092 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2093 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2094 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2096 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2098 struct ctf_node *list;
2100 $$ = make_node(scanner, NODE_TYPEDEF);
2101 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2102 $$->u._typedef.type_specifier_list = list;
2103 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2104 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2106 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
2108 struct ctf_node *list;
2110 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2111 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2112 $$ = make_node(scanner, NODE_TYPEDEF);
2113 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2114 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2116 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
2118 struct ctf_node *list;
2120 $$ = make_node(scanner, NODE_TYPEALIAS);
2121 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2122 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2124 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2125 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2126 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2127 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2129 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2130 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2131 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2132 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2136 alias_declaration_specifiers:
2139 struct ctf_node *node;
2141 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2142 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2143 node->u.type_specifier.type = TYPESPEC_CONST;
2144 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2148 struct ctf_node *node;
2150 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2152 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2156 struct ctf_node *node;
2158 add_type(scanner, $1);
2159 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2160 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2161 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2162 node->u.type_specifier.id_type = yylval.gs->s;
2163 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2165 | alias_declaration_specifiers CONST
2167 struct ctf_node *node;
2170 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2171 node->u.type_specifier.type = TYPESPEC_CONST;
2172 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2174 | alias_declaration_specifiers type_specifier
2177 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2179 | alias_declaration_specifiers IDENTIFIER
2181 struct ctf_node *node;
2183 add_type(scanner, $2);
2185 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2186 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2187 node->u.type_specifier.id_type = yylval.gs->s;
2188 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2192 struct_or_variant_declarator_list:
2193 struct_or_variant_declarator
2195 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2198 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2202 struct_or_variant_declarator:
2205 | COLON unary_expression
2207 | declarator COLON unary_expression
2210 if (set_parent_node($3, $1))
2211 reparent_error(scanner, "struct_or_variant_declarator");
2218 | enumerator_list COMMA enumerator
2221 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2228 $$ = make_node(scanner, NODE_ENUMERATOR);
2229 $$->u.enumerator.id = $1->s;
2233 $$ = make_node(scanner, NODE_ENUMERATOR);
2234 $$->u.enumerator.id = $1->s;
2238 $$ = make_node(scanner, NODE_ENUMERATOR);
2239 $$->u.enumerator.id = $1->s;
2243 $$ = make_node(scanner, NODE_ENUMERATOR);
2244 $$->u.enumerator.id = $1->s;
2246 | IDENTIFIER EQUAL unary_expression_or_range
2248 $$ = make_node(scanner, NODE_ENUMERATOR);
2249 $$->u.enumerator.id = $1->s;
2250 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2252 | ID_TYPE EQUAL unary_expression_or_range
2254 $$ = make_node(scanner, NODE_ENUMERATOR);
2255 $$->u.enumerator.id = $1->s;
2256 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2258 | keywords EQUAL unary_expression_or_range
2260 $$ = make_node(scanner, NODE_ENUMERATOR);
2261 $$->u.enumerator.id = $1->s;
2262 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2264 | STRING_LITERAL EQUAL unary_expression_or_range
2266 $$ = make_node(scanner, NODE_ENUMERATOR);
2267 $$->u.enumerator.id = $1->s;
2268 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2272 abstract_declarator_list:
2275 | abstract_declarator_list COMMA abstract_declarator
2278 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2282 abstract_declarator:
2283 direct_abstract_declarator
2285 | pointer direct_abstract_declarator
2288 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2292 direct_abstract_declarator:
2295 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2296 $$->u.type_declarator.type = TYPEDEC_ID;
2301 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2302 $$->u.type_declarator.type = TYPEDEC_ID;
2303 $$->u.type_declarator.u.id = $1->s;
2305 | LPAREN abstract_declarator RPAREN
2307 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2308 $$->u.type_declarator.type = TYPEDEC_NESTED;
2309 $$->u.type_declarator.u.nested.type_declarator = $2;
2311 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2313 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2314 $$->u.type_declarator.type = TYPEDEC_NESTED;
2315 $$->u.type_declarator.u.nested.type_declarator = $1;
2316 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2317 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2319 | direct_abstract_declarator LSBRAC RSBRAC
2321 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2322 $$->u.type_declarator.type = TYPEDEC_NESTED;
2323 $$->u.type_declarator.u.nested.type_declarator = $1;
2324 $$->u.type_declarator.u.nested.abstract_array = 1;
2328 alias_abstract_declarator_list:
2329 alias_abstract_declarator
2331 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2334 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2338 alias_abstract_declarator:
2339 direct_alias_abstract_declarator
2341 | pointer direct_alias_abstract_declarator
2344 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2348 direct_alias_abstract_declarator:
2351 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2352 $$->u.type_declarator.type = TYPEDEC_ID;
2355 | LPAREN alias_abstract_declarator RPAREN
2357 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2358 $$->u.type_declarator.type = TYPEDEC_NESTED;
2359 $$->u.type_declarator.u.nested.type_declarator = $2;
2361 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2363 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2364 $$->u.type_declarator.type = TYPEDEC_NESTED;
2365 $$->u.type_declarator.u.nested.type_declarator = $1;
2366 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2367 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2369 | direct_alias_abstract_declarator LSBRAC RSBRAC
2371 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2372 $$->u.type_declarator.type = TYPEDEC_NESTED;
2373 $$->u.type_declarator.u.nested.type_declarator = $1;
2374 $$->u.type_declarator.u.nested.abstract_array = 1;
2381 | pointer direct_declarator
2384 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2391 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2392 $$->u.type_declarator.type = TYPEDEC_ID;
2393 $$->u.type_declarator.u.id = $1->s;
2395 | LPAREN declarator RPAREN
2397 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2398 $$->u.type_declarator.type = TYPEDEC_NESTED;
2399 $$->u.type_declarator.u.nested.type_declarator = $2;
2401 | direct_declarator LSBRAC unary_expression RSBRAC
2403 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2404 $$->u.type_declarator.type = TYPEDEC_NESTED;
2405 $$->u.type_declarator.u.nested.type_declarator = $1;
2406 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2407 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2412 direct_type_declarator
2414 | pointer direct_type_declarator
2417 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2421 direct_type_declarator:
2424 add_type(scanner, $1);
2425 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2426 $$->u.type_declarator.type = TYPEDEC_ID;
2427 $$->u.type_declarator.u.id = $1->s;
2429 | LPAREN type_declarator RPAREN
2431 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2432 $$->u.type_declarator.type = TYPEDEC_NESTED;
2433 $$->u.type_declarator.u.nested.type_declarator = $2;
2435 | direct_type_declarator LSBRAC unary_expression RSBRAC
2437 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2438 $$->u.type_declarator.type = TYPEDEC_NESTED;
2439 $$->u.type_declarator.u.nested.type_declarator = $1;
2440 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2441 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2448 $$ = make_node(scanner, NODE_POINTER);
2452 $$ = make_node(scanner, NODE_POINTER);
2453 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2455 | STAR type_qualifier_list pointer
2457 $$ = make_node(scanner, NODE_POINTER);
2458 $$->u.pointer.const_qualifier = 1;
2459 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2463 type_qualifier_list:
2464 /* pointer assumes only const type qualifier */
2466 | type_qualifier_list CONST
2469 /* 2.3: CTF-specific declarations */
2471 ctf_assignment_expression_list:
2472 ctf_assignment_expression SEMICOLON
2474 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2477 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2481 ctf_assignment_expression:
2482 unary_expression EQUAL unary_expression
2485 * Because we have left and right, cannot use
2488 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2489 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2490 if ($1->u.unary_expression.type != UNARY_STRING)
2491 reparent_error(scanner, "ctf_assignment_expression left expects string");
2492 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2494 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2497 * Because we have left and right, cannot use
2500 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2501 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2502 if ($1->u.unary_expression.type != UNARY_STRING)
2503 reparent_error(scanner, "ctf_assignment_expression left expects string");
2504 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2506 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2508 struct ctf_node *list;
2510 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2511 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2512 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2513 $$ = make_node(scanner, NODE_TYPEDEF);
2514 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2515 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2517 | TYPEDEF declaration_specifiers type_declarator_list
2519 struct ctf_node *list;
2521 $$ = make_node(scanner, NODE_TYPEDEF);
2522 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2523 $$->u._typedef.type_specifier_list = list;
2524 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2525 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2527 | declaration_specifiers TYPEDEF type_declarator_list
2529 struct ctf_node *list;
2531 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2532 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2533 $$ = make_node(scanner, NODE_TYPEDEF);
2534 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2535 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2537 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2539 struct ctf_node *list;
2541 $$ = make_node(scanner, NODE_TYPEALIAS);
2542 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2543 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2545 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2546 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2547 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2548 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2550 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2551 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2552 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2553 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);