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 "ctf-scanner.h"
30 #include "ctf-parser.h"
34 * TODO: support enum, variant and struct declarations in scopes.
37 /* Join two lists, put "add" at the end of "head". */
39 _cds_list_splice_tail (struct cds_list_head *add, struct cds_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 #define printf_dbg(fmt, args...) fprintf(stderr, "%s: " fmt, __func__, ## args)
52 int yyparse(struct ctf_scanner *scanner);
53 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
54 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
55 int yylex_destroy(yyscan_t yyscanner);
56 void yyrestart(FILE * in_str, yyscan_t scanner);
61 struct cds_list_head gc;
66 static const char *node_type_to_str[] = {
67 [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
68 [ NODE_ROOT ] = "NODE_ROOT",
69 [ NODE_EVENT ] = "NODE_EVENT",
70 [ NODE_STREAM ] = "NODE_STREAM",
71 [ NODE_TRACE ] = "NODE_TRACE",
72 [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
73 [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
74 [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
75 [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
76 [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
77 [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
78 [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
79 [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
80 [ NODE_POINTER ] = "NODE_POINTER",
81 [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
82 [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
83 [ NODE_INTEGER ] = "NODE_INTEGER",
84 [ NODE_STRING ] = "NODE_STRING",
85 [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
86 [ NODE_ENUM ] = "NODE_ENUM",
87 [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
88 [ NODE_VARIANT ] = "NODE_VARIANT",
89 [ NODE_STRUCT ] = "NODE_STRUCT",
92 const char *node_type(struct ctf_node *node)
94 if (node->type < NR_NODE_TYPES)
95 return node_type_to_str[node->type];
100 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
103 struct gc_string *gstr;
106 /* TODO: could be faster with find first bit or glib Gstring */
107 /* sizeof long to account for malloc header (int or long ?) */
108 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
111 gstr = malloc(alloclen);
112 cds_list_add(&gstr->gc, &scanner->allocated_strings);
113 gstr->alloclen = alloclen;
118 * note: never use gc_string_append on a string that has external references.
119 * gsrc will be garbage collected immediately, and gstr might be.
120 * Should only be used to append characters to a string literal or constant.
122 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
123 struct gc_string *gstr,
124 struct gc_string *gsrc)
126 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
129 /* TODO: could be faster with find first bit or glib Gstring */
130 /* sizeof long to account for malloc header (int or long ?) */
131 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
134 if (alloclen > gstr->alloclen) {
135 struct gc_string *newgstr;
137 newgstr = gc_string_alloc(scanner, newlen);
138 strcpy(newgstr->s, gstr->s);
139 strcat(newgstr->s, gsrc->s);
140 cds_list_del(&gstr->gc);
144 strcat(gstr->s, gsrc->s);
146 cds_list_del(&gsrc->gc);
151 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
153 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
154 strcpy(lvalp->gs->s, src);
157 static void init_scope(struct ctf_scanner_scope *scope,
158 struct ctf_scanner_scope *parent)
160 scope->parent = parent;
161 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
165 static void finalize_scope(struct ctf_scanner_scope *scope)
167 g_hash_table_destroy(scope->types);
170 static void push_scope(struct ctf_scanner *scanner)
172 struct ctf_scanner_scope *ns;
174 printf_dbg("push scope\n");
175 ns = malloc(sizeof(struct ctf_scanner_scope));
176 init_scope(ns, scanner->cs);
180 static void pop_scope(struct ctf_scanner *scanner)
182 struct ctf_scanner_scope *os;
184 printf_dbg("pop scope\n");
186 scanner->cs = os->parent;
191 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
195 ret = (int) (long) g_hash_table_lookup(s->types, id);
196 printf_dbg("lookup %p %s %d\n", s, id, ret);
200 int is_type(struct ctf_scanner *scanner, const char *id)
202 struct ctf_scanner_scope *it;
205 for (it = scanner->cs; it != NULL; it = it->parent) {
206 if (lookup_type(it, id)) {
211 printf_dbg("is type %s %d\n", id, ret);
215 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
217 printf_dbg("add type %s\n", id->s);
218 if (lookup_type(scanner->cs, id->s))
220 g_hash_table_insert(scanner->cs->types, id->s, id->s);
223 static struct ctf_node *make_node(struct ctf_scanner *scanner,
226 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
227 struct ctf_node *node;
229 node = malloc(sizeof(*node));
232 memset(node, 0, sizeof(*node));
234 CDS_INIT_LIST_HEAD(&node->tmp_head);
235 cds_list_add(&node->gc, &ast->allocated_nodes);
236 cds_list_add(&node->siblings, &node->tmp_head);
240 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
244 CDS_INIT_LIST_HEAD(&node->u.event.declaration_list);
247 CDS_INIT_LIST_HEAD(&node->u.stream.declaration_list);
250 CDS_INIT_LIST_HEAD(&node->u.trace.declaration_list);
253 case NODE_CTF_EXPRESSION:
254 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.left);
255 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.right);
257 case NODE_UNARY_EXPRESSION:
261 CDS_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
263 case NODE_TYPEALIAS_TARGET:
264 CDS_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
266 case NODE_TYPEALIAS_ALIAS:
267 CDS_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
272 case NODE_TYPE_SPECIFIER:
274 case NODE_TYPE_SPECIFIER_LIST:
275 CDS_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
279 case NODE_TYPE_DECLARATOR:
280 CDS_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
283 case NODE_FLOATING_POINT:
284 CDS_INIT_LIST_HEAD(&node->u.floating_point.expressions);
287 CDS_INIT_LIST_HEAD(&node->u.integer.expressions);
290 CDS_INIT_LIST_HEAD(&node->u.string.expressions);
292 case NODE_ENUMERATOR:
293 CDS_INIT_LIST_HEAD(&node->u.enumerator.values);
296 CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
298 case NODE_STRUCT_OR_VARIANT_DECLARATION:
299 CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
302 CDS_INIT_LIST_HEAD(&node->u.variant.declaration_list);
305 CDS_INIT_LIST_HEAD(&node->u._struct.declaration_list);
310 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
318 static int reparent_ctf_expression(struct ctf_node *node,
319 struct ctf_node *parent)
321 switch (parent->type) {
323 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
326 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
329 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
331 case NODE_FLOATING_POINT:
332 _cds_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
335 _cds_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
338 _cds_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
342 case NODE_CTF_EXPRESSION:
344 case NODE_TYPEALIAS_TARGET:
345 case NODE_TYPEALIAS_ALIAS:
347 case NODE_TYPE_SPECIFIER:
348 case NODE_TYPE_SPECIFIER_LIST:
350 case NODE_TYPE_DECLARATOR:
351 case NODE_ENUMERATOR:
353 case NODE_STRUCT_OR_VARIANT_DECLARATION:
356 case NODE_UNARY_EXPRESSION:
361 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
368 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
370 switch (parent->type) {
372 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
375 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
378 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
381 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
384 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
387 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
390 case NODE_FLOATING_POINT:
393 case NODE_CTF_EXPRESSION:
395 case NODE_TYPEALIAS_TARGET:
396 case NODE_TYPEALIAS_ALIAS:
398 case NODE_TYPE_SPECIFIER:
399 case NODE_TYPE_SPECIFIER_LIST:
401 case NODE_TYPE_DECLARATOR:
402 case NODE_ENUMERATOR:
404 case NODE_STRUCT_OR_VARIANT_DECLARATION:
405 case NODE_UNARY_EXPRESSION:
410 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
417 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
419 switch (parent->type) {
421 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
424 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
427 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
430 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
433 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
436 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
439 case NODE_FLOATING_POINT:
442 case NODE_CTF_EXPRESSION:
444 case NODE_TYPEALIAS_TARGET:
445 case NODE_TYPEALIAS_ALIAS:
447 case NODE_TYPE_SPECIFIER:
448 case NODE_TYPE_SPECIFIER_LIST:
450 case NODE_TYPE_DECLARATOR:
451 case NODE_ENUMERATOR:
453 case NODE_STRUCT_OR_VARIANT_DECLARATION:
454 case NODE_UNARY_EXPRESSION:
459 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
466 static int reparent_type_specifier(struct ctf_node *node,
467 struct ctf_node *parent)
469 switch (parent->type) {
470 case NODE_TYPE_SPECIFIER_LIST:
471 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
474 case NODE_TYPE_SPECIFIER:
481 case NODE_TYPEALIAS_TARGET:
482 case NODE_TYPEALIAS_ALIAS:
483 case NODE_TYPE_DECLARATOR:
485 case NODE_STRUCT_OR_VARIANT_DECLARATION:
487 case NODE_FLOATING_POINT:
490 case NODE_CTF_EXPRESSION:
492 case NODE_ENUMERATOR:
493 case NODE_UNARY_EXPRESSION:
498 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
505 static int reparent_type_specifier_list(struct ctf_node *node,
506 struct ctf_node *parent)
508 switch (parent->type) {
510 cds_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
513 cds_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
516 cds_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
519 cds_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
522 cds_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
525 cds_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
528 parent->u._typedef.type_specifier_list = node;
530 case NODE_TYPEALIAS_TARGET:
531 parent->u.typealias_target.type_specifier_list = node;
533 case NODE_TYPEALIAS_ALIAS:
534 parent->u.typealias_alias.type_specifier_list = node;
536 case NODE_TYPE_DECLARATOR:
537 parent->u.type_declarator.type = TYPEDEC_NESTED;
538 parent->u.type_declarator.u.nested.length = node;
541 parent->u._enum.container_type = node;
543 case NODE_STRUCT_OR_VARIANT_DECLARATION:
544 parent->u.struct_or_variant_declaration.type_specifier_list = node;
546 case NODE_TYPE_SPECIFIER:
548 case NODE_FLOATING_POINT:
551 case NODE_CTF_EXPRESSION:
553 case NODE_ENUMERATOR:
554 case NODE_UNARY_EXPRESSION:
559 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
566 static int reparent_type_declarator(struct ctf_node *node,
567 struct ctf_node *parent)
569 switch (parent->type) {
570 case NODE_TYPE_DECLARATOR:
571 parent->u.type_declarator.type = TYPEDEC_NESTED;
572 parent->u.type_declarator.u.nested.type_declarator = node;
574 case NODE_STRUCT_OR_VARIANT_DECLARATION:
575 _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
578 _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
580 case NODE_TYPEALIAS_TARGET:
581 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
583 case NODE_TYPEALIAS_ALIAS:
584 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
595 case NODE_FLOATING_POINT:
598 case NODE_CTF_EXPRESSION:
599 case NODE_TYPE_SPECIFIER:
600 case NODE_TYPE_SPECIFIER_LIST:
602 case NODE_ENUMERATOR:
603 case NODE_UNARY_EXPRESSION:
608 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
618 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
619 * create the link declared by the input, -ENOENT if node or parent is NULL,
620 * -EINVAL if there is an internal structure problem.
622 static int set_parent_node(struct ctf_node *node,
623 struct ctf_node *parent)
625 if (!node || !parent)
628 /* Note: Linking to parent will be done only by an external visitor */
630 switch (node->type) {
632 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
636 if (parent->type == NODE_ROOT) {
637 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.event);
643 if (parent->type == NODE_ROOT) {
644 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
650 if (parent->type == NODE_ROOT) {
651 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
657 case NODE_CTF_EXPRESSION:
658 return reparent_ctf_expression(node, parent);
659 case NODE_UNARY_EXPRESSION:
660 if (parent->type == NODE_TYPE_DECLARATOR)
661 parent->u.type_declarator.bitfield_len = node;
667 return reparent_typedef(node, parent);
668 case NODE_TYPEALIAS_TARGET:
669 if (parent->type == NODE_TYPEALIAS)
670 parent->u.typealias.target = node;
673 case NODE_TYPEALIAS_ALIAS:
674 if (parent->type == NODE_TYPEALIAS)
675 parent->u.typealias.alias = node;
679 return reparent_typealias(node, parent);
682 if (parent->type == NODE_TYPE_DECLARATOR) {
683 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
687 case NODE_TYPE_DECLARATOR:
688 return reparent_type_declarator(node, parent);
690 case NODE_TYPE_SPECIFIER_LIST:
691 return reparent_type_specifier_list(node, parent);
693 case NODE_TYPE_SPECIFIER:
694 return reparent_type_specifier(node, parent);
696 case NODE_FLOATING_POINT:
702 return -EINVAL; /* Dealt with internally within grammar */
704 case NODE_ENUMERATOR:
705 if (parent->type == NODE_ENUM) {
706 _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
711 case NODE_STRUCT_OR_VARIANT_DECLARATION:
712 switch (parent->type) {
714 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
717 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
726 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
733 void yyerror(struct ctf_scanner *scanner, const char *str)
735 fprintf(stderr, "error %s\n", str);
743 #define reparent_error(scanner, str) \
745 yyerror(scanner, YY_("reparent_error: " str "\n")); \
749 static void free_strings(struct cds_list_head *list)
751 struct gc_string *gstr, *tmp;
753 cds_list_for_each_entry_safe(gstr, tmp, list, gc)
757 static struct ctf_ast *ctf_ast_alloc(void)
761 ast = malloc(sizeof(*ast));
764 memset(ast, 0, sizeof(*ast));
765 CDS_INIT_LIST_HEAD(&ast->allocated_nodes);
766 ast->root.type = NODE_ROOT;
767 CDS_INIT_LIST_HEAD(&ast->root.tmp_head);
768 CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
769 CDS_INIT_LIST_HEAD(&ast->root.u.root.trace);
770 CDS_INIT_LIST_HEAD(&ast->root.u.root.stream);
771 CDS_INIT_LIST_HEAD(&ast->root.u.root.event);
775 static void ctf_ast_free(struct ctf_ast *ast)
777 struct ctf_node *node, *tmp;
779 cds_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
783 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
785 return yyparse(scanner);
788 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
790 struct ctf_scanner *scanner;
793 scanner = malloc(sizeof(*scanner));
796 memset(scanner, 0, sizeof(*scanner));
798 ret = yylex_init_extra(scanner, &scanner->scanner);
800 fprintf(stderr, "yylex_init error\n");
801 goto cleanup_scanner;
803 /* Start processing new stream */
804 yyrestart(input, scanner->scanner);
806 scanner->ast = ctf_ast_alloc();
809 init_scope(&scanner->root_scope, NULL);
810 scanner->cs = &scanner->root_scope;
811 CDS_INIT_LIST_HEAD(&scanner->allocated_strings);
814 fprintf(stdout, "Scanner input is a%s.\n",
815 isatty(fileno(input)) ? "n interactive tty" :
816 " noninteractive file");
821 ret = yylex_destroy(scanner->scanner);
823 fprintf(stderr, "yylex_destroy error\n");
829 void ctf_scanner_free(struct ctf_scanner *scanner)
833 finalize_scope(&scanner->root_scope);
834 free_strings(&scanner->allocated_strings);
835 ctf_ast_free(scanner->ast);
836 ret = yylex_destroy(scanner->scanner);
838 fprintf(stderr, "yylex_destroy error\n");
846 %parse-param {struct ctf_scanner *scanner}
847 %lex-param {struct ctf_scanner *scanner}
849 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
850 * vs struct { int :value; } (unnamed bit-field). The default is to
851 * shift, so whenever we encounter an enumeration, we are doing the
852 * proper thing (shift). It is illegal to declare an enumeration
853 * "bit-field", so it is OK if this situation ends up in a parsing
858 %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 EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT
859 %token <gs> IDENTIFIER ID_TYPE
865 struct gc_string *gs;
870 %type <gs> s_char s_char_sequence c_char c_char_sequence
872 %type <n> postfix_expression unary_expression unary_expression_or_range
874 %type <n> declaration
875 %type <n> event_declaration
876 %type <n> stream_declaration
877 %type <n> trace_declaration
878 %type <n> integer_declaration_specifiers
879 %type <n> declaration_specifiers
880 %type <n> alias_declaration_specifiers
882 %type <n> type_declarator_list
883 %type <n> integer_type_specifier
884 %type <n> type_specifier
885 %type <n> struct_type_specifier
886 %type <n> variant_type_specifier
887 %type <n> declaration_specifiers_or_integer_constant
888 %type <n> enum_type_specifier
889 %type <n> struct_or_variant_declaration_list
890 %type <n> struct_or_variant_declaration
891 %type <n> struct_or_variant_declarator_list
892 %type <n> struct_or_variant_declarator
893 %type <n> enumerator_list
895 %type <n> abstract_declarator_list
896 %type <n> abstract_declarator
897 %type <n> direct_abstract_declarator
898 %type <n> alias_abstract_declarator_list
899 %type <n> alias_abstract_declarator
900 %type <n> direct_alias_abstract_declarator
902 %type <n> direct_declarator
903 %type <n> type_declarator
904 %type <n> direct_type_declarator
906 %type <n> ctf_assignment_expression_list
907 %type <n> ctf_assignment_expression
914 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
915 reparent_error(scanner, "error reparenting to root");
919 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
920 reparent_error(scanner, "error reparenting to root");
978 | c_char_sequence c_char
979 { $$ = gc_string_append(scanner, $1, $2); }
987 reparent_error(scanner, "escape sequences not supported yet");
991 /* 1.6 String literals */
996 | s_char_sequence s_char
997 { $$ = gc_string_append(scanner, $1, $2); }
1005 reparent_error(scanner, "escape sequences not supported yet");
1009 /* 2: Phrase structure grammar */
1014 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1015 $$->u.unary_expression.type = UNARY_STRING;
1016 $$->u.unary_expression.u.string = yylval.gs->s;
1020 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1021 $$->u.unary_expression.type = UNARY_STRING;
1022 $$->u.unary_expression.u.string = yylval.gs->s;
1026 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1027 $$->u.unary_expression.type = UNARY_STRING;
1028 $$->u.unary_expression.u.string = yylval.gs->s;
1032 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1033 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1034 sscanf(yylval.gs->s, "%" PRIu64,
1035 &$$->u.unary_expression.u.unsigned_constant);
1039 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1040 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1041 sscanf(yylval.gs->s, "0%" PRIo64,
1042 &$$->u.unary_expression.u.unsigned_constant);
1044 | HEXADECIMAL_CONSTANT
1046 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1047 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1048 sscanf(yylval.gs->s, "0x%" PRIx64,
1049 &$$->u.unary_expression.u.unsigned_constant);
1051 | STRING_LITERAL_START DQUOTE
1053 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1054 $$->u.unary_expression.type = UNARY_STRING;
1055 $$->u.unary_expression.u.string = "";
1057 | STRING_LITERAL_START s_char_sequence DQUOTE
1059 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1060 $$->u.unary_expression.type = UNARY_STRING;
1061 $$->u.unary_expression.u.string = $2->s;
1063 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1065 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1066 $$->u.unary_expression.type = UNARY_STRING;
1067 $$->u.unary_expression.u.string = $2->s;
1069 | LPAREN unary_expression RPAREN
1071 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1072 $$->u.unary_expression.type = UNARY_NESTED;
1073 $$->u.unary_expression.u.nested_exp = $2;
1075 | postfix_expression LSBRAC unary_expression RSBRAC
1077 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1078 $$->u.unary_expression.type = UNARY_SBRAC;
1079 $$->u.unary_expression.u.sbrac_exp = $3;
1080 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1081 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1083 | postfix_expression DOT IDENTIFIER
1085 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1086 $$->u.unary_expression.type = UNARY_STRING;
1087 $$->u.unary_expression.u.string = yylval.gs->s;
1088 $$->u.unary_expression.link = UNARY_DOTLINK;
1089 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1090 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1092 | postfix_expression DOT ID_TYPE
1094 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1095 $$->u.unary_expression.type = UNARY_STRING;
1096 $$->u.unary_expression.u.string = yylval.gs->s;
1097 $$->u.unary_expression.link = UNARY_DOTLINK;
1098 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1099 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1101 | postfix_expression RARROW IDENTIFIER
1103 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1104 $$->u.unary_expression.type = UNARY_STRING;
1105 $$->u.unary_expression.u.string = yylval.gs->s;
1106 $$->u.unary_expression.link = UNARY_ARROWLINK;
1107 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1108 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1110 | postfix_expression RARROW ID_TYPE
1112 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1113 $$->u.unary_expression.type = UNARY_STRING;
1114 $$->u.unary_expression.u.string = yylval.gs->s;
1115 $$->u.unary_expression.link = UNARY_ARROWLINK;
1116 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1117 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1124 | PLUS postfix_expression
1126 | MINUS postfix_expression
1129 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1130 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1131 reparent_error(scanner, "expecting numeric constant");
1133 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1134 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1135 $$->u.unary_expression.u.signed_constant =
1136 -($$->u.unary_expression.u.unsigned_constant);
1138 $$->u.unary_expression.u.signed_constant =
1139 -($$->u.unary_expression.u.signed_constant);
1144 unary_expression_or_range:
1145 unary_expression DOTDOTDOT unary_expression
1148 _cds_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1149 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1155 /* 2.2: Declarations */
1158 declaration_specifiers SEMICOLON
1162 | stream_declaration
1166 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1168 struct ctf_node *list;
1170 $$ = make_node(scanner, NODE_TYPEDEF);
1171 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1172 $$->u._typedef.type_specifier_list = list;
1173 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1174 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1175 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1177 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1179 struct ctf_node *list;
1181 $$ = make_node(scanner, NODE_TYPEDEF);
1182 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1183 $$->u._typedef.type_specifier_list = list;
1184 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1185 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1187 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1189 struct ctf_node *list;
1191 $$ = make_node(scanner, NODE_TYPEDEF);
1192 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1193 $$->u._typedef.type_specifier_list = list;
1194 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1195 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1197 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1199 struct ctf_node *list;
1201 $$ = make_node(scanner, NODE_TYPEALIAS);
1202 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1203 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1205 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1206 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1207 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1208 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1210 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1211 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1212 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1213 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1218 event_declaration_begin event_declaration_end
1220 $$ = make_node(scanner, NODE_EVENT);
1222 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1224 $$ = make_node(scanner, NODE_EVENT);
1225 if (set_parent_node($2, $$))
1226 reparent_error(scanner, "event_declaration");
1230 event_declaration_begin:
1232 { push_scope(scanner); }
1235 event_declaration_end:
1237 { pop_scope(scanner); }
1242 stream_declaration_begin stream_declaration_end
1244 $$ = make_node(scanner, NODE_STREAM);
1246 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1248 $$ = make_node(scanner, NODE_STREAM);
1249 if (set_parent_node($2, $$))
1250 reparent_error(scanner, "stream_declaration");
1254 stream_declaration_begin:
1256 { push_scope(scanner); }
1259 stream_declaration_end:
1261 { pop_scope(scanner); }
1266 trace_declaration_begin trace_declaration_end
1268 $$ = make_node(scanner, NODE_TRACE);
1270 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1272 $$ = make_node(scanner, NODE_TRACE);
1273 if (set_parent_node($2, $$))
1274 reparent_error(scanner, "trace_declaration");
1278 trace_declaration_begin:
1280 { push_scope(scanner); }
1283 trace_declaration_end:
1285 { pop_scope(scanner); }
1288 integer_declaration_specifiers:
1291 struct ctf_node *node;
1293 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1294 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1295 node->u.type_specifier.type = TYPESPEC_CONST;
1296 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1298 | integer_type_specifier
1300 struct ctf_node *node;
1302 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1304 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1306 | integer_declaration_specifiers CONST
1308 struct ctf_node *node;
1311 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1312 node->u.type_specifier.type = TYPESPEC_CONST;
1313 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1315 | integer_declaration_specifiers integer_type_specifier
1318 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1322 declaration_specifiers:
1325 struct ctf_node *node;
1327 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1328 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1329 node->u.type_specifier.type = TYPESPEC_CONST;
1330 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1334 struct ctf_node *node;
1336 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1338 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1340 | declaration_specifiers CONST
1342 struct ctf_node *node;
1345 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1346 node->u.type_specifier.type = TYPESPEC_CONST;
1347 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1349 | declaration_specifiers type_specifier
1352 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1356 type_declarator_list:
1359 | type_declarator_list COMMA type_declarator
1362 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1366 integer_type_specifier:
1369 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1370 $$->u.type_specifier.type = TYPESPEC_CHAR;
1374 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1375 $$->u.type_specifier.type = TYPESPEC_SHORT;
1379 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1380 $$->u.type_specifier.type = TYPESPEC_INT;
1384 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1385 $$->u.type_specifier.type = TYPESPEC_LONG;
1389 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1390 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1394 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1395 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1399 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1400 $$->u.type_specifier.type = TYPESPEC_BOOL;
1404 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1405 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1406 $$->u.type_specifier.id_type = yylval.gs->s;
1408 | INTEGER LBRAC RBRAC
1410 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1411 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1412 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1414 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1416 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1417 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1418 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1419 if (set_parent_node($3, $$->u.type_specifier.node))
1420 reparent_error(scanner, "integer reparent error");
1427 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1428 $$->u.type_specifier.type = TYPESPEC_VOID;
1432 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1433 $$->u.type_specifier.type = TYPESPEC_CHAR;
1437 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1438 $$->u.type_specifier.type = TYPESPEC_SHORT;
1442 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1443 $$->u.type_specifier.type = TYPESPEC_INT;
1447 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1448 $$->u.type_specifier.type = TYPESPEC_LONG;
1452 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1453 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1457 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1458 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1462 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1463 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1467 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1468 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1472 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1473 $$->u.type_specifier.type = TYPESPEC_BOOL;
1477 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1478 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1482 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1483 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1487 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1488 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1489 $$->u.type_specifier.id_type = yylval.gs->s;
1491 | FLOATING_POINT LBRAC RBRAC
1493 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1494 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1495 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1497 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1499 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1500 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1501 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1502 if (set_parent_node($3, $$->u.type_specifier.node))
1503 reparent_error(scanner, "floating point reparent error");
1505 | INTEGER LBRAC RBRAC
1507 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1508 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1509 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1511 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1513 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1514 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1515 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1516 if (set_parent_node($3, $$->u.type_specifier.node))
1517 reparent_error(scanner, "integer reparent error");
1519 | STRING LBRAC RBRAC
1521 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1522 $$->u.type_specifier.type = TYPESPEC_STRING;
1523 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1525 | STRING LBRAC ctf_assignment_expression_list RBRAC
1527 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1528 $$->u.type_specifier.type = TYPESPEC_STRING;
1529 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1530 if (set_parent_node($3, $$->u.type_specifier.node))
1531 reparent_error(scanner, "string reparent error");
1533 | ENUM enum_type_specifier
1535 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1536 $$->u.type_specifier.type = TYPESPEC_ENUM;
1537 $$->u.type_specifier.node = $2;
1539 | VARIANT variant_type_specifier
1541 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1542 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1543 $$->u.type_specifier.node = $2;
1545 | STRUCT struct_type_specifier
1547 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1548 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1549 $$->u.type_specifier.node = $2;
1553 struct_type_specifier:
1554 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1556 $$ = make_node(scanner, NODE_STRUCT);
1557 $$->u._struct.has_body = 1;
1558 if ($2 && set_parent_node($2, $$))
1559 reparent_error(scanner, "struct reparent error");
1561 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1563 $$ = make_node(scanner, NODE_STRUCT);
1564 $$->u._struct.has_body = 1;
1565 $$->u._struct.name = $1->s;
1566 if ($3 && set_parent_node($3, $$))
1567 reparent_error(scanner, "struct reparent error");
1569 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1571 $$ = make_node(scanner, NODE_STRUCT);
1572 $$->u._struct.has_body = 1;
1573 $$->u._struct.name = $1->s;
1574 if ($3 && set_parent_node($3, $$))
1575 reparent_error(scanner, "struct reparent error");
1579 $$ = make_node(scanner, NODE_STRUCT);
1580 $$->u._struct.has_body = 0;
1581 $$->u._struct.name = $1->s;
1585 $$ = make_node(scanner, NODE_STRUCT);
1586 $$->u._struct.has_body = 0;
1587 $$->u._struct.name = $1->s;
1591 struct_declaration_begin:
1593 { push_scope(scanner); }
1596 struct_declaration_end:
1598 { pop_scope(scanner); }
1601 variant_type_specifier:
1602 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1604 $$ = make_node(scanner, NODE_VARIANT);
1605 $$->u.variant.has_body = 1;
1606 if ($2 && set_parent_node($2, $$))
1607 reparent_error(scanner, "variant reparent error");
1609 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1611 $$ = make_node(scanner, NODE_VARIANT);
1612 $$->u.variant.has_body = 1;
1613 $$->u.variant.choice = $2->s;
1614 if ($5 && set_parent_node($5, $$))
1615 reparent_error(scanner, "variant reparent error");
1617 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1619 $$ = make_node(scanner, NODE_VARIANT);
1620 $$->u.variant.has_body = 1;
1621 $$->u.variant.choice = $2->s;
1622 if ($5 && set_parent_node($5, $$))
1623 reparent_error(scanner, "variant reparent error");
1625 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1627 $$ = make_node(scanner, NODE_VARIANT);
1628 $$->u.variant.has_body = 1;
1629 $$->u.variant.name = $1->s;
1630 if ($3 && set_parent_node($3, $$))
1631 reparent_error(scanner, "variant reparent error");
1633 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1635 $$ = make_node(scanner, NODE_VARIANT);
1636 $$->u.variant.has_body = 1;
1637 $$->u.variant.name = $1->s;
1638 $$->u.variant.choice = $3->s;
1639 if ($6 && set_parent_node($6, $$))
1640 reparent_error(scanner, "variant reparent error");
1642 | IDENTIFIER LT IDENTIFIER GT
1644 $$ = make_node(scanner, NODE_VARIANT);
1645 $$->u.variant.has_body = 0;
1646 $$->u.variant.name = $1->s;
1647 $$->u.variant.choice = $3->s;
1649 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1651 $$ = make_node(scanner, NODE_VARIANT);
1652 $$->u.variant.has_body = 1;
1653 $$->u.variant.name = $1->s;
1654 $$->u.variant.choice = $3->s;
1655 if ($6 && set_parent_node($6, $$))
1656 reparent_error(scanner, "variant reparent error");
1658 | IDENTIFIER LT ID_TYPE GT
1660 $$ = make_node(scanner, NODE_VARIANT);
1661 $$->u.variant.has_body = 0;
1662 $$->u.variant.name = $1->s;
1663 $$->u.variant.choice = $3->s;
1665 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1667 $$ = make_node(scanner, NODE_VARIANT);
1668 $$->u.variant.has_body = 1;
1669 $$->u.variant.name = $1->s;
1670 if ($3 && set_parent_node($3, $$))
1671 reparent_error(scanner, "variant reparent error");
1673 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1675 $$ = make_node(scanner, NODE_VARIANT);
1676 $$->u.variant.has_body = 1;
1677 $$->u.variant.name = $1->s;
1678 $$->u.variant.choice = $3->s;
1679 if ($6 && set_parent_node($6, $$))
1680 reparent_error(scanner, "variant reparent error");
1682 | ID_TYPE LT IDENTIFIER GT
1684 $$ = make_node(scanner, NODE_VARIANT);
1685 $$->u.variant.has_body = 0;
1686 $$->u.variant.name = $1->s;
1687 $$->u.variant.choice = $3->s;
1689 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1691 $$ = make_node(scanner, NODE_VARIANT);
1692 $$->u.variant.has_body = 1;
1693 $$->u.variant.name = $1->s;
1694 $$->u.variant.choice = $3->s;
1695 if ($6 && set_parent_node($6, $$))
1696 reparent_error(scanner, "variant reparent error");
1698 | ID_TYPE LT ID_TYPE GT
1700 $$ = make_node(scanner, NODE_VARIANT);
1701 $$->u.variant.has_body = 0;
1702 $$->u.variant.name = $1->s;
1703 $$->u.variant.choice = $3->s;
1707 variant_declaration_begin:
1709 { push_scope(scanner); }
1712 variant_declaration_end:
1714 { pop_scope(scanner); }
1717 declaration_specifiers_or_integer_constant:
1718 declaration_specifiers
1722 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1723 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1724 sscanf(yylval.gs->s, "%" PRIu64,
1725 &$$->u.unary_expression.u.unsigned_constant);
1729 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1730 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1731 sscanf(yylval.gs->s, "0%" PRIo64,
1732 &$$->u.unary_expression.u.unsigned_constant);
1734 | HEXADECIMAL_CONSTANT
1736 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1737 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1738 sscanf(yylval.gs->s, "0x%" PRIx64,
1739 &$$->u.unary_expression.u.unsigned_constant);
1743 enum_type_specifier:
1744 LBRAC enumerator_list RBRAC
1746 $$ = make_node(scanner, NODE_ENUM);
1747 $$->u._enum.has_body = 1;
1748 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1750 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1752 $$ = make_node(scanner, NODE_ENUM);
1753 $$->u._enum.has_body = 1;
1754 ($$)->u._enum.container_type = $2;
1755 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1757 | IDENTIFIER LBRAC enumerator_list RBRAC
1759 $$ = make_node(scanner, NODE_ENUM);
1760 $$->u._enum.has_body = 1;
1761 $$->u._enum.enum_id = $1->s;
1762 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1764 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1766 $$ = make_node(scanner, NODE_ENUM);
1767 $$->u._enum.has_body = 1;
1768 $$->u._enum.enum_id = $1->s;
1769 ($$)->u._enum.container_type = $3;
1770 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1772 | ID_TYPE LBRAC enumerator_list RBRAC
1774 $$ = make_node(scanner, NODE_ENUM);
1775 $$->u._enum.has_body = 1;
1776 $$->u._enum.enum_id = $1->s;
1777 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1779 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1781 $$ = make_node(scanner, NODE_ENUM);
1782 $$->u._enum.has_body = 1;
1783 $$->u._enum.enum_id = $1->s;
1784 ($$)->u._enum.container_type = $3;
1785 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1787 | LBRAC enumerator_list COMMA RBRAC
1789 $$ = make_node(scanner, NODE_ENUM);
1790 $$->u._enum.has_body = 1;
1791 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1793 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1795 $$ = make_node(scanner, NODE_ENUM);
1796 $$->u._enum.has_body = 1;
1797 ($$)->u._enum.container_type = $2;
1798 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1800 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1802 $$ = make_node(scanner, NODE_ENUM);
1803 $$->u._enum.has_body = 1;
1804 $$->u._enum.enum_id = $1->s;
1805 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1807 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1809 $$ = make_node(scanner, NODE_ENUM);
1810 $$->u._enum.has_body = 1;
1811 $$->u._enum.enum_id = $1->s;
1812 ($$)->u._enum.container_type = $3;
1813 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1817 $$ = make_node(scanner, NODE_ENUM);
1818 $$->u._enum.has_body = 0;
1819 $$->u._enum.enum_id = $1->s;
1821 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1823 $$ = make_node(scanner, NODE_ENUM);
1824 $$->u._enum.has_body = 1;
1825 $$->u._enum.enum_id = $1->s;
1826 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1828 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1830 $$ = make_node(scanner, NODE_ENUM);
1831 $$->u._enum.has_body = 1;
1832 $$->u._enum.enum_id = $1->s;
1833 ($$)->u._enum.container_type = $3;
1834 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1838 $$ = make_node(scanner, NODE_ENUM);
1839 $$->u._enum.has_body = 0;
1840 $$->u._enum.enum_id = $1->s;
1844 struct_or_variant_declaration_list:
1847 | struct_or_variant_declaration_list struct_or_variant_declaration
1851 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1854 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1859 struct_or_variant_declaration:
1860 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
1862 struct ctf_node *list;
1864 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1865 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1866 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1867 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1868 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
1870 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1872 struct ctf_node *list;
1874 $$ = make_node(scanner, NODE_TYPEDEF);
1875 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1876 $$->u._typedef.type_specifier_list = list;
1877 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1878 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1879 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1881 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1883 struct ctf_node *list;
1885 $$ = make_node(scanner, NODE_TYPEDEF);
1886 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1887 $$->u._typedef.type_specifier_list = list;
1888 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1889 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1891 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1893 struct ctf_node *list;
1895 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1896 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1897 $$ = make_node(scanner, NODE_TYPEDEF);
1898 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1899 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1901 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1903 struct ctf_node *list;
1905 $$ = make_node(scanner, NODE_TYPEALIAS);
1906 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1907 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1909 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1910 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1911 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1912 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1914 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1915 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1916 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1917 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1921 alias_declaration_specifiers:
1924 struct ctf_node *node;
1926 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1927 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1928 node->u.type_specifier.type = TYPESPEC_CONST;
1929 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1933 struct ctf_node *node;
1935 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1937 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1941 struct ctf_node *node;
1943 add_type(scanner, $1);
1944 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1945 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1946 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
1947 node->u.type_specifier.id_type = yylval.gs->s;
1948 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1950 | alias_declaration_specifiers CONST
1952 struct ctf_node *node;
1955 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1956 node->u.type_specifier.type = TYPESPEC_CONST;
1957 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1959 | alias_declaration_specifiers type_specifier
1962 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1964 | alias_declaration_specifiers IDENTIFIER
1966 struct ctf_node *node;
1968 add_type(scanner, $2);
1970 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1971 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
1972 node->u.type_specifier.id_type = yylval.gs->s;
1973 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1977 struct_or_variant_declarator_list:
1978 struct_or_variant_declarator
1980 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
1983 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1987 struct_or_variant_declarator:
1990 | COLON unary_expression
1992 | declarator COLON unary_expression
1995 if (set_parent_node($3, $1))
1996 reparent_error(scanner, "struct_or_variant_declarator");
2003 | enumerator_list COMMA enumerator
2006 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2013 $$ = make_node(scanner, NODE_ENUMERATOR);
2014 $$->u.enumerator.id = $1->s;
2018 $$ = make_node(scanner, NODE_ENUMERATOR);
2019 $$->u.enumerator.id = $1->s;
2023 $$ = make_node(scanner, NODE_ENUMERATOR);
2024 $$->u.enumerator.id = $1->s;
2026 | STRING_LITERAL_START DQUOTE
2028 $$ = make_node(scanner, NODE_ENUMERATOR);
2029 $$->u.enumerator.id = "";
2031 | STRING_LITERAL_START s_char_sequence DQUOTE
2033 $$ = make_node(scanner, NODE_ENUMERATOR);
2034 $$->u.enumerator.id = $2->s;
2036 | IDENTIFIER EQUAL unary_expression_or_range
2038 $$ = make_node(scanner, NODE_ENUMERATOR);
2039 $$->u.enumerator.id = $1->s;
2040 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2042 | ID_TYPE EQUAL unary_expression_or_range
2044 $$ = make_node(scanner, NODE_ENUMERATOR);
2045 $$->u.enumerator.id = $1->s;
2046 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2048 | keywords EQUAL unary_expression_or_range
2050 $$ = make_node(scanner, NODE_ENUMERATOR);
2051 $$->u.enumerator.id = $1->s;
2052 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2054 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
2056 $$ = make_node(scanner, NODE_ENUMERATOR);
2057 $$->u.enumerator.id = "";
2058 cds_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
2060 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
2062 $$ = make_node(scanner, NODE_ENUMERATOR);
2063 $$->u.enumerator.id = $2->s;
2064 cds_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
2068 abstract_declarator_list:
2071 | abstract_declarator_list COMMA abstract_declarator
2074 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2078 abstract_declarator:
2079 direct_abstract_declarator
2081 | pointer direct_abstract_declarator
2084 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2088 direct_abstract_declarator:
2091 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2092 $$->u.type_declarator.type = TYPEDEC_ID;
2097 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2098 $$->u.type_declarator.type = TYPEDEC_ID;
2099 $$->u.type_declarator.u.id = $1->s;
2101 | LPAREN abstract_declarator RPAREN
2103 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2104 $$->u.type_declarator.type = TYPEDEC_NESTED;
2105 $$->u.type_declarator.u.nested.type_declarator = $2;
2107 | direct_abstract_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2109 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2110 $$->u.type_declarator.type = TYPEDEC_NESTED;
2111 $$->u.type_declarator.u.nested.type_declarator = $1;
2112 ($$)->u.type_declarator.u.nested.length = $3;
2114 | direct_abstract_declarator LSBRAC RSBRAC
2116 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2117 $$->u.type_declarator.type = TYPEDEC_NESTED;
2118 $$->u.type_declarator.u.nested.type_declarator = $1;
2119 $$->u.type_declarator.u.nested.abstract_array = 1;
2123 alias_abstract_declarator_list:
2124 alias_abstract_declarator
2126 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2129 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2133 alias_abstract_declarator:
2134 direct_alias_abstract_declarator
2136 | pointer direct_alias_abstract_declarator
2139 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2143 direct_alias_abstract_declarator:
2146 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2147 $$->u.type_declarator.type = TYPEDEC_ID;
2150 | LPAREN alias_abstract_declarator RPAREN
2152 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2153 $$->u.type_declarator.type = TYPEDEC_NESTED;
2154 $$->u.type_declarator.u.nested.type_declarator = $2;
2156 | direct_alias_abstract_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2158 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2159 $$->u.type_declarator.type = TYPEDEC_NESTED;
2160 $$->u.type_declarator.u.nested.type_declarator = $1;
2161 ($$)->u.type_declarator.u.nested.length = $3;
2163 | direct_alias_abstract_declarator LSBRAC RSBRAC
2165 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2166 $$->u.type_declarator.type = TYPEDEC_NESTED;
2167 $$->u.type_declarator.u.nested.type_declarator = $1;
2168 $$->u.type_declarator.u.nested.abstract_array = 1;
2175 | pointer direct_declarator
2178 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2185 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2186 $$->u.type_declarator.type = TYPEDEC_ID;
2187 $$->u.type_declarator.u.id = $1->s;
2189 | LPAREN declarator RPAREN
2191 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2192 $$->u.type_declarator.type = TYPEDEC_NESTED;
2193 $$->u.type_declarator.u.nested.type_declarator = $2;
2195 | direct_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2197 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2198 $$->u.type_declarator.type = TYPEDEC_NESTED;
2199 $$->u.type_declarator.u.nested.type_declarator = $1;
2200 ($$)->u.type_declarator.u.nested.length = $3;
2205 direct_type_declarator
2207 | pointer direct_type_declarator
2210 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2214 direct_type_declarator:
2217 add_type(scanner, $1);
2218 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2219 $$->u.type_declarator.type = TYPEDEC_ID;
2220 $$->u.type_declarator.u.id = $1->s;
2222 | LPAREN type_declarator RPAREN
2224 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2225 $$->u.type_declarator.type = TYPEDEC_NESTED;
2226 $$->u.type_declarator.u.nested.type_declarator = $2;
2228 | direct_type_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2230 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2231 $$->u.type_declarator.type = TYPEDEC_NESTED;
2232 $$->u.type_declarator.u.nested.type_declarator = $1;
2233 ($$)->u.type_declarator.u.nested.length = $3;
2240 $$ = make_node(scanner, NODE_POINTER);
2244 $$ = make_node(scanner, NODE_POINTER);
2245 cds_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2247 | STAR type_qualifier_list pointer
2249 $$ = make_node(scanner, NODE_POINTER);
2250 $$->u.pointer.const_qualifier = 1;
2251 cds_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2255 type_qualifier_list:
2256 /* pointer assumes only const type qualifier */
2258 | type_qualifier_list CONST
2261 /* 2.3: CTF-specific declarations */
2263 ctf_assignment_expression_list:
2264 ctf_assignment_expression SEMICOLON
2266 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2269 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2273 ctf_assignment_expression:
2274 unary_expression EQUAL unary_expression
2277 * Because we have left and right, cannot use
2280 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2281 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2282 if ($1->u.unary_expression.type != UNARY_STRING)
2283 reparent_error(scanner, "ctf_assignment_expression left expects string");
2284 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2286 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2289 * Because we have left and right, cannot use
2292 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2293 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2294 if ($1->u.unary_expression.type != UNARY_STRING)
2295 reparent_error(scanner, "ctf_assignment_expression left expects string");
2296 cds_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2298 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2300 struct ctf_node *list;
2302 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2303 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2304 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2305 $$ = make_node(scanner, NODE_TYPEDEF);
2306 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2307 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2309 | TYPEDEF declaration_specifiers type_declarator_list
2311 struct ctf_node *list;
2313 $$ = make_node(scanner, NODE_TYPEDEF);
2314 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2315 $$->u._typedef.type_specifier_list = list;
2316 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2317 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2319 | declaration_specifiers TYPEDEF type_declarator_list
2321 struct ctf_node *list;
2323 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2324 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2325 $$ = make_node(scanner, NODE_TYPEDEF);
2326 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2327 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2329 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2331 struct ctf_node *list;
2333 $$ = make_node(scanner, NODE_TYPEALIAS);
2334 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2335 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2337 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2338 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2339 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2340 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2342 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2343 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2344 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2345 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);