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
36 #include <babeltrace/list.h>
37 #include <babeltrace/babeltrace-internal.h>
38 #include "ctf-scanner.h"
39 #include "ctf-parser.h"
45 /* Join two lists, put "add" at the end of "head". */
47 _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
49 /* Do nothing if the list which gets added is empty. */
50 if (add != add->next) {
51 add->next->prev = head->prev;
52 add->prev->next = head;
53 head->prev->next = add->next;
54 head->prev = add->prev;
59 int yyparse(struct ctf_scanner *scanner);
61 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
63 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
65 int yylex_destroy(yyscan_t yyscanner);
67 void yyrestart(FILE * in_str, yyscan_t scanner);
69 int yyget_lineno(yyscan_t yyscanner);
71 char *yyget_text(yyscan_t yyscanner);
74 struct bt_list_head gc;
79 static const char *node_type_to_str[] = {
80 [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
81 [ NODE_ROOT ] = "NODE_ROOT",
82 [ NODE_EVENT ] = "NODE_EVENT",
83 [ NODE_ENV ] = "NODE_ENV",
84 [ NODE_STREAM ] = "NODE_STREAM",
85 [ NODE_TRACE ] = "NODE_TRACE",
86 [ NODE_CLOCK ] = "NODE_CLOCK",
87 [ NODE_CALLSITE ] = "NODE_CALLSITE",
88 [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
89 [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
90 [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
91 [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
92 [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
93 [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
94 [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
95 [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
96 [ NODE_POINTER ] = "NODE_POINTER",
97 [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
98 [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
99 [ NODE_INTEGER ] = "NODE_INTEGER",
100 [ NODE_STRING ] = "NODE_STRING",
101 [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
102 [ NODE_ENUM ] = "NODE_ENUM",
103 [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
104 [ NODE_VARIANT ] = "NODE_VARIANT",
105 [ NODE_STRUCT ] = "NODE_STRUCT",
109 const char *node_type(struct ctf_node *node)
111 if (node->type < NR_NODE_TYPES)
112 return node_type_to_str[node->type];
117 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
120 struct gc_string *gstr;
123 /* TODO: could be faster with find first bit or glib Gstring */
124 /* sizeof long to account for malloc header (int or long ?) */
125 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
128 gstr = malloc(alloclen);
129 bt_list_add(&gstr->gc, &scanner->allocated_strings);
130 gstr->alloclen = alloclen;
135 * note: never use gc_string_append on a string that has external references.
136 * gsrc will be garbage collected immediately, and gstr might be.
137 * Should only be used to append characters to a string literal or constant.
140 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
141 struct gc_string *gstr,
142 struct gc_string *gsrc)
144 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
147 /* TODO: could be faster with find first bit or glib Gstring */
148 /* sizeof long to account for malloc header (int or long ?) */
149 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
152 if (alloclen > gstr->alloclen) {
153 struct gc_string *newgstr;
155 newgstr = gc_string_alloc(scanner, newlen);
156 strcpy(newgstr->s, gstr->s);
157 strcat(newgstr->s, gsrc->s);
158 bt_list_del(&gstr->gc);
162 strcat(gstr->s, gsrc->s);
164 bt_list_del(&gsrc->gc);
169 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
171 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
172 strcpy(lvalp->gs->s, src);
175 static void init_scope(struct ctf_scanner_scope *scope,
176 struct ctf_scanner_scope *parent)
178 scope->parent = parent;
179 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
183 static void finalize_scope(struct ctf_scanner_scope *scope)
185 g_hash_table_destroy(scope->types);
188 static void push_scope(struct ctf_scanner *scanner)
190 struct ctf_scanner_scope *ns;
192 printf_debug("push scope\n");
193 ns = malloc(sizeof(struct ctf_scanner_scope));
194 init_scope(ns, scanner->cs);
198 static void pop_scope(struct ctf_scanner *scanner)
200 struct ctf_scanner_scope *os;
202 printf_debug("pop scope\n");
204 scanner->cs = os->parent;
209 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
213 ret = (int) (long) g_hash_table_lookup(s->types, id);
214 printf_debug("lookup %p %s %d\n", s, id, ret);
219 int is_type(struct ctf_scanner *scanner, const char *id)
221 struct ctf_scanner_scope *it;
224 for (it = scanner->cs; it != NULL; it = it->parent) {
225 if (lookup_type(it, id)) {
230 printf_debug("is type %s %d\n", id, ret);
234 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
236 printf_debug("add type %s\n", id->s);
237 if (lookup_type(scanner->cs, id->s))
239 g_hash_table_insert(scanner->cs->types, id->s, id->s);
242 static struct ctf_node *make_node(struct ctf_scanner *scanner,
245 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
246 struct ctf_node *node;
248 node = malloc(sizeof(*node));
251 memset(node, 0, sizeof(*node));
253 BT_INIT_LIST_HEAD(&node->tmp_head);
254 bt_list_add(&node->gc, &ast->allocated_nodes);
255 bt_list_add(&node->siblings, &node->tmp_head);
259 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
263 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
266 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
269 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
272 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
275 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
278 BT_INIT_LIST_HEAD(&node->u.callsite.declaration_list);
281 case NODE_CTF_EXPRESSION:
282 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
283 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
285 case NODE_UNARY_EXPRESSION:
289 BT_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
291 case NODE_TYPEALIAS_TARGET:
292 BT_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
294 case NODE_TYPEALIAS_ALIAS:
295 BT_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
300 case NODE_TYPE_SPECIFIER:
302 case NODE_TYPE_SPECIFIER_LIST:
303 BT_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
307 case NODE_TYPE_DECLARATOR:
308 BT_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
311 case NODE_FLOATING_POINT:
312 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
315 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
318 BT_INIT_LIST_HEAD(&node->u.string.expressions);
320 case NODE_ENUMERATOR:
321 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
324 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
326 case NODE_STRUCT_OR_VARIANT_DECLARATION:
327 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
330 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
333 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
334 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
339 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
347 static int reparent_ctf_expression(struct ctf_node *node,
348 struct ctf_node *parent)
350 switch (parent->type) {
352 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
355 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
358 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
361 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
364 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
367 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
369 case NODE_FLOATING_POINT:
370 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
373 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
376 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
380 case NODE_CTF_EXPRESSION:
382 case NODE_TYPEALIAS_TARGET:
383 case NODE_TYPEALIAS_ALIAS:
385 case NODE_TYPE_SPECIFIER:
386 case NODE_TYPE_SPECIFIER_LIST:
388 case NODE_TYPE_DECLARATOR:
389 case NODE_ENUMERATOR:
391 case NODE_STRUCT_OR_VARIANT_DECLARATION:
394 case NODE_UNARY_EXPRESSION:
399 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
406 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
408 switch (parent->type) {
410 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
413 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
416 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
419 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
422 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
425 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
428 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
431 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
434 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
437 case NODE_FLOATING_POINT:
440 case NODE_CTF_EXPRESSION:
442 case NODE_TYPEALIAS_TARGET:
443 case NODE_TYPEALIAS_ALIAS:
445 case NODE_TYPE_SPECIFIER:
446 case NODE_TYPE_SPECIFIER_LIST:
448 case NODE_TYPE_DECLARATOR:
449 case NODE_ENUMERATOR:
451 case NODE_STRUCT_OR_VARIANT_DECLARATION:
452 case NODE_UNARY_EXPRESSION:
457 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
464 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
466 switch (parent->type) {
468 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
471 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
474 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
477 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
480 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
483 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
486 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
489 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
492 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
495 case NODE_FLOATING_POINT:
498 case NODE_CTF_EXPRESSION:
500 case NODE_TYPEALIAS_TARGET:
501 case NODE_TYPEALIAS_ALIAS:
503 case NODE_TYPE_SPECIFIER:
504 case NODE_TYPE_SPECIFIER_LIST:
506 case NODE_TYPE_DECLARATOR:
507 case NODE_ENUMERATOR:
509 case NODE_STRUCT_OR_VARIANT_DECLARATION:
510 case NODE_UNARY_EXPRESSION:
515 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
522 static int reparent_type_specifier(struct ctf_node *node,
523 struct ctf_node *parent)
525 switch (parent->type) {
526 case NODE_TYPE_SPECIFIER_LIST:
527 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
530 case NODE_TYPE_SPECIFIER:
540 case NODE_TYPEALIAS_TARGET:
541 case NODE_TYPEALIAS_ALIAS:
542 case NODE_TYPE_DECLARATOR:
544 case NODE_STRUCT_OR_VARIANT_DECLARATION:
546 case NODE_FLOATING_POINT:
549 case NODE_CTF_EXPRESSION:
551 case NODE_ENUMERATOR:
552 case NODE_UNARY_EXPRESSION:
557 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
564 static int reparent_type_specifier_list(struct ctf_node *node,
565 struct ctf_node *parent)
567 switch (parent->type) {
569 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
572 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
575 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
578 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
581 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
584 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
587 bt_list_add_tail(&node->siblings, &parent->u.callsite.declaration_list);
590 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
593 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
596 parent->u._typedef.type_specifier_list = node;
598 case NODE_TYPEALIAS_TARGET:
599 parent->u.typealias_target.type_specifier_list = node;
601 case NODE_TYPEALIAS_ALIAS:
602 parent->u.typealias_alias.type_specifier_list = node;
605 parent->u._enum.container_type = node;
607 case NODE_STRUCT_OR_VARIANT_DECLARATION:
608 parent->u.struct_or_variant_declaration.type_specifier_list = node;
610 case NODE_TYPE_DECLARATOR:
611 case NODE_TYPE_SPECIFIER:
613 case NODE_FLOATING_POINT:
616 case NODE_CTF_EXPRESSION:
618 case NODE_ENUMERATOR:
619 case NODE_UNARY_EXPRESSION:
624 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
631 static int reparent_type_declarator(struct ctf_node *node,
632 struct ctf_node *parent)
634 switch (parent->type) {
635 case NODE_TYPE_DECLARATOR:
636 parent->u.type_declarator.type = TYPEDEC_NESTED;
637 parent->u.type_declarator.u.nested.type_declarator = node;
639 case NODE_STRUCT_OR_VARIANT_DECLARATION:
640 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
643 _bt_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
645 case NODE_TYPEALIAS_TARGET:
646 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
648 case NODE_TYPEALIAS_ALIAS:
649 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
663 case NODE_FLOATING_POINT:
666 case NODE_CTF_EXPRESSION:
667 case NODE_TYPE_SPECIFIER:
668 case NODE_TYPE_SPECIFIER_LIST:
670 case NODE_ENUMERATOR:
671 case NODE_UNARY_EXPRESSION:
676 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
686 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
687 * create the link declared by the input, -ENOENT if node or parent is NULL,
688 * -EINVAL if there is an internal structure problem.
690 static int set_parent_node(struct ctf_node *node,
691 struct ctf_node *parent)
693 if (!node || !parent)
696 /* Note: Linking to parent will be done only by an external visitor */
698 switch (node->type) {
700 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
704 if (parent->type == NODE_ROOT) {
705 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
711 if (parent->type == NODE_ROOT) {
712 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
718 if (parent->type == NODE_ROOT) {
719 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
725 if (parent->type == NODE_ROOT) {
726 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
732 if (parent->type == NODE_ROOT) {
733 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
739 if (parent->type == NODE_ROOT) {
740 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.callsite);
746 case NODE_CTF_EXPRESSION:
747 return reparent_ctf_expression(node, parent);
748 case NODE_UNARY_EXPRESSION:
749 if (parent->type == NODE_TYPE_DECLARATOR)
750 parent->u.type_declarator.bitfield_len = node;
756 return reparent_typedef(node, parent);
757 case NODE_TYPEALIAS_TARGET:
758 if (parent->type == NODE_TYPEALIAS)
759 parent->u.typealias.target = node;
762 case NODE_TYPEALIAS_ALIAS:
763 if (parent->type == NODE_TYPEALIAS)
764 parent->u.typealias.alias = node;
768 return reparent_typealias(node, parent);
771 if (parent->type == NODE_TYPE_DECLARATOR) {
772 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
776 case NODE_TYPE_DECLARATOR:
777 return reparent_type_declarator(node, parent);
779 case NODE_TYPE_SPECIFIER_LIST:
780 return reparent_type_specifier_list(node, parent);
782 case NODE_TYPE_SPECIFIER:
783 return reparent_type_specifier(node, parent);
785 case NODE_FLOATING_POINT:
791 return -EINVAL; /* Dealt with internally within grammar */
793 case NODE_ENUMERATOR:
794 if (parent->type == NODE_ENUM) {
795 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
800 case NODE_STRUCT_OR_VARIANT_DECLARATION:
801 switch (parent->type) {
803 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
806 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
815 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
823 void yyerror(struct ctf_scanner *scanner, const char *str)
825 fprintf(stderr, "error at line %d, token \"%s\": %s\n",
826 yyget_lineno(scanner->scanner),
827 yyget_text(scanner->scanner), str);
836 #define reparent_error(scanner, str) \
838 yyerror(scanner, YY_("reparent_error: " str "\n")); \
842 static void free_strings(struct bt_list_head *list)
844 struct gc_string *gstr, *tmp;
846 bt_list_for_each_entry_safe(gstr, tmp, list, gc)
850 static struct ctf_ast *ctf_ast_alloc(void)
854 ast = malloc(sizeof(*ast));
857 memset(ast, 0, sizeof(*ast));
858 BT_INIT_LIST_HEAD(&ast->allocated_nodes);
859 ast->root.type = NODE_ROOT;
860 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
861 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
862 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
863 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
864 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
865 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
866 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
867 BT_INIT_LIST_HEAD(&ast->root.u.root.callsite);
871 static void ctf_ast_free(struct ctf_ast *ast)
873 struct ctf_node *node, *tmp;
875 bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
880 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
882 return yyparse(scanner);
885 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
887 struct ctf_scanner *scanner;
890 yydebug = babeltrace_debug;
892 scanner = malloc(sizeof(*scanner));
895 memset(scanner, 0, sizeof(*scanner));
897 ret = yylex_init_extra(scanner, &scanner->scanner);
899 fprintf(stderr, "yylex_init error\n");
900 goto cleanup_scanner;
902 /* Start processing new stream */
903 yyrestart(input, scanner->scanner);
905 scanner->ast = ctf_ast_alloc();
908 init_scope(&scanner->root_scope, NULL);
909 scanner->cs = &scanner->root_scope;
910 BT_INIT_LIST_HEAD(&scanner->allocated_strings);
913 fprintf(stdout, "Scanner input is a%s.\n",
914 isatty(fileno(input)) ? "n interactive tty" :
915 " noninteractive file");
920 ret = yylex_destroy(scanner->scanner);
922 fprintf(stderr, "yylex_destroy error\n");
928 void ctf_scanner_free(struct ctf_scanner *scanner)
932 finalize_scope(&scanner->root_scope);
933 free_strings(&scanner->allocated_strings);
934 ctf_ast_free(scanner->ast);
935 ret = yylex_destroy(scanner->scanner);
937 fprintf(stderr, "yylex_destroy error\n");
946 %parse-param {struct ctf_scanner *scanner}
947 %lex-param {struct ctf_scanner *scanner}
949 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
950 * vs struct { int :value; } (unnamed bit-field). The default is to
951 * shift, so whenever we encounter an enumeration, we are doing the
952 * proper thing (shift). It is illegal to declare an enumeration
953 * "bit-field", so it is OK if this situation ends up in a parsing
958 %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 CALLSITE CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT TOK_ALIGN
959 %token <gs> IDENTIFIER ID_TYPE
965 struct gc_string *gs;
970 %type <gs> s_char s_char_sequence c_char c_char_sequence
972 %type <n> postfix_expression unary_expression unary_expression_or_range
974 %type <n> declaration
975 %type <n> event_declaration
976 %type <n> stream_declaration
977 %type <n> env_declaration
978 %type <n> trace_declaration
979 %type <n> clock_declaration
980 %type <n> callsite_declaration
981 %type <n> integer_declaration_specifiers
982 %type <n> declaration_specifiers
983 %type <n> alias_declaration_specifiers
985 %type <n> type_declarator_list
986 %type <n> integer_type_specifier
987 %type <n> type_specifier
988 %type <n> struct_type_specifier
989 %type <n> variant_type_specifier
990 %type <n> enum_type_specifier
991 %type <n> struct_or_variant_declaration_list
992 %type <n> struct_or_variant_declaration
993 %type <n> struct_or_variant_declarator_list
994 %type <n> struct_or_variant_declarator
995 %type <n> enumerator_list
997 %type <n> abstract_declarator_list
998 %type <n> abstract_declarator
999 %type <n> direct_abstract_declarator
1000 %type <n> alias_abstract_declarator_list
1001 %type <n> alias_abstract_declarator
1002 %type <n> direct_alias_abstract_declarator
1003 %type <n> declarator
1004 %type <n> direct_declarator
1005 %type <n> type_declarator
1006 %type <n> direct_type_declarator
1008 %type <n> ctf_assignment_expression_list
1009 %type <n> ctf_assignment_expression
1016 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
1017 reparent_error(scanner, "error reparenting to root");
1021 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
1022 reparent_error(scanner, "error reparenting to root");
1088 | c_char_sequence c_char
1089 { $$ = gc_string_append(scanner, $1, $2); }
1097 reparent_error(scanner, "escape sequences not supported yet");
1101 /* 1.6 String literals */
1106 | s_char_sequence s_char
1107 { $$ = gc_string_append(scanner, $1, $2); }
1115 reparent_error(scanner, "escape sequences not supported yet");
1119 /* 2: Phrase structure grammar */
1124 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1125 $$->u.unary_expression.type = UNARY_STRING;
1126 $$->u.unary_expression.u.string = yylval.gs->s;
1130 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1131 $$->u.unary_expression.type = UNARY_STRING;
1132 $$->u.unary_expression.u.string = yylval.gs->s;
1136 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1137 $$->u.unary_expression.type = UNARY_STRING;
1138 $$->u.unary_expression.u.string = yylval.gs->s;
1142 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1143 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1144 sscanf(yylval.gs->s, "%" PRIu64,
1145 &$$->u.unary_expression.u.unsigned_constant);
1149 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1150 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1151 sscanf(yylval.gs->s, "0%" PRIo64,
1152 &$$->u.unary_expression.u.unsigned_constant);
1154 | HEXADECIMAL_CONSTANT
1156 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1157 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1158 sscanf(yylval.gs->s, "0x%" PRIx64,
1159 &$$->u.unary_expression.u.unsigned_constant);
1161 | STRING_LITERAL_START DQUOTE
1163 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1164 $$->u.unary_expression.type = UNARY_STRING;
1165 $$->u.unary_expression.u.string = "";
1167 | STRING_LITERAL_START s_char_sequence DQUOTE
1169 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1170 $$->u.unary_expression.type = UNARY_STRING;
1171 $$->u.unary_expression.u.string = $2->s;
1173 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1175 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1176 $$->u.unary_expression.type = UNARY_STRING;
1177 $$->u.unary_expression.u.string = $2->s;
1179 | LPAREN unary_expression RPAREN
1181 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1182 $$->u.unary_expression.type = UNARY_NESTED;
1183 $$->u.unary_expression.u.nested_exp = $2;
1185 | postfix_expression LSBRAC unary_expression RSBRAC
1187 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1188 $$->u.unary_expression.type = UNARY_SBRAC;
1189 $$->u.unary_expression.u.sbrac_exp = $3;
1190 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1191 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1193 | postfix_expression DOT IDENTIFIER
1195 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1196 $$->u.unary_expression.type = UNARY_STRING;
1197 $$->u.unary_expression.u.string = yylval.gs->s;
1198 $$->u.unary_expression.link = UNARY_DOTLINK;
1199 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1200 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1202 | postfix_expression DOT ID_TYPE
1204 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1205 $$->u.unary_expression.type = UNARY_STRING;
1206 $$->u.unary_expression.u.string = yylval.gs->s;
1207 $$->u.unary_expression.link = UNARY_DOTLINK;
1208 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1209 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1211 | postfix_expression RARROW IDENTIFIER
1213 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1214 $$->u.unary_expression.type = UNARY_STRING;
1215 $$->u.unary_expression.u.string = yylval.gs->s;
1216 $$->u.unary_expression.link = UNARY_ARROWLINK;
1217 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1218 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1220 | postfix_expression RARROW ID_TYPE
1222 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1223 $$->u.unary_expression.type = UNARY_STRING;
1224 $$->u.unary_expression.u.string = yylval.gs->s;
1225 $$->u.unary_expression.link = UNARY_ARROWLINK;
1226 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1227 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1234 | PLUS postfix_expression
1236 | MINUS postfix_expression
1239 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1240 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1241 reparent_error(scanner, "expecting numeric constant");
1243 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1244 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1245 $$->u.unary_expression.u.signed_constant =
1246 -($$->u.unary_expression.u.unsigned_constant);
1248 $$->u.unary_expression.u.signed_constant =
1249 -($$->u.unary_expression.u.signed_constant);
1254 unary_expression_or_range:
1255 unary_expression DOTDOTDOT unary_expression
1258 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1259 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1265 /* 2.2: Declarations */
1268 declaration_specifiers SEMICOLON
1272 | stream_declaration
1280 | callsite_declaration
1282 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1284 struct ctf_node *list;
1286 $$ = make_node(scanner, NODE_TYPEDEF);
1287 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1288 $$->u._typedef.type_specifier_list = list;
1289 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1290 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1291 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1293 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1295 struct ctf_node *list;
1297 $$ = make_node(scanner, NODE_TYPEDEF);
1298 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1299 $$->u._typedef.type_specifier_list = list;
1300 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1301 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1303 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1305 struct ctf_node *list;
1307 $$ = make_node(scanner, NODE_TYPEDEF);
1308 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1309 $$->u._typedef.type_specifier_list = list;
1310 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1311 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1313 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1315 struct ctf_node *list;
1317 $$ = make_node(scanner, NODE_TYPEALIAS);
1318 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1319 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1321 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1322 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1323 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1324 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1326 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1327 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1328 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1329 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1334 event_declaration_begin event_declaration_end
1336 $$ = make_node(scanner, NODE_EVENT);
1338 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1340 $$ = make_node(scanner, NODE_EVENT);
1341 if (set_parent_node($2, $$))
1342 reparent_error(scanner, "event_declaration");
1346 event_declaration_begin:
1348 { push_scope(scanner); }
1351 event_declaration_end:
1353 { pop_scope(scanner); }
1358 stream_declaration_begin stream_declaration_end
1360 $$ = make_node(scanner, NODE_STREAM);
1362 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1364 $$ = make_node(scanner, NODE_STREAM);
1365 if (set_parent_node($2, $$))
1366 reparent_error(scanner, "stream_declaration");
1370 stream_declaration_begin:
1372 { push_scope(scanner); }
1375 stream_declaration_end:
1377 { pop_scope(scanner); }
1381 env_declaration_begin env_declaration_end
1383 $$ = make_node(scanner, NODE_ENV);
1385 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1387 $$ = make_node(scanner, NODE_ENV);
1388 if (set_parent_node($2, $$))
1389 reparent_error(scanner, "env declaration");
1393 env_declaration_begin:
1395 { push_scope(scanner); }
1398 env_declaration_end:
1400 { pop_scope(scanner); }
1404 trace_declaration_begin trace_declaration_end
1406 $$ = make_node(scanner, NODE_TRACE);
1408 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1410 $$ = make_node(scanner, NODE_TRACE);
1411 if (set_parent_node($2, $$))
1412 reparent_error(scanner, "trace_declaration");
1416 trace_declaration_begin:
1418 { push_scope(scanner); }
1421 trace_declaration_end:
1423 { pop_scope(scanner); }
1427 CLOCK clock_declaration_begin clock_declaration_end
1429 $$ = make_node(scanner, NODE_CLOCK);
1431 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1433 $$ = make_node(scanner, NODE_CLOCK);
1434 if (set_parent_node($3, $$))
1435 reparent_error(scanner, "trace_declaration");
1439 clock_declaration_begin:
1441 { push_scope(scanner); }
1444 clock_declaration_end:
1446 { pop_scope(scanner); }
1449 callsite_declaration:
1450 CALLSITE callsite_declaration_begin callsite_declaration_end
1452 $$ = make_node(scanner, NODE_CALLSITE);
1454 | CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1456 $$ = make_node(scanner, NODE_CALLSITE);
1457 if (set_parent_node($3, $$))
1458 reparent_error(scanner, "trace_declaration");
1462 callsite_declaration_begin:
1464 { push_scope(scanner); }
1467 callsite_declaration_end:
1469 { pop_scope(scanner); }
1472 integer_declaration_specifiers:
1475 struct ctf_node *node;
1477 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1478 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1479 node->u.type_specifier.type = TYPESPEC_CONST;
1480 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1482 | integer_type_specifier
1484 struct ctf_node *node;
1486 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1488 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1490 | integer_declaration_specifiers CONST
1492 struct ctf_node *node;
1495 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1496 node->u.type_specifier.type = TYPESPEC_CONST;
1497 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1499 | integer_declaration_specifiers integer_type_specifier
1502 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1506 declaration_specifiers:
1509 struct ctf_node *node;
1511 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1512 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1513 node->u.type_specifier.type = TYPESPEC_CONST;
1514 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1518 struct ctf_node *node;
1520 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1522 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1524 | declaration_specifiers CONST
1526 struct ctf_node *node;
1529 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1530 node->u.type_specifier.type = TYPESPEC_CONST;
1531 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1533 | declaration_specifiers type_specifier
1536 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1540 type_declarator_list:
1543 | type_declarator_list COMMA type_declarator
1546 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1550 integer_type_specifier:
1553 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1554 $$->u.type_specifier.type = TYPESPEC_CHAR;
1558 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1559 $$->u.type_specifier.type = TYPESPEC_SHORT;
1563 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1564 $$->u.type_specifier.type = TYPESPEC_INT;
1568 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1569 $$->u.type_specifier.type = TYPESPEC_LONG;
1573 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1574 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1578 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1579 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1583 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1584 $$->u.type_specifier.type = TYPESPEC_BOOL;
1588 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1589 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1590 $$->u.type_specifier.id_type = yylval.gs->s;
1592 | INTEGER LBRAC RBRAC
1594 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1595 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1596 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1598 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1600 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1601 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1602 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1603 if (set_parent_node($3, $$->u.type_specifier.node))
1604 reparent_error(scanner, "integer reparent error");
1611 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1612 $$->u.type_specifier.type = TYPESPEC_VOID;
1616 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1617 $$->u.type_specifier.type = TYPESPEC_CHAR;
1621 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1622 $$->u.type_specifier.type = TYPESPEC_SHORT;
1626 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1627 $$->u.type_specifier.type = TYPESPEC_INT;
1631 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1632 $$->u.type_specifier.type = TYPESPEC_LONG;
1636 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1637 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1641 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1642 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1646 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1647 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1651 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1652 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1656 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1657 $$->u.type_specifier.type = TYPESPEC_BOOL;
1661 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1662 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1666 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1667 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1671 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1672 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1673 $$->u.type_specifier.id_type = yylval.gs->s;
1675 | FLOATING_POINT LBRAC RBRAC
1677 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1678 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1679 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1681 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1683 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1684 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1685 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1686 if (set_parent_node($3, $$->u.type_specifier.node))
1687 reparent_error(scanner, "floating point reparent error");
1689 | INTEGER LBRAC RBRAC
1691 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1692 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1693 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1695 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1697 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1698 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1699 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1700 if (set_parent_node($3, $$->u.type_specifier.node))
1701 reparent_error(scanner, "integer reparent error");
1705 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1706 $$->u.type_specifier.type = TYPESPEC_STRING;
1707 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1709 | STRING LBRAC RBRAC
1711 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1712 $$->u.type_specifier.type = TYPESPEC_STRING;
1713 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1715 | STRING LBRAC ctf_assignment_expression_list RBRAC
1717 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1718 $$->u.type_specifier.type = TYPESPEC_STRING;
1719 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1720 if (set_parent_node($3, $$->u.type_specifier.node))
1721 reparent_error(scanner, "string reparent error");
1723 | ENUM enum_type_specifier
1725 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1726 $$->u.type_specifier.type = TYPESPEC_ENUM;
1727 $$->u.type_specifier.node = $2;
1729 | VARIANT variant_type_specifier
1731 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1732 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1733 $$->u.type_specifier.node = $2;
1735 | STRUCT struct_type_specifier
1737 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1738 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1739 $$->u.type_specifier.node = $2;
1743 struct_type_specifier:
1744 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1746 $$ = make_node(scanner, NODE_STRUCT);
1747 $$->u._struct.has_body = 1;
1748 if ($2 && set_parent_node($2, $$))
1749 reparent_error(scanner, "struct reparent error");
1751 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1753 $$ = make_node(scanner, NODE_STRUCT);
1754 $$->u._struct.has_body = 1;
1755 $$->u._struct.name = $1->s;
1756 if ($3 && set_parent_node($3, $$))
1757 reparent_error(scanner, "struct reparent error");
1759 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1761 $$ = make_node(scanner, NODE_STRUCT);
1762 $$->u._struct.has_body = 1;
1763 $$->u._struct.name = $1->s;
1764 if ($3 && set_parent_node($3, $$))
1765 reparent_error(scanner, "struct reparent error");
1769 $$ = make_node(scanner, NODE_STRUCT);
1770 $$->u._struct.has_body = 0;
1771 $$->u._struct.name = $1->s;
1775 $$ = make_node(scanner, NODE_STRUCT);
1776 $$->u._struct.has_body = 0;
1777 $$->u._struct.name = $1->s;
1779 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1781 $$ = make_node(scanner, NODE_STRUCT);
1782 $$->u._struct.has_body = 1;
1783 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1784 if ($2 && set_parent_node($2, $$))
1785 reparent_error(scanner, "struct reparent error");
1787 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1789 $$ = make_node(scanner, NODE_STRUCT);
1790 $$->u._struct.has_body = 1;
1791 $$->u._struct.name = $1->s;
1792 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1793 if ($3 && set_parent_node($3, $$))
1794 reparent_error(scanner, "struct reparent error");
1796 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1798 $$ = make_node(scanner, NODE_STRUCT);
1799 $$->u._struct.has_body = 1;
1800 $$->u._struct.name = $1->s;
1801 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1802 if ($3 && set_parent_node($3, $$))
1803 reparent_error(scanner, "struct reparent error");
1807 struct_declaration_begin:
1809 { push_scope(scanner); }
1812 struct_declaration_end:
1814 { pop_scope(scanner); }
1817 variant_type_specifier:
1818 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1820 $$ = make_node(scanner, NODE_VARIANT);
1821 $$->u.variant.has_body = 1;
1822 if ($2 && set_parent_node($2, $$))
1823 reparent_error(scanner, "variant reparent error");
1825 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1827 $$ = make_node(scanner, NODE_VARIANT);
1828 $$->u.variant.has_body = 1;
1829 $$->u.variant.choice = $2->s;
1830 if ($5 && set_parent_node($5, $$))
1831 reparent_error(scanner, "variant reparent error");
1833 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1835 $$ = make_node(scanner, NODE_VARIANT);
1836 $$->u.variant.has_body = 1;
1837 $$->u.variant.choice = $2->s;
1838 if ($5 && set_parent_node($5, $$))
1839 reparent_error(scanner, "variant reparent error");
1841 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1843 $$ = make_node(scanner, NODE_VARIANT);
1844 $$->u.variant.has_body = 1;
1845 $$->u.variant.name = $1->s;
1846 if ($3 && set_parent_node($3, $$))
1847 reparent_error(scanner, "variant reparent error");
1849 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1851 $$ = make_node(scanner, NODE_VARIANT);
1852 $$->u.variant.has_body = 1;
1853 $$->u.variant.name = $1->s;
1854 $$->u.variant.choice = $3->s;
1855 if ($6 && set_parent_node($6, $$))
1856 reparent_error(scanner, "variant reparent error");
1858 | IDENTIFIER LT IDENTIFIER GT
1860 $$ = make_node(scanner, NODE_VARIANT);
1861 $$->u.variant.has_body = 0;
1862 $$->u.variant.name = $1->s;
1863 $$->u.variant.choice = $3->s;
1865 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1867 $$ = make_node(scanner, NODE_VARIANT);
1868 $$->u.variant.has_body = 1;
1869 $$->u.variant.name = $1->s;
1870 $$->u.variant.choice = $3->s;
1871 if ($6 && set_parent_node($6, $$))
1872 reparent_error(scanner, "variant reparent error");
1874 | IDENTIFIER LT ID_TYPE GT
1876 $$ = make_node(scanner, NODE_VARIANT);
1877 $$->u.variant.has_body = 0;
1878 $$->u.variant.name = $1->s;
1879 $$->u.variant.choice = $3->s;
1881 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1883 $$ = make_node(scanner, NODE_VARIANT);
1884 $$->u.variant.has_body = 1;
1885 $$->u.variant.name = $1->s;
1886 if ($3 && set_parent_node($3, $$))
1887 reparent_error(scanner, "variant reparent error");
1889 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1891 $$ = make_node(scanner, NODE_VARIANT);
1892 $$->u.variant.has_body = 1;
1893 $$->u.variant.name = $1->s;
1894 $$->u.variant.choice = $3->s;
1895 if ($6 && set_parent_node($6, $$))
1896 reparent_error(scanner, "variant reparent error");
1898 | ID_TYPE LT IDENTIFIER GT
1900 $$ = make_node(scanner, NODE_VARIANT);
1901 $$->u.variant.has_body = 0;
1902 $$->u.variant.name = $1->s;
1903 $$->u.variant.choice = $3->s;
1905 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1907 $$ = make_node(scanner, NODE_VARIANT);
1908 $$->u.variant.has_body = 1;
1909 $$->u.variant.name = $1->s;
1910 $$->u.variant.choice = $3->s;
1911 if ($6 && set_parent_node($6, $$))
1912 reparent_error(scanner, "variant reparent error");
1914 | ID_TYPE LT ID_TYPE GT
1916 $$ = make_node(scanner, NODE_VARIANT);
1917 $$->u.variant.has_body = 0;
1918 $$->u.variant.name = $1->s;
1919 $$->u.variant.choice = $3->s;
1923 variant_declaration_begin:
1925 { push_scope(scanner); }
1928 variant_declaration_end:
1930 { pop_scope(scanner); }
1933 enum_type_specifier:
1934 LBRAC enumerator_list RBRAC
1936 $$ = make_node(scanner, NODE_ENUM);
1937 $$->u._enum.has_body = 1;
1938 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1940 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1942 $$ = make_node(scanner, NODE_ENUM);
1943 $$->u._enum.has_body = 1;
1944 ($$)->u._enum.container_type = $2;
1945 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1947 | IDENTIFIER LBRAC enumerator_list RBRAC
1949 $$ = make_node(scanner, NODE_ENUM);
1950 $$->u._enum.has_body = 1;
1951 $$->u._enum.enum_id = $1->s;
1952 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1954 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1956 $$ = make_node(scanner, NODE_ENUM);
1957 $$->u._enum.has_body = 1;
1958 $$->u._enum.enum_id = $1->s;
1959 ($$)->u._enum.container_type = $3;
1960 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1962 | ID_TYPE LBRAC enumerator_list RBRAC
1964 $$ = make_node(scanner, NODE_ENUM);
1965 $$->u._enum.has_body = 1;
1966 $$->u._enum.enum_id = $1->s;
1967 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1969 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1971 $$ = make_node(scanner, NODE_ENUM);
1972 $$->u._enum.has_body = 1;
1973 $$->u._enum.enum_id = $1->s;
1974 ($$)->u._enum.container_type = $3;
1975 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1977 | LBRAC enumerator_list COMMA RBRAC
1979 $$ = make_node(scanner, NODE_ENUM);
1980 $$->u._enum.has_body = 1;
1981 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1983 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1985 $$ = make_node(scanner, NODE_ENUM);
1986 $$->u._enum.has_body = 1;
1987 ($$)->u._enum.container_type = $2;
1988 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1990 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1992 $$ = make_node(scanner, NODE_ENUM);
1993 $$->u._enum.has_body = 1;
1994 $$->u._enum.enum_id = $1->s;
1995 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1997 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1999 $$ = make_node(scanner, NODE_ENUM);
2000 $$->u._enum.has_body = 1;
2001 $$->u._enum.enum_id = $1->s;
2002 ($$)->u._enum.container_type = $3;
2003 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2007 $$ = make_node(scanner, NODE_ENUM);
2008 $$->u._enum.has_body = 0;
2009 $$->u._enum.enum_id = $1->s;
2011 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
2013 $$ = make_node(scanner, NODE_ENUM);
2014 $$->u._enum.has_body = 1;
2015 $$->u._enum.enum_id = $1->s;
2016 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
2018 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
2020 $$ = make_node(scanner, NODE_ENUM);
2021 $$->u._enum.has_body = 1;
2022 $$->u._enum.enum_id = $1->s;
2023 ($$)->u._enum.container_type = $3;
2024 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
2028 $$ = make_node(scanner, NODE_ENUM);
2029 $$->u._enum.has_body = 0;
2030 $$->u._enum.enum_id = $1->s;
2034 struct_or_variant_declaration_list:
2037 | struct_or_variant_declaration_list struct_or_variant_declaration
2041 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2044 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
2049 struct_or_variant_declaration:
2050 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
2052 struct ctf_node *list;
2054 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2055 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2056 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
2057 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2058 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
2060 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2062 struct ctf_node *list;
2064 $$ = make_node(scanner, NODE_TYPEDEF);
2065 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2066 $$->u._typedef.type_specifier_list = list;
2067 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2068 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2069 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2071 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
2073 struct ctf_node *list;
2075 $$ = make_node(scanner, NODE_TYPEDEF);
2076 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2077 $$->u._typedef.type_specifier_list = list;
2078 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2079 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2081 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
2083 struct ctf_node *list;
2085 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2086 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2087 $$ = make_node(scanner, NODE_TYPEDEF);
2088 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2089 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2091 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
2093 struct ctf_node *list;
2095 $$ = make_node(scanner, NODE_TYPEALIAS);
2096 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2097 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2099 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2100 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2101 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2102 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2104 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2105 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2106 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2107 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2111 alias_declaration_specifiers:
2114 struct ctf_node *node;
2116 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2117 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2118 node->u.type_specifier.type = TYPESPEC_CONST;
2119 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2123 struct ctf_node *node;
2125 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2127 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2131 struct ctf_node *node;
2133 add_type(scanner, $1);
2134 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2135 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2136 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2137 node->u.type_specifier.id_type = yylval.gs->s;
2138 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2140 | alias_declaration_specifiers CONST
2142 struct ctf_node *node;
2145 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2146 node->u.type_specifier.type = TYPESPEC_CONST;
2147 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2149 | alias_declaration_specifiers type_specifier
2152 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2154 | alias_declaration_specifiers IDENTIFIER
2156 struct ctf_node *node;
2158 add_type(scanner, $2);
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);
2167 struct_or_variant_declarator_list:
2168 struct_or_variant_declarator
2170 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2173 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2177 struct_or_variant_declarator:
2180 | COLON unary_expression
2182 | declarator COLON unary_expression
2185 if (set_parent_node($3, $1))
2186 reparent_error(scanner, "struct_or_variant_declarator");
2193 | enumerator_list COMMA enumerator
2196 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2203 $$ = make_node(scanner, NODE_ENUMERATOR);
2204 $$->u.enumerator.id = $1->s;
2208 $$ = make_node(scanner, NODE_ENUMERATOR);
2209 $$->u.enumerator.id = $1->s;
2213 $$ = make_node(scanner, NODE_ENUMERATOR);
2214 $$->u.enumerator.id = $1->s;
2216 | STRING_LITERAL_START DQUOTE
2218 $$ = make_node(scanner, NODE_ENUMERATOR);
2219 $$->u.enumerator.id = "";
2221 | STRING_LITERAL_START s_char_sequence DQUOTE
2223 $$ = make_node(scanner, NODE_ENUMERATOR);
2224 $$->u.enumerator.id = $2->s;
2226 | IDENTIFIER EQUAL unary_expression_or_range
2228 $$ = make_node(scanner, NODE_ENUMERATOR);
2229 $$->u.enumerator.id = $1->s;
2230 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2232 | ID_TYPE EQUAL unary_expression_or_range
2234 $$ = make_node(scanner, NODE_ENUMERATOR);
2235 $$->u.enumerator.id = $1->s;
2236 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2238 | keywords EQUAL unary_expression_or_range
2240 $$ = make_node(scanner, NODE_ENUMERATOR);
2241 $$->u.enumerator.id = $1->s;
2242 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2244 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
2246 $$ = make_node(scanner, NODE_ENUMERATOR);
2247 $$->u.enumerator.id = "";
2248 bt_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
2250 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
2252 $$ = make_node(scanner, NODE_ENUMERATOR);
2253 $$->u.enumerator.id = $2->s;
2254 bt_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
2258 abstract_declarator_list:
2261 | abstract_declarator_list COMMA abstract_declarator
2264 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2268 abstract_declarator:
2269 direct_abstract_declarator
2271 | pointer direct_abstract_declarator
2274 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2278 direct_abstract_declarator:
2281 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2282 $$->u.type_declarator.type = TYPEDEC_ID;
2287 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2288 $$->u.type_declarator.type = TYPEDEC_ID;
2289 $$->u.type_declarator.u.id = $1->s;
2291 | LPAREN abstract_declarator RPAREN
2293 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2294 $$->u.type_declarator.type = TYPEDEC_NESTED;
2295 $$->u.type_declarator.u.nested.type_declarator = $2;
2297 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2299 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2300 $$->u.type_declarator.type = TYPEDEC_NESTED;
2301 $$->u.type_declarator.u.nested.type_declarator = $1;
2302 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2303 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2305 | direct_abstract_declarator LSBRAC RSBRAC
2307 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2308 $$->u.type_declarator.type = TYPEDEC_NESTED;
2309 $$->u.type_declarator.u.nested.type_declarator = $1;
2310 $$->u.type_declarator.u.nested.abstract_array = 1;
2314 alias_abstract_declarator_list:
2315 alias_abstract_declarator
2317 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2320 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2324 alias_abstract_declarator:
2325 direct_alias_abstract_declarator
2327 | pointer direct_alias_abstract_declarator
2330 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2334 direct_alias_abstract_declarator:
2337 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2338 $$->u.type_declarator.type = TYPEDEC_ID;
2341 | LPAREN alias_abstract_declarator RPAREN
2343 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2344 $$->u.type_declarator.type = TYPEDEC_NESTED;
2345 $$->u.type_declarator.u.nested.type_declarator = $2;
2347 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2349 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2350 $$->u.type_declarator.type = TYPEDEC_NESTED;
2351 $$->u.type_declarator.u.nested.type_declarator = $1;
2352 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2353 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2355 | direct_alias_abstract_declarator LSBRAC RSBRAC
2357 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2358 $$->u.type_declarator.type = TYPEDEC_NESTED;
2359 $$->u.type_declarator.u.nested.type_declarator = $1;
2360 $$->u.type_declarator.u.nested.abstract_array = 1;
2367 | pointer direct_declarator
2370 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2377 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2378 $$->u.type_declarator.type = TYPEDEC_ID;
2379 $$->u.type_declarator.u.id = $1->s;
2381 | LPAREN declarator RPAREN
2383 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2384 $$->u.type_declarator.type = TYPEDEC_NESTED;
2385 $$->u.type_declarator.u.nested.type_declarator = $2;
2387 | direct_declarator LSBRAC unary_expression RSBRAC
2389 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2390 $$->u.type_declarator.type = TYPEDEC_NESTED;
2391 $$->u.type_declarator.u.nested.type_declarator = $1;
2392 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2393 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2398 direct_type_declarator
2400 | pointer direct_type_declarator
2403 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2407 direct_type_declarator:
2410 add_type(scanner, $1);
2411 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2412 $$->u.type_declarator.type = TYPEDEC_ID;
2413 $$->u.type_declarator.u.id = $1->s;
2415 | LPAREN type_declarator RPAREN
2417 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2418 $$->u.type_declarator.type = TYPEDEC_NESTED;
2419 $$->u.type_declarator.u.nested.type_declarator = $2;
2421 | direct_type_declarator LSBRAC unary_expression RSBRAC
2423 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2424 $$->u.type_declarator.type = TYPEDEC_NESTED;
2425 $$->u.type_declarator.u.nested.type_declarator = $1;
2426 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2427 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2434 $$ = make_node(scanner, NODE_POINTER);
2438 $$ = make_node(scanner, NODE_POINTER);
2439 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2441 | STAR type_qualifier_list pointer
2443 $$ = make_node(scanner, NODE_POINTER);
2444 $$->u.pointer.const_qualifier = 1;
2445 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2449 type_qualifier_list:
2450 /* pointer assumes only const type qualifier */
2452 | type_qualifier_list CONST
2455 /* 2.3: CTF-specific declarations */
2457 ctf_assignment_expression_list:
2458 ctf_assignment_expression SEMICOLON
2460 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2463 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2467 ctf_assignment_expression:
2468 unary_expression EQUAL unary_expression
2471 * Because we have left and right, cannot use
2474 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2475 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2476 if ($1->u.unary_expression.type != UNARY_STRING)
2477 reparent_error(scanner, "ctf_assignment_expression left expects string");
2478 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2480 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2483 * Because we have left and right, cannot use
2486 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2487 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2488 if ($1->u.unary_expression.type != UNARY_STRING)
2489 reparent_error(scanner, "ctf_assignment_expression left expects string");
2490 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2492 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2494 struct ctf_node *list;
2496 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2497 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2498 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2499 $$ = make_node(scanner, NODE_TYPEDEF);
2500 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2501 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2503 | TYPEDEF declaration_specifiers type_declarator_list
2505 struct ctf_node *list;
2507 $$ = make_node(scanner, NODE_TYPEDEF);
2508 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2509 $$->u._typedef.type_specifier_list = list;
2510 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2511 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2513 | declaration_specifiers TYPEDEF type_declarator_list
2515 struct ctf_node *list;
2517 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2518 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2519 $$ = make_node(scanner, NODE_TYPEDEF);
2520 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2521 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2523 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2525 struct ctf_node *list;
2527 $$ = make_node(scanner, NODE_TYPEALIAS);
2528 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2529 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2531 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2532 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2533 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2534 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2536 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2537 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2538 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2539 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);