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_CLOCK ] = "NODE_CLOCK",
70 [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
71 [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
72 [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
73 [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
74 [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
75 [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
76 [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
77 [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
78 [ NODE_POINTER ] = "NODE_POINTER",
79 [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
80 [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
81 [ NODE_INTEGER ] = "NODE_INTEGER",
82 [ NODE_STRING ] = "NODE_STRING",
83 [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
84 [ NODE_ENUM ] = "NODE_ENUM",
85 [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
86 [ NODE_VARIANT ] = "NODE_VARIANT",
87 [ NODE_STRUCT ] = "NODE_STRUCT",
90 const char *node_type(struct ctf_node *node)
92 if (node->type < NR_NODE_TYPES)
93 return node_type_to_str[node->type];
98 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
101 struct gc_string *gstr;
104 /* TODO: could be faster with find first bit or glib Gstring */
105 /* sizeof long to account for malloc header (int or long ?) */
106 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
109 gstr = malloc(alloclen);
110 cds_list_add(&gstr->gc, &scanner->allocated_strings);
111 gstr->alloclen = alloclen;
116 * note: never use gc_string_append on a string that has external references.
117 * gsrc will be garbage collected immediately, and gstr might be.
118 * Should only be used to append characters to a string literal or constant.
120 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
121 struct gc_string *gstr,
122 struct gc_string *gsrc)
124 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
127 /* TODO: could be faster with find first bit or glib Gstring */
128 /* sizeof long to account for malloc header (int or long ?) */
129 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
132 if (alloclen > gstr->alloclen) {
133 struct gc_string *newgstr;
135 newgstr = gc_string_alloc(scanner, newlen);
136 strcpy(newgstr->s, gstr->s);
137 strcat(newgstr->s, gsrc->s);
138 cds_list_del(&gstr->gc);
142 strcat(gstr->s, gsrc->s);
144 cds_list_del(&gsrc->gc);
149 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
151 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
152 strcpy(lvalp->gs->s, src);
155 static void init_scope(struct ctf_scanner_scope *scope,
156 struct ctf_scanner_scope *parent)
158 scope->parent = parent;
159 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
163 static void finalize_scope(struct ctf_scanner_scope *scope)
165 g_hash_table_destroy(scope->types);
168 static void push_scope(struct ctf_scanner *scanner)
170 struct ctf_scanner_scope *ns;
172 printf_debug("push scope\n");
173 ns = malloc(sizeof(struct ctf_scanner_scope));
174 init_scope(ns, scanner->cs);
178 static void pop_scope(struct ctf_scanner *scanner)
180 struct ctf_scanner_scope *os;
182 printf_debug("pop scope\n");
184 scanner->cs = os->parent;
189 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
193 ret = (int) (long) g_hash_table_lookup(s->types, id);
194 printf_debug("lookup %p %s %d\n", s, id, ret);
198 int is_type(struct ctf_scanner *scanner, const char *id)
200 struct ctf_scanner_scope *it;
203 for (it = scanner->cs; it != NULL; it = it->parent) {
204 if (lookup_type(it, id)) {
209 printf_debug("is type %s %d\n", id, ret);
213 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
215 printf_debug("add type %s\n", id->s);
216 if (lookup_type(scanner->cs, id->s))
218 g_hash_table_insert(scanner->cs->types, id->s, id->s);
221 static struct ctf_node *make_node(struct ctf_scanner *scanner,
224 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
225 struct ctf_node *node;
227 node = malloc(sizeof(*node));
230 memset(node, 0, sizeof(*node));
232 CDS_INIT_LIST_HEAD(&node->tmp_head);
233 cds_list_add(&node->gc, &ast->allocated_nodes);
234 cds_list_add(&node->siblings, &node->tmp_head);
238 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
242 CDS_INIT_LIST_HEAD(&node->u.event.declaration_list);
245 CDS_INIT_LIST_HEAD(&node->u.stream.declaration_list);
248 CDS_INIT_LIST_HEAD(&node->u.trace.declaration_list);
251 CDS_INIT_LIST_HEAD(&node->u.clock.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);
334 _cds_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
336 case NODE_FLOATING_POINT:
337 _cds_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
340 _cds_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
343 _cds_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
347 case NODE_CTF_EXPRESSION:
349 case NODE_TYPEALIAS_TARGET:
350 case NODE_TYPEALIAS_ALIAS:
352 case NODE_TYPE_SPECIFIER:
353 case NODE_TYPE_SPECIFIER_LIST:
355 case NODE_TYPE_DECLARATOR:
356 case NODE_ENUMERATOR:
358 case NODE_STRUCT_OR_VARIANT_DECLARATION:
361 case NODE_UNARY_EXPRESSION:
366 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
373 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
375 switch (parent->type) {
377 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
380 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
383 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
386 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
389 _cds_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
392 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
395 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
398 case NODE_FLOATING_POINT:
401 case NODE_CTF_EXPRESSION:
403 case NODE_TYPEALIAS_TARGET:
404 case NODE_TYPEALIAS_ALIAS:
406 case NODE_TYPE_SPECIFIER:
407 case NODE_TYPE_SPECIFIER_LIST:
409 case NODE_TYPE_DECLARATOR:
410 case NODE_ENUMERATOR:
412 case NODE_STRUCT_OR_VARIANT_DECLARATION:
413 case NODE_UNARY_EXPRESSION:
418 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
425 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
427 switch (parent->type) {
429 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
432 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
435 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
438 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
441 _cds_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
444 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
447 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
450 case NODE_FLOATING_POINT:
453 case NODE_CTF_EXPRESSION:
455 case NODE_TYPEALIAS_TARGET:
456 case NODE_TYPEALIAS_ALIAS:
458 case NODE_TYPE_SPECIFIER:
459 case NODE_TYPE_SPECIFIER_LIST:
461 case NODE_TYPE_DECLARATOR:
462 case NODE_ENUMERATOR:
464 case NODE_STRUCT_OR_VARIANT_DECLARATION:
465 case NODE_UNARY_EXPRESSION:
470 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
477 static int reparent_type_specifier(struct ctf_node *node,
478 struct ctf_node *parent)
480 switch (parent->type) {
481 case NODE_TYPE_SPECIFIER_LIST:
482 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
485 case NODE_TYPE_SPECIFIER:
493 case NODE_TYPEALIAS_TARGET:
494 case NODE_TYPEALIAS_ALIAS:
495 case NODE_TYPE_DECLARATOR:
497 case NODE_STRUCT_OR_VARIANT_DECLARATION:
499 case NODE_FLOATING_POINT:
502 case NODE_CTF_EXPRESSION:
504 case NODE_ENUMERATOR:
505 case NODE_UNARY_EXPRESSION:
510 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
517 static int reparent_type_specifier_list(struct ctf_node *node,
518 struct ctf_node *parent)
520 switch (parent->type) {
522 cds_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
525 cds_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
528 cds_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
531 cds_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
534 cds_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
537 cds_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
540 cds_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
543 parent->u._typedef.type_specifier_list = node;
545 case NODE_TYPEALIAS_TARGET:
546 parent->u.typealias_target.type_specifier_list = node;
548 case NODE_TYPEALIAS_ALIAS:
549 parent->u.typealias_alias.type_specifier_list = node;
552 parent->u._enum.container_type = node;
554 case NODE_STRUCT_OR_VARIANT_DECLARATION:
555 parent->u.struct_or_variant_declaration.type_specifier_list = node;
557 case NODE_TYPE_DECLARATOR:
558 case NODE_TYPE_SPECIFIER:
560 case NODE_FLOATING_POINT:
563 case NODE_CTF_EXPRESSION:
565 case NODE_ENUMERATOR:
566 case NODE_UNARY_EXPRESSION:
571 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
578 static int reparent_type_declarator(struct ctf_node *node,
579 struct ctf_node *parent)
581 switch (parent->type) {
582 case NODE_TYPE_DECLARATOR:
583 parent->u.type_declarator.type = TYPEDEC_NESTED;
584 parent->u.type_declarator.u.nested.type_declarator = node;
586 case NODE_STRUCT_OR_VARIANT_DECLARATION:
587 _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
590 _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
592 case NODE_TYPEALIAS_TARGET:
593 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
595 case NODE_TYPEALIAS_ALIAS:
596 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
608 case NODE_FLOATING_POINT:
611 case NODE_CTF_EXPRESSION:
612 case NODE_TYPE_SPECIFIER:
613 case NODE_TYPE_SPECIFIER_LIST:
615 case NODE_ENUMERATOR:
616 case NODE_UNARY_EXPRESSION:
621 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
631 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
632 * create the link declared by the input, -ENOENT if node or parent is NULL,
633 * -EINVAL if there is an internal structure problem.
635 static int set_parent_node(struct ctf_node *node,
636 struct ctf_node *parent)
638 if (!node || !parent)
641 /* Note: Linking to parent will be done only by an external visitor */
643 switch (node->type) {
645 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
649 if (parent->type == NODE_ROOT) {
650 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.event);
656 if (parent->type == NODE_ROOT) {
657 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
663 if (parent->type == NODE_ROOT) {
664 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
670 if (parent->type == NODE_ROOT) {
671 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
677 case NODE_CTF_EXPRESSION:
678 return reparent_ctf_expression(node, parent);
679 case NODE_UNARY_EXPRESSION:
680 if (parent->type == NODE_TYPE_DECLARATOR)
681 parent->u.type_declarator.bitfield_len = node;
687 return reparent_typedef(node, parent);
688 case NODE_TYPEALIAS_TARGET:
689 if (parent->type == NODE_TYPEALIAS)
690 parent->u.typealias.target = node;
693 case NODE_TYPEALIAS_ALIAS:
694 if (parent->type == NODE_TYPEALIAS)
695 parent->u.typealias.alias = node;
699 return reparent_typealias(node, parent);
702 if (parent->type == NODE_TYPE_DECLARATOR) {
703 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
707 case NODE_TYPE_DECLARATOR:
708 return reparent_type_declarator(node, parent);
710 case NODE_TYPE_SPECIFIER_LIST:
711 return reparent_type_specifier_list(node, parent);
713 case NODE_TYPE_SPECIFIER:
714 return reparent_type_specifier(node, parent);
716 case NODE_FLOATING_POINT:
722 return -EINVAL; /* Dealt with internally within grammar */
724 case NODE_ENUMERATOR:
725 if (parent->type == NODE_ENUM) {
726 _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
731 case NODE_STRUCT_OR_VARIANT_DECLARATION:
732 switch (parent->type) {
734 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
737 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
746 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
753 void yyerror(struct ctf_scanner *scanner, const char *str)
755 fprintf(stderr, "error %s\n", str);
763 #define reparent_error(scanner, str) \
765 yyerror(scanner, YY_("reparent_error: " str "\n")); \
769 static void free_strings(struct cds_list_head *list)
771 struct gc_string *gstr, *tmp;
773 cds_list_for_each_entry_safe(gstr, tmp, list, gc)
777 static struct ctf_ast *ctf_ast_alloc(void)
781 ast = malloc(sizeof(*ast));
784 memset(ast, 0, sizeof(*ast));
785 CDS_INIT_LIST_HEAD(&ast->allocated_nodes);
786 ast->root.type = NODE_ROOT;
787 CDS_INIT_LIST_HEAD(&ast->root.tmp_head);
788 CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
789 CDS_INIT_LIST_HEAD(&ast->root.u.root.trace);
790 CDS_INIT_LIST_HEAD(&ast->root.u.root.stream);
791 CDS_INIT_LIST_HEAD(&ast->root.u.root.event);
792 CDS_INIT_LIST_HEAD(&ast->root.u.root.clock);
796 static void ctf_ast_free(struct ctf_ast *ast)
798 struct ctf_node *node, *tmp;
800 cds_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
804 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
806 return yyparse(scanner);
809 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
811 struct ctf_scanner *scanner;
814 yydebug = babeltrace_debug;
816 scanner = malloc(sizeof(*scanner));
819 memset(scanner, 0, sizeof(*scanner));
821 ret = yylex_init_extra(scanner, &scanner->scanner);
823 fprintf(stderr, "yylex_init error\n");
824 goto cleanup_scanner;
826 /* Start processing new stream */
827 yyrestart(input, scanner->scanner);
829 scanner->ast = ctf_ast_alloc();
832 init_scope(&scanner->root_scope, NULL);
833 scanner->cs = &scanner->root_scope;
834 CDS_INIT_LIST_HEAD(&scanner->allocated_strings);
837 fprintf(stdout, "Scanner input is a%s.\n",
838 isatty(fileno(input)) ? "n interactive tty" :
839 " noninteractive file");
844 ret = yylex_destroy(scanner->scanner);
846 fprintf(stderr, "yylex_destroy error\n");
852 void ctf_scanner_free(struct ctf_scanner *scanner)
856 finalize_scope(&scanner->root_scope);
857 free_strings(&scanner->allocated_strings);
858 ctf_ast_free(scanner->ast);
859 ret = yylex_destroy(scanner->scanner);
861 fprintf(stderr, "yylex_destroy error\n");
869 %parse-param {struct ctf_scanner *scanner}
870 %lex-param {struct ctf_scanner *scanner}
872 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
873 * vs struct { int :value; } (unnamed bit-field). The default is to
874 * shift, so whenever we encounter an enumeration, we are doing the
875 * proper thing (shift). It is illegal to declare an enumeration
876 * "bit-field", so it is OK if this situation ends up in a parsing
881 %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 CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT TOK_ALIGN
882 %token <gs> IDENTIFIER ID_TYPE
888 struct gc_string *gs;
893 %type <gs> s_char s_char_sequence c_char c_char_sequence
895 %type <n> postfix_expression unary_expression unary_expression_or_range
897 %type <n> declaration
898 %type <n> event_declaration
899 %type <n> stream_declaration
900 %type <n> trace_declaration
901 %type <n> clock_declaration
902 %type <n> integer_declaration_specifiers
903 %type <n> declaration_specifiers
904 %type <n> alias_declaration_specifiers
906 %type <n> type_declarator_list
907 %type <n> integer_type_specifier
908 %type <n> type_specifier
909 %type <n> struct_type_specifier
910 %type <n> variant_type_specifier
911 %type <n> enum_type_specifier
912 %type <n> struct_or_variant_declaration_list
913 %type <n> struct_or_variant_declaration
914 %type <n> struct_or_variant_declarator_list
915 %type <n> struct_or_variant_declarator
916 %type <n> enumerator_list
918 %type <n> abstract_declarator_list
919 %type <n> abstract_declarator
920 %type <n> direct_abstract_declarator
921 %type <n> alias_abstract_declarator_list
922 %type <n> alias_abstract_declarator
923 %type <n> direct_alias_abstract_declarator
925 %type <n> direct_declarator
926 %type <n> type_declarator
927 %type <n> direct_type_declarator
929 %type <n> ctf_assignment_expression_list
930 %type <n> ctf_assignment_expression
937 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
938 reparent_error(scanner, "error reparenting to root");
942 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
943 reparent_error(scanner, "error reparenting to root");
1005 | c_char_sequence c_char
1006 { $$ = gc_string_append(scanner, $1, $2); }
1014 reparent_error(scanner, "escape sequences not supported yet");
1018 /* 1.6 String literals */
1023 | s_char_sequence s_char
1024 { $$ = gc_string_append(scanner, $1, $2); }
1032 reparent_error(scanner, "escape sequences not supported yet");
1036 /* 2: Phrase structure grammar */
1041 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1042 $$->u.unary_expression.type = UNARY_STRING;
1043 $$->u.unary_expression.u.string = yylval.gs->s;
1047 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1048 $$->u.unary_expression.type = UNARY_STRING;
1049 $$->u.unary_expression.u.string = yylval.gs->s;
1053 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1054 $$->u.unary_expression.type = UNARY_STRING;
1055 $$->u.unary_expression.u.string = yylval.gs->s;
1059 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1060 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1061 sscanf(yylval.gs->s, "%" PRIu64,
1062 &$$->u.unary_expression.u.unsigned_constant);
1066 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1067 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1068 sscanf(yylval.gs->s, "0%" PRIo64,
1069 &$$->u.unary_expression.u.unsigned_constant);
1071 | HEXADECIMAL_CONSTANT
1073 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1074 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1075 sscanf(yylval.gs->s, "0x%" PRIx64,
1076 &$$->u.unary_expression.u.unsigned_constant);
1078 | STRING_LITERAL_START DQUOTE
1080 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1081 $$->u.unary_expression.type = UNARY_STRING;
1082 $$->u.unary_expression.u.string = "";
1084 | STRING_LITERAL_START s_char_sequence DQUOTE
1086 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1087 $$->u.unary_expression.type = UNARY_STRING;
1088 $$->u.unary_expression.u.string = $2->s;
1090 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1092 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1093 $$->u.unary_expression.type = UNARY_STRING;
1094 $$->u.unary_expression.u.string = $2->s;
1096 | LPAREN unary_expression RPAREN
1098 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1099 $$->u.unary_expression.type = UNARY_NESTED;
1100 $$->u.unary_expression.u.nested_exp = $2;
1102 | postfix_expression LSBRAC unary_expression RSBRAC
1104 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1105 $$->u.unary_expression.type = UNARY_SBRAC;
1106 $$->u.unary_expression.u.sbrac_exp = $3;
1107 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1108 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1110 | postfix_expression DOT IDENTIFIER
1112 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1113 $$->u.unary_expression.type = UNARY_STRING;
1114 $$->u.unary_expression.u.string = yylval.gs->s;
1115 $$->u.unary_expression.link = UNARY_DOTLINK;
1116 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1117 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1119 | postfix_expression DOT ID_TYPE
1121 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1122 $$->u.unary_expression.type = UNARY_STRING;
1123 $$->u.unary_expression.u.string = yylval.gs->s;
1124 $$->u.unary_expression.link = UNARY_DOTLINK;
1125 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1126 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1128 | postfix_expression RARROW IDENTIFIER
1130 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1131 $$->u.unary_expression.type = UNARY_STRING;
1132 $$->u.unary_expression.u.string = yylval.gs->s;
1133 $$->u.unary_expression.link = UNARY_ARROWLINK;
1134 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1135 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1137 | postfix_expression RARROW ID_TYPE
1139 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1140 $$->u.unary_expression.type = UNARY_STRING;
1141 $$->u.unary_expression.u.string = yylval.gs->s;
1142 $$->u.unary_expression.link = UNARY_ARROWLINK;
1143 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1144 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1151 | PLUS postfix_expression
1153 | MINUS postfix_expression
1156 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1157 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1158 reparent_error(scanner, "expecting numeric constant");
1160 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1161 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1162 $$->u.unary_expression.u.signed_constant =
1163 -($$->u.unary_expression.u.unsigned_constant);
1165 $$->u.unary_expression.u.signed_constant =
1166 -($$->u.unary_expression.u.signed_constant);
1171 unary_expression_or_range:
1172 unary_expression DOTDOTDOT unary_expression
1175 _cds_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1176 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1182 /* 2.2: Declarations */
1185 declaration_specifiers SEMICOLON
1189 | stream_declaration
1195 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1197 struct ctf_node *list;
1199 $$ = make_node(scanner, NODE_TYPEDEF);
1200 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1201 $$->u._typedef.type_specifier_list = list;
1202 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1203 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1204 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1206 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1208 struct ctf_node *list;
1210 $$ = make_node(scanner, NODE_TYPEDEF);
1211 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1212 $$->u._typedef.type_specifier_list = list;
1213 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1214 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1216 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1218 struct ctf_node *list;
1220 $$ = make_node(scanner, NODE_TYPEDEF);
1221 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1222 $$->u._typedef.type_specifier_list = list;
1223 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1224 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1226 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1228 struct ctf_node *list;
1230 $$ = make_node(scanner, NODE_TYPEALIAS);
1231 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1232 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1234 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1235 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1236 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1237 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1239 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1240 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1241 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1242 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1247 event_declaration_begin event_declaration_end
1249 $$ = make_node(scanner, NODE_EVENT);
1251 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1253 $$ = make_node(scanner, NODE_EVENT);
1254 if (set_parent_node($2, $$))
1255 reparent_error(scanner, "event_declaration");
1259 event_declaration_begin:
1261 { push_scope(scanner); }
1264 event_declaration_end:
1266 { pop_scope(scanner); }
1271 stream_declaration_begin stream_declaration_end
1273 $$ = make_node(scanner, NODE_STREAM);
1275 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1277 $$ = make_node(scanner, NODE_STREAM);
1278 if (set_parent_node($2, $$))
1279 reparent_error(scanner, "stream_declaration");
1283 stream_declaration_begin:
1285 { push_scope(scanner); }
1288 stream_declaration_end:
1290 { pop_scope(scanner); }
1294 trace_declaration_begin trace_declaration_end
1296 $$ = make_node(scanner, NODE_TRACE);
1298 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1300 $$ = make_node(scanner, NODE_TRACE);
1301 if (set_parent_node($2, $$))
1302 reparent_error(scanner, "trace_declaration");
1306 trace_declaration_begin:
1308 { push_scope(scanner); }
1311 trace_declaration_end:
1313 { pop_scope(scanner); }
1317 CLOCK clock_declaration_begin clock_declaration_end
1319 $$ = make_node(scanner, NODE_CLOCK);
1321 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1323 $$ = make_node(scanner, NODE_CLOCK);
1324 if (set_parent_node($3, $$))
1325 reparent_error(scanner, "trace_declaration");
1329 clock_declaration_begin:
1331 { push_scope(scanner); }
1334 clock_declaration_end:
1336 { pop_scope(scanner); }
1339 integer_declaration_specifiers:
1342 struct ctf_node *node;
1344 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1345 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1346 node->u.type_specifier.type = TYPESPEC_CONST;
1347 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1349 | integer_type_specifier
1351 struct ctf_node *node;
1353 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1355 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1357 | integer_declaration_specifiers CONST
1359 struct ctf_node *node;
1362 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1363 node->u.type_specifier.type = TYPESPEC_CONST;
1364 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1366 | integer_declaration_specifiers integer_type_specifier
1369 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1373 declaration_specifiers:
1376 struct ctf_node *node;
1378 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1379 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1380 node->u.type_specifier.type = TYPESPEC_CONST;
1381 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1385 struct ctf_node *node;
1387 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1389 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1391 | declaration_specifiers CONST
1393 struct ctf_node *node;
1396 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1397 node->u.type_specifier.type = TYPESPEC_CONST;
1398 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1400 | declaration_specifiers type_specifier
1403 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1407 type_declarator_list:
1410 | type_declarator_list COMMA type_declarator
1413 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1417 integer_type_specifier:
1420 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1421 $$->u.type_specifier.type = TYPESPEC_CHAR;
1425 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1426 $$->u.type_specifier.type = TYPESPEC_SHORT;
1430 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1431 $$->u.type_specifier.type = TYPESPEC_INT;
1435 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1436 $$->u.type_specifier.type = TYPESPEC_LONG;
1440 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1441 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1445 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1446 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1450 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1451 $$->u.type_specifier.type = TYPESPEC_BOOL;
1455 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1456 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1457 $$->u.type_specifier.id_type = yylval.gs->s;
1459 | INTEGER LBRAC RBRAC
1461 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1462 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1463 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1465 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1467 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1468 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1469 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1470 if (set_parent_node($3, $$->u.type_specifier.node))
1471 reparent_error(scanner, "integer reparent error");
1478 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1479 $$->u.type_specifier.type = TYPESPEC_VOID;
1483 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1484 $$->u.type_specifier.type = TYPESPEC_CHAR;
1488 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1489 $$->u.type_specifier.type = TYPESPEC_SHORT;
1493 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1494 $$->u.type_specifier.type = TYPESPEC_INT;
1498 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1499 $$->u.type_specifier.type = TYPESPEC_LONG;
1503 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1504 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1508 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1509 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1513 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1514 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1518 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1519 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1523 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1524 $$->u.type_specifier.type = TYPESPEC_BOOL;
1528 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1529 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1533 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1534 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1538 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1539 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1540 $$->u.type_specifier.id_type = yylval.gs->s;
1542 | FLOATING_POINT LBRAC RBRAC
1544 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1545 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1546 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1548 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1550 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1551 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1552 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1553 if (set_parent_node($3, $$->u.type_specifier.node))
1554 reparent_error(scanner, "floating point reparent error");
1556 | INTEGER LBRAC RBRAC
1558 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1559 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1560 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1562 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1564 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1565 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1566 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1567 if (set_parent_node($3, $$->u.type_specifier.node))
1568 reparent_error(scanner, "integer reparent error");
1572 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1573 $$->u.type_specifier.type = TYPESPEC_STRING;
1574 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1576 | STRING LBRAC RBRAC
1578 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1579 $$->u.type_specifier.type = TYPESPEC_STRING;
1580 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1582 | STRING LBRAC ctf_assignment_expression_list RBRAC
1584 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1585 $$->u.type_specifier.type = TYPESPEC_STRING;
1586 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1587 if (set_parent_node($3, $$->u.type_specifier.node))
1588 reparent_error(scanner, "string reparent error");
1590 | ENUM enum_type_specifier
1592 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1593 $$->u.type_specifier.type = TYPESPEC_ENUM;
1594 $$->u.type_specifier.node = $2;
1596 | VARIANT variant_type_specifier
1598 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1599 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1600 $$->u.type_specifier.node = $2;
1602 | STRUCT struct_type_specifier
1604 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1605 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1606 $$->u.type_specifier.node = $2;
1610 struct_type_specifier:
1611 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1613 $$ = make_node(scanner, NODE_STRUCT);
1614 $$->u._struct.has_body = 1;
1615 if ($2 && set_parent_node($2, $$))
1616 reparent_error(scanner, "struct reparent error");
1618 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1620 $$ = make_node(scanner, NODE_STRUCT);
1621 $$->u._struct.has_body = 1;
1622 $$->u._struct.name = $1->s;
1623 if ($3 && set_parent_node($3, $$))
1624 reparent_error(scanner, "struct reparent error");
1626 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1628 $$ = make_node(scanner, NODE_STRUCT);
1629 $$->u._struct.has_body = 1;
1630 $$->u._struct.name = $1->s;
1631 if ($3 && set_parent_node($3, $$))
1632 reparent_error(scanner, "struct reparent error");
1636 $$ = make_node(scanner, NODE_STRUCT);
1637 $$->u._struct.has_body = 0;
1638 $$->u._struct.name = $1->s;
1642 $$ = make_node(scanner, NODE_STRUCT);
1643 $$->u._struct.has_body = 0;
1644 $$->u._struct.name = $1->s;
1646 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1648 $$ = make_node(scanner, NODE_STRUCT);
1649 $$->u._struct.has_body = 1;
1650 cds_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1651 if ($2 && set_parent_node($2, $$))
1652 reparent_error(scanner, "struct reparent error");
1654 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1656 $$ = make_node(scanner, NODE_STRUCT);
1657 $$->u._struct.has_body = 1;
1658 $$->u._struct.name = $1->s;
1659 cds_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1660 if ($3 && set_parent_node($3, $$))
1661 reparent_error(scanner, "struct reparent error");
1663 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1665 $$ = make_node(scanner, NODE_STRUCT);
1666 $$->u._struct.has_body = 1;
1667 $$->u._struct.name = $1->s;
1668 cds_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1669 if ($3 && set_parent_node($3, $$))
1670 reparent_error(scanner, "struct reparent error");
1674 struct_declaration_begin:
1676 { push_scope(scanner); }
1679 struct_declaration_end:
1681 { pop_scope(scanner); }
1684 variant_type_specifier:
1685 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1687 $$ = make_node(scanner, NODE_VARIANT);
1688 $$->u.variant.has_body = 1;
1689 if ($2 && set_parent_node($2, $$))
1690 reparent_error(scanner, "variant reparent error");
1692 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1694 $$ = make_node(scanner, NODE_VARIANT);
1695 $$->u.variant.has_body = 1;
1696 $$->u.variant.choice = $2->s;
1697 if ($5 && set_parent_node($5, $$))
1698 reparent_error(scanner, "variant reparent error");
1700 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1702 $$ = make_node(scanner, NODE_VARIANT);
1703 $$->u.variant.has_body = 1;
1704 $$->u.variant.choice = $2->s;
1705 if ($5 && set_parent_node($5, $$))
1706 reparent_error(scanner, "variant reparent error");
1708 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1710 $$ = make_node(scanner, NODE_VARIANT);
1711 $$->u.variant.has_body = 1;
1712 $$->u.variant.name = $1->s;
1713 if ($3 && set_parent_node($3, $$))
1714 reparent_error(scanner, "variant reparent error");
1716 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1718 $$ = make_node(scanner, NODE_VARIANT);
1719 $$->u.variant.has_body = 1;
1720 $$->u.variant.name = $1->s;
1721 $$->u.variant.choice = $3->s;
1722 if ($6 && set_parent_node($6, $$))
1723 reparent_error(scanner, "variant reparent error");
1725 | IDENTIFIER LT IDENTIFIER GT
1727 $$ = make_node(scanner, NODE_VARIANT);
1728 $$->u.variant.has_body = 0;
1729 $$->u.variant.name = $1->s;
1730 $$->u.variant.choice = $3->s;
1732 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1734 $$ = make_node(scanner, NODE_VARIANT);
1735 $$->u.variant.has_body = 1;
1736 $$->u.variant.name = $1->s;
1737 $$->u.variant.choice = $3->s;
1738 if ($6 && set_parent_node($6, $$))
1739 reparent_error(scanner, "variant reparent error");
1741 | IDENTIFIER LT ID_TYPE GT
1743 $$ = make_node(scanner, NODE_VARIANT);
1744 $$->u.variant.has_body = 0;
1745 $$->u.variant.name = $1->s;
1746 $$->u.variant.choice = $3->s;
1748 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1750 $$ = make_node(scanner, NODE_VARIANT);
1751 $$->u.variant.has_body = 1;
1752 $$->u.variant.name = $1->s;
1753 if ($3 && set_parent_node($3, $$))
1754 reparent_error(scanner, "variant reparent error");
1756 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1758 $$ = make_node(scanner, NODE_VARIANT);
1759 $$->u.variant.has_body = 1;
1760 $$->u.variant.name = $1->s;
1761 $$->u.variant.choice = $3->s;
1762 if ($6 && set_parent_node($6, $$))
1763 reparent_error(scanner, "variant reparent error");
1765 | ID_TYPE LT IDENTIFIER GT
1767 $$ = make_node(scanner, NODE_VARIANT);
1768 $$->u.variant.has_body = 0;
1769 $$->u.variant.name = $1->s;
1770 $$->u.variant.choice = $3->s;
1772 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1774 $$ = make_node(scanner, NODE_VARIANT);
1775 $$->u.variant.has_body = 1;
1776 $$->u.variant.name = $1->s;
1777 $$->u.variant.choice = $3->s;
1778 if ($6 && set_parent_node($6, $$))
1779 reparent_error(scanner, "variant reparent error");
1781 | ID_TYPE LT ID_TYPE GT
1783 $$ = make_node(scanner, NODE_VARIANT);
1784 $$->u.variant.has_body = 0;
1785 $$->u.variant.name = $1->s;
1786 $$->u.variant.choice = $3->s;
1790 variant_declaration_begin:
1792 { push_scope(scanner); }
1795 variant_declaration_end:
1797 { pop_scope(scanner); }
1800 enum_type_specifier:
1801 LBRAC enumerator_list RBRAC
1803 $$ = make_node(scanner, NODE_ENUM);
1804 $$->u._enum.has_body = 1;
1805 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1807 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1809 $$ = make_node(scanner, NODE_ENUM);
1810 $$->u._enum.has_body = 1;
1811 ($$)->u._enum.container_type = $2;
1812 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1814 | IDENTIFIER LBRAC enumerator_list RBRAC
1816 $$ = make_node(scanner, NODE_ENUM);
1817 $$->u._enum.has_body = 1;
1818 $$->u._enum.enum_id = $1->s;
1819 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1821 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1823 $$ = make_node(scanner, NODE_ENUM);
1824 $$->u._enum.has_body = 1;
1825 $$->u._enum.enum_id = $1->s;
1826 ($$)->u._enum.container_type = $3;
1827 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1829 | ID_TYPE LBRAC enumerator_list 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 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);
1844 | LBRAC enumerator_list COMMA RBRAC
1846 $$ = make_node(scanner, NODE_ENUM);
1847 $$->u._enum.has_body = 1;
1848 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1850 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1852 $$ = make_node(scanner, NODE_ENUM);
1853 $$->u._enum.has_body = 1;
1854 ($$)->u._enum.container_type = $2;
1855 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1857 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1859 $$ = make_node(scanner, NODE_ENUM);
1860 $$->u._enum.has_body = 1;
1861 $$->u._enum.enum_id = $1->s;
1862 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1864 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1866 $$ = make_node(scanner, NODE_ENUM);
1867 $$->u._enum.has_body = 1;
1868 $$->u._enum.enum_id = $1->s;
1869 ($$)->u._enum.container_type = $3;
1870 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1874 $$ = make_node(scanner, NODE_ENUM);
1875 $$->u._enum.has_body = 0;
1876 $$->u._enum.enum_id = $1->s;
1878 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1880 $$ = make_node(scanner, NODE_ENUM);
1881 $$->u._enum.has_body = 1;
1882 $$->u._enum.enum_id = $1->s;
1883 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1885 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1887 $$ = make_node(scanner, NODE_ENUM);
1888 $$->u._enum.has_body = 1;
1889 $$->u._enum.enum_id = $1->s;
1890 ($$)->u._enum.container_type = $3;
1891 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1895 $$ = make_node(scanner, NODE_ENUM);
1896 $$->u._enum.has_body = 0;
1897 $$->u._enum.enum_id = $1->s;
1901 struct_or_variant_declaration_list:
1904 | struct_or_variant_declaration_list struct_or_variant_declaration
1908 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1911 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1916 struct_or_variant_declaration:
1917 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
1919 struct ctf_node *list;
1921 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1922 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1923 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1924 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1925 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
1927 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1929 struct ctf_node *list;
1931 $$ = make_node(scanner, NODE_TYPEDEF);
1932 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1933 $$->u._typedef.type_specifier_list = list;
1934 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1935 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1936 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1938 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1940 struct ctf_node *list;
1942 $$ = make_node(scanner, NODE_TYPEDEF);
1943 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1944 $$->u._typedef.type_specifier_list = list;
1945 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1946 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1948 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1950 struct ctf_node *list;
1952 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1953 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1954 $$ = make_node(scanner, NODE_TYPEDEF);
1955 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1956 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1958 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1960 struct ctf_node *list;
1962 $$ = make_node(scanner, NODE_TYPEALIAS);
1963 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1964 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1966 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1967 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1968 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1969 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1971 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1972 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1973 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1974 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1978 alias_declaration_specifiers:
1981 struct ctf_node *node;
1983 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1984 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1985 node->u.type_specifier.type = TYPESPEC_CONST;
1986 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1990 struct ctf_node *node;
1992 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1994 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1998 struct ctf_node *node;
2000 add_type(scanner, $1);
2001 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2002 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2003 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2004 node->u.type_specifier.id_type = yylval.gs->s;
2005 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2007 | alias_declaration_specifiers CONST
2009 struct ctf_node *node;
2012 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2013 node->u.type_specifier.type = TYPESPEC_CONST;
2014 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2016 | alias_declaration_specifiers type_specifier
2019 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2021 | alias_declaration_specifiers IDENTIFIER
2023 struct ctf_node *node;
2025 add_type(scanner, $2);
2027 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2028 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2029 node->u.type_specifier.id_type = yylval.gs->s;
2030 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2034 struct_or_variant_declarator_list:
2035 struct_or_variant_declarator
2037 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2040 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2044 struct_or_variant_declarator:
2047 | COLON unary_expression
2049 | declarator COLON unary_expression
2052 if (set_parent_node($3, $1))
2053 reparent_error(scanner, "struct_or_variant_declarator");
2060 | enumerator_list COMMA enumerator
2063 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2070 $$ = make_node(scanner, NODE_ENUMERATOR);
2071 $$->u.enumerator.id = $1->s;
2075 $$ = make_node(scanner, NODE_ENUMERATOR);
2076 $$->u.enumerator.id = $1->s;
2080 $$ = make_node(scanner, NODE_ENUMERATOR);
2081 $$->u.enumerator.id = $1->s;
2083 | STRING_LITERAL_START DQUOTE
2085 $$ = make_node(scanner, NODE_ENUMERATOR);
2086 $$->u.enumerator.id = "";
2088 | STRING_LITERAL_START s_char_sequence DQUOTE
2090 $$ = make_node(scanner, NODE_ENUMERATOR);
2091 $$->u.enumerator.id = $2->s;
2093 | IDENTIFIER EQUAL unary_expression_or_range
2095 $$ = make_node(scanner, NODE_ENUMERATOR);
2096 $$->u.enumerator.id = $1->s;
2097 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2099 | ID_TYPE EQUAL unary_expression_or_range
2101 $$ = make_node(scanner, NODE_ENUMERATOR);
2102 $$->u.enumerator.id = $1->s;
2103 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2105 | keywords EQUAL unary_expression_or_range
2107 $$ = make_node(scanner, NODE_ENUMERATOR);
2108 $$->u.enumerator.id = $1->s;
2109 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2111 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
2113 $$ = make_node(scanner, NODE_ENUMERATOR);
2114 $$->u.enumerator.id = "";
2115 cds_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
2117 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
2119 $$ = make_node(scanner, NODE_ENUMERATOR);
2120 $$->u.enumerator.id = $2->s;
2121 cds_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
2125 abstract_declarator_list:
2128 | abstract_declarator_list COMMA abstract_declarator
2131 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2135 abstract_declarator:
2136 direct_abstract_declarator
2138 | pointer direct_abstract_declarator
2141 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2145 direct_abstract_declarator:
2148 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2149 $$->u.type_declarator.type = TYPEDEC_ID;
2154 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2155 $$->u.type_declarator.type = TYPEDEC_ID;
2156 $$->u.type_declarator.u.id = $1->s;
2158 | LPAREN abstract_declarator RPAREN
2160 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2161 $$->u.type_declarator.type = TYPEDEC_NESTED;
2162 $$->u.type_declarator.u.nested.type_declarator = $2;
2164 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2166 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2167 $$->u.type_declarator.type = TYPEDEC_NESTED;
2168 $$->u.type_declarator.u.nested.type_declarator = $1;
2169 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2170 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2172 | direct_abstract_declarator LSBRAC RSBRAC
2174 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2175 $$->u.type_declarator.type = TYPEDEC_NESTED;
2176 $$->u.type_declarator.u.nested.type_declarator = $1;
2177 $$->u.type_declarator.u.nested.abstract_array = 1;
2181 alias_abstract_declarator_list:
2182 alias_abstract_declarator
2184 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2187 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2191 alias_abstract_declarator:
2192 direct_alias_abstract_declarator
2194 | pointer direct_alias_abstract_declarator
2197 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2201 direct_alias_abstract_declarator:
2204 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2205 $$->u.type_declarator.type = TYPEDEC_ID;
2208 | LPAREN alias_abstract_declarator RPAREN
2210 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2211 $$->u.type_declarator.type = TYPEDEC_NESTED;
2212 $$->u.type_declarator.u.nested.type_declarator = $2;
2214 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2216 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2217 $$->u.type_declarator.type = TYPEDEC_NESTED;
2218 $$->u.type_declarator.u.nested.type_declarator = $1;
2219 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2220 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2222 | direct_alias_abstract_declarator LSBRAC RSBRAC
2224 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2225 $$->u.type_declarator.type = TYPEDEC_NESTED;
2226 $$->u.type_declarator.u.nested.type_declarator = $1;
2227 $$->u.type_declarator.u.nested.abstract_array = 1;
2234 | pointer direct_declarator
2237 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2244 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2245 $$->u.type_declarator.type = TYPEDEC_ID;
2246 $$->u.type_declarator.u.id = $1->s;
2248 | LPAREN declarator RPAREN
2250 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2251 $$->u.type_declarator.type = TYPEDEC_NESTED;
2252 $$->u.type_declarator.u.nested.type_declarator = $2;
2254 | direct_declarator LSBRAC unary_expression RSBRAC
2256 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2257 $$->u.type_declarator.type = TYPEDEC_NESTED;
2258 $$->u.type_declarator.u.nested.type_declarator = $1;
2259 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2260 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2265 direct_type_declarator
2267 | pointer direct_type_declarator
2270 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2274 direct_type_declarator:
2277 add_type(scanner, $1);
2278 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2279 $$->u.type_declarator.type = TYPEDEC_ID;
2280 $$->u.type_declarator.u.id = $1->s;
2282 | LPAREN type_declarator RPAREN
2284 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2285 $$->u.type_declarator.type = TYPEDEC_NESTED;
2286 $$->u.type_declarator.u.nested.type_declarator = $2;
2288 | direct_type_declarator LSBRAC unary_expression RSBRAC
2290 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2291 $$->u.type_declarator.type = TYPEDEC_NESTED;
2292 $$->u.type_declarator.u.nested.type_declarator = $1;
2293 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2294 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2301 $$ = make_node(scanner, NODE_POINTER);
2305 $$ = make_node(scanner, NODE_POINTER);
2306 cds_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2308 | STAR type_qualifier_list pointer
2310 $$ = make_node(scanner, NODE_POINTER);
2311 $$->u.pointer.const_qualifier = 1;
2312 cds_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2316 type_qualifier_list:
2317 /* pointer assumes only const type qualifier */
2319 | type_qualifier_list CONST
2322 /* 2.3: CTF-specific declarations */
2324 ctf_assignment_expression_list:
2325 ctf_assignment_expression SEMICOLON
2327 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2330 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2334 ctf_assignment_expression:
2335 unary_expression EQUAL unary_expression
2338 * Because we have left and right, cannot use
2341 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2342 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2343 if ($1->u.unary_expression.type != UNARY_STRING)
2344 reparent_error(scanner, "ctf_assignment_expression left expects string");
2345 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2347 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2350 * Because we have left and right, cannot use
2353 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2354 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2355 if ($1->u.unary_expression.type != UNARY_STRING)
2356 reparent_error(scanner, "ctf_assignment_expression left expects string");
2357 cds_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2359 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2361 struct ctf_node *list;
2363 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2364 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2365 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2366 $$ = make_node(scanner, NODE_TYPEDEF);
2367 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2368 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2370 | TYPEDEF declaration_specifiers type_declarator_list
2372 struct ctf_node *list;
2374 $$ = make_node(scanner, NODE_TYPEDEF);
2375 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2376 $$->u._typedef.type_specifier_list = list;
2377 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2378 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2380 | declaration_specifiers TYPEDEF type_declarator_list
2382 struct ctf_node *list;
2384 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2385 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2386 $$ = make_node(scanner, NODE_TYPEDEF);
2387 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2388 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2390 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2392 struct ctf_node *list;
2394 $$ = make_node(scanner, NODE_TYPEALIAS);
2395 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2396 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2398 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2399 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2400 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2401 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2403 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2404 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2405 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2406 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);