5 * Common Trace Format Metadata Grammar.
7 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
28 #include <babeltrace/list.h>
29 #include <babeltrace/babeltrace.h>
30 #include "ctf-scanner.h"
31 #include "ctf-parser.h"
37 * TODO: support enum, variant and struct declarations in scopes.
40 /* Join two lists, put "add" at the end of "head". */
42 _cds_list_splice_tail (struct cds_list_head *add, struct cds_list_head *head)
44 /* Do nothing if the list which gets added is empty. */
45 if (add != add->next) {
46 add->next->prev = head->prev;
47 add->prev->next = head;
48 head->prev->next = add->next;
49 head->prev = add->prev;
53 int yyparse(struct ctf_scanner *scanner);
54 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
55 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
56 int yylex_destroy(yyscan_t yyscanner);
57 void yyrestart(FILE * in_str, yyscan_t scanner);
62 struct cds_list_head gc;
67 static const char *node_type_to_str[] = {
68 [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
69 [ NODE_ROOT ] = "NODE_ROOT",
70 [ NODE_EVENT ] = "NODE_EVENT",
71 [ NODE_STREAM ] = "NODE_STREAM",
72 [ NODE_TRACE ] = "NODE_TRACE",
73 [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
74 [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
75 [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
76 [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
77 [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
78 [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
79 [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
80 [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
81 [ NODE_POINTER ] = "NODE_POINTER",
82 [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
83 [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
84 [ NODE_INTEGER ] = "NODE_INTEGER",
85 [ NODE_STRING ] = "NODE_STRING",
86 [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
87 [ NODE_ENUM ] = "NODE_ENUM",
88 [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
89 [ NODE_VARIANT ] = "NODE_VARIANT",
90 [ NODE_STRUCT ] = "NODE_STRUCT",
93 const char *node_type(struct ctf_node *node)
95 if (node->type < NR_NODE_TYPES)
96 return node_type_to_str[node->type];
101 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
104 struct gc_string *gstr;
107 /* TODO: could be faster with find first bit or glib Gstring */
108 /* sizeof long to account for malloc header (int or long ?) */
109 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
112 gstr = malloc(alloclen);
113 cds_list_add(&gstr->gc, &scanner->allocated_strings);
114 gstr->alloclen = alloclen;
119 * note: never use gc_string_append on a string that has external references.
120 * gsrc will be garbage collected immediately, and gstr might be.
121 * Should only be used to append characters to a string literal or constant.
123 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
124 struct gc_string *gstr,
125 struct gc_string *gsrc)
127 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
130 /* TODO: could be faster with find first bit or glib Gstring */
131 /* sizeof long to account for malloc header (int or long ?) */
132 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
135 if (alloclen > gstr->alloclen) {
136 struct gc_string *newgstr;
138 newgstr = gc_string_alloc(scanner, newlen);
139 strcpy(newgstr->s, gstr->s);
140 strcat(newgstr->s, gsrc->s);
141 cds_list_del(&gstr->gc);
145 strcat(gstr->s, gsrc->s);
147 cds_list_del(&gsrc->gc);
152 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
154 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
155 strcpy(lvalp->gs->s, src);
158 static void init_scope(struct ctf_scanner_scope *scope,
159 struct ctf_scanner_scope *parent)
161 scope->parent = parent;
162 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
166 static void finalize_scope(struct ctf_scanner_scope *scope)
168 g_hash_table_destroy(scope->types);
171 static void push_scope(struct ctf_scanner *scanner)
173 struct ctf_scanner_scope *ns;
175 printf_debug("push scope\n");
176 ns = malloc(sizeof(struct ctf_scanner_scope));
177 init_scope(ns, scanner->cs);
181 static void pop_scope(struct ctf_scanner *scanner)
183 struct ctf_scanner_scope *os;
185 printf_debug("pop scope\n");
187 scanner->cs = os->parent;
192 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
196 ret = (int) (long) g_hash_table_lookup(s->types, id);
197 printf_debug("lookup %p %s %d\n", s, id, ret);
201 int is_type(struct ctf_scanner *scanner, const char *id)
203 struct ctf_scanner_scope *it;
206 for (it = scanner->cs; it != NULL; it = it->parent) {
207 if (lookup_type(it, id)) {
212 printf_debug("is type %s %d\n", id, ret);
216 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
218 printf_debug("add type %s\n", id->s);
219 if (lookup_type(scanner->cs, id->s))
221 g_hash_table_insert(scanner->cs->types, id->s, id->s);
224 static struct ctf_node *make_node(struct ctf_scanner *scanner,
227 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
228 struct ctf_node *node;
230 node = malloc(sizeof(*node));
233 memset(node, 0, sizeof(*node));
235 CDS_INIT_LIST_HEAD(&node->tmp_head);
236 cds_list_add(&node->gc, &ast->allocated_nodes);
237 cds_list_add(&node->siblings, &node->tmp_head);
241 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
245 CDS_INIT_LIST_HEAD(&node->u.event.declaration_list);
248 CDS_INIT_LIST_HEAD(&node->u.stream.declaration_list);
251 CDS_INIT_LIST_HEAD(&node->u.trace.declaration_list);
254 case NODE_CTF_EXPRESSION:
255 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.left);
256 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.right);
258 case NODE_UNARY_EXPRESSION:
262 CDS_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
264 case NODE_TYPEALIAS_TARGET:
265 CDS_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
267 case NODE_TYPEALIAS_ALIAS:
268 CDS_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
273 case NODE_TYPE_SPECIFIER:
275 case NODE_TYPE_SPECIFIER_LIST:
276 CDS_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
280 case NODE_TYPE_DECLARATOR:
281 CDS_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
284 case NODE_FLOATING_POINT:
285 CDS_INIT_LIST_HEAD(&node->u.floating_point.expressions);
288 CDS_INIT_LIST_HEAD(&node->u.integer.expressions);
291 CDS_INIT_LIST_HEAD(&node->u.string.expressions);
293 case NODE_ENUMERATOR:
294 CDS_INIT_LIST_HEAD(&node->u.enumerator.values);
297 CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
299 case NODE_STRUCT_OR_VARIANT_DECLARATION:
300 CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
303 CDS_INIT_LIST_HEAD(&node->u.variant.declaration_list);
306 CDS_INIT_LIST_HEAD(&node->u._struct.declaration_list);
307 CDS_INIT_LIST_HEAD(&node->u._struct.min_align);
312 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
320 static int reparent_ctf_expression(struct ctf_node *node,
321 struct ctf_node *parent)
323 switch (parent->type) {
325 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
328 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
331 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
333 case NODE_FLOATING_POINT:
334 _cds_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
337 _cds_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
340 _cds_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
344 case NODE_CTF_EXPRESSION:
346 case NODE_TYPEALIAS_TARGET:
347 case NODE_TYPEALIAS_ALIAS:
349 case NODE_TYPE_SPECIFIER:
350 case NODE_TYPE_SPECIFIER_LIST:
352 case NODE_TYPE_DECLARATOR:
353 case NODE_ENUMERATOR:
355 case NODE_STRUCT_OR_VARIANT_DECLARATION:
358 case NODE_UNARY_EXPRESSION:
363 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
370 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
372 switch (parent->type) {
374 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
377 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
380 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
383 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
386 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
389 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
392 case NODE_FLOATING_POINT:
395 case NODE_CTF_EXPRESSION:
397 case NODE_TYPEALIAS_TARGET:
398 case NODE_TYPEALIAS_ALIAS:
400 case NODE_TYPE_SPECIFIER:
401 case NODE_TYPE_SPECIFIER_LIST:
403 case NODE_TYPE_DECLARATOR:
404 case NODE_ENUMERATOR:
406 case NODE_STRUCT_OR_VARIANT_DECLARATION:
407 case NODE_UNARY_EXPRESSION:
412 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
419 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
421 switch (parent->type) {
423 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
426 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
429 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
432 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
435 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
438 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
441 case NODE_FLOATING_POINT:
444 case NODE_CTF_EXPRESSION:
446 case NODE_TYPEALIAS_TARGET:
447 case NODE_TYPEALIAS_ALIAS:
449 case NODE_TYPE_SPECIFIER:
450 case NODE_TYPE_SPECIFIER_LIST:
452 case NODE_TYPE_DECLARATOR:
453 case NODE_ENUMERATOR:
455 case NODE_STRUCT_OR_VARIANT_DECLARATION:
456 case NODE_UNARY_EXPRESSION:
461 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
468 static int reparent_type_specifier(struct ctf_node *node,
469 struct ctf_node *parent)
471 switch (parent->type) {
472 case NODE_TYPE_SPECIFIER_LIST:
473 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
476 case NODE_TYPE_SPECIFIER:
483 case NODE_TYPEALIAS_TARGET:
484 case NODE_TYPEALIAS_ALIAS:
485 case NODE_TYPE_DECLARATOR:
487 case NODE_STRUCT_OR_VARIANT_DECLARATION:
489 case NODE_FLOATING_POINT:
492 case NODE_CTF_EXPRESSION:
494 case NODE_ENUMERATOR:
495 case NODE_UNARY_EXPRESSION:
500 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
507 static int reparent_type_specifier_list(struct ctf_node *node,
508 struct ctf_node *parent)
510 switch (parent->type) {
512 cds_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
515 cds_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
518 cds_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
521 cds_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
524 cds_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
527 cds_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
530 parent->u._typedef.type_specifier_list = node;
532 case NODE_TYPEALIAS_TARGET:
533 parent->u.typealias_target.type_specifier_list = node;
535 case NODE_TYPEALIAS_ALIAS:
536 parent->u.typealias_alias.type_specifier_list = node;
539 parent->u._enum.container_type = node;
541 case NODE_STRUCT_OR_VARIANT_DECLARATION:
542 parent->u.struct_or_variant_declaration.type_specifier_list = node;
544 case NODE_TYPE_DECLARATOR:
545 case NODE_TYPE_SPECIFIER:
547 case NODE_FLOATING_POINT:
550 case NODE_CTF_EXPRESSION:
552 case NODE_ENUMERATOR:
553 case NODE_UNARY_EXPRESSION:
558 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
565 static int reparent_type_declarator(struct ctf_node *node,
566 struct ctf_node *parent)
568 switch (parent->type) {
569 case NODE_TYPE_DECLARATOR:
570 parent->u.type_declarator.type = TYPEDEC_NESTED;
571 parent->u.type_declarator.u.nested.type_declarator = node;
573 case NODE_STRUCT_OR_VARIANT_DECLARATION:
574 _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
577 _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
579 case NODE_TYPEALIAS_TARGET:
580 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
582 case NODE_TYPEALIAS_ALIAS:
583 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
594 case NODE_FLOATING_POINT:
597 case NODE_CTF_EXPRESSION:
598 case NODE_TYPE_SPECIFIER:
599 case NODE_TYPE_SPECIFIER_LIST:
601 case NODE_ENUMERATOR:
602 case NODE_UNARY_EXPRESSION:
607 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
617 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
618 * create the link declared by the input, -ENOENT if node or parent is NULL,
619 * -EINVAL if there is an internal structure problem.
621 static int set_parent_node(struct ctf_node *node,
622 struct ctf_node *parent)
624 if (!node || !parent)
627 /* Note: Linking to parent will be done only by an external visitor */
629 switch (node->type) {
631 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
635 if (parent->type == NODE_ROOT) {
636 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.event);
642 if (parent->type == NODE_ROOT) {
643 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
649 if (parent->type == NODE_ROOT) {
650 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
656 case NODE_CTF_EXPRESSION:
657 return reparent_ctf_expression(node, parent);
658 case NODE_UNARY_EXPRESSION:
659 if (parent->type == NODE_TYPE_DECLARATOR)
660 parent->u.type_declarator.bitfield_len = node;
666 return reparent_typedef(node, parent);
667 case NODE_TYPEALIAS_TARGET:
668 if (parent->type == NODE_TYPEALIAS)
669 parent->u.typealias.target = node;
672 case NODE_TYPEALIAS_ALIAS:
673 if (parent->type == NODE_TYPEALIAS)
674 parent->u.typealias.alias = node;
678 return reparent_typealias(node, parent);
681 if (parent->type == NODE_TYPE_DECLARATOR) {
682 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
686 case NODE_TYPE_DECLARATOR:
687 return reparent_type_declarator(node, parent);
689 case NODE_TYPE_SPECIFIER_LIST:
690 return reparent_type_specifier_list(node, parent);
692 case NODE_TYPE_SPECIFIER:
693 return reparent_type_specifier(node, parent);
695 case NODE_FLOATING_POINT:
701 return -EINVAL; /* Dealt with internally within grammar */
703 case NODE_ENUMERATOR:
704 if (parent->type == NODE_ENUM) {
705 _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
710 case NODE_STRUCT_OR_VARIANT_DECLARATION:
711 switch (parent->type) {
713 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
716 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
725 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
732 void yyerror(struct ctf_scanner *scanner, const char *str)
734 fprintf(stderr, "error %s\n", str);
742 #define reparent_error(scanner, str) \
744 yyerror(scanner, YY_("reparent_error: " str "\n")); \
748 static void free_strings(struct cds_list_head *list)
750 struct gc_string *gstr, *tmp;
752 cds_list_for_each_entry_safe(gstr, tmp, list, gc)
756 static struct ctf_ast *ctf_ast_alloc(void)
760 ast = malloc(sizeof(*ast));
763 memset(ast, 0, sizeof(*ast));
764 CDS_INIT_LIST_HEAD(&ast->allocated_nodes);
765 ast->root.type = NODE_ROOT;
766 CDS_INIT_LIST_HEAD(&ast->root.tmp_head);
767 CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
768 CDS_INIT_LIST_HEAD(&ast->root.u.root.trace);
769 CDS_INIT_LIST_HEAD(&ast->root.u.root.stream);
770 CDS_INIT_LIST_HEAD(&ast->root.u.root.event);
774 static void ctf_ast_free(struct ctf_ast *ast)
776 struct ctf_node *node, *tmp;
778 cds_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
782 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
784 return yyparse(scanner);
787 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
789 struct ctf_scanner *scanner;
792 yydebug = babeltrace_debug;
794 scanner = malloc(sizeof(*scanner));
797 memset(scanner, 0, sizeof(*scanner));
799 ret = yylex_init_extra(scanner, &scanner->scanner);
801 fprintf(stderr, "yylex_init error\n");
802 goto cleanup_scanner;
804 /* Start processing new stream */
805 yyrestart(input, scanner->scanner);
807 scanner->ast = ctf_ast_alloc();
810 init_scope(&scanner->root_scope, NULL);
811 scanner->cs = &scanner->root_scope;
812 CDS_INIT_LIST_HEAD(&scanner->allocated_strings);
815 fprintf(stdout, "Scanner input is a%s.\n",
816 isatty(fileno(input)) ? "n interactive tty" :
817 " noninteractive file");
822 ret = yylex_destroy(scanner->scanner);
824 fprintf(stderr, "yylex_destroy error\n");
830 void ctf_scanner_free(struct ctf_scanner *scanner)
834 finalize_scope(&scanner->root_scope);
835 free_strings(&scanner->allocated_strings);
836 ctf_ast_free(scanner->ast);
837 ret = yylex_destroy(scanner->scanner);
839 fprintf(stderr, "yylex_destroy error\n");
847 %parse-param {struct ctf_scanner *scanner}
848 %lex-param {struct ctf_scanner *scanner}
850 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
851 * vs struct { int :value; } (unnamed bit-field). The default is to
852 * shift, so whenever we encounter an enumeration, we are doing the
853 * proper thing (shift). It is illegal to declare an enumeration
854 * "bit-field", so it is OK if this situation ends up in a parsing
859 %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 TOK_ALIGN
860 %token <gs> IDENTIFIER ID_TYPE
866 struct gc_string *gs;
871 %type <gs> s_char s_char_sequence c_char c_char_sequence
873 %type <n> postfix_expression unary_expression unary_expression_or_range
875 %type <n> declaration
876 %type <n> event_declaration
877 %type <n> stream_declaration
878 %type <n> trace_declaration
879 %type <n> integer_declaration_specifiers
880 %type <n> declaration_specifiers
881 %type <n> alias_declaration_specifiers
883 %type <n> type_declarator_list
884 %type <n> integer_type_specifier
885 %type <n> type_specifier
886 %type <n> struct_type_specifier
887 %type <n> variant_type_specifier
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");
980 | c_char_sequence c_char
981 { $$ = gc_string_append(scanner, $1, $2); }
989 reparent_error(scanner, "escape sequences not supported yet");
993 /* 1.6 String literals */
998 | s_char_sequence s_char
999 { $$ = gc_string_append(scanner, $1, $2); }
1007 reparent_error(scanner, "escape sequences not supported yet");
1011 /* 2: Phrase structure grammar */
1016 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1017 $$->u.unary_expression.type = UNARY_STRING;
1018 $$->u.unary_expression.u.string = yylval.gs->s;
1022 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1023 $$->u.unary_expression.type = UNARY_STRING;
1024 $$->u.unary_expression.u.string = yylval.gs->s;
1028 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1029 $$->u.unary_expression.type = UNARY_STRING;
1030 $$->u.unary_expression.u.string = yylval.gs->s;
1034 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1035 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1036 sscanf(yylval.gs->s, "%" PRIu64,
1037 &$$->u.unary_expression.u.unsigned_constant);
1041 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1042 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1043 sscanf(yylval.gs->s, "0%" PRIo64,
1044 &$$->u.unary_expression.u.unsigned_constant);
1046 | HEXADECIMAL_CONSTANT
1048 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1049 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1050 sscanf(yylval.gs->s, "0x%" PRIx64,
1051 &$$->u.unary_expression.u.unsigned_constant);
1053 | STRING_LITERAL_START DQUOTE
1055 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1056 $$->u.unary_expression.type = UNARY_STRING;
1057 $$->u.unary_expression.u.string = "";
1059 | STRING_LITERAL_START s_char_sequence DQUOTE
1061 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1062 $$->u.unary_expression.type = UNARY_STRING;
1063 $$->u.unary_expression.u.string = $2->s;
1065 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1067 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1068 $$->u.unary_expression.type = UNARY_STRING;
1069 $$->u.unary_expression.u.string = $2->s;
1071 | LPAREN unary_expression RPAREN
1073 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1074 $$->u.unary_expression.type = UNARY_NESTED;
1075 $$->u.unary_expression.u.nested_exp = $2;
1077 | postfix_expression LSBRAC unary_expression RSBRAC
1079 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1080 $$->u.unary_expression.type = UNARY_SBRAC;
1081 $$->u.unary_expression.u.sbrac_exp = $3;
1082 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1083 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1085 | postfix_expression DOT IDENTIFIER
1087 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1088 $$->u.unary_expression.type = UNARY_STRING;
1089 $$->u.unary_expression.u.string = yylval.gs->s;
1090 $$->u.unary_expression.link = UNARY_DOTLINK;
1091 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1092 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1094 | postfix_expression DOT ID_TYPE
1096 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1097 $$->u.unary_expression.type = UNARY_STRING;
1098 $$->u.unary_expression.u.string = yylval.gs->s;
1099 $$->u.unary_expression.link = UNARY_DOTLINK;
1100 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1101 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1103 | postfix_expression RARROW IDENTIFIER
1105 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1106 $$->u.unary_expression.type = UNARY_STRING;
1107 $$->u.unary_expression.u.string = yylval.gs->s;
1108 $$->u.unary_expression.link = UNARY_ARROWLINK;
1109 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1110 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1112 | postfix_expression RARROW ID_TYPE
1114 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1115 $$->u.unary_expression.type = UNARY_STRING;
1116 $$->u.unary_expression.u.string = yylval.gs->s;
1117 $$->u.unary_expression.link = UNARY_ARROWLINK;
1118 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1119 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1126 | PLUS postfix_expression
1128 | MINUS postfix_expression
1131 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1132 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1133 reparent_error(scanner, "expecting numeric constant");
1135 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1136 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1137 $$->u.unary_expression.u.signed_constant =
1138 -($$->u.unary_expression.u.unsigned_constant);
1140 $$->u.unary_expression.u.signed_constant =
1141 -($$->u.unary_expression.u.signed_constant);
1146 unary_expression_or_range:
1147 unary_expression DOTDOTDOT unary_expression
1150 _cds_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1151 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1157 /* 2.2: Declarations */
1160 declaration_specifiers SEMICOLON
1164 | stream_declaration
1168 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1170 struct ctf_node *list;
1172 $$ = make_node(scanner, NODE_TYPEDEF);
1173 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1174 $$->u._typedef.type_specifier_list = list;
1175 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1176 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1177 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1179 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1181 struct ctf_node *list;
1183 $$ = make_node(scanner, NODE_TYPEDEF);
1184 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1185 $$->u._typedef.type_specifier_list = list;
1186 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1187 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1189 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1191 struct ctf_node *list;
1193 $$ = make_node(scanner, NODE_TYPEDEF);
1194 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1195 $$->u._typedef.type_specifier_list = list;
1196 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1197 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1199 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1201 struct ctf_node *list;
1203 $$ = make_node(scanner, NODE_TYPEALIAS);
1204 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1205 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1207 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1208 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1209 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1210 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1212 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1213 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1214 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1215 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1220 event_declaration_begin event_declaration_end
1222 $$ = make_node(scanner, NODE_EVENT);
1224 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1226 $$ = make_node(scanner, NODE_EVENT);
1227 if (set_parent_node($2, $$))
1228 reparent_error(scanner, "event_declaration");
1232 event_declaration_begin:
1234 { push_scope(scanner); }
1237 event_declaration_end:
1239 { pop_scope(scanner); }
1244 stream_declaration_begin stream_declaration_end
1246 $$ = make_node(scanner, NODE_STREAM);
1248 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1250 $$ = make_node(scanner, NODE_STREAM);
1251 if (set_parent_node($2, $$))
1252 reparent_error(scanner, "stream_declaration");
1256 stream_declaration_begin:
1258 { push_scope(scanner); }
1261 stream_declaration_end:
1263 { pop_scope(scanner); }
1268 trace_declaration_begin trace_declaration_end
1270 $$ = make_node(scanner, NODE_TRACE);
1272 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1274 $$ = make_node(scanner, NODE_TRACE);
1275 if (set_parent_node($2, $$))
1276 reparent_error(scanner, "trace_declaration");
1280 trace_declaration_begin:
1282 { push_scope(scanner); }
1285 trace_declaration_end:
1287 { pop_scope(scanner); }
1290 integer_declaration_specifiers:
1293 struct ctf_node *node;
1295 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1296 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1297 node->u.type_specifier.type = TYPESPEC_CONST;
1298 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1300 | integer_type_specifier
1302 struct ctf_node *node;
1304 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1306 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1308 | integer_declaration_specifiers CONST
1310 struct ctf_node *node;
1313 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1314 node->u.type_specifier.type = TYPESPEC_CONST;
1315 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1317 | integer_declaration_specifiers integer_type_specifier
1320 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1324 declaration_specifiers:
1327 struct ctf_node *node;
1329 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1330 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1331 node->u.type_specifier.type = TYPESPEC_CONST;
1332 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1336 struct ctf_node *node;
1338 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1340 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1342 | declaration_specifiers CONST
1344 struct ctf_node *node;
1347 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1348 node->u.type_specifier.type = TYPESPEC_CONST;
1349 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1351 | declaration_specifiers type_specifier
1354 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1358 type_declarator_list:
1361 | type_declarator_list COMMA type_declarator
1364 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1368 integer_type_specifier:
1371 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1372 $$->u.type_specifier.type = TYPESPEC_CHAR;
1376 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1377 $$->u.type_specifier.type = TYPESPEC_SHORT;
1381 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1382 $$->u.type_specifier.type = TYPESPEC_INT;
1386 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1387 $$->u.type_specifier.type = TYPESPEC_LONG;
1391 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1392 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1396 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1397 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1401 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1402 $$->u.type_specifier.type = TYPESPEC_BOOL;
1406 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1407 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1408 $$->u.type_specifier.id_type = yylval.gs->s;
1410 | INTEGER LBRAC RBRAC
1412 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1413 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1414 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1416 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1418 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1419 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1420 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1421 if (set_parent_node($3, $$->u.type_specifier.node))
1422 reparent_error(scanner, "integer reparent error");
1429 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1430 $$->u.type_specifier.type = TYPESPEC_VOID;
1434 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1435 $$->u.type_specifier.type = TYPESPEC_CHAR;
1439 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1440 $$->u.type_specifier.type = TYPESPEC_SHORT;
1444 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1445 $$->u.type_specifier.type = TYPESPEC_INT;
1449 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1450 $$->u.type_specifier.type = TYPESPEC_LONG;
1454 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1455 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1459 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1460 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1464 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1465 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1469 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1470 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1474 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1475 $$->u.type_specifier.type = TYPESPEC_BOOL;
1479 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1480 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1484 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1485 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1489 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1490 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1491 $$->u.type_specifier.id_type = yylval.gs->s;
1493 | FLOATING_POINT LBRAC RBRAC
1495 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1496 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1497 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1499 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1501 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1502 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1503 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1504 if (set_parent_node($3, $$->u.type_specifier.node))
1505 reparent_error(scanner, "floating point reparent error");
1507 | INTEGER LBRAC RBRAC
1509 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1510 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1511 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1513 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1515 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1516 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1517 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1518 if (set_parent_node($3, $$->u.type_specifier.node))
1519 reparent_error(scanner, "integer reparent error");
1523 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1524 $$->u.type_specifier.type = TYPESPEC_STRING;
1525 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1527 | STRING LBRAC RBRAC
1529 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1530 $$->u.type_specifier.type = TYPESPEC_STRING;
1531 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1533 | STRING LBRAC ctf_assignment_expression_list RBRAC
1535 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1536 $$->u.type_specifier.type = TYPESPEC_STRING;
1537 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1538 if (set_parent_node($3, $$->u.type_specifier.node))
1539 reparent_error(scanner, "string reparent error");
1541 | ENUM enum_type_specifier
1543 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1544 $$->u.type_specifier.type = TYPESPEC_ENUM;
1545 $$->u.type_specifier.node = $2;
1547 | VARIANT variant_type_specifier
1549 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1550 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1551 $$->u.type_specifier.node = $2;
1553 | STRUCT struct_type_specifier
1555 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1556 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1557 $$->u.type_specifier.node = $2;
1561 struct_type_specifier:
1562 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1564 $$ = make_node(scanner, NODE_STRUCT);
1565 $$->u._struct.has_body = 1;
1566 if ($2 && set_parent_node($2, $$))
1567 reparent_error(scanner, "struct reparent error");
1569 | IDENTIFIER 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");
1577 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1579 $$ = make_node(scanner, NODE_STRUCT);
1580 $$->u._struct.has_body = 1;
1581 $$->u._struct.name = $1->s;
1582 if ($3 && set_parent_node($3, $$))
1583 reparent_error(scanner, "struct reparent error");
1587 $$ = make_node(scanner, NODE_STRUCT);
1588 $$->u._struct.has_body = 0;
1589 $$->u._struct.name = $1->s;
1593 $$ = make_node(scanner, NODE_STRUCT);
1594 $$->u._struct.has_body = 0;
1595 $$->u._struct.name = $1->s;
1597 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1599 $$ = make_node(scanner, NODE_STRUCT);
1600 $$->u._struct.has_body = 1;
1601 cds_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1602 if ($2 && set_parent_node($2, $$))
1603 reparent_error(scanner, "struct reparent error");
1605 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1607 $$ = make_node(scanner, NODE_STRUCT);
1608 $$->u._struct.has_body = 1;
1609 $$->u._struct.name = $1->s;
1610 cds_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1611 if ($3 && set_parent_node($3, $$))
1612 reparent_error(scanner, "struct reparent error");
1614 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1616 $$ = make_node(scanner, NODE_STRUCT);
1617 $$->u._struct.has_body = 1;
1618 $$->u._struct.name = $1->s;
1619 cds_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1620 if ($3 && set_parent_node($3, $$))
1621 reparent_error(scanner, "struct reparent error");
1625 struct_declaration_begin:
1627 { push_scope(scanner); }
1630 struct_declaration_end:
1632 { pop_scope(scanner); }
1635 variant_type_specifier:
1636 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1638 $$ = make_node(scanner, NODE_VARIANT);
1639 $$->u.variant.has_body = 1;
1640 if ($2 && set_parent_node($2, $$))
1641 reparent_error(scanner, "variant reparent error");
1643 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1645 $$ = make_node(scanner, NODE_VARIANT);
1646 $$->u.variant.has_body = 1;
1647 $$->u.variant.choice = $2->s;
1648 if ($5 && set_parent_node($5, $$))
1649 reparent_error(scanner, "variant reparent error");
1651 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1653 $$ = make_node(scanner, NODE_VARIANT);
1654 $$->u.variant.has_body = 1;
1655 $$->u.variant.choice = $2->s;
1656 if ($5 && set_parent_node($5, $$))
1657 reparent_error(scanner, "variant reparent error");
1659 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1661 $$ = make_node(scanner, NODE_VARIANT);
1662 $$->u.variant.has_body = 1;
1663 $$->u.variant.name = $1->s;
1664 if ($3 && set_parent_node($3, $$))
1665 reparent_error(scanner, "variant reparent error");
1667 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1669 $$ = make_node(scanner, NODE_VARIANT);
1670 $$->u.variant.has_body = 1;
1671 $$->u.variant.name = $1->s;
1672 $$->u.variant.choice = $3->s;
1673 if ($6 && set_parent_node($6, $$))
1674 reparent_error(scanner, "variant reparent error");
1676 | IDENTIFIER LT IDENTIFIER GT
1678 $$ = make_node(scanner, NODE_VARIANT);
1679 $$->u.variant.has_body = 0;
1680 $$->u.variant.name = $1->s;
1681 $$->u.variant.choice = $3->s;
1683 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1685 $$ = make_node(scanner, NODE_VARIANT);
1686 $$->u.variant.has_body = 1;
1687 $$->u.variant.name = $1->s;
1688 $$->u.variant.choice = $3->s;
1689 if ($6 && set_parent_node($6, $$))
1690 reparent_error(scanner, "variant reparent error");
1692 | IDENTIFIER LT ID_TYPE GT
1694 $$ = make_node(scanner, NODE_VARIANT);
1695 $$->u.variant.has_body = 0;
1696 $$->u.variant.name = $1->s;
1697 $$->u.variant.choice = $3->s;
1699 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1701 $$ = make_node(scanner, NODE_VARIANT);
1702 $$->u.variant.has_body = 1;
1703 $$->u.variant.name = $1->s;
1704 if ($3 && set_parent_node($3, $$))
1705 reparent_error(scanner, "variant reparent error");
1707 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1709 $$ = make_node(scanner, NODE_VARIANT);
1710 $$->u.variant.has_body = 1;
1711 $$->u.variant.name = $1->s;
1712 $$->u.variant.choice = $3->s;
1713 if ($6 && set_parent_node($6, $$))
1714 reparent_error(scanner, "variant reparent error");
1716 | ID_TYPE LT IDENTIFIER GT
1718 $$ = make_node(scanner, NODE_VARIANT);
1719 $$->u.variant.has_body = 0;
1720 $$->u.variant.name = $1->s;
1721 $$->u.variant.choice = $3->s;
1723 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1725 $$ = make_node(scanner, NODE_VARIANT);
1726 $$->u.variant.has_body = 1;
1727 $$->u.variant.name = $1->s;
1728 $$->u.variant.choice = $3->s;
1729 if ($6 && set_parent_node($6, $$))
1730 reparent_error(scanner, "variant reparent error");
1732 | ID_TYPE LT ID_TYPE GT
1734 $$ = make_node(scanner, NODE_VARIANT);
1735 $$->u.variant.has_body = 0;
1736 $$->u.variant.name = $1->s;
1737 $$->u.variant.choice = $3->s;
1741 variant_declaration_begin:
1743 { push_scope(scanner); }
1746 variant_declaration_end:
1748 { pop_scope(scanner); }
1751 enum_type_specifier:
1752 LBRAC enumerator_list RBRAC
1754 $$ = make_node(scanner, NODE_ENUM);
1755 $$->u._enum.has_body = 1;
1756 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1758 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1760 $$ = make_node(scanner, NODE_ENUM);
1761 $$->u._enum.has_body = 1;
1762 ($$)->u._enum.container_type = $2;
1763 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1765 | IDENTIFIER LBRAC enumerator_list RBRAC
1767 $$ = make_node(scanner, NODE_ENUM);
1768 $$->u._enum.has_body = 1;
1769 $$->u._enum.enum_id = $1->s;
1770 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1772 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1774 $$ = make_node(scanner, NODE_ENUM);
1775 $$->u._enum.has_body = 1;
1776 $$->u._enum.enum_id = $1->s;
1777 ($$)->u._enum.container_type = $3;
1778 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1780 | ID_TYPE LBRAC enumerator_list RBRAC
1782 $$ = make_node(scanner, NODE_ENUM);
1783 $$->u._enum.has_body = 1;
1784 $$->u._enum.enum_id = $1->s;
1785 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1787 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1789 $$ = make_node(scanner, NODE_ENUM);
1790 $$->u._enum.has_body = 1;
1791 $$->u._enum.enum_id = $1->s;
1792 ($$)->u._enum.container_type = $3;
1793 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1795 | LBRAC enumerator_list COMMA RBRAC
1797 $$ = make_node(scanner, NODE_ENUM);
1798 $$->u._enum.has_body = 1;
1799 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1801 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1803 $$ = make_node(scanner, NODE_ENUM);
1804 $$->u._enum.has_body = 1;
1805 ($$)->u._enum.container_type = $2;
1806 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1808 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1810 $$ = make_node(scanner, NODE_ENUM);
1811 $$->u._enum.has_body = 1;
1812 $$->u._enum.enum_id = $1->s;
1813 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1815 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1817 $$ = make_node(scanner, NODE_ENUM);
1818 $$->u._enum.has_body = 1;
1819 $$->u._enum.enum_id = $1->s;
1820 ($$)->u._enum.container_type = $3;
1821 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1825 $$ = make_node(scanner, NODE_ENUM);
1826 $$->u._enum.has_body = 0;
1827 $$->u._enum.enum_id = $1->s;
1829 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1831 $$ = make_node(scanner, NODE_ENUM);
1832 $$->u._enum.has_body = 1;
1833 $$->u._enum.enum_id = $1->s;
1834 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1836 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1838 $$ = make_node(scanner, NODE_ENUM);
1839 $$->u._enum.has_body = 1;
1840 $$->u._enum.enum_id = $1->s;
1841 ($$)->u._enum.container_type = $3;
1842 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1846 $$ = make_node(scanner, NODE_ENUM);
1847 $$->u._enum.has_body = 0;
1848 $$->u._enum.enum_id = $1->s;
1852 struct_or_variant_declaration_list:
1855 | struct_or_variant_declaration_list struct_or_variant_declaration
1859 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1862 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1867 struct_or_variant_declaration:
1868 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
1870 struct ctf_node *list;
1872 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1873 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1874 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1875 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1876 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
1878 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1880 struct ctf_node *list;
1882 $$ = make_node(scanner, NODE_TYPEDEF);
1883 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1884 $$->u._typedef.type_specifier_list = list;
1885 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1886 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1887 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1889 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1891 struct ctf_node *list;
1893 $$ = make_node(scanner, NODE_TYPEDEF);
1894 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1895 $$->u._typedef.type_specifier_list = list;
1896 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1897 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1899 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1901 struct ctf_node *list;
1903 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1904 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1905 $$ = make_node(scanner, NODE_TYPEDEF);
1906 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1907 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1909 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1911 struct ctf_node *list;
1913 $$ = make_node(scanner, NODE_TYPEALIAS);
1914 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1915 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1917 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1918 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1919 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1920 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1922 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1923 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1924 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1925 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1929 alias_declaration_specifiers:
1932 struct ctf_node *node;
1934 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1935 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1936 node->u.type_specifier.type = TYPESPEC_CONST;
1937 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1941 struct ctf_node *node;
1943 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1945 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1949 struct ctf_node *node;
1951 add_type(scanner, $1);
1952 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1953 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1954 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
1955 node->u.type_specifier.id_type = yylval.gs->s;
1956 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1958 | alias_declaration_specifiers CONST
1960 struct ctf_node *node;
1963 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1964 node->u.type_specifier.type = TYPESPEC_CONST;
1965 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1967 | alias_declaration_specifiers type_specifier
1970 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1972 | alias_declaration_specifiers IDENTIFIER
1974 struct ctf_node *node;
1976 add_type(scanner, $2);
1978 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1979 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
1980 node->u.type_specifier.id_type = yylval.gs->s;
1981 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1985 struct_or_variant_declarator_list:
1986 struct_or_variant_declarator
1988 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
1991 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1995 struct_or_variant_declarator:
1998 | COLON unary_expression
2000 | declarator COLON unary_expression
2003 if (set_parent_node($3, $1))
2004 reparent_error(scanner, "struct_or_variant_declarator");
2011 | enumerator_list COMMA enumerator
2014 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2021 $$ = make_node(scanner, NODE_ENUMERATOR);
2022 $$->u.enumerator.id = $1->s;
2026 $$ = make_node(scanner, NODE_ENUMERATOR);
2027 $$->u.enumerator.id = $1->s;
2031 $$ = make_node(scanner, NODE_ENUMERATOR);
2032 $$->u.enumerator.id = $1->s;
2034 | STRING_LITERAL_START DQUOTE
2036 $$ = make_node(scanner, NODE_ENUMERATOR);
2037 $$->u.enumerator.id = "";
2039 | STRING_LITERAL_START s_char_sequence DQUOTE
2041 $$ = make_node(scanner, NODE_ENUMERATOR);
2042 $$->u.enumerator.id = $2->s;
2044 | IDENTIFIER EQUAL unary_expression_or_range
2046 $$ = make_node(scanner, NODE_ENUMERATOR);
2047 $$->u.enumerator.id = $1->s;
2048 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2050 | ID_TYPE EQUAL unary_expression_or_range
2052 $$ = make_node(scanner, NODE_ENUMERATOR);
2053 $$->u.enumerator.id = $1->s;
2054 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2056 | keywords EQUAL unary_expression_or_range
2058 $$ = make_node(scanner, NODE_ENUMERATOR);
2059 $$->u.enumerator.id = $1->s;
2060 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2062 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
2064 $$ = make_node(scanner, NODE_ENUMERATOR);
2065 $$->u.enumerator.id = "";
2066 cds_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
2068 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
2070 $$ = make_node(scanner, NODE_ENUMERATOR);
2071 $$->u.enumerator.id = $2->s;
2072 cds_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
2076 abstract_declarator_list:
2079 | abstract_declarator_list COMMA abstract_declarator
2082 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2086 abstract_declarator:
2087 direct_abstract_declarator
2089 | pointer direct_abstract_declarator
2092 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2096 direct_abstract_declarator:
2099 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2100 $$->u.type_declarator.type = TYPEDEC_ID;
2105 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2106 $$->u.type_declarator.type = TYPEDEC_ID;
2107 $$->u.type_declarator.u.id = $1->s;
2109 | LPAREN abstract_declarator RPAREN
2111 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2112 $$->u.type_declarator.type = TYPEDEC_NESTED;
2113 $$->u.type_declarator.u.nested.type_declarator = $2;
2115 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2117 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2118 $$->u.type_declarator.type = TYPEDEC_NESTED;
2119 $$->u.type_declarator.u.nested.type_declarator = $1;
2120 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2121 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2123 | direct_abstract_declarator LSBRAC RSBRAC
2125 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2126 $$->u.type_declarator.type = TYPEDEC_NESTED;
2127 $$->u.type_declarator.u.nested.type_declarator = $1;
2128 $$->u.type_declarator.u.nested.abstract_array = 1;
2132 alias_abstract_declarator_list:
2133 alias_abstract_declarator
2135 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2138 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2142 alias_abstract_declarator:
2143 direct_alias_abstract_declarator
2145 | pointer direct_alias_abstract_declarator
2148 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2152 direct_alias_abstract_declarator:
2155 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2156 $$->u.type_declarator.type = TYPEDEC_ID;
2159 | LPAREN alias_abstract_declarator RPAREN
2161 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2162 $$->u.type_declarator.type = TYPEDEC_NESTED;
2163 $$->u.type_declarator.u.nested.type_declarator = $2;
2165 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2167 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2168 $$->u.type_declarator.type = TYPEDEC_NESTED;
2169 $$->u.type_declarator.u.nested.type_declarator = $1;
2170 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2171 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2173 | direct_alias_abstract_declarator LSBRAC RSBRAC
2175 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2176 $$->u.type_declarator.type = TYPEDEC_NESTED;
2177 $$->u.type_declarator.u.nested.type_declarator = $1;
2178 $$->u.type_declarator.u.nested.abstract_array = 1;
2185 | pointer direct_declarator
2188 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2195 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2196 $$->u.type_declarator.type = TYPEDEC_ID;
2197 $$->u.type_declarator.u.id = $1->s;
2199 | LPAREN declarator RPAREN
2201 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2202 $$->u.type_declarator.type = TYPEDEC_NESTED;
2203 $$->u.type_declarator.u.nested.type_declarator = $2;
2205 | direct_declarator LSBRAC unary_expression RSBRAC
2207 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2208 $$->u.type_declarator.type = TYPEDEC_NESTED;
2209 $$->u.type_declarator.u.nested.type_declarator = $1;
2210 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2211 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2216 direct_type_declarator
2218 | pointer direct_type_declarator
2221 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2225 direct_type_declarator:
2228 add_type(scanner, $1);
2229 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2230 $$->u.type_declarator.type = TYPEDEC_ID;
2231 $$->u.type_declarator.u.id = $1->s;
2233 | LPAREN type_declarator RPAREN
2235 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2236 $$->u.type_declarator.type = TYPEDEC_NESTED;
2237 $$->u.type_declarator.u.nested.type_declarator = $2;
2239 | direct_type_declarator LSBRAC unary_expression RSBRAC
2241 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2242 $$->u.type_declarator.type = TYPEDEC_NESTED;
2243 $$->u.type_declarator.u.nested.type_declarator = $1;
2244 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2245 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2252 $$ = make_node(scanner, NODE_POINTER);
2256 $$ = make_node(scanner, NODE_POINTER);
2257 cds_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2259 | STAR type_qualifier_list pointer
2261 $$ = make_node(scanner, NODE_POINTER);
2262 $$->u.pointer.const_qualifier = 1;
2263 cds_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2267 type_qualifier_list:
2268 /* pointer assumes only const type qualifier */
2270 | type_qualifier_list CONST
2273 /* 2.3: CTF-specific declarations */
2275 ctf_assignment_expression_list:
2276 ctf_assignment_expression SEMICOLON
2278 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2281 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2285 ctf_assignment_expression:
2286 unary_expression EQUAL unary_expression
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_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2298 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2301 * Because we have left and right, cannot use
2304 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2305 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2306 if ($1->u.unary_expression.type != UNARY_STRING)
2307 reparent_error(scanner, "ctf_assignment_expression left expects string");
2308 cds_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2310 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2312 struct ctf_node *list;
2314 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2315 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2316 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2317 $$ = make_node(scanner, NODE_TYPEDEF);
2318 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2319 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2321 | TYPEDEF declaration_specifiers type_declarator_list
2323 struct ctf_node *list;
2325 $$ = make_node(scanner, NODE_TYPEDEF);
2326 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2327 $$->u._typedef.type_specifier_list = list;
2328 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2329 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2331 | declaration_specifiers TYPEDEF type_declarator_list
2333 struct ctf_node *list;
2335 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2336 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2337 $$ = make_node(scanner, NODE_TYPEDEF);
2338 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2339 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2341 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2343 struct ctf_node *list;
2345 $$ = make_node(scanner, NODE_TYPEALIAS);
2346 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2347 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2349 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2350 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2351 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2352 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2354 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2355 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2356 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2357 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);