5 * Common Trace Format Metadata Grammar.
7 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
28 #include <babeltrace/list.h>
29 #include <babeltrace/babeltrace-internal.h>
30 #include "ctf-scanner.h"
31 #include "ctf-parser.h"
36 /* Join two lists, put "add" at the end of "head". */
38 _cds_list_splice_tail (struct cds_list_head *add, struct cds_list_head *head)
40 /* Do nothing if the list which gets added is empty. */
41 if (add != add->next) {
42 add->next->prev = head->prev;
43 add->prev->next = head;
44 head->prev->next = add->next;
45 head->prev = add->prev;
49 int yyparse(struct ctf_scanner *scanner);
50 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
51 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
52 int yylex_destroy(yyscan_t yyscanner);
53 void yyrestart(FILE * in_str, yyscan_t scanner);
58 struct cds_list_head gc;
63 static const char *node_type_to_str[] = {
64 [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
65 [ NODE_ROOT ] = "NODE_ROOT",
66 [ NODE_EVENT ] = "NODE_EVENT",
67 [ NODE_STREAM ] = "NODE_STREAM",
68 [ NODE_TRACE ] = "NODE_TRACE",
69 [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
70 [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
71 [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
72 [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
73 [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
74 [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
75 [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
76 [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
77 [ NODE_POINTER ] = "NODE_POINTER",
78 [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
79 [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
80 [ NODE_INTEGER ] = "NODE_INTEGER",
81 [ NODE_STRING ] = "NODE_STRING",
82 [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
83 [ NODE_ENUM ] = "NODE_ENUM",
84 [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
85 [ NODE_VARIANT ] = "NODE_VARIANT",
86 [ NODE_STRUCT ] = "NODE_STRUCT",
89 const char *node_type(struct ctf_node *node)
91 if (node->type < NR_NODE_TYPES)
92 return node_type_to_str[node->type];
97 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
100 struct gc_string *gstr;
103 /* TODO: could be faster with find first bit or glib Gstring */
104 /* sizeof long to account for malloc header (int or long ?) */
105 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
108 gstr = malloc(alloclen);
109 cds_list_add(&gstr->gc, &scanner->allocated_strings);
110 gstr->alloclen = alloclen;
115 * note: never use gc_string_append on a string that has external references.
116 * gsrc will be garbage collected immediately, and gstr might be.
117 * Should only be used to append characters to a string literal or constant.
119 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
120 struct gc_string *gstr,
121 struct gc_string *gsrc)
123 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
126 /* TODO: could be faster with find first bit or glib Gstring */
127 /* sizeof long to account for malloc header (int or long ?) */
128 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
131 if (alloclen > gstr->alloclen) {
132 struct gc_string *newgstr;
134 newgstr = gc_string_alloc(scanner, newlen);
135 strcpy(newgstr->s, gstr->s);
136 strcat(newgstr->s, gsrc->s);
137 cds_list_del(&gstr->gc);
141 strcat(gstr->s, gsrc->s);
143 cds_list_del(&gsrc->gc);
148 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
150 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
151 strcpy(lvalp->gs->s, src);
154 static void init_scope(struct ctf_scanner_scope *scope,
155 struct ctf_scanner_scope *parent)
157 scope->parent = parent;
158 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
162 static void finalize_scope(struct ctf_scanner_scope *scope)
164 g_hash_table_destroy(scope->types);
167 static void push_scope(struct ctf_scanner *scanner)
169 struct ctf_scanner_scope *ns;
171 printf_debug("push scope\n");
172 ns = malloc(sizeof(struct ctf_scanner_scope));
173 init_scope(ns, scanner->cs);
177 static void pop_scope(struct ctf_scanner *scanner)
179 struct ctf_scanner_scope *os;
181 printf_debug("pop scope\n");
183 scanner->cs = os->parent;
188 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
192 ret = (int) (long) g_hash_table_lookup(s->types, id);
193 printf_debug("lookup %p %s %d\n", s, id, ret);
197 int is_type(struct ctf_scanner *scanner, const char *id)
199 struct ctf_scanner_scope *it;
202 for (it = scanner->cs; it != NULL; it = it->parent) {
203 if (lookup_type(it, id)) {
208 printf_debug("is type %s %d\n", id, ret);
212 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
214 printf_debug("add type %s\n", id->s);
215 if (lookup_type(scanner->cs, id->s))
217 g_hash_table_insert(scanner->cs->types, id->s, id->s);
220 static struct ctf_node *make_node(struct ctf_scanner *scanner,
223 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
224 struct ctf_node *node;
226 node = malloc(sizeof(*node));
229 memset(node, 0, sizeof(*node));
231 CDS_INIT_LIST_HEAD(&node->tmp_head);
232 cds_list_add(&node->gc, &ast->allocated_nodes);
233 cds_list_add(&node->siblings, &node->tmp_head);
237 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
241 CDS_INIT_LIST_HEAD(&node->u.event.declaration_list);
244 CDS_INIT_LIST_HEAD(&node->u.stream.declaration_list);
247 CDS_INIT_LIST_HEAD(&node->u.trace.declaration_list);
250 case NODE_CTF_EXPRESSION:
251 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.left);
252 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.right);
254 case NODE_UNARY_EXPRESSION:
258 CDS_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
260 case NODE_TYPEALIAS_TARGET:
261 CDS_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
263 case NODE_TYPEALIAS_ALIAS:
264 CDS_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
269 case NODE_TYPE_SPECIFIER:
271 case NODE_TYPE_SPECIFIER_LIST:
272 CDS_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
276 case NODE_TYPE_DECLARATOR:
277 CDS_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
280 case NODE_FLOATING_POINT:
281 CDS_INIT_LIST_HEAD(&node->u.floating_point.expressions);
284 CDS_INIT_LIST_HEAD(&node->u.integer.expressions);
287 CDS_INIT_LIST_HEAD(&node->u.string.expressions);
289 case NODE_ENUMERATOR:
290 CDS_INIT_LIST_HEAD(&node->u.enumerator.values);
293 CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
295 case NODE_STRUCT_OR_VARIANT_DECLARATION:
296 CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
299 CDS_INIT_LIST_HEAD(&node->u.variant.declaration_list);
302 CDS_INIT_LIST_HEAD(&node->u._struct.declaration_list);
303 CDS_INIT_LIST_HEAD(&node->u._struct.min_align);
308 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
316 static int reparent_ctf_expression(struct ctf_node *node,
317 struct ctf_node *parent)
319 switch (parent->type) {
321 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
324 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
327 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
329 case NODE_FLOATING_POINT:
330 _cds_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
333 _cds_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
336 _cds_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
340 case NODE_CTF_EXPRESSION:
342 case NODE_TYPEALIAS_TARGET:
343 case NODE_TYPEALIAS_ALIAS:
345 case NODE_TYPE_SPECIFIER:
346 case NODE_TYPE_SPECIFIER_LIST:
348 case NODE_TYPE_DECLARATOR:
349 case NODE_ENUMERATOR:
351 case NODE_STRUCT_OR_VARIANT_DECLARATION:
354 case NODE_UNARY_EXPRESSION:
359 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
366 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
368 switch (parent->type) {
370 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
373 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
376 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
379 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
382 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
385 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
388 case NODE_FLOATING_POINT:
391 case NODE_CTF_EXPRESSION:
393 case NODE_TYPEALIAS_TARGET:
394 case NODE_TYPEALIAS_ALIAS:
396 case NODE_TYPE_SPECIFIER:
397 case NODE_TYPE_SPECIFIER_LIST:
399 case NODE_TYPE_DECLARATOR:
400 case NODE_ENUMERATOR:
402 case NODE_STRUCT_OR_VARIANT_DECLARATION:
403 case NODE_UNARY_EXPRESSION:
408 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
415 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
417 switch (parent->type) {
419 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
422 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
425 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
428 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
431 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
434 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
437 case NODE_FLOATING_POINT:
440 case NODE_CTF_EXPRESSION:
442 case NODE_TYPEALIAS_TARGET:
443 case NODE_TYPEALIAS_ALIAS:
445 case NODE_TYPE_SPECIFIER:
446 case NODE_TYPE_SPECIFIER_LIST:
448 case NODE_TYPE_DECLARATOR:
449 case NODE_ENUMERATOR:
451 case NODE_STRUCT_OR_VARIANT_DECLARATION:
452 case NODE_UNARY_EXPRESSION:
457 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
464 static int reparent_type_specifier(struct ctf_node *node,
465 struct ctf_node *parent)
467 switch (parent->type) {
468 case NODE_TYPE_SPECIFIER_LIST:
469 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
472 case NODE_TYPE_SPECIFIER:
479 case NODE_TYPEALIAS_TARGET:
480 case NODE_TYPEALIAS_ALIAS:
481 case NODE_TYPE_DECLARATOR:
483 case NODE_STRUCT_OR_VARIANT_DECLARATION:
485 case NODE_FLOATING_POINT:
488 case NODE_CTF_EXPRESSION:
490 case NODE_ENUMERATOR:
491 case NODE_UNARY_EXPRESSION:
496 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
503 static int reparent_type_specifier_list(struct ctf_node *node,
504 struct ctf_node *parent)
506 switch (parent->type) {
508 cds_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
511 cds_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
514 cds_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
517 cds_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
520 cds_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
523 cds_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
526 parent->u._typedef.type_specifier_list = node;
528 case NODE_TYPEALIAS_TARGET:
529 parent->u.typealias_target.type_specifier_list = node;
531 case NODE_TYPEALIAS_ALIAS:
532 parent->u.typealias_alias.type_specifier_list = node;
535 parent->u._enum.container_type = node;
537 case NODE_STRUCT_OR_VARIANT_DECLARATION:
538 parent->u.struct_or_variant_declaration.type_specifier_list = node;
540 case NODE_TYPE_DECLARATOR:
541 case NODE_TYPE_SPECIFIER:
543 case NODE_FLOATING_POINT:
546 case NODE_CTF_EXPRESSION:
548 case NODE_ENUMERATOR:
549 case NODE_UNARY_EXPRESSION:
554 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
561 static int reparent_type_declarator(struct ctf_node *node,
562 struct ctf_node *parent)
564 switch (parent->type) {
565 case NODE_TYPE_DECLARATOR:
566 parent->u.type_declarator.type = TYPEDEC_NESTED;
567 parent->u.type_declarator.u.nested.type_declarator = node;
569 case NODE_STRUCT_OR_VARIANT_DECLARATION:
570 _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
573 _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
575 case NODE_TYPEALIAS_TARGET:
576 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
578 case NODE_TYPEALIAS_ALIAS:
579 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
590 case NODE_FLOATING_POINT:
593 case NODE_CTF_EXPRESSION:
594 case NODE_TYPE_SPECIFIER:
595 case NODE_TYPE_SPECIFIER_LIST:
597 case NODE_ENUMERATOR:
598 case NODE_UNARY_EXPRESSION:
603 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
613 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
614 * create the link declared by the input, -ENOENT if node or parent is NULL,
615 * -EINVAL if there is an internal structure problem.
617 static int set_parent_node(struct ctf_node *node,
618 struct ctf_node *parent)
620 if (!node || !parent)
623 /* Note: Linking to parent will be done only by an external visitor */
625 switch (node->type) {
627 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
631 if (parent->type == NODE_ROOT) {
632 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.event);
638 if (parent->type == NODE_ROOT) {
639 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
645 if (parent->type == NODE_ROOT) {
646 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
652 case NODE_CTF_EXPRESSION:
653 return reparent_ctf_expression(node, parent);
654 case NODE_UNARY_EXPRESSION:
655 if (parent->type == NODE_TYPE_DECLARATOR)
656 parent->u.type_declarator.bitfield_len = node;
662 return reparent_typedef(node, parent);
663 case NODE_TYPEALIAS_TARGET:
664 if (parent->type == NODE_TYPEALIAS)
665 parent->u.typealias.target = node;
668 case NODE_TYPEALIAS_ALIAS:
669 if (parent->type == NODE_TYPEALIAS)
670 parent->u.typealias.alias = node;
674 return reparent_typealias(node, parent);
677 if (parent->type == NODE_TYPE_DECLARATOR) {
678 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
682 case NODE_TYPE_DECLARATOR:
683 return reparent_type_declarator(node, parent);
685 case NODE_TYPE_SPECIFIER_LIST:
686 return reparent_type_specifier_list(node, parent);
688 case NODE_TYPE_SPECIFIER:
689 return reparent_type_specifier(node, parent);
691 case NODE_FLOATING_POINT:
697 return -EINVAL; /* Dealt with internally within grammar */
699 case NODE_ENUMERATOR:
700 if (parent->type == NODE_ENUM) {
701 _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
706 case NODE_STRUCT_OR_VARIANT_DECLARATION:
707 switch (parent->type) {
709 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
712 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
721 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
728 void yyerror(struct ctf_scanner *scanner, const char *str)
730 fprintf(stderr, "error %s\n", str);
738 #define reparent_error(scanner, str) \
740 yyerror(scanner, YY_("reparent_error: " str "\n")); \
744 static void free_strings(struct cds_list_head *list)
746 struct gc_string *gstr, *tmp;
748 cds_list_for_each_entry_safe(gstr, tmp, list, gc)
752 static struct ctf_ast *ctf_ast_alloc(void)
756 ast = malloc(sizeof(*ast));
759 memset(ast, 0, sizeof(*ast));
760 CDS_INIT_LIST_HEAD(&ast->allocated_nodes);
761 ast->root.type = NODE_ROOT;
762 CDS_INIT_LIST_HEAD(&ast->root.tmp_head);
763 CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
764 CDS_INIT_LIST_HEAD(&ast->root.u.root.trace);
765 CDS_INIT_LIST_HEAD(&ast->root.u.root.stream);
766 CDS_INIT_LIST_HEAD(&ast->root.u.root.event);
770 static void ctf_ast_free(struct ctf_ast *ast)
772 struct ctf_node *node, *tmp;
774 cds_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
778 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
780 return yyparse(scanner);
783 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
785 struct ctf_scanner *scanner;
788 yydebug = babeltrace_debug;
790 scanner = malloc(sizeof(*scanner));
793 memset(scanner, 0, sizeof(*scanner));
795 ret = yylex_init_extra(scanner, &scanner->scanner);
797 fprintf(stderr, "yylex_init error\n");
798 goto cleanup_scanner;
800 /* Start processing new stream */
801 yyrestart(input, scanner->scanner);
803 scanner->ast = ctf_ast_alloc();
806 init_scope(&scanner->root_scope, NULL);
807 scanner->cs = &scanner->root_scope;
808 CDS_INIT_LIST_HEAD(&scanner->allocated_strings);
811 fprintf(stdout, "Scanner input is a%s.\n",
812 isatty(fileno(input)) ? "n interactive tty" :
813 " noninteractive file");
818 ret = yylex_destroy(scanner->scanner);
820 fprintf(stderr, "yylex_destroy error\n");
826 void ctf_scanner_free(struct ctf_scanner *scanner)
830 finalize_scope(&scanner->root_scope);
831 free_strings(&scanner->allocated_strings);
832 ctf_ast_free(scanner->ast);
833 ret = yylex_destroy(scanner->scanner);
835 fprintf(stderr, "yylex_destroy error\n");
843 %parse-param {struct ctf_scanner *scanner}
844 %lex-param {struct ctf_scanner *scanner}
846 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
847 * vs struct { int :value; } (unnamed bit-field). The default is to
848 * shift, so whenever we encounter an enumeration, we are doing the
849 * proper thing (shift). It is illegal to declare an enumeration
850 * "bit-field", so it is OK if this situation ends up in a parsing
855 %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
856 %token <gs> IDENTIFIER ID_TYPE
862 struct gc_string *gs;
867 %type <gs> s_char s_char_sequence c_char c_char_sequence
869 %type <n> postfix_expression unary_expression unary_expression_or_range
871 %type <n> declaration
872 %type <n> event_declaration
873 %type <n> stream_declaration
874 %type <n> trace_declaration
875 %type <n> integer_declaration_specifiers
876 %type <n> declaration_specifiers
877 %type <n> alias_declaration_specifiers
879 %type <n> type_declarator_list
880 %type <n> integer_type_specifier
881 %type <n> type_specifier
882 %type <n> struct_type_specifier
883 %type <n> variant_type_specifier
884 %type <n> enum_type_specifier
885 %type <n> struct_or_variant_declaration_list
886 %type <n> struct_or_variant_declaration
887 %type <n> struct_or_variant_declarator_list
888 %type <n> struct_or_variant_declarator
889 %type <n> enumerator_list
891 %type <n> abstract_declarator_list
892 %type <n> abstract_declarator
893 %type <n> direct_abstract_declarator
894 %type <n> alias_abstract_declarator_list
895 %type <n> alias_abstract_declarator
896 %type <n> direct_alias_abstract_declarator
898 %type <n> direct_declarator
899 %type <n> type_declarator
900 %type <n> direct_type_declarator
902 %type <n> ctf_assignment_expression_list
903 %type <n> ctf_assignment_expression
910 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
911 reparent_error(scanner, "error reparenting to root");
915 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
916 reparent_error(scanner, "error reparenting to root");
976 | c_char_sequence c_char
977 { $$ = gc_string_append(scanner, $1, $2); }
985 reparent_error(scanner, "escape sequences not supported yet");
989 /* 1.6 String literals */
994 | s_char_sequence s_char
995 { $$ = gc_string_append(scanner, $1, $2); }
1003 reparent_error(scanner, "escape sequences not supported yet");
1007 /* 2: Phrase structure grammar */
1012 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1013 $$->u.unary_expression.type = UNARY_STRING;
1014 $$->u.unary_expression.u.string = yylval.gs->s;
1018 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1019 $$->u.unary_expression.type = UNARY_STRING;
1020 $$->u.unary_expression.u.string = yylval.gs->s;
1024 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1025 $$->u.unary_expression.type = UNARY_STRING;
1026 $$->u.unary_expression.u.string = yylval.gs->s;
1030 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1031 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1032 sscanf(yylval.gs->s, "%" PRIu64,
1033 &$$->u.unary_expression.u.unsigned_constant);
1037 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1038 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1039 sscanf(yylval.gs->s, "0%" PRIo64,
1040 &$$->u.unary_expression.u.unsigned_constant);
1042 | HEXADECIMAL_CONSTANT
1044 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1045 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1046 sscanf(yylval.gs->s, "0x%" PRIx64,
1047 &$$->u.unary_expression.u.unsigned_constant);
1049 | STRING_LITERAL_START DQUOTE
1051 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1052 $$->u.unary_expression.type = UNARY_STRING;
1053 $$->u.unary_expression.u.string = "";
1055 | STRING_LITERAL_START s_char_sequence DQUOTE
1057 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1058 $$->u.unary_expression.type = UNARY_STRING;
1059 $$->u.unary_expression.u.string = $2->s;
1061 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1063 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1064 $$->u.unary_expression.type = UNARY_STRING;
1065 $$->u.unary_expression.u.string = $2->s;
1067 | LPAREN unary_expression RPAREN
1069 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1070 $$->u.unary_expression.type = UNARY_NESTED;
1071 $$->u.unary_expression.u.nested_exp = $2;
1073 | postfix_expression LSBRAC unary_expression RSBRAC
1075 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1076 $$->u.unary_expression.type = UNARY_SBRAC;
1077 $$->u.unary_expression.u.sbrac_exp = $3;
1078 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1079 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1081 | postfix_expression DOT IDENTIFIER
1083 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1084 $$->u.unary_expression.type = UNARY_STRING;
1085 $$->u.unary_expression.u.string = yylval.gs->s;
1086 $$->u.unary_expression.link = UNARY_DOTLINK;
1087 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1088 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1090 | postfix_expression DOT ID_TYPE
1092 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1093 $$->u.unary_expression.type = UNARY_STRING;
1094 $$->u.unary_expression.u.string = yylval.gs->s;
1095 $$->u.unary_expression.link = UNARY_DOTLINK;
1096 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1097 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1099 | postfix_expression RARROW IDENTIFIER
1101 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1102 $$->u.unary_expression.type = UNARY_STRING;
1103 $$->u.unary_expression.u.string = yylval.gs->s;
1104 $$->u.unary_expression.link = UNARY_ARROWLINK;
1105 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1106 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1108 | postfix_expression RARROW ID_TYPE
1110 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1111 $$->u.unary_expression.type = UNARY_STRING;
1112 $$->u.unary_expression.u.string = yylval.gs->s;
1113 $$->u.unary_expression.link = UNARY_ARROWLINK;
1114 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1115 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1122 | PLUS postfix_expression
1124 | MINUS postfix_expression
1127 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1128 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1129 reparent_error(scanner, "expecting numeric constant");
1131 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1132 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1133 $$->u.unary_expression.u.signed_constant =
1134 -($$->u.unary_expression.u.unsigned_constant);
1136 $$->u.unary_expression.u.signed_constant =
1137 -($$->u.unary_expression.u.signed_constant);
1142 unary_expression_or_range:
1143 unary_expression DOTDOTDOT unary_expression
1146 _cds_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1147 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1153 /* 2.2: Declarations */
1156 declaration_specifiers SEMICOLON
1160 | stream_declaration
1164 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1166 struct ctf_node *list;
1168 $$ = make_node(scanner, NODE_TYPEDEF);
1169 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1170 $$->u._typedef.type_specifier_list = list;
1171 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1172 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1173 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1175 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1177 struct ctf_node *list;
1179 $$ = make_node(scanner, NODE_TYPEDEF);
1180 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1181 $$->u._typedef.type_specifier_list = list;
1182 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1183 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1185 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1187 struct ctf_node *list;
1189 $$ = make_node(scanner, NODE_TYPEDEF);
1190 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1191 $$->u._typedef.type_specifier_list = list;
1192 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1193 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1195 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1197 struct ctf_node *list;
1199 $$ = make_node(scanner, NODE_TYPEALIAS);
1200 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1201 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1203 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1204 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1205 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1206 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1208 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1209 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1210 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1211 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1216 event_declaration_begin event_declaration_end
1218 $$ = make_node(scanner, NODE_EVENT);
1220 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1222 $$ = make_node(scanner, NODE_EVENT);
1223 if (set_parent_node($2, $$))
1224 reparent_error(scanner, "event_declaration");
1228 event_declaration_begin:
1230 { push_scope(scanner); }
1233 event_declaration_end:
1235 { pop_scope(scanner); }
1240 stream_declaration_begin stream_declaration_end
1242 $$ = make_node(scanner, NODE_STREAM);
1244 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1246 $$ = make_node(scanner, NODE_STREAM);
1247 if (set_parent_node($2, $$))
1248 reparent_error(scanner, "stream_declaration");
1252 stream_declaration_begin:
1254 { push_scope(scanner); }
1257 stream_declaration_end:
1259 { pop_scope(scanner); }
1264 trace_declaration_begin trace_declaration_end
1266 $$ = make_node(scanner, NODE_TRACE);
1268 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1270 $$ = make_node(scanner, NODE_TRACE);
1271 if (set_parent_node($2, $$))
1272 reparent_error(scanner, "trace_declaration");
1276 trace_declaration_begin:
1278 { push_scope(scanner); }
1281 trace_declaration_end:
1283 { pop_scope(scanner); }
1286 integer_declaration_specifiers:
1289 struct ctf_node *node;
1291 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1292 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1293 node->u.type_specifier.type = TYPESPEC_CONST;
1294 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1296 | integer_type_specifier
1298 struct ctf_node *node;
1300 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1302 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1304 | integer_declaration_specifiers CONST
1306 struct ctf_node *node;
1309 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1310 node->u.type_specifier.type = TYPESPEC_CONST;
1311 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1313 | integer_declaration_specifiers integer_type_specifier
1316 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1320 declaration_specifiers:
1323 struct ctf_node *node;
1325 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1326 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1327 node->u.type_specifier.type = TYPESPEC_CONST;
1328 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1332 struct ctf_node *node;
1334 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1336 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1338 | declaration_specifiers CONST
1340 struct ctf_node *node;
1343 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1344 node->u.type_specifier.type = TYPESPEC_CONST;
1345 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1347 | declaration_specifiers type_specifier
1350 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1354 type_declarator_list:
1357 | type_declarator_list COMMA type_declarator
1360 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1364 integer_type_specifier:
1367 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1368 $$->u.type_specifier.type = TYPESPEC_CHAR;
1372 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1373 $$->u.type_specifier.type = TYPESPEC_SHORT;
1377 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1378 $$->u.type_specifier.type = TYPESPEC_INT;
1382 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1383 $$->u.type_specifier.type = TYPESPEC_LONG;
1387 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1388 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1392 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1393 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1397 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1398 $$->u.type_specifier.type = TYPESPEC_BOOL;
1402 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1403 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1404 $$->u.type_specifier.id_type = yylval.gs->s;
1406 | INTEGER LBRAC RBRAC
1408 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1409 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1410 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1412 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1414 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1415 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1416 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1417 if (set_parent_node($3, $$->u.type_specifier.node))
1418 reparent_error(scanner, "integer reparent error");
1425 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1426 $$->u.type_specifier.type = TYPESPEC_VOID;
1430 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1431 $$->u.type_specifier.type = TYPESPEC_CHAR;
1435 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1436 $$->u.type_specifier.type = TYPESPEC_SHORT;
1440 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1441 $$->u.type_specifier.type = TYPESPEC_INT;
1445 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1446 $$->u.type_specifier.type = TYPESPEC_LONG;
1450 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1451 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1455 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1456 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1460 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1461 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1465 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1466 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1470 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1471 $$->u.type_specifier.type = TYPESPEC_BOOL;
1475 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1476 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1480 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1481 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1485 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1486 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1487 $$->u.type_specifier.id_type = yylval.gs->s;
1489 | FLOATING_POINT LBRAC RBRAC
1491 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1492 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1493 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1495 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1497 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1498 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1499 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1500 if (set_parent_node($3, $$->u.type_specifier.node))
1501 reparent_error(scanner, "floating point reparent error");
1503 | INTEGER LBRAC RBRAC
1505 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1506 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1507 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1509 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1511 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1512 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1513 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1514 if (set_parent_node($3, $$->u.type_specifier.node))
1515 reparent_error(scanner, "integer reparent error");
1519 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1520 $$->u.type_specifier.type = TYPESPEC_STRING;
1521 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1523 | STRING LBRAC RBRAC
1525 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1526 $$->u.type_specifier.type = TYPESPEC_STRING;
1527 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1529 | STRING LBRAC ctf_assignment_expression_list RBRAC
1531 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1532 $$->u.type_specifier.type = TYPESPEC_STRING;
1533 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1534 if (set_parent_node($3, $$->u.type_specifier.node))
1535 reparent_error(scanner, "string reparent error");
1537 | ENUM enum_type_specifier
1539 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1540 $$->u.type_specifier.type = TYPESPEC_ENUM;
1541 $$->u.type_specifier.node = $2;
1543 | VARIANT variant_type_specifier
1545 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1546 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1547 $$->u.type_specifier.node = $2;
1549 | STRUCT struct_type_specifier
1551 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1552 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1553 $$->u.type_specifier.node = $2;
1557 struct_type_specifier:
1558 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1560 $$ = make_node(scanner, NODE_STRUCT);
1561 $$->u._struct.has_body = 1;
1562 if ($2 && set_parent_node($2, $$))
1563 reparent_error(scanner, "struct reparent error");
1565 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1567 $$ = make_node(scanner, NODE_STRUCT);
1568 $$->u._struct.has_body = 1;
1569 $$->u._struct.name = $1->s;
1570 if ($3 && set_parent_node($3, $$))
1571 reparent_error(scanner, "struct reparent error");
1573 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1575 $$ = make_node(scanner, NODE_STRUCT);
1576 $$->u._struct.has_body = 1;
1577 $$->u._struct.name = $1->s;
1578 if ($3 && set_parent_node($3, $$))
1579 reparent_error(scanner, "struct reparent error");
1583 $$ = make_node(scanner, NODE_STRUCT);
1584 $$->u._struct.has_body = 0;
1585 $$->u._struct.name = $1->s;
1589 $$ = make_node(scanner, NODE_STRUCT);
1590 $$->u._struct.has_body = 0;
1591 $$->u._struct.name = $1->s;
1593 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1595 $$ = make_node(scanner, NODE_STRUCT);
1596 $$->u._struct.has_body = 1;
1597 cds_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1598 if ($2 && set_parent_node($2, $$))
1599 reparent_error(scanner, "struct reparent error");
1601 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1603 $$ = make_node(scanner, NODE_STRUCT);
1604 $$->u._struct.has_body = 1;
1605 $$->u._struct.name = $1->s;
1606 cds_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1607 if ($3 && set_parent_node($3, $$))
1608 reparent_error(scanner, "struct reparent error");
1610 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1612 $$ = make_node(scanner, NODE_STRUCT);
1613 $$->u._struct.has_body = 1;
1614 $$->u._struct.name = $1->s;
1615 cds_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1616 if ($3 && set_parent_node($3, $$))
1617 reparent_error(scanner, "struct reparent error");
1621 struct_declaration_begin:
1623 { push_scope(scanner); }
1626 struct_declaration_end:
1628 { pop_scope(scanner); }
1631 variant_type_specifier:
1632 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1634 $$ = make_node(scanner, NODE_VARIANT);
1635 $$->u.variant.has_body = 1;
1636 if ($2 && set_parent_node($2, $$))
1637 reparent_error(scanner, "variant reparent error");
1639 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1641 $$ = make_node(scanner, NODE_VARIANT);
1642 $$->u.variant.has_body = 1;
1643 $$->u.variant.choice = $2->s;
1644 if ($5 && set_parent_node($5, $$))
1645 reparent_error(scanner, "variant reparent error");
1647 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1649 $$ = make_node(scanner, NODE_VARIANT);
1650 $$->u.variant.has_body = 1;
1651 $$->u.variant.choice = $2->s;
1652 if ($5 && set_parent_node($5, $$))
1653 reparent_error(scanner, "variant reparent error");
1655 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1657 $$ = make_node(scanner, NODE_VARIANT);
1658 $$->u.variant.has_body = 1;
1659 $$->u.variant.name = $1->s;
1660 if ($3 && set_parent_node($3, $$))
1661 reparent_error(scanner, "variant reparent error");
1663 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1665 $$ = make_node(scanner, NODE_VARIANT);
1666 $$->u.variant.has_body = 1;
1667 $$->u.variant.name = $1->s;
1668 $$->u.variant.choice = $3->s;
1669 if ($6 && set_parent_node($6, $$))
1670 reparent_error(scanner, "variant reparent error");
1672 | IDENTIFIER LT IDENTIFIER GT
1674 $$ = make_node(scanner, NODE_VARIANT);
1675 $$->u.variant.has_body = 0;
1676 $$->u.variant.name = $1->s;
1677 $$->u.variant.choice = $3->s;
1679 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1681 $$ = make_node(scanner, NODE_VARIANT);
1682 $$->u.variant.has_body = 1;
1683 $$->u.variant.name = $1->s;
1684 $$->u.variant.choice = $3->s;
1685 if ($6 && set_parent_node($6, $$))
1686 reparent_error(scanner, "variant reparent error");
1688 | IDENTIFIER LT ID_TYPE GT
1690 $$ = make_node(scanner, NODE_VARIANT);
1691 $$->u.variant.has_body = 0;
1692 $$->u.variant.name = $1->s;
1693 $$->u.variant.choice = $3->s;
1695 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1697 $$ = make_node(scanner, NODE_VARIANT);
1698 $$->u.variant.has_body = 1;
1699 $$->u.variant.name = $1->s;
1700 if ($3 && set_parent_node($3, $$))
1701 reparent_error(scanner, "variant reparent error");
1703 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1705 $$ = make_node(scanner, NODE_VARIANT);
1706 $$->u.variant.has_body = 1;
1707 $$->u.variant.name = $1->s;
1708 $$->u.variant.choice = $3->s;
1709 if ($6 && set_parent_node($6, $$))
1710 reparent_error(scanner, "variant reparent error");
1712 | ID_TYPE LT IDENTIFIER GT
1714 $$ = make_node(scanner, NODE_VARIANT);
1715 $$->u.variant.has_body = 0;
1716 $$->u.variant.name = $1->s;
1717 $$->u.variant.choice = $3->s;
1719 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1721 $$ = make_node(scanner, NODE_VARIANT);
1722 $$->u.variant.has_body = 1;
1723 $$->u.variant.name = $1->s;
1724 $$->u.variant.choice = $3->s;
1725 if ($6 && set_parent_node($6, $$))
1726 reparent_error(scanner, "variant reparent error");
1728 | ID_TYPE LT ID_TYPE GT
1730 $$ = make_node(scanner, NODE_VARIANT);
1731 $$->u.variant.has_body = 0;
1732 $$->u.variant.name = $1->s;
1733 $$->u.variant.choice = $3->s;
1737 variant_declaration_begin:
1739 { push_scope(scanner); }
1742 variant_declaration_end:
1744 { pop_scope(scanner); }
1747 enum_type_specifier:
1748 LBRAC enumerator_list RBRAC
1750 $$ = make_node(scanner, NODE_ENUM);
1751 $$->u._enum.has_body = 1;
1752 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1754 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1756 $$ = make_node(scanner, NODE_ENUM);
1757 $$->u._enum.has_body = 1;
1758 ($$)->u._enum.container_type = $2;
1759 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1761 | IDENTIFIER LBRAC enumerator_list RBRAC
1763 $$ = make_node(scanner, NODE_ENUM);
1764 $$->u._enum.has_body = 1;
1765 $$->u._enum.enum_id = $1->s;
1766 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1768 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1770 $$ = make_node(scanner, NODE_ENUM);
1771 $$->u._enum.has_body = 1;
1772 $$->u._enum.enum_id = $1->s;
1773 ($$)->u._enum.container_type = $3;
1774 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1776 | ID_TYPE LBRAC enumerator_list RBRAC
1778 $$ = make_node(scanner, NODE_ENUM);
1779 $$->u._enum.has_body = 1;
1780 $$->u._enum.enum_id = $1->s;
1781 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1783 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1785 $$ = make_node(scanner, NODE_ENUM);
1786 $$->u._enum.has_body = 1;
1787 $$->u._enum.enum_id = $1->s;
1788 ($$)->u._enum.container_type = $3;
1789 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1791 | LBRAC enumerator_list COMMA RBRAC
1793 $$ = make_node(scanner, NODE_ENUM);
1794 $$->u._enum.has_body = 1;
1795 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1797 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1799 $$ = make_node(scanner, NODE_ENUM);
1800 $$->u._enum.has_body = 1;
1801 ($$)->u._enum.container_type = $2;
1802 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1804 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1806 $$ = make_node(scanner, NODE_ENUM);
1807 $$->u._enum.has_body = 1;
1808 $$->u._enum.enum_id = $1->s;
1809 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1811 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1813 $$ = make_node(scanner, NODE_ENUM);
1814 $$->u._enum.has_body = 1;
1815 $$->u._enum.enum_id = $1->s;
1816 ($$)->u._enum.container_type = $3;
1817 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1821 $$ = make_node(scanner, NODE_ENUM);
1822 $$->u._enum.has_body = 0;
1823 $$->u._enum.enum_id = $1->s;
1825 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1827 $$ = make_node(scanner, NODE_ENUM);
1828 $$->u._enum.has_body = 1;
1829 $$->u._enum.enum_id = $1->s;
1830 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1832 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1834 $$ = make_node(scanner, NODE_ENUM);
1835 $$->u._enum.has_body = 1;
1836 $$->u._enum.enum_id = $1->s;
1837 ($$)->u._enum.container_type = $3;
1838 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1842 $$ = make_node(scanner, NODE_ENUM);
1843 $$->u._enum.has_body = 0;
1844 $$->u._enum.enum_id = $1->s;
1848 struct_or_variant_declaration_list:
1851 | struct_or_variant_declaration_list struct_or_variant_declaration
1855 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1858 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1863 struct_or_variant_declaration:
1864 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
1866 struct ctf_node *list;
1868 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1869 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1870 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1871 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1872 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
1874 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1876 struct ctf_node *list;
1878 $$ = make_node(scanner, NODE_TYPEDEF);
1879 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1880 $$->u._typedef.type_specifier_list = list;
1881 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1882 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1883 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1885 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1887 struct ctf_node *list;
1889 $$ = make_node(scanner, NODE_TYPEDEF);
1890 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1891 $$->u._typedef.type_specifier_list = list;
1892 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1893 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1895 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1897 struct ctf_node *list;
1899 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1900 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1901 $$ = make_node(scanner, NODE_TYPEDEF);
1902 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1903 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1905 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1907 struct ctf_node *list;
1909 $$ = make_node(scanner, NODE_TYPEALIAS);
1910 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1911 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1913 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1914 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1915 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1916 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1918 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1919 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1920 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1921 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1925 alias_declaration_specifiers:
1928 struct ctf_node *node;
1930 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1931 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1932 node->u.type_specifier.type = TYPESPEC_CONST;
1933 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1937 struct ctf_node *node;
1939 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1941 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1945 struct ctf_node *node;
1947 add_type(scanner, $1);
1948 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1949 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1950 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
1951 node->u.type_specifier.id_type = yylval.gs->s;
1952 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1954 | alias_declaration_specifiers CONST
1956 struct ctf_node *node;
1959 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1960 node->u.type_specifier.type = TYPESPEC_CONST;
1961 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1963 | alias_declaration_specifiers type_specifier
1966 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1968 | alias_declaration_specifiers IDENTIFIER
1970 struct ctf_node *node;
1972 add_type(scanner, $2);
1974 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1975 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
1976 node->u.type_specifier.id_type = yylval.gs->s;
1977 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1981 struct_or_variant_declarator_list:
1982 struct_or_variant_declarator
1984 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
1987 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1991 struct_or_variant_declarator:
1994 | COLON unary_expression
1996 | declarator COLON unary_expression
1999 if (set_parent_node($3, $1))
2000 reparent_error(scanner, "struct_or_variant_declarator");
2007 | enumerator_list COMMA enumerator
2010 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2017 $$ = make_node(scanner, NODE_ENUMERATOR);
2018 $$->u.enumerator.id = $1->s;
2022 $$ = make_node(scanner, NODE_ENUMERATOR);
2023 $$->u.enumerator.id = $1->s;
2027 $$ = make_node(scanner, NODE_ENUMERATOR);
2028 $$->u.enumerator.id = $1->s;
2030 | STRING_LITERAL_START DQUOTE
2032 $$ = make_node(scanner, NODE_ENUMERATOR);
2033 $$->u.enumerator.id = "";
2035 | STRING_LITERAL_START s_char_sequence DQUOTE
2037 $$ = make_node(scanner, NODE_ENUMERATOR);
2038 $$->u.enumerator.id = $2->s;
2040 | IDENTIFIER EQUAL unary_expression_or_range
2042 $$ = make_node(scanner, NODE_ENUMERATOR);
2043 $$->u.enumerator.id = $1->s;
2044 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2046 | ID_TYPE EQUAL unary_expression_or_range
2048 $$ = make_node(scanner, NODE_ENUMERATOR);
2049 $$->u.enumerator.id = $1->s;
2050 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2052 | keywords EQUAL unary_expression_or_range
2054 $$ = make_node(scanner, NODE_ENUMERATOR);
2055 $$->u.enumerator.id = $1->s;
2056 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2058 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
2060 $$ = make_node(scanner, NODE_ENUMERATOR);
2061 $$->u.enumerator.id = "";
2062 cds_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
2064 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
2066 $$ = make_node(scanner, NODE_ENUMERATOR);
2067 $$->u.enumerator.id = $2->s;
2068 cds_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
2072 abstract_declarator_list:
2075 | abstract_declarator_list COMMA abstract_declarator
2078 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2082 abstract_declarator:
2083 direct_abstract_declarator
2085 | pointer direct_abstract_declarator
2088 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2092 direct_abstract_declarator:
2095 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2096 $$->u.type_declarator.type = TYPEDEC_ID;
2101 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2102 $$->u.type_declarator.type = TYPEDEC_ID;
2103 $$->u.type_declarator.u.id = $1->s;
2105 | LPAREN abstract_declarator RPAREN
2107 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2108 $$->u.type_declarator.type = TYPEDEC_NESTED;
2109 $$->u.type_declarator.u.nested.type_declarator = $2;
2111 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2113 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2114 $$->u.type_declarator.type = TYPEDEC_NESTED;
2115 $$->u.type_declarator.u.nested.type_declarator = $1;
2116 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2117 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2119 | direct_abstract_declarator LSBRAC RSBRAC
2121 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2122 $$->u.type_declarator.type = TYPEDEC_NESTED;
2123 $$->u.type_declarator.u.nested.type_declarator = $1;
2124 $$->u.type_declarator.u.nested.abstract_array = 1;
2128 alias_abstract_declarator_list:
2129 alias_abstract_declarator
2131 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2134 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2138 alias_abstract_declarator:
2139 direct_alias_abstract_declarator
2141 | pointer direct_alias_abstract_declarator
2144 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2148 direct_alias_abstract_declarator:
2151 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2152 $$->u.type_declarator.type = TYPEDEC_ID;
2155 | LPAREN alias_abstract_declarator RPAREN
2157 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2158 $$->u.type_declarator.type = TYPEDEC_NESTED;
2159 $$->u.type_declarator.u.nested.type_declarator = $2;
2161 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2163 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2164 $$->u.type_declarator.type = TYPEDEC_NESTED;
2165 $$->u.type_declarator.u.nested.type_declarator = $1;
2166 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2167 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2169 | direct_alias_abstract_declarator LSBRAC RSBRAC
2171 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2172 $$->u.type_declarator.type = TYPEDEC_NESTED;
2173 $$->u.type_declarator.u.nested.type_declarator = $1;
2174 $$->u.type_declarator.u.nested.abstract_array = 1;
2181 | pointer direct_declarator
2184 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2191 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2192 $$->u.type_declarator.type = TYPEDEC_ID;
2193 $$->u.type_declarator.u.id = $1->s;
2195 | LPAREN declarator RPAREN
2197 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2198 $$->u.type_declarator.type = TYPEDEC_NESTED;
2199 $$->u.type_declarator.u.nested.type_declarator = $2;
2201 | direct_declarator LSBRAC unary_expression RSBRAC
2203 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2204 $$->u.type_declarator.type = TYPEDEC_NESTED;
2205 $$->u.type_declarator.u.nested.type_declarator = $1;
2206 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2207 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2212 direct_type_declarator
2214 | pointer direct_type_declarator
2217 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2221 direct_type_declarator:
2224 add_type(scanner, $1);
2225 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2226 $$->u.type_declarator.type = TYPEDEC_ID;
2227 $$->u.type_declarator.u.id = $1->s;
2229 | LPAREN type_declarator RPAREN
2231 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2232 $$->u.type_declarator.type = TYPEDEC_NESTED;
2233 $$->u.type_declarator.u.nested.type_declarator = $2;
2235 | direct_type_declarator LSBRAC unary_expression RSBRAC
2237 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2238 $$->u.type_declarator.type = TYPEDEC_NESTED;
2239 $$->u.type_declarator.u.nested.type_declarator = $1;
2240 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2241 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2248 $$ = make_node(scanner, NODE_POINTER);
2252 $$ = make_node(scanner, NODE_POINTER);
2253 cds_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2255 | STAR type_qualifier_list pointer
2257 $$ = make_node(scanner, NODE_POINTER);
2258 $$->u.pointer.const_qualifier = 1;
2259 cds_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2263 type_qualifier_list:
2264 /* pointer assumes only const type qualifier */
2266 | type_qualifier_list CONST
2269 /* 2.3: CTF-specific declarations */
2271 ctf_assignment_expression_list:
2272 ctf_assignment_expression SEMICOLON
2274 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2277 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2281 ctf_assignment_expression:
2282 unary_expression EQUAL unary_expression
2285 * Because we have left and right, cannot use
2288 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2289 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2290 if ($1->u.unary_expression.type != UNARY_STRING)
2291 reparent_error(scanner, "ctf_assignment_expression left expects string");
2292 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2294 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2297 * Because we have left and right, cannot use
2300 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2301 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2302 if ($1->u.unary_expression.type != UNARY_STRING)
2303 reparent_error(scanner, "ctf_assignment_expression left expects string");
2304 cds_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2306 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2308 struct ctf_node *list;
2310 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2311 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2312 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2313 $$ = make_node(scanner, NODE_TYPEDEF);
2314 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2315 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2317 | TYPEDEF declaration_specifiers type_declarator_list
2319 struct ctf_node *list;
2321 $$ = make_node(scanner, NODE_TYPEDEF);
2322 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2323 $$->u._typedef.type_specifier_list = list;
2324 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2325 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2327 | declaration_specifiers TYPEDEF type_declarator_list
2329 struct ctf_node *list;
2331 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2332 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2333 $$ = make_node(scanner, NODE_TYPEDEF);
2334 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2335 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2337 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2339 struct ctf_node *list;
2341 $$ = make_node(scanner, NODE_TYPEALIAS);
2342 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2343 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2345 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2346 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2347 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2348 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2350 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2351 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2352 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2353 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);