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.
28 #include <babeltrace/list.h>
29 #include <babeltrace/babeltrace-internal.h>
30 #include "ctf-scanner.h"
31 #include "ctf-parser.h"
34 __attribute__((visibility("protected")))
37 /* Join two lists, put "add" at the end of "head". */
39 _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
41 /* Do nothing if the list which gets added is empty. */
42 if (add != add->next) {
43 add->next->prev = head->prev;
44 add->prev->next = head;
45 head->prev->next = add->next;
46 head->prev = add->prev;
50 __attribute__((visibility("protected")))
51 int yyparse(struct ctf_scanner *scanner);
52 __attribute__((visibility("protected")))
53 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
54 __attribute__((visibility("protected")))
55 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
56 __attribute__((visibility("protected")))
57 int yylex_destroy(yyscan_t yyscanner);
58 __attribute__((visibility("protected")))
59 void yyrestart(FILE * in_str, yyscan_t scanner);
62 struct bt_list_head gc;
67 static const char *node_type_to_str[] = {
68 [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
69 [ NODE_ROOT ] = "NODE_ROOT",
70 [ NODE_EVENT ] = "NODE_EVENT",
71 [ NODE_ENV ] = "NODE_ENV",
72 [ NODE_STREAM ] = "NODE_STREAM",
73 [ NODE_TRACE ] = "NODE_TRACE",
74 [ NODE_CLOCK ] = "NODE_CLOCK",
75 [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
76 [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
77 [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
78 [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
79 [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
80 [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
81 [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
82 [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
83 [ NODE_POINTER ] = "NODE_POINTER",
84 [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
85 [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
86 [ NODE_INTEGER ] = "NODE_INTEGER",
87 [ NODE_STRING ] = "NODE_STRING",
88 [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
89 [ NODE_ENUM ] = "NODE_ENUM",
90 [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
91 [ NODE_VARIANT ] = "NODE_VARIANT",
92 [ NODE_STRUCT ] = "NODE_STRUCT",
95 __attribute__((visibility("protected")))
96 const char *node_type(struct ctf_node *node)
98 if (node->type < NR_NODE_TYPES)
99 return node_type_to_str[node->type];
104 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
107 struct gc_string *gstr;
110 /* TODO: could be faster with find first bit or glib Gstring */
111 /* sizeof long to account for malloc header (int or long ?) */
112 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
115 gstr = malloc(alloclen);
116 bt_list_add(&gstr->gc, &scanner->allocated_strings);
117 gstr->alloclen = alloclen;
122 * note: never use gc_string_append on a string that has external references.
123 * gsrc will be garbage collected immediately, and gstr might be.
124 * Should only be used to append characters to a string literal or constant.
126 __attribute__((visibility("protected")))
127 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
128 struct gc_string *gstr,
129 struct gc_string *gsrc)
131 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
134 /* TODO: could be faster with find first bit or glib Gstring */
135 /* sizeof long to account for malloc header (int or long ?) */
136 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
139 if (alloclen > gstr->alloclen) {
140 struct gc_string *newgstr;
142 newgstr = gc_string_alloc(scanner, newlen);
143 strcpy(newgstr->s, gstr->s);
144 strcat(newgstr->s, gsrc->s);
145 bt_list_del(&gstr->gc);
149 strcat(gstr->s, gsrc->s);
151 bt_list_del(&gsrc->gc);
156 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
158 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
159 strcpy(lvalp->gs->s, src);
162 static void init_scope(struct ctf_scanner_scope *scope,
163 struct ctf_scanner_scope *parent)
165 scope->parent = parent;
166 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
170 static void finalize_scope(struct ctf_scanner_scope *scope)
172 g_hash_table_destroy(scope->types);
175 static void push_scope(struct ctf_scanner *scanner)
177 struct ctf_scanner_scope *ns;
179 printf_debug("push scope\n");
180 ns = malloc(sizeof(struct ctf_scanner_scope));
181 init_scope(ns, scanner->cs);
185 static void pop_scope(struct ctf_scanner *scanner)
187 struct ctf_scanner_scope *os;
189 printf_debug("pop scope\n");
191 scanner->cs = os->parent;
196 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
200 ret = (int) (long) g_hash_table_lookup(s->types, id);
201 printf_debug("lookup %p %s %d\n", s, id, ret);
205 __attribute__((visibility("protected")))
206 int is_type(struct ctf_scanner *scanner, const char *id)
208 struct ctf_scanner_scope *it;
211 for (it = scanner->cs; it != NULL; it = it->parent) {
212 if (lookup_type(it, id)) {
217 printf_debug("is type %s %d\n", id, ret);
221 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
223 printf_debug("add type %s\n", id->s);
224 if (lookup_type(scanner->cs, id->s))
226 g_hash_table_insert(scanner->cs->types, id->s, id->s);
229 static struct ctf_node *make_node(struct ctf_scanner *scanner,
232 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
233 struct ctf_node *node;
235 node = malloc(sizeof(*node));
238 memset(node, 0, sizeof(*node));
240 BT_INIT_LIST_HEAD(&node->tmp_head);
241 bt_list_add(&node->gc, &ast->allocated_nodes);
242 bt_list_add(&node->siblings, &node->tmp_head);
246 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
250 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
253 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
256 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
259 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
262 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
265 case NODE_CTF_EXPRESSION:
266 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
267 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
269 case NODE_UNARY_EXPRESSION:
273 BT_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
275 case NODE_TYPEALIAS_TARGET:
276 BT_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
278 case NODE_TYPEALIAS_ALIAS:
279 BT_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
284 case NODE_TYPE_SPECIFIER:
286 case NODE_TYPE_SPECIFIER_LIST:
287 BT_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
291 case NODE_TYPE_DECLARATOR:
292 BT_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
295 case NODE_FLOATING_POINT:
296 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
299 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
302 BT_INIT_LIST_HEAD(&node->u.string.expressions);
304 case NODE_ENUMERATOR:
305 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
308 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
310 case NODE_STRUCT_OR_VARIANT_DECLARATION:
311 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
314 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
317 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
318 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
323 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
331 static int reparent_ctf_expression(struct ctf_node *node,
332 struct ctf_node *parent)
334 switch (parent->type) {
336 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
339 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
342 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
345 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
348 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
350 case NODE_FLOATING_POINT:
351 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
354 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
357 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
361 case NODE_CTF_EXPRESSION:
363 case NODE_TYPEALIAS_TARGET:
364 case NODE_TYPEALIAS_ALIAS:
366 case NODE_TYPE_SPECIFIER:
367 case NODE_TYPE_SPECIFIER_LIST:
369 case NODE_TYPE_DECLARATOR:
370 case NODE_ENUMERATOR:
372 case NODE_STRUCT_OR_VARIANT_DECLARATION:
375 case NODE_UNARY_EXPRESSION:
380 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
387 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
389 switch (parent->type) {
391 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
394 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
397 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
400 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
403 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
406 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
409 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
412 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
415 case NODE_FLOATING_POINT:
418 case NODE_CTF_EXPRESSION:
420 case NODE_TYPEALIAS_TARGET:
421 case NODE_TYPEALIAS_ALIAS:
423 case NODE_TYPE_SPECIFIER:
424 case NODE_TYPE_SPECIFIER_LIST:
426 case NODE_TYPE_DECLARATOR:
427 case NODE_ENUMERATOR:
429 case NODE_STRUCT_OR_VARIANT_DECLARATION:
430 case NODE_UNARY_EXPRESSION:
435 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
442 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
444 switch (parent->type) {
446 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
449 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
452 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
455 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
458 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
461 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
464 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
467 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
470 case NODE_FLOATING_POINT:
473 case NODE_CTF_EXPRESSION:
475 case NODE_TYPEALIAS_TARGET:
476 case NODE_TYPEALIAS_ALIAS:
478 case NODE_TYPE_SPECIFIER:
479 case NODE_TYPE_SPECIFIER_LIST:
481 case NODE_TYPE_DECLARATOR:
482 case NODE_ENUMERATOR:
484 case NODE_STRUCT_OR_VARIANT_DECLARATION:
485 case NODE_UNARY_EXPRESSION:
490 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
497 static int reparent_type_specifier(struct ctf_node *node,
498 struct ctf_node *parent)
500 switch (parent->type) {
501 case NODE_TYPE_SPECIFIER_LIST:
502 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
505 case NODE_TYPE_SPECIFIER:
514 case NODE_TYPEALIAS_TARGET:
515 case NODE_TYPEALIAS_ALIAS:
516 case NODE_TYPE_DECLARATOR:
518 case NODE_STRUCT_OR_VARIANT_DECLARATION:
520 case NODE_FLOATING_POINT:
523 case NODE_CTF_EXPRESSION:
525 case NODE_ENUMERATOR:
526 case NODE_UNARY_EXPRESSION:
531 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
538 static int reparent_type_specifier_list(struct ctf_node *node,
539 struct ctf_node *parent)
541 switch (parent->type) {
543 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
546 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
549 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
552 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
555 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
558 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
561 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
564 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
567 parent->u._typedef.type_specifier_list = node;
569 case NODE_TYPEALIAS_TARGET:
570 parent->u.typealias_target.type_specifier_list = node;
572 case NODE_TYPEALIAS_ALIAS:
573 parent->u.typealias_alias.type_specifier_list = node;
576 parent->u._enum.container_type = node;
578 case NODE_STRUCT_OR_VARIANT_DECLARATION:
579 parent->u.struct_or_variant_declaration.type_specifier_list = node;
581 case NODE_TYPE_DECLARATOR:
582 case NODE_TYPE_SPECIFIER:
584 case NODE_FLOATING_POINT:
587 case NODE_CTF_EXPRESSION:
589 case NODE_ENUMERATOR:
590 case NODE_UNARY_EXPRESSION:
595 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
602 static int reparent_type_declarator(struct ctf_node *node,
603 struct ctf_node *parent)
605 switch (parent->type) {
606 case NODE_TYPE_DECLARATOR:
607 parent->u.type_declarator.type = TYPEDEC_NESTED;
608 parent->u.type_declarator.u.nested.type_declarator = node;
610 case NODE_STRUCT_OR_VARIANT_DECLARATION:
611 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
614 _bt_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
616 case NODE_TYPEALIAS_TARGET:
617 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
619 case NODE_TYPEALIAS_ALIAS:
620 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
633 case NODE_FLOATING_POINT:
636 case NODE_CTF_EXPRESSION:
637 case NODE_TYPE_SPECIFIER:
638 case NODE_TYPE_SPECIFIER_LIST:
640 case NODE_ENUMERATOR:
641 case NODE_UNARY_EXPRESSION:
646 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
656 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
657 * create the link declared by the input, -ENOENT if node or parent is NULL,
658 * -EINVAL if there is an internal structure problem.
660 static int set_parent_node(struct ctf_node *node,
661 struct ctf_node *parent)
663 if (!node || !parent)
666 /* Note: Linking to parent will be done only by an external visitor */
668 switch (node->type) {
670 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
674 if (parent->type == NODE_ROOT) {
675 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
681 if (parent->type == NODE_ROOT) {
682 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
688 if (parent->type == NODE_ROOT) {
689 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
695 if (parent->type == NODE_ROOT) {
696 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
702 if (parent->type == NODE_ROOT) {
703 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
709 case NODE_CTF_EXPRESSION:
710 return reparent_ctf_expression(node, parent);
711 case NODE_UNARY_EXPRESSION:
712 if (parent->type == NODE_TYPE_DECLARATOR)
713 parent->u.type_declarator.bitfield_len = node;
719 return reparent_typedef(node, parent);
720 case NODE_TYPEALIAS_TARGET:
721 if (parent->type == NODE_TYPEALIAS)
722 parent->u.typealias.target = node;
725 case NODE_TYPEALIAS_ALIAS:
726 if (parent->type == NODE_TYPEALIAS)
727 parent->u.typealias.alias = node;
731 return reparent_typealias(node, parent);
734 if (parent->type == NODE_TYPE_DECLARATOR) {
735 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
739 case NODE_TYPE_DECLARATOR:
740 return reparent_type_declarator(node, parent);
742 case NODE_TYPE_SPECIFIER_LIST:
743 return reparent_type_specifier_list(node, parent);
745 case NODE_TYPE_SPECIFIER:
746 return reparent_type_specifier(node, parent);
748 case NODE_FLOATING_POINT:
754 return -EINVAL; /* Dealt with internally within grammar */
756 case NODE_ENUMERATOR:
757 if (parent->type == NODE_ENUM) {
758 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
763 case NODE_STRUCT_OR_VARIANT_DECLARATION:
764 switch (parent->type) {
766 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
769 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
778 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
785 __attribute__((visibility("protected")))
786 void yyerror(struct ctf_scanner *scanner, const char *str)
788 fprintf(stderr, "error %s\n", str);
791 __attribute__((visibility("protected")))
797 #define reparent_error(scanner, str) \
799 yyerror(scanner, YY_("reparent_error: " str "\n")); \
803 static void free_strings(struct bt_list_head *list)
805 struct gc_string *gstr, *tmp;
807 bt_list_for_each_entry_safe(gstr, tmp, list, gc)
811 static struct ctf_ast *ctf_ast_alloc(void)
815 ast = malloc(sizeof(*ast));
818 memset(ast, 0, sizeof(*ast));
819 BT_INIT_LIST_HEAD(&ast->allocated_nodes);
820 ast->root.type = NODE_ROOT;
821 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
822 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
823 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
824 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
825 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
826 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
827 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
831 static void ctf_ast_free(struct ctf_ast *ast)
833 struct ctf_node *node, *tmp;
835 bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
839 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
841 return yyparse(scanner);
844 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
846 struct ctf_scanner *scanner;
849 yydebug = babeltrace_debug;
851 scanner = malloc(sizeof(*scanner));
854 memset(scanner, 0, sizeof(*scanner));
856 ret = yylex_init_extra(scanner, &scanner->scanner);
858 fprintf(stderr, "yylex_init error\n");
859 goto cleanup_scanner;
861 /* Start processing new stream */
862 yyrestart(input, scanner->scanner);
864 scanner->ast = ctf_ast_alloc();
867 init_scope(&scanner->root_scope, NULL);
868 scanner->cs = &scanner->root_scope;
869 BT_INIT_LIST_HEAD(&scanner->allocated_strings);
872 fprintf(stdout, "Scanner input is a%s.\n",
873 isatty(fileno(input)) ? "n interactive tty" :
874 " noninteractive file");
879 ret = yylex_destroy(scanner->scanner);
881 fprintf(stderr, "yylex_destroy error\n");
887 void ctf_scanner_free(struct ctf_scanner *scanner)
891 finalize_scope(&scanner->root_scope);
892 free_strings(&scanner->allocated_strings);
893 ctf_ast_free(scanner->ast);
894 ret = yylex_destroy(scanner->scanner);
896 fprintf(stderr, "yylex_destroy error\n");
904 %parse-param {struct ctf_scanner *scanner}
905 %lex-param {struct ctf_scanner *scanner}
907 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
908 * vs struct { int :value; } (unnamed bit-field). The default is to
909 * shift, so whenever we encounter an enumeration, we are doing the
910 * proper thing (shift). It is illegal to declare an enumeration
911 * "bit-field", so it is OK if this situation ends up in a parsing
916 %token CHARACTER_CONSTANT_START SQUOTE STRING_LITERAL_START DQUOTE ESCSEQ CHAR_STRING_TOKEN 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 CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT TOK_ALIGN
917 %token <gs> IDENTIFIER ID_TYPE
923 struct gc_string *gs;
928 %type <gs> s_char s_char_sequence c_char c_char_sequence
930 %type <n> postfix_expression unary_expression unary_expression_or_range
932 %type <n> declaration
933 %type <n> event_declaration
934 %type <n> stream_declaration
935 %type <n> env_declaration
936 %type <n> trace_declaration
937 %type <n> clock_declaration
938 %type <n> integer_declaration_specifiers
939 %type <n> declaration_specifiers
940 %type <n> alias_declaration_specifiers
942 %type <n> type_declarator_list
943 %type <n> integer_type_specifier
944 %type <n> type_specifier
945 %type <n> struct_type_specifier
946 %type <n> variant_type_specifier
947 %type <n> enum_type_specifier
948 %type <n> struct_or_variant_declaration_list
949 %type <n> struct_or_variant_declaration
950 %type <n> struct_or_variant_declarator_list
951 %type <n> struct_or_variant_declarator
952 %type <n> enumerator_list
954 %type <n> abstract_declarator_list
955 %type <n> abstract_declarator
956 %type <n> direct_abstract_declarator
957 %type <n> alias_abstract_declarator_list
958 %type <n> alias_abstract_declarator
959 %type <n> direct_alias_abstract_declarator
961 %type <n> direct_declarator
962 %type <n> type_declarator
963 %type <n> direct_type_declarator
965 %type <n> ctf_assignment_expression_list
966 %type <n> ctf_assignment_expression
973 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
974 reparent_error(scanner, "error reparenting to root");
978 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
979 reparent_error(scanner, "error reparenting to root");
1043 | c_char_sequence c_char
1044 { $$ = gc_string_append(scanner, $1, $2); }
1052 reparent_error(scanner, "escape sequences not supported yet");
1056 /* 1.6 String literals */
1061 | s_char_sequence s_char
1062 { $$ = gc_string_append(scanner, $1, $2); }
1070 reparent_error(scanner, "escape sequences not supported yet");
1074 /* 2: Phrase structure grammar */
1079 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1080 $$->u.unary_expression.type = UNARY_STRING;
1081 $$->u.unary_expression.u.string = yylval.gs->s;
1085 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1086 $$->u.unary_expression.type = UNARY_STRING;
1087 $$->u.unary_expression.u.string = yylval.gs->s;
1091 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1092 $$->u.unary_expression.type = UNARY_STRING;
1093 $$->u.unary_expression.u.string = yylval.gs->s;
1097 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1098 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1099 sscanf(yylval.gs->s, "%" PRIu64,
1100 &$$->u.unary_expression.u.unsigned_constant);
1104 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1105 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1106 sscanf(yylval.gs->s, "0%" PRIo64,
1107 &$$->u.unary_expression.u.unsigned_constant);
1109 | HEXADECIMAL_CONSTANT
1111 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1112 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1113 sscanf(yylval.gs->s, "0x%" PRIx64,
1114 &$$->u.unary_expression.u.unsigned_constant);
1116 | STRING_LITERAL_START DQUOTE
1118 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1119 $$->u.unary_expression.type = UNARY_STRING;
1120 $$->u.unary_expression.u.string = "";
1122 | STRING_LITERAL_START s_char_sequence DQUOTE
1124 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1125 $$->u.unary_expression.type = UNARY_STRING;
1126 $$->u.unary_expression.u.string = $2->s;
1128 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1130 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1131 $$->u.unary_expression.type = UNARY_STRING;
1132 $$->u.unary_expression.u.string = $2->s;
1134 | LPAREN unary_expression RPAREN
1136 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1137 $$->u.unary_expression.type = UNARY_NESTED;
1138 $$->u.unary_expression.u.nested_exp = $2;
1140 | postfix_expression LSBRAC unary_expression RSBRAC
1142 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1143 $$->u.unary_expression.type = UNARY_SBRAC;
1144 $$->u.unary_expression.u.sbrac_exp = $3;
1145 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1146 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1148 | postfix_expression DOT IDENTIFIER
1150 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1151 $$->u.unary_expression.type = UNARY_STRING;
1152 $$->u.unary_expression.u.string = yylval.gs->s;
1153 $$->u.unary_expression.link = UNARY_DOTLINK;
1154 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1155 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1157 | postfix_expression DOT ID_TYPE
1159 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1160 $$->u.unary_expression.type = UNARY_STRING;
1161 $$->u.unary_expression.u.string = yylval.gs->s;
1162 $$->u.unary_expression.link = UNARY_DOTLINK;
1163 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1164 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1166 | postfix_expression RARROW IDENTIFIER
1168 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1169 $$->u.unary_expression.type = UNARY_STRING;
1170 $$->u.unary_expression.u.string = yylval.gs->s;
1171 $$->u.unary_expression.link = UNARY_ARROWLINK;
1172 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1173 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1175 | postfix_expression RARROW ID_TYPE
1177 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1178 $$->u.unary_expression.type = UNARY_STRING;
1179 $$->u.unary_expression.u.string = yylval.gs->s;
1180 $$->u.unary_expression.link = UNARY_ARROWLINK;
1181 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1182 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1189 | PLUS postfix_expression
1191 | MINUS postfix_expression
1194 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1195 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1196 reparent_error(scanner, "expecting numeric constant");
1198 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1199 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1200 $$->u.unary_expression.u.signed_constant =
1201 -($$->u.unary_expression.u.unsigned_constant);
1203 $$->u.unary_expression.u.signed_constant =
1204 -($$->u.unary_expression.u.signed_constant);
1209 unary_expression_or_range:
1210 unary_expression DOTDOTDOT unary_expression
1213 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1214 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1220 /* 2.2: Declarations */
1223 declaration_specifiers SEMICOLON
1227 | stream_declaration
1235 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1237 struct ctf_node *list;
1239 $$ = make_node(scanner, NODE_TYPEDEF);
1240 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1241 $$->u._typedef.type_specifier_list = list;
1242 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1243 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1244 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1246 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1248 struct ctf_node *list;
1250 $$ = make_node(scanner, NODE_TYPEDEF);
1251 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1252 $$->u._typedef.type_specifier_list = list;
1253 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1254 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1256 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1258 struct ctf_node *list;
1260 $$ = make_node(scanner, NODE_TYPEDEF);
1261 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1262 $$->u._typedef.type_specifier_list = list;
1263 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1264 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1266 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1268 struct ctf_node *list;
1270 $$ = make_node(scanner, NODE_TYPEALIAS);
1271 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1272 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1274 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1275 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1276 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1277 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1279 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1280 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1281 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1282 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1287 event_declaration_begin event_declaration_end
1289 $$ = make_node(scanner, NODE_EVENT);
1291 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1293 $$ = make_node(scanner, NODE_EVENT);
1294 if (set_parent_node($2, $$))
1295 reparent_error(scanner, "event_declaration");
1299 event_declaration_begin:
1301 { push_scope(scanner); }
1304 event_declaration_end:
1306 { pop_scope(scanner); }
1311 stream_declaration_begin stream_declaration_end
1313 $$ = make_node(scanner, NODE_STREAM);
1315 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1317 $$ = make_node(scanner, NODE_STREAM);
1318 if (set_parent_node($2, $$))
1319 reparent_error(scanner, "stream_declaration");
1323 stream_declaration_begin:
1325 { push_scope(scanner); }
1328 stream_declaration_end:
1330 { pop_scope(scanner); }
1334 env_declaration_begin env_declaration_end
1336 $$ = make_node(scanner, NODE_ENV);
1338 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1340 $$ = make_node(scanner, NODE_ENV);
1341 if (set_parent_node($2, $$))
1342 reparent_error(scanner, "env declaration");
1346 env_declaration_begin:
1348 { push_scope(scanner); }
1351 env_declaration_end:
1353 { pop_scope(scanner); }
1357 trace_declaration_begin trace_declaration_end
1359 $$ = make_node(scanner, NODE_TRACE);
1361 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1363 $$ = make_node(scanner, NODE_TRACE);
1364 if (set_parent_node($2, $$))
1365 reparent_error(scanner, "trace_declaration");
1369 trace_declaration_begin:
1371 { push_scope(scanner); }
1374 trace_declaration_end:
1376 { pop_scope(scanner); }
1380 CLOCK clock_declaration_begin clock_declaration_end
1382 $$ = make_node(scanner, NODE_CLOCK);
1384 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1386 $$ = make_node(scanner, NODE_CLOCK);
1387 if (set_parent_node($3, $$))
1388 reparent_error(scanner, "trace_declaration");
1392 clock_declaration_begin:
1394 { push_scope(scanner); }
1397 clock_declaration_end:
1399 { pop_scope(scanner); }
1402 integer_declaration_specifiers:
1405 struct ctf_node *node;
1407 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1408 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1409 node->u.type_specifier.type = TYPESPEC_CONST;
1410 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1412 | integer_type_specifier
1414 struct ctf_node *node;
1416 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1418 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1420 | integer_declaration_specifiers CONST
1422 struct ctf_node *node;
1425 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1426 node->u.type_specifier.type = TYPESPEC_CONST;
1427 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1429 | integer_declaration_specifiers integer_type_specifier
1432 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1436 declaration_specifiers:
1439 struct ctf_node *node;
1441 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1442 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1443 node->u.type_specifier.type = TYPESPEC_CONST;
1444 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1448 struct ctf_node *node;
1450 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1452 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1454 | declaration_specifiers CONST
1456 struct ctf_node *node;
1459 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1460 node->u.type_specifier.type = TYPESPEC_CONST;
1461 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1463 | declaration_specifiers type_specifier
1466 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1470 type_declarator_list:
1473 | type_declarator_list COMMA type_declarator
1476 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1480 integer_type_specifier:
1483 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1484 $$->u.type_specifier.type = TYPESPEC_CHAR;
1488 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1489 $$->u.type_specifier.type = TYPESPEC_SHORT;
1493 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1494 $$->u.type_specifier.type = TYPESPEC_INT;
1498 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1499 $$->u.type_specifier.type = TYPESPEC_LONG;
1503 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1504 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1508 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1509 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1513 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1514 $$->u.type_specifier.type = TYPESPEC_BOOL;
1518 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1519 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1520 $$->u.type_specifier.id_type = yylval.gs->s;
1522 | INTEGER LBRAC RBRAC
1524 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1525 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1526 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1528 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1530 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1531 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1532 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1533 if (set_parent_node($3, $$->u.type_specifier.node))
1534 reparent_error(scanner, "integer reparent error");
1541 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1542 $$->u.type_specifier.type = TYPESPEC_VOID;
1546 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1547 $$->u.type_specifier.type = TYPESPEC_CHAR;
1551 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1552 $$->u.type_specifier.type = TYPESPEC_SHORT;
1556 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1557 $$->u.type_specifier.type = TYPESPEC_INT;
1561 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1562 $$->u.type_specifier.type = TYPESPEC_LONG;
1566 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1567 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1571 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1572 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1576 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1577 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1581 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1582 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1586 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1587 $$->u.type_specifier.type = TYPESPEC_BOOL;
1591 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1592 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1596 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1597 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1601 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1602 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1603 $$->u.type_specifier.id_type = yylval.gs->s;
1605 | FLOATING_POINT LBRAC RBRAC
1607 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1608 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1609 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1611 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1613 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1614 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1615 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1616 if (set_parent_node($3, $$->u.type_specifier.node))
1617 reparent_error(scanner, "floating point reparent error");
1619 | INTEGER LBRAC RBRAC
1621 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1622 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1623 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1625 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1627 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1628 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1629 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1630 if (set_parent_node($3, $$->u.type_specifier.node))
1631 reparent_error(scanner, "integer reparent error");
1635 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1636 $$->u.type_specifier.type = TYPESPEC_STRING;
1637 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1639 | STRING LBRAC RBRAC
1641 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1642 $$->u.type_specifier.type = TYPESPEC_STRING;
1643 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1645 | STRING LBRAC ctf_assignment_expression_list RBRAC
1647 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1648 $$->u.type_specifier.type = TYPESPEC_STRING;
1649 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1650 if (set_parent_node($3, $$->u.type_specifier.node))
1651 reparent_error(scanner, "string reparent error");
1653 | ENUM enum_type_specifier
1655 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1656 $$->u.type_specifier.type = TYPESPEC_ENUM;
1657 $$->u.type_specifier.node = $2;
1659 | VARIANT variant_type_specifier
1661 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1662 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1663 $$->u.type_specifier.node = $2;
1665 | STRUCT struct_type_specifier
1667 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1668 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1669 $$->u.type_specifier.node = $2;
1673 struct_type_specifier:
1674 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1676 $$ = make_node(scanner, NODE_STRUCT);
1677 $$->u._struct.has_body = 1;
1678 if ($2 && set_parent_node($2, $$))
1679 reparent_error(scanner, "struct reparent error");
1681 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1683 $$ = make_node(scanner, NODE_STRUCT);
1684 $$->u._struct.has_body = 1;
1685 $$->u._struct.name = $1->s;
1686 if ($3 && set_parent_node($3, $$))
1687 reparent_error(scanner, "struct reparent error");
1689 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1691 $$ = make_node(scanner, NODE_STRUCT);
1692 $$->u._struct.has_body = 1;
1693 $$->u._struct.name = $1->s;
1694 if ($3 && set_parent_node($3, $$))
1695 reparent_error(scanner, "struct reparent error");
1699 $$ = make_node(scanner, NODE_STRUCT);
1700 $$->u._struct.has_body = 0;
1701 $$->u._struct.name = $1->s;
1705 $$ = make_node(scanner, NODE_STRUCT);
1706 $$->u._struct.has_body = 0;
1707 $$->u._struct.name = $1->s;
1709 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1711 $$ = make_node(scanner, NODE_STRUCT);
1712 $$->u._struct.has_body = 1;
1713 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1714 if ($2 && set_parent_node($2, $$))
1715 reparent_error(scanner, "struct reparent error");
1717 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1719 $$ = make_node(scanner, NODE_STRUCT);
1720 $$->u._struct.has_body = 1;
1721 $$->u._struct.name = $1->s;
1722 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1723 if ($3 && set_parent_node($3, $$))
1724 reparent_error(scanner, "struct reparent error");
1726 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1728 $$ = make_node(scanner, NODE_STRUCT);
1729 $$->u._struct.has_body = 1;
1730 $$->u._struct.name = $1->s;
1731 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1732 if ($3 && set_parent_node($3, $$))
1733 reparent_error(scanner, "struct reparent error");
1737 struct_declaration_begin:
1739 { push_scope(scanner); }
1742 struct_declaration_end:
1744 { pop_scope(scanner); }
1747 variant_type_specifier:
1748 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1750 $$ = make_node(scanner, NODE_VARIANT);
1751 $$->u.variant.has_body = 1;
1752 if ($2 && set_parent_node($2, $$))
1753 reparent_error(scanner, "variant reparent error");
1755 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1757 $$ = make_node(scanner, NODE_VARIANT);
1758 $$->u.variant.has_body = 1;
1759 $$->u.variant.choice = $2->s;
1760 if ($5 && set_parent_node($5, $$))
1761 reparent_error(scanner, "variant reparent error");
1763 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1765 $$ = make_node(scanner, NODE_VARIANT);
1766 $$->u.variant.has_body = 1;
1767 $$->u.variant.choice = $2->s;
1768 if ($5 && set_parent_node($5, $$))
1769 reparent_error(scanner, "variant reparent error");
1771 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1773 $$ = make_node(scanner, NODE_VARIANT);
1774 $$->u.variant.has_body = 1;
1775 $$->u.variant.name = $1->s;
1776 if ($3 && set_parent_node($3, $$))
1777 reparent_error(scanner, "variant reparent error");
1779 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1781 $$ = make_node(scanner, NODE_VARIANT);
1782 $$->u.variant.has_body = 1;
1783 $$->u.variant.name = $1->s;
1784 $$->u.variant.choice = $3->s;
1785 if ($6 && set_parent_node($6, $$))
1786 reparent_error(scanner, "variant reparent error");
1788 | IDENTIFIER LT IDENTIFIER GT
1790 $$ = make_node(scanner, NODE_VARIANT);
1791 $$->u.variant.has_body = 0;
1792 $$->u.variant.name = $1->s;
1793 $$->u.variant.choice = $3->s;
1795 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1797 $$ = make_node(scanner, NODE_VARIANT);
1798 $$->u.variant.has_body = 1;
1799 $$->u.variant.name = $1->s;
1800 $$->u.variant.choice = $3->s;
1801 if ($6 && set_parent_node($6, $$))
1802 reparent_error(scanner, "variant reparent error");
1804 | IDENTIFIER LT ID_TYPE GT
1806 $$ = make_node(scanner, NODE_VARIANT);
1807 $$->u.variant.has_body = 0;
1808 $$->u.variant.name = $1->s;
1809 $$->u.variant.choice = $3->s;
1811 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1813 $$ = make_node(scanner, NODE_VARIANT);
1814 $$->u.variant.has_body = 1;
1815 $$->u.variant.name = $1->s;
1816 if ($3 && set_parent_node($3, $$))
1817 reparent_error(scanner, "variant reparent error");
1819 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1821 $$ = make_node(scanner, NODE_VARIANT);
1822 $$->u.variant.has_body = 1;
1823 $$->u.variant.name = $1->s;
1824 $$->u.variant.choice = $3->s;
1825 if ($6 && set_parent_node($6, $$))
1826 reparent_error(scanner, "variant reparent error");
1828 | ID_TYPE LT IDENTIFIER GT
1830 $$ = make_node(scanner, NODE_VARIANT);
1831 $$->u.variant.has_body = 0;
1832 $$->u.variant.name = $1->s;
1833 $$->u.variant.choice = $3->s;
1835 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1837 $$ = make_node(scanner, NODE_VARIANT);
1838 $$->u.variant.has_body = 1;
1839 $$->u.variant.name = $1->s;
1840 $$->u.variant.choice = $3->s;
1841 if ($6 && set_parent_node($6, $$))
1842 reparent_error(scanner, "variant reparent error");
1844 | ID_TYPE LT ID_TYPE GT
1846 $$ = make_node(scanner, NODE_VARIANT);
1847 $$->u.variant.has_body = 0;
1848 $$->u.variant.name = $1->s;
1849 $$->u.variant.choice = $3->s;
1853 variant_declaration_begin:
1855 { push_scope(scanner); }
1858 variant_declaration_end:
1860 { pop_scope(scanner); }
1863 enum_type_specifier:
1864 LBRAC enumerator_list RBRAC
1866 $$ = make_node(scanner, NODE_ENUM);
1867 $$->u._enum.has_body = 1;
1868 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1870 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1872 $$ = make_node(scanner, NODE_ENUM);
1873 $$->u._enum.has_body = 1;
1874 ($$)->u._enum.container_type = $2;
1875 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1877 | IDENTIFIER LBRAC enumerator_list RBRAC
1879 $$ = make_node(scanner, NODE_ENUM);
1880 $$->u._enum.has_body = 1;
1881 $$->u._enum.enum_id = $1->s;
1882 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1884 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1886 $$ = make_node(scanner, NODE_ENUM);
1887 $$->u._enum.has_body = 1;
1888 $$->u._enum.enum_id = $1->s;
1889 ($$)->u._enum.container_type = $3;
1890 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1892 | ID_TYPE LBRAC enumerator_list RBRAC
1894 $$ = make_node(scanner, NODE_ENUM);
1895 $$->u._enum.has_body = 1;
1896 $$->u._enum.enum_id = $1->s;
1897 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1899 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1901 $$ = make_node(scanner, NODE_ENUM);
1902 $$->u._enum.has_body = 1;
1903 $$->u._enum.enum_id = $1->s;
1904 ($$)->u._enum.container_type = $3;
1905 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1907 | LBRAC enumerator_list COMMA RBRAC
1909 $$ = make_node(scanner, NODE_ENUM);
1910 $$->u._enum.has_body = 1;
1911 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1913 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1915 $$ = make_node(scanner, NODE_ENUM);
1916 $$->u._enum.has_body = 1;
1917 ($$)->u._enum.container_type = $2;
1918 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1920 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1922 $$ = make_node(scanner, NODE_ENUM);
1923 $$->u._enum.has_body = 1;
1924 $$->u._enum.enum_id = $1->s;
1925 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1927 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1929 $$ = make_node(scanner, NODE_ENUM);
1930 $$->u._enum.has_body = 1;
1931 $$->u._enum.enum_id = $1->s;
1932 ($$)->u._enum.container_type = $3;
1933 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1937 $$ = make_node(scanner, NODE_ENUM);
1938 $$->u._enum.has_body = 0;
1939 $$->u._enum.enum_id = $1->s;
1941 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1943 $$ = make_node(scanner, NODE_ENUM);
1944 $$->u._enum.has_body = 1;
1945 $$->u._enum.enum_id = $1->s;
1946 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1948 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1950 $$ = make_node(scanner, NODE_ENUM);
1951 $$->u._enum.has_body = 1;
1952 $$->u._enum.enum_id = $1->s;
1953 ($$)->u._enum.container_type = $3;
1954 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1958 $$ = make_node(scanner, NODE_ENUM);
1959 $$->u._enum.has_body = 0;
1960 $$->u._enum.enum_id = $1->s;
1964 struct_or_variant_declaration_list:
1967 | struct_or_variant_declaration_list struct_or_variant_declaration
1971 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1974 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1979 struct_or_variant_declaration:
1980 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
1982 struct ctf_node *list;
1984 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1985 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1986 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1987 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1988 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
1990 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1992 struct ctf_node *list;
1994 $$ = make_node(scanner, NODE_TYPEDEF);
1995 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1996 $$->u._typedef.type_specifier_list = list;
1997 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1998 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1999 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2001 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2003 struct ctf_node *list;
2005 $$ = make_node(scanner, NODE_TYPEDEF);
2006 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2007 $$->u._typedef.type_specifier_list = list;
2008 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2009 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2011 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
2013 struct ctf_node *list;
2015 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2016 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2017 $$ = make_node(scanner, NODE_TYPEDEF);
2018 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2019 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2021 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
2023 struct ctf_node *list;
2025 $$ = make_node(scanner, NODE_TYPEALIAS);
2026 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2027 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2029 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2030 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2031 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2032 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2034 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2035 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2036 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2037 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2041 alias_declaration_specifiers:
2044 struct ctf_node *node;
2046 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2047 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2048 node->u.type_specifier.type = TYPESPEC_CONST;
2049 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2053 struct ctf_node *node;
2055 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2057 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2061 struct ctf_node *node;
2063 add_type(scanner, $1);
2064 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2065 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2066 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2067 node->u.type_specifier.id_type = yylval.gs->s;
2068 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2070 | alias_declaration_specifiers CONST
2072 struct ctf_node *node;
2075 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2076 node->u.type_specifier.type = TYPESPEC_CONST;
2077 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2079 | alias_declaration_specifiers type_specifier
2082 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2084 | alias_declaration_specifiers IDENTIFIER
2086 struct ctf_node *node;
2088 add_type(scanner, $2);
2090 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2091 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2092 node->u.type_specifier.id_type = yylval.gs->s;
2093 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2097 struct_or_variant_declarator_list:
2098 struct_or_variant_declarator
2100 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2103 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2107 struct_or_variant_declarator:
2110 | COLON unary_expression
2112 | declarator COLON unary_expression
2115 if (set_parent_node($3, $1))
2116 reparent_error(scanner, "struct_or_variant_declarator");
2123 | enumerator_list COMMA enumerator
2126 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2133 $$ = make_node(scanner, NODE_ENUMERATOR);
2134 $$->u.enumerator.id = $1->s;
2138 $$ = make_node(scanner, NODE_ENUMERATOR);
2139 $$->u.enumerator.id = $1->s;
2143 $$ = make_node(scanner, NODE_ENUMERATOR);
2144 $$->u.enumerator.id = $1->s;
2146 | STRING_LITERAL_START DQUOTE
2148 $$ = make_node(scanner, NODE_ENUMERATOR);
2149 $$->u.enumerator.id = "";
2151 | STRING_LITERAL_START s_char_sequence DQUOTE
2153 $$ = make_node(scanner, NODE_ENUMERATOR);
2154 $$->u.enumerator.id = $2->s;
2156 | IDENTIFIER EQUAL unary_expression_or_range
2158 $$ = make_node(scanner, NODE_ENUMERATOR);
2159 $$->u.enumerator.id = $1->s;
2160 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2162 | ID_TYPE EQUAL unary_expression_or_range
2164 $$ = make_node(scanner, NODE_ENUMERATOR);
2165 $$->u.enumerator.id = $1->s;
2166 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2168 | keywords EQUAL unary_expression_or_range
2170 $$ = make_node(scanner, NODE_ENUMERATOR);
2171 $$->u.enumerator.id = $1->s;
2172 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2174 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
2176 $$ = make_node(scanner, NODE_ENUMERATOR);
2177 $$->u.enumerator.id = "";
2178 bt_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
2180 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
2182 $$ = make_node(scanner, NODE_ENUMERATOR);
2183 $$->u.enumerator.id = $2->s;
2184 bt_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
2188 abstract_declarator_list:
2191 | abstract_declarator_list COMMA abstract_declarator
2194 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2198 abstract_declarator:
2199 direct_abstract_declarator
2201 | pointer direct_abstract_declarator
2204 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2208 direct_abstract_declarator:
2211 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2212 $$->u.type_declarator.type = TYPEDEC_ID;
2217 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2218 $$->u.type_declarator.type = TYPEDEC_ID;
2219 $$->u.type_declarator.u.id = $1->s;
2221 | LPAREN abstract_declarator RPAREN
2223 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2224 $$->u.type_declarator.type = TYPEDEC_NESTED;
2225 $$->u.type_declarator.u.nested.type_declarator = $2;
2227 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2229 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2230 $$->u.type_declarator.type = TYPEDEC_NESTED;
2231 $$->u.type_declarator.u.nested.type_declarator = $1;
2232 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2233 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2235 | direct_abstract_declarator LSBRAC RSBRAC
2237 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2238 $$->u.type_declarator.type = TYPEDEC_NESTED;
2239 $$->u.type_declarator.u.nested.type_declarator = $1;
2240 $$->u.type_declarator.u.nested.abstract_array = 1;
2244 alias_abstract_declarator_list:
2245 alias_abstract_declarator
2247 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2250 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2254 alias_abstract_declarator:
2255 direct_alias_abstract_declarator
2257 | pointer direct_alias_abstract_declarator
2260 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2264 direct_alias_abstract_declarator:
2267 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2268 $$->u.type_declarator.type = TYPEDEC_ID;
2271 | LPAREN alias_abstract_declarator RPAREN
2273 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2274 $$->u.type_declarator.type = TYPEDEC_NESTED;
2275 $$->u.type_declarator.u.nested.type_declarator = $2;
2277 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2279 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2280 $$->u.type_declarator.type = TYPEDEC_NESTED;
2281 $$->u.type_declarator.u.nested.type_declarator = $1;
2282 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2283 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2285 | direct_alias_abstract_declarator LSBRAC RSBRAC
2287 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2288 $$->u.type_declarator.type = TYPEDEC_NESTED;
2289 $$->u.type_declarator.u.nested.type_declarator = $1;
2290 $$->u.type_declarator.u.nested.abstract_array = 1;
2297 | pointer direct_declarator
2300 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2307 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2308 $$->u.type_declarator.type = TYPEDEC_ID;
2309 $$->u.type_declarator.u.id = $1->s;
2311 | LPAREN declarator RPAREN
2313 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2314 $$->u.type_declarator.type = TYPEDEC_NESTED;
2315 $$->u.type_declarator.u.nested.type_declarator = $2;
2317 | direct_declarator LSBRAC unary_expression RSBRAC
2319 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2320 $$->u.type_declarator.type = TYPEDEC_NESTED;
2321 $$->u.type_declarator.u.nested.type_declarator = $1;
2322 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2323 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2328 direct_type_declarator
2330 | pointer direct_type_declarator
2333 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2337 direct_type_declarator:
2340 add_type(scanner, $1);
2341 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2342 $$->u.type_declarator.type = TYPEDEC_ID;
2343 $$->u.type_declarator.u.id = $1->s;
2345 | LPAREN type_declarator RPAREN
2347 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2348 $$->u.type_declarator.type = TYPEDEC_NESTED;
2349 $$->u.type_declarator.u.nested.type_declarator = $2;
2351 | direct_type_declarator LSBRAC unary_expression RSBRAC
2353 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2354 $$->u.type_declarator.type = TYPEDEC_NESTED;
2355 $$->u.type_declarator.u.nested.type_declarator = $1;
2356 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2357 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2364 $$ = make_node(scanner, NODE_POINTER);
2368 $$ = make_node(scanner, NODE_POINTER);
2369 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2371 | STAR type_qualifier_list pointer
2373 $$ = make_node(scanner, NODE_POINTER);
2374 $$->u.pointer.const_qualifier = 1;
2375 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2379 type_qualifier_list:
2380 /* pointer assumes only const type qualifier */
2382 | type_qualifier_list CONST
2385 /* 2.3: CTF-specific declarations */
2387 ctf_assignment_expression_list:
2388 ctf_assignment_expression SEMICOLON
2390 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2393 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2397 ctf_assignment_expression:
2398 unary_expression EQUAL unary_expression
2401 * Because we have left and right, cannot use
2404 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2405 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2406 if ($1->u.unary_expression.type != UNARY_STRING)
2407 reparent_error(scanner, "ctf_assignment_expression left expects string");
2408 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2410 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2413 * Because we have left and right, cannot use
2416 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2417 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2418 if ($1->u.unary_expression.type != UNARY_STRING)
2419 reparent_error(scanner, "ctf_assignment_expression left expects string");
2420 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2422 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2424 struct ctf_node *list;
2426 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2427 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2428 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2429 $$ = make_node(scanner, NODE_TYPEDEF);
2430 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2431 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2433 | TYPEDEF declaration_specifiers type_declarator_list
2435 struct ctf_node *list;
2437 $$ = make_node(scanner, NODE_TYPEDEF);
2438 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2439 $$->u._typedef.type_specifier_list = list;
2440 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2441 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2443 | declaration_specifiers TYPEDEF type_declarator_list
2445 struct ctf_node *list;
2447 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2448 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2449 $$ = make_node(scanner, NODE_TYPEDEF);
2450 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2451 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2453 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2455 struct ctf_node *list;
2457 $$ = make_node(scanner, NODE_TYPEALIAS);
2458 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2459 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2461 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2462 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2463 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2464 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2466 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2467 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2468 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2469 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);