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_ENV ] = "NODE_ENV",
68 [ NODE_STREAM ] = "NODE_STREAM",
69 [ NODE_TRACE ] = "NODE_TRACE",
70 [ NODE_CLOCK ] = "NODE_CLOCK",
71 [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
72 [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
73 [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
74 [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
75 [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
76 [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
77 [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
78 [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
79 [ NODE_POINTER ] = "NODE_POINTER",
80 [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
81 [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
82 [ NODE_INTEGER ] = "NODE_INTEGER",
83 [ NODE_STRING ] = "NODE_STRING",
84 [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
85 [ NODE_ENUM ] = "NODE_ENUM",
86 [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
87 [ NODE_VARIANT ] = "NODE_VARIANT",
88 [ NODE_STRUCT ] = "NODE_STRUCT",
91 const char *node_type(struct ctf_node *node)
93 if (node->type < NR_NODE_TYPES)
94 return node_type_to_str[node->type];
99 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
102 struct gc_string *gstr;
105 /* TODO: could be faster with find first bit or glib Gstring */
106 /* sizeof long to account for malloc header (int or long ?) */
107 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
110 gstr = malloc(alloclen);
111 cds_list_add(&gstr->gc, &scanner->allocated_strings);
112 gstr->alloclen = alloclen;
117 * note: never use gc_string_append on a string that has external references.
118 * gsrc will be garbage collected immediately, and gstr might be.
119 * Should only be used to append characters to a string literal or constant.
121 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
122 struct gc_string *gstr,
123 struct gc_string *gsrc)
125 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
128 /* TODO: could be faster with find first bit or glib Gstring */
129 /* sizeof long to account for malloc header (int or long ?) */
130 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
133 if (alloclen > gstr->alloclen) {
134 struct gc_string *newgstr;
136 newgstr = gc_string_alloc(scanner, newlen);
137 strcpy(newgstr->s, gstr->s);
138 strcat(newgstr->s, gsrc->s);
139 cds_list_del(&gstr->gc);
143 strcat(gstr->s, gsrc->s);
145 cds_list_del(&gsrc->gc);
150 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
152 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
153 strcpy(lvalp->gs->s, src);
156 static void init_scope(struct ctf_scanner_scope *scope,
157 struct ctf_scanner_scope *parent)
159 scope->parent = parent;
160 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
164 static void finalize_scope(struct ctf_scanner_scope *scope)
166 g_hash_table_destroy(scope->types);
169 static void push_scope(struct ctf_scanner *scanner)
171 struct ctf_scanner_scope *ns;
173 printf_debug("push scope\n");
174 ns = malloc(sizeof(struct ctf_scanner_scope));
175 init_scope(ns, scanner->cs);
179 static void pop_scope(struct ctf_scanner *scanner)
181 struct ctf_scanner_scope *os;
183 printf_debug("pop scope\n");
185 scanner->cs = os->parent;
190 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
194 ret = (int) (long) g_hash_table_lookup(s->types, id);
195 printf_debug("lookup %p %s %d\n", s, id, ret);
199 int is_type(struct ctf_scanner *scanner, const char *id)
201 struct ctf_scanner_scope *it;
204 for (it = scanner->cs; it != NULL; it = it->parent) {
205 if (lookup_type(it, id)) {
210 printf_debug("is type %s %d\n", id, ret);
214 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
216 printf_debug("add type %s\n", id->s);
217 if (lookup_type(scanner->cs, id->s))
219 g_hash_table_insert(scanner->cs->types, id->s, id->s);
222 static struct ctf_node *make_node(struct ctf_scanner *scanner,
225 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
226 struct ctf_node *node;
228 node = malloc(sizeof(*node));
231 memset(node, 0, sizeof(*node));
233 CDS_INIT_LIST_HEAD(&node->tmp_head);
234 cds_list_add(&node->gc, &ast->allocated_nodes);
235 cds_list_add(&node->siblings, &node->tmp_head);
239 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
243 CDS_INIT_LIST_HEAD(&node->u.event.declaration_list);
246 CDS_INIT_LIST_HEAD(&node->u.stream.declaration_list);
249 CDS_INIT_LIST_HEAD(&node->u.env.declaration_list);
252 CDS_INIT_LIST_HEAD(&node->u.trace.declaration_list);
255 CDS_INIT_LIST_HEAD(&node->u.clock.declaration_list);
258 case NODE_CTF_EXPRESSION:
259 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.left);
260 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.right);
262 case NODE_UNARY_EXPRESSION:
266 CDS_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
268 case NODE_TYPEALIAS_TARGET:
269 CDS_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
271 case NODE_TYPEALIAS_ALIAS:
272 CDS_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
277 case NODE_TYPE_SPECIFIER:
279 case NODE_TYPE_SPECIFIER_LIST:
280 CDS_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
284 case NODE_TYPE_DECLARATOR:
285 CDS_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
288 case NODE_FLOATING_POINT:
289 CDS_INIT_LIST_HEAD(&node->u.floating_point.expressions);
292 CDS_INIT_LIST_HEAD(&node->u.integer.expressions);
295 CDS_INIT_LIST_HEAD(&node->u.string.expressions);
297 case NODE_ENUMERATOR:
298 CDS_INIT_LIST_HEAD(&node->u.enumerator.values);
301 CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
303 case NODE_STRUCT_OR_VARIANT_DECLARATION:
304 CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
307 CDS_INIT_LIST_HEAD(&node->u.variant.declaration_list);
310 CDS_INIT_LIST_HEAD(&node->u._struct.declaration_list);
311 CDS_INIT_LIST_HEAD(&node->u._struct.min_align);
316 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
324 static int reparent_ctf_expression(struct ctf_node *node,
325 struct ctf_node *parent)
327 switch (parent->type) {
329 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
332 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
335 _cds_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
338 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
341 _cds_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
343 case NODE_FLOATING_POINT:
344 _cds_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
347 _cds_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
350 _cds_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
354 case NODE_CTF_EXPRESSION:
356 case NODE_TYPEALIAS_TARGET:
357 case NODE_TYPEALIAS_ALIAS:
359 case NODE_TYPE_SPECIFIER:
360 case NODE_TYPE_SPECIFIER_LIST:
362 case NODE_TYPE_DECLARATOR:
363 case NODE_ENUMERATOR:
365 case NODE_STRUCT_OR_VARIANT_DECLARATION:
368 case NODE_UNARY_EXPRESSION:
373 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
380 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
382 switch (parent->type) {
384 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
387 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
390 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
393 _cds_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
396 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
399 _cds_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
402 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
405 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
408 case NODE_FLOATING_POINT:
411 case NODE_CTF_EXPRESSION:
413 case NODE_TYPEALIAS_TARGET:
414 case NODE_TYPEALIAS_ALIAS:
416 case NODE_TYPE_SPECIFIER:
417 case NODE_TYPE_SPECIFIER_LIST:
419 case NODE_TYPE_DECLARATOR:
420 case NODE_ENUMERATOR:
422 case NODE_STRUCT_OR_VARIANT_DECLARATION:
423 case NODE_UNARY_EXPRESSION:
428 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
435 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
437 switch (parent->type) {
439 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
442 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
445 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
448 _cds_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
451 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
454 _cds_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
457 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
460 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
463 case NODE_FLOATING_POINT:
466 case NODE_CTF_EXPRESSION:
468 case NODE_TYPEALIAS_TARGET:
469 case NODE_TYPEALIAS_ALIAS:
471 case NODE_TYPE_SPECIFIER:
472 case NODE_TYPE_SPECIFIER_LIST:
474 case NODE_TYPE_DECLARATOR:
475 case NODE_ENUMERATOR:
477 case NODE_STRUCT_OR_VARIANT_DECLARATION:
478 case NODE_UNARY_EXPRESSION:
483 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
490 static int reparent_type_specifier(struct ctf_node *node,
491 struct ctf_node *parent)
493 switch (parent->type) {
494 case NODE_TYPE_SPECIFIER_LIST:
495 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
498 case NODE_TYPE_SPECIFIER:
507 case NODE_TYPEALIAS_TARGET:
508 case NODE_TYPEALIAS_ALIAS:
509 case NODE_TYPE_DECLARATOR:
511 case NODE_STRUCT_OR_VARIANT_DECLARATION:
513 case NODE_FLOATING_POINT:
516 case NODE_CTF_EXPRESSION:
518 case NODE_ENUMERATOR:
519 case NODE_UNARY_EXPRESSION:
524 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
531 static int reparent_type_specifier_list(struct ctf_node *node,
532 struct ctf_node *parent)
534 switch (parent->type) {
536 cds_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
539 cds_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
542 cds_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
545 cds_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
548 cds_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
551 cds_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
554 cds_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
557 cds_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
560 parent->u._typedef.type_specifier_list = node;
562 case NODE_TYPEALIAS_TARGET:
563 parent->u.typealias_target.type_specifier_list = node;
565 case NODE_TYPEALIAS_ALIAS:
566 parent->u.typealias_alias.type_specifier_list = node;
569 parent->u._enum.container_type = node;
571 case NODE_STRUCT_OR_VARIANT_DECLARATION:
572 parent->u.struct_or_variant_declaration.type_specifier_list = node;
574 case NODE_TYPE_DECLARATOR:
575 case NODE_TYPE_SPECIFIER:
577 case NODE_FLOATING_POINT:
580 case NODE_CTF_EXPRESSION:
582 case NODE_ENUMERATOR:
583 case NODE_UNARY_EXPRESSION:
588 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
595 static int reparent_type_declarator(struct ctf_node *node,
596 struct ctf_node *parent)
598 switch (parent->type) {
599 case NODE_TYPE_DECLARATOR:
600 parent->u.type_declarator.type = TYPEDEC_NESTED;
601 parent->u.type_declarator.u.nested.type_declarator = node;
603 case NODE_STRUCT_OR_VARIANT_DECLARATION:
604 _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
607 _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
609 case NODE_TYPEALIAS_TARGET:
610 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
612 case NODE_TYPEALIAS_ALIAS:
613 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
626 case NODE_FLOATING_POINT:
629 case NODE_CTF_EXPRESSION:
630 case NODE_TYPE_SPECIFIER:
631 case NODE_TYPE_SPECIFIER_LIST:
633 case NODE_ENUMERATOR:
634 case NODE_UNARY_EXPRESSION:
639 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
649 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
650 * create the link declared by the input, -ENOENT if node or parent is NULL,
651 * -EINVAL if there is an internal structure problem.
653 static int set_parent_node(struct ctf_node *node,
654 struct ctf_node *parent)
656 if (!node || !parent)
659 /* Note: Linking to parent will be done only by an external visitor */
661 switch (node->type) {
663 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
667 if (parent->type == NODE_ROOT) {
668 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.event);
674 if (parent->type == NODE_ROOT) {
675 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
681 if (parent->type == NODE_ROOT) {
682 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.env);
688 if (parent->type == NODE_ROOT) {
689 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
695 if (parent->type == NODE_ROOT) {
696 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
702 case NODE_CTF_EXPRESSION:
703 return reparent_ctf_expression(node, parent);
704 case NODE_UNARY_EXPRESSION:
705 if (parent->type == NODE_TYPE_DECLARATOR)
706 parent->u.type_declarator.bitfield_len = node;
712 return reparent_typedef(node, parent);
713 case NODE_TYPEALIAS_TARGET:
714 if (parent->type == NODE_TYPEALIAS)
715 parent->u.typealias.target = node;
718 case NODE_TYPEALIAS_ALIAS:
719 if (parent->type == NODE_TYPEALIAS)
720 parent->u.typealias.alias = node;
724 return reparent_typealias(node, parent);
727 if (parent->type == NODE_TYPE_DECLARATOR) {
728 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
732 case NODE_TYPE_DECLARATOR:
733 return reparent_type_declarator(node, parent);
735 case NODE_TYPE_SPECIFIER_LIST:
736 return reparent_type_specifier_list(node, parent);
738 case NODE_TYPE_SPECIFIER:
739 return reparent_type_specifier(node, parent);
741 case NODE_FLOATING_POINT:
747 return -EINVAL; /* Dealt with internally within grammar */
749 case NODE_ENUMERATOR:
750 if (parent->type == NODE_ENUM) {
751 _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
756 case NODE_STRUCT_OR_VARIANT_DECLARATION:
757 switch (parent->type) {
759 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
762 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
771 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
778 void yyerror(struct ctf_scanner *scanner, const char *str)
780 fprintf(stderr, "error %s\n", str);
788 #define reparent_error(scanner, str) \
790 yyerror(scanner, YY_("reparent_error: " str "\n")); \
794 static void free_strings(struct cds_list_head *list)
796 struct gc_string *gstr, *tmp;
798 cds_list_for_each_entry_safe(gstr, tmp, list, gc)
802 static struct ctf_ast *ctf_ast_alloc(void)
806 ast = malloc(sizeof(*ast));
809 memset(ast, 0, sizeof(*ast));
810 CDS_INIT_LIST_HEAD(&ast->allocated_nodes);
811 ast->root.type = NODE_ROOT;
812 CDS_INIT_LIST_HEAD(&ast->root.tmp_head);
813 CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
814 CDS_INIT_LIST_HEAD(&ast->root.u.root.trace);
815 CDS_INIT_LIST_HEAD(&ast->root.u.root.env);
816 CDS_INIT_LIST_HEAD(&ast->root.u.root.stream);
817 CDS_INIT_LIST_HEAD(&ast->root.u.root.event);
818 CDS_INIT_LIST_HEAD(&ast->root.u.root.clock);
822 static void ctf_ast_free(struct ctf_ast *ast)
824 struct ctf_node *node, *tmp;
826 cds_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
830 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
832 return yyparse(scanner);
835 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
837 struct ctf_scanner *scanner;
840 yydebug = babeltrace_debug;
842 scanner = malloc(sizeof(*scanner));
845 memset(scanner, 0, sizeof(*scanner));
847 ret = yylex_init_extra(scanner, &scanner->scanner);
849 fprintf(stderr, "yylex_init error\n");
850 goto cleanup_scanner;
852 /* Start processing new stream */
853 yyrestart(input, scanner->scanner);
855 scanner->ast = ctf_ast_alloc();
858 init_scope(&scanner->root_scope, NULL);
859 scanner->cs = &scanner->root_scope;
860 CDS_INIT_LIST_HEAD(&scanner->allocated_strings);
863 fprintf(stdout, "Scanner input is a%s.\n",
864 isatty(fileno(input)) ? "n interactive tty" :
865 " noninteractive file");
870 ret = yylex_destroy(scanner->scanner);
872 fprintf(stderr, "yylex_destroy error\n");
878 void ctf_scanner_free(struct ctf_scanner *scanner)
882 finalize_scope(&scanner->root_scope);
883 free_strings(&scanner->allocated_strings);
884 ctf_ast_free(scanner->ast);
885 ret = yylex_destroy(scanner->scanner);
887 fprintf(stderr, "yylex_destroy error\n");
895 %parse-param {struct ctf_scanner *scanner}
896 %lex-param {struct ctf_scanner *scanner}
898 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
899 * vs struct { int :value; } (unnamed bit-field). The default is to
900 * shift, so whenever we encounter an enumeration, we are doing the
901 * proper thing (shift). It is illegal to declare an enumeration
902 * "bit-field", so it is OK if this situation ends up in a parsing
907 %token CHARACTER_CONSTANT_START SQUOTE STRING_LITERAL_START DQUOTE ESCSEQ CHAR_STRING_TOKEN LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM ENV EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT TOK_ALIGN
908 %token <gs> IDENTIFIER ID_TYPE
914 struct gc_string *gs;
919 %type <gs> s_char s_char_sequence c_char c_char_sequence
921 %type <n> postfix_expression unary_expression unary_expression_or_range
923 %type <n> declaration
924 %type <n> event_declaration
925 %type <n> stream_declaration
926 %type <n> env_declaration
927 %type <n> trace_declaration
928 %type <n> clock_declaration
929 %type <n> integer_declaration_specifiers
930 %type <n> declaration_specifiers
931 %type <n> alias_declaration_specifiers
933 %type <n> type_declarator_list
934 %type <n> integer_type_specifier
935 %type <n> type_specifier
936 %type <n> struct_type_specifier
937 %type <n> variant_type_specifier
938 %type <n> enum_type_specifier
939 %type <n> struct_or_variant_declaration_list
940 %type <n> struct_or_variant_declaration
941 %type <n> struct_or_variant_declarator_list
942 %type <n> struct_or_variant_declarator
943 %type <n> enumerator_list
945 %type <n> abstract_declarator_list
946 %type <n> abstract_declarator
947 %type <n> direct_abstract_declarator
948 %type <n> alias_abstract_declarator_list
949 %type <n> alias_abstract_declarator
950 %type <n> direct_alias_abstract_declarator
952 %type <n> direct_declarator
953 %type <n> type_declarator
954 %type <n> direct_type_declarator
956 %type <n> ctf_assignment_expression_list
957 %type <n> ctf_assignment_expression
964 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
965 reparent_error(scanner, "error reparenting to root");
969 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
970 reparent_error(scanner, "error reparenting to root");
1032 | c_char_sequence c_char
1033 { $$ = gc_string_append(scanner, $1, $2); }
1041 reparent_error(scanner, "escape sequences not supported yet");
1045 /* 1.6 String literals */
1050 | s_char_sequence s_char
1051 { $$ = gc_string_append(scanner, $1, $2); }
1059 reparent_error(scanner, "escape sequences not supported yet");
1063 /* 2: Phrase structure grammar */
1068 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1069 $$->u.unary_expression.type = UNARY_STRING;
1070 $$->u.unary_expression.u.string = yylval.gs->s;
1074 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1075 $$->u.unary_expression.type = UNARY_STRING;
1076 $$->u.unary_expression.u.string = yylval.gs->s;
1080 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1081 $$->u.unary_expression.type = UNARY_STRING;
1082 $$->u.unary_expression.u.string = yylval.gs->s;
1086 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1087 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1088 sscanf(yylval.gs->s, "%" PRIu64,
1089 &$$->u.unary_expression.u.unsigned_constant);
1093 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1094 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1095 sscanf(yylval.gs->s, "0%" PRIo64,
1096 &$$->u.unary_expression.u.unsigned_constant);
1098 | HEXADECIMAL_CONSTANT
1100 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1101 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1102 sscanf(yylval.gs->s, "0x%" PRIx64,
1103 &$$->u.unary_expression.u.unsigned_constant);
1105 | STRING_LITERAL_START DQUOTE
1107 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1108 $$->u.unary_expression.type = UNARY_STRING;
1109 $$->u.unary_expression.u.string = "";
1111 | STRING_LITERAL_START s_char_sequence DQUOTE
1113 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1114 $$->u.unary_expression.type = UNARY_STRING;
1115 $$->u.unary_expression.u.string = $2->s;
1117 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1119 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1120 $$->u.unary_expression.type = UNARY_STRING;
1121 $$->u.unary_expression.u.string = $2->s;
1123 | LPAREN unary_expression RPAREN
1125 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1126 $$->u.unary_expression.type = UNARY_NESTED;
1127 $$->u.unary_expression.u.nested_exp = $2;
1129 | postfix_expression LSBRAC unary_expression RSBRAC
1131 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1132 $$->u.unary_expression.type = UNARY_SBRAC;
1133 $$->u.unary_expression.u.sbrac_exp = $3;
1134 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1135 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1137 | postfix_expression DOT IDENTIFIER
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_DOTLINK;
1143 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1144 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1146 | postfix_expression DOT ID_TYPE
1148 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1149 $$->u.unary_expression.type = UNARY_STRING;
1150 $$->u.unary_expression.u.string = yylval.gs->s;
1151 $$->u.unary_expression.link = UNARY_DOTLINK;
1152 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1153 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1155 | postfix_expression RARROW IDENTIFIER
1157 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1158 $$->u.unary_expression.type = UNARY_STRING;
1159 $$->u.unary_expression.u.string = yylval.gs->s;
1160 $$->u.unary_expression.link = UNARY_ARROWLINK;
1161 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1162 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1164 | postfix_expression RARROW ID_TYPE
1166 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1167 $$->u.unary_expression.type = UNARY_STRING;
1168 $$->u.unary_expression.u.string = yylval.gs->s;
1169 $$->u.unary_expression.link = UNARY_ARROWLINK;
1170 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1171 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1178 | PLUS postfix_expression
1180 | MINUS postfix_expression
1183 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1184 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1185 reparent_error(scanner, "expecting numeric constant");
1187 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1188 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1189 $$->u.unary_expression.u.signed_constant =
1190 -($$->u.unary_expression.u.unsigned_constant);
1192 $$->u.unary_expression.u.signed_constant =
1193 -($$->u.unary_expression.u.signed_constant);
1198 unary_expression_or_range:
1199 unary_expression DOTDOTDOT unary_expression
1202 _cds_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1203 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1209 /* 2.2: Declarations */
1212 declaration_specifiers SEMICOLON
1216 | stream_declaration
1224 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1226 struct ctf_node *list;
1228 $$ = make_node(scanner, NODE_TYPEDEF);
1229 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1230 $$->u._typedef.type_specifier_list = list;
1231 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1232 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1233 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1235 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1237 struct ctf_node *list;
1239 $$ = make_node(scanner, NODE_TYPEDEF);
1240 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1241 $$->u._typedef.type_specifier_list = list;
1242 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1243 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1245 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1247 struct ctf_node *list;
1249 $$ = make_node(scanner, NODE_TYPEDEF);
1250 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1251 $$->u._typedef.type_specifier_list = list;
1252 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1253 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1255 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1257 struct ctf_node *list;
1259 $$ = make_node(scanner, NODE_TYPEALIAS);
1260 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1261 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1263 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1264 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1265 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1266 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1268 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1269 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1270 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1271 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1276 event_declaration_begin event_declaration_end
1278 $$ = make_node(scanner, NODE_EVENT);
1280 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1282 $$ = make_node(scanner, NODE_EVENT);
1283 if (set_parent_node($2, $$))
1284 reparent_error(scanner, "event_declaration");
1288 event_declaration_begin:
1290 { push_scope(scanner); }
1293 event_declaration_end:
1295 { pop_scope(scanner); }
1300 stream_declaration_begin stream_declaration_end
1302 $$ = make_node(scanner, NODE_STREAM);
1304 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1306 $$ = make_node(scanner, NODE_STREAM);
1307 if (set_parent_node($2, $$))
1308 reparent_error(scanner, "stream_declaration");
1312 stream_declaration_begin:
1314 { push_scope(scanner); }
1317 stream_declaration_end:
1319 { pop_scope(scanner); }
1323 env_declaration_begin env_declaration_end
1325 $$ = make_node(scanner, NODE_ENV);
1327 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1329 $$ = make_node(scanner, NODE_ENV);
1330 if (set_parent_node($2, $$))
1331 reparent_error(scanner, "env declaration");
1335 env_declaration_begin:
1337 { push_scope(scanner); }
1340 env_declaration_end:
1342 { pop_scope(scanner); }
1346 trace_declaration_begin trace_declaration_end
1348 $$ = make_node(scanner, NODE_TRACE);
1350 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1352 $$ = make_node(scanner, NODE_TRACE);
1353 if (set_parent_node($2, $$))
1354 reparent_error(scanner, "trace_declaration");
1358 trace_declaration_begin:
1360 { push_scope(scanner); }
1363 trace_declaration_end:
1365 { pop_scope(scanner); }
1369 CLOCK clock_declaration_begin clock_declaration_end
1371 $$ = make_node(scanner, NODE_CLOCK);
1373 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1375 $$ = make_node(scanner, NODE_CLOCK);
1376 if (set_parent_node($3, $$))
1377 reparent_error(scanner, "trace_declaration");
1381 clock_declaration_begin:
1383 { push_scope(scanner); }
1386 clock_declaration_end:
1388 { pop_scope(scanner); }
1391 integer_declaration_specifiers:
1394 struct ctf_node *node;
1396 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1397 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1398 node->u.type_specifier.type = TYPESPEC_CONST;
1399 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1401 | integer_type_specifier
1403 struct ctf_node *node;
1405 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1407 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1409 | integer_declaration_specifiers CONST
1411 struct ctf_node *node;
1414 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1415 node->u.type_specifier.type = TYPESPEC_CONST;
1416 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1418 | integer_declaration_specifiers integer_type_specifier
1421 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1425 declaration_specifiers:
1428 struct ctf_node *node;
1430 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1431 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1432 node->u.type_specifier.type = TYPESPEC_CONST;
1433 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1437 struct ctf_node *node;
1439 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1441 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1443 | declaration_specifiers CONST
1445 struct ctf_node *node;
1448 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1449 node->u.type_specifier.type = TYPESPEC_CONST;
1450 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1452 | declaration_specifiers type_specifier
1455 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1459 type_declarator_list:
1462 | type_declarator_list COMMA type_declarator
1465 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1469 integer_type_specifier:
1472 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1473 $$->u.type_specifier.type = TYPESPEC_CHAR;
1477 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1478 $$->u.type_specifier.type = TYPESPEC_SHORT;
1482 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1483 $$->u.type_specifier.type = TYPESPEC_INT;
1487 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1488 $$->u.type_specifier.type = TYPESPEC_LONG;
1492 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1493 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1497 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1498 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1502 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1503 $$->u.type_specifier.type = TYPESPEC_BOOL;
1507 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1508 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1509 $$->u.type_specifier.id_type = yylval.gs->s;
1511 | INTEGER LBRAC RBRAC
1513 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1514 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1515 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1517 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1519 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1520 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1521 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1522 if (set_parent_node($3, $$->u.type_specifier.node))
1523 reparent_error(scanner, "integer reparent error");
1530 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1531 $$->u.type_specifier.type = TYPESPEC_VOID;
1535 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1536 $$->u.type_specifier.type = TYPESPEC_CHAR;
1540 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1541 $$->u.type_specifier.type = TYPESPEC_SHORT;
1545 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1546 $$->u.type_specifier.type = TYPESPEC_INT;
1550 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1551 $$->u.type_specifier.type = TYPESPEC_LONG;
1555 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1556 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1560 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1561 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1565 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1566 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1570 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1571 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1575 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1576 $$->u.type_specifier.type = TYPESPEC_BOOL;
1580 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1581 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1585 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1586 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1590 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1591 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1592 $$->u.type_specifier.id_type = yylval.gs->s;
1594 | FLOATING_POINT LBRAC RBRAC
1596 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1597 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1598 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1600 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1602 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1603 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1604 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1605 if (set_parent_node($3, $$->u.type_specifier.node))
1606 reparent_error(scanner, "floating point reparent error");
1608 | INTEGER LBRAC RBRAC
1610 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1611 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1612 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1614 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1616 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1617 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1618 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1619 if (set_parent_node($3, $$->u.type_specifier.node))
1620 reparent_error(scanner, "integer reparent error");
1624 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1625 $$->u.type_specifier.type = TYPESPEC_STRING;
1626 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1628 | STRING LBRAC RBRAC
1630 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1631 $$->u.type_specifier.type = TYPESPEC_STRING;
1632 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1634 | STRING LBRAC ctf_assignment_expression_list RBRAC
1636 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1637 $$->u.type_specifier.type = TYPESPEC_STRING;
1638 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1639 if (set_parent_node($3, $$->u.type_specifier.node))
1640 reparent_error(scanner, "string reparent error");
1642 | ENUM enum_type_specifier
1644 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1645 $$->u.type_specifier.type = TYPESPEC_ENUM;
1646 $$->u.type_specifier.node = $2;
1648 | VARIANT variant_type_specifier
1650 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1651 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1652 $$->u.type_specifier.node = $2;
1654 | STRUCT struct_type_specifier
1656 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1657 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1658 $$->u.type_specifier.node = $2;
1662 struct_type_specifier:
1663 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1665 $$ = make_node(scanner, NODE_STRUCT);
1666 $$->u._struct.has_body = 1;
1667 if ($2 && set_parent_node($2, $$))
1668 reparent_error(scanner, "struct reparent error");
1670 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1672 $$ = make_node(scanner, NODE_STRUCT);
1673 $$->u._struct.has_body = 1;
1674 $$->u._struct.name = $1->s;
1675 if ($3 && set_parent_node($3, $$))
1676 reparent_error(scanner, "struct reparent error");
1678 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1680 $$ = make_node(scanner, NODE_STRUCT);
1681 $$->u._struct.has_body = 1;
1682 $$->u._struct.name = $1->s;
1683 if ($3 && set_parent_node($3, $$))
1684 reparent_error(scanner, "struct reparent error");
1688 $$ = make_node(scanner, NODE_STRUCT);
1689 $$->u._struct.has_body = 0;
1690 $$->u._struct.name = $1->s;
1694 $$ = make_node(scanner, NODE_STRUCT);
1695 $$->u._struct.has_body = 0;
1696 $$->u._struct.name = $1->s;
1698 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1700 $$ = make_node(scanner, NODE_STRUCT);
1701 $$->u._struct.has_body = 1;
1702 cds_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1703 if ($2 && set_parent_node($2, $$))
1704 reparent_error(scanner, "struct reparent error");
1706 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1708 $$ = make_node(scanner, NODE_STRUCT);
1709 $$->u._struct.has_body = 1;
1710 $$->u._struct.name = $1->s;
1711 cds_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1712 if ($3 && set_parent_node($3, $$))
1713 reparent_error(scanner, "struct reparent error");
1715 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1717 $$ = make_node(scanner, NODE_STRUCT);
1718 $$->u._struct.has_body = 1;
1719 $$->u._struct.name = $1->s;
1720 cds_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1721 if ($3 && set_parent_node($3, $$))
1722 reparent_error(scanner, "struct reparent error");
1726 struct_declaration_begin:
1728 { push_scope(scanner); }
1731 struct_declaration_end:
1733 { pop_scope(scanner); }
1736 variant_type_specifier:
1737 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1739 $$ = make_node(scanner, NODE_VARIANT);
1740 $$->u.variant.has_body = 1;
1741 if ($2 && set_parent_node($2, $$))
1742 reparent_error(scanner, "variant reparent error");
1744 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1746 $$ = make_node(scanner, NODE_VARIANT);
1747 $$->u.variant.has_body = 1;
1748 $$->u.variant.choice = $2->s;
1749 if ($5 && set_parent_node($5, $$))
1750 reparent_error(scanner, "variant reparent error");
1752 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1754 $$ = make_node(scanner, NODE_VARIANT);
1755 $$->u.variant.has_body = 1;
1756 $$->u.variant.choice = $2->s;
1757 if ($5 && set_parent_node($5, $$))
1758 reparent_error(scanner, "variant reparent error");
1760 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1762 $$ = make_node(scanner, NODE_VARIANT);
1763 $$->u.variant.has_body = 1;
1764 $$->u.variant.name = $1->s;
1765 if ($3 && set_parent_node($3, $$))
1766 reparent_error(scanner, "variant reparent error");
1768 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1770 $$ = make_node(scanner, NODE_VARIANT);
1771 $$->u.variant.has_body = 1;
1772 $$->u.variant.name = $1->s;
1773 $$->u.variant.choice = $3->s;
1774 if ($6 && set_parent_node($6, $$))
1775 reparent_error(scanner, "variant reparent error");
1777 | IDENTIFIER LT IDENTIFIER GT
1779 $$ = make_node(scanner, NODE_VARIANT);
1780 $$->u.variant.has_body = 0;
1781 $$->u.variant.name = $1->s;
1782 $$->u.variant.choice = $3->s;
1784 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1786 $$ = make_node(scanner, NODE_VARIANT);
1787 $$->u.variant.has_body = 1;
1788 $$->u.variant.name = $1->s;
1789 $$->u.variant.choice = $3->s;
1790 if ($6 && set_parent_node($6, $$))
1791 reparent_error(scanner, "variant reparent error");
1793 | IDENTIFIER LT ID_TYPE GT
1795 $$ = make_node(scanner, NODE_VARIANT);
1796 $$->u.variant.has_body = 0;
1797 $$->u.variant.name = $1->s;
1798 $$->u.variant.choice = $3->s;
1800 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1802 $$ = make_node(scanner, NODE_VARIANT);
1803 $$->u.variant.has_body = 1;
1804 $$->u.variant.name = $1->s;
1805 if ($3 && set_parent_node($3, $$))
1806 reparent_error(scanner, "variant reparent error");
1808 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1810 $$ = make_node(scanner, NODE_VARIANT);
1811 $$->u.variant.has_body = 1;
1812 $$->u.variant.name = $1->s;
1813 $$->u.variant.choice = $3->s;
1814 if ($6 && set_parent_node($6, $$))
1815 reparent_error(scanner, "variant reparent error");
1817 | ID_TYPE LT IDENTIFIER GT
1819 $$ = make_node(scanner, NODE_VARIANT);
1820 $$->u.variant.has_body = 0;
1821 $$->u.variant.name = $1->s;
1822 $$->u.variant.choice = $3->s;
1824 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1826 $$ = make_node(scanner, NODE_VARIANT);
1827 $$->u.variant.has_body = 1;
1828 $$->u.variant.name = $1->s;
1829 $$->u.variant.choice = $3->s;
1830 if ($6 && set_parent_node($6, $$))
1831 reparent_error(scanner, "variant reparent error");
1833 | ID_TYPE LT ID_TYPE GT
1835 $$ = make_node(scanner, NODE_VARIANT);
1836 $$->u.variant.has_body = 0;
1837 $$->u.variant.name = $1->s;
1838 $$->u.variant.choice = $3->s;
1842 variant_declaration_begin:
1844 { push_scope(scanner); }
1847 variant_declaration_end:
1849 { pop_scope(scanner); }
1852 enum_type_specifier:
1853 LBRAC enumerator_list RBRAC
1855 $$ = make_node(scanner, NODE_ENUM);
1856 $$->u._enum.has_body = 1;
1857 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1859 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1861 $$ = make_node(scanner, NODE_ENUM);
1862 $$->u._enum.has_body = 1;
1863 ($$)->u._enum.container_type = $2;
1864 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1866 | IDENTIFIER LBRAC enumerator_list RBRAC
1868 $$ = make_node(scanner, NODE_ENUM);
1869 $$->u._enum.has_body = 1;
1870 $$->u._enum.enum_id = $1->s;
1871 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1873 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1875 $$ = make_node(scanner, NODE_ENUM);
1876 $$->u._enum.has_body = 1;
1877 $$->u._enum.enum_id = $1->s;
1878 ($$)->u._enum.container_type = $3;
1879 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1881 | ID_TYPE LBRAC enumerator_list RBRAC
1883 $$ = make_node(scanner, NODE_ENUM);
1884 $$->u._enum.has_body = 1;
1885 $$->u._enum.enum_id = $1->s;
1886 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1888 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1890 $$ = make_node(scanner, NODE_ENUM);
1891 $$->u._enum.has_body = 1;
1892 $$->u._enum.enum_id = $1->s;
1893 ($$)->u._enum.container_type = $3;
1894 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1896 | LBRAC enumerator_list COMMA RBRAC
1898 $$ = make_node(scanner, NODE_ENUM);
1899 $$->u._enum.has_body = 1;
1900 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1902 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1904 $$ = make_node(scanner, NODE_ENUM);
1905 $$->u._enum.has_body = 1;
1906 ($$)->u._enum.container_type = $2;
1907 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1909 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1911 $$ = make_node(scanner, NODE_ENUM);
1912 $$->u._enum.has_body = 1;
1913 $$->u._enum.enum_id = $1->s;
1914 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1916 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1918 $$ = make_node(scanner, NODE_ENUM);
1919 $$->u._enum.has_body = 1;
1920 $$->u._enum.enum_id = $1->s;
1921 ($$)->u._enum.container_type = $3;
1922 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1926 $$ = make_node(scanner, NODE_ENUM);
1927 $$->u._enum.has_body = 0;
1928 $$->u._enum.enum_id = $1->s;
1930 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1932 $$ = make_node(scanner, NODE_ENUM);
1933 $$->u._enum.has_body = 1;
1934 $$->u._enum.enum_id = $1->s;
1935 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1937 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1939 $$ = make_node(scanner, NODE_ENUM);
1940 $$->u._enum.has_body = 1;
1941 $$->u._enum.enum_id = $1->s;
1942 ($$)->u._enum.container_type = $3;
1943 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1947 $$ = make_node(scanner, NODE_ENUM);
1948 $$->u._enum.has_body = 0;
1949 $$->u._enum.enum_id = $1->s;
1953 struct_or_variant_declaration_list:
1956 | struct_or_variant_declaration_list struct_or_variant_declaration
1960 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1963 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1968 struct_or_variant_declaration:
1969 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
1971 struct ctf_node *list;
1973 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1974 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1975 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1976 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1977 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
1979 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1981 struct ctf_node *list;
1983 $$ = make_node(scanner, NODE_TYPEDEF);
1984 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1985 $$->u._typedef.type_specifier_list = list;
1986 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1987 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1988 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1990 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1992 struct ctf_node *list;
1994 $$ = make_node(scanner, NODE_TYPEDEF);
1995 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1996 $$->u._typedef.type_specifier_list = list;
1997 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1998 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2000 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
2002 struct ctf_node *list;
2004 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2005 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2006 $$ = make_node(scanner, NODE_TYPEDEF);
2007 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2008 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2010 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
2012 struct ctf_node *list;
2014 $$ = make_node(scanner, NODE_TYPEALIAS);
2015 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2016 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2018 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2019 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2020 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2021 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2023 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2024 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2025 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2026 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2030 alias_declaration_specifiers:
2033 struct ctf_node *node;
2035 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2036 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2037 node->u.type_specifier.type = TYPESPEC_CONST;
2038 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2042 struct ctf_node *node;
2044 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2046 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2050 struct ctf_node *node;
2052 add_type(scanner, $1);
2053 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2054 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2055 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2056 node->u.type_specifier.id_type = yylval.gs->s;
2057 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2059 | alias_declaration_specifiers CONST
2061 struct ctf_node *node;
2064 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2065 node->u.type_specifier.type = TYPESPEC_CONST;
2066 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2068 | alias_declaration_specifiers type_specifier
2071 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2073 | alias_declaration_specifiers IDENTIFIER
2075 struct ctf_node *node;
2077 add_type(scanner, $2);
2079 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2080 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2081 node->u.type_specifier.id_type = yylval.gs->s;
2082 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2086 struct_or_variant_declarator_list:
2087 struct_or_variant_declarator
2089 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2092 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2096 struct_or_variant_declarator:
2099 | COLON unary_expression
2101 | declarator COLON unary_expression
2104 if (set_parent_node($3, $1))
2105 reparent_error(scanner, "struct_or_variant_declarator");
2112 | enumerator_list COMMA enumerator
2115 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2122 $$ = make_node(scanner, NODE_ENUMERATOR);
2123 $$->u.enumerator.id = $1->s;
2127 $$ = make_node(scanner, NODE_ENUMERATOR);
2128 $$->u.enumerator.id = $1->s;
2132 $$ = make_node(scanner, NODE_ENUMERATOR);
2133 $$->u.enumerator.id = $1->s;
2135 | STRING_LITERAL_START DQUOTE
2137 $$ = make_node(scanner, NODE_ENUMERATOR);
2138 $$->u.enumerator.id = "";
2140 | STRING_LITERAL_START s_char_sequence DQUOTE
2142 $$ = make_node(scanner, NODE_ENUMERATOR);
2143 $$->u.enumerator.id = $2->s;
2145 | IDENTIFIER EQUAL unary_expression_or_range
2147 $$ = make_node(scanner, NODE_ENUMERATOR);
2148 $$->u.enumerator.id = $1->s;
2149 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2151 | ID_TYPE EQUAL unary_expression_or_range
2153 $$ = make_node(scanner, NODE_ENUMERATOR);
2154 $$->u.enumerator.id = $1->s;
2155 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2157 | keywords EQUAL unary_expression_or_range
2159 $$ = make_node(scanner, NODE_ENUMERATOR);
2160 $$->u.enumerator.id = $1->s;
2161 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2163 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
2165 $$ = make_node(scanner, NODE_ENUMERATOR);
2166 $$->u.enumerator.id = "";
2167 cds_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
2169 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
2171 $$ = make_node(scanner, NODE_ENUMERATOR);
2172 $$->u.enumerator.id = $2->s;
2173 cds_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
2177 abstract_declarator_list:
2180 | abstract_declarator_list COMMA abstract_declarator
2183 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2187 abstract_declarator:
2188 direct_abstract_declarator
2190 | pointer direct_abstract_declarator
2193 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2197 direct_abstract_declarator:
2200 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2201 $$->u.type_declarator.type = TYPEDEC_ID;
2206 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2207 $$->u.type_declarator.type = TYPEDEC_ID;
2208 $$->u.type_declarator.u.id = $1->s;
2210 | LPAREN abstract_declarator RPAREN
2212 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2213 $$->u.type_declarator.type = TYPEDEC_NESTED;
2214 $$->u.type_declarator.u.nested.type_declarator = $2;
2216 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2218 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2219 $$->u.type_declarator.type = TYPEDEC_NESTED;
2220 $$->u.type_declarator.u.nested.type_declarator = $1;
2221 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2222 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2224 | direct_abstract_declarator LSBRAC RSBRAC
2226 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2227 $$->u.type_declarator.type = TYPEDEC_NESTED;
2228 $$->u.type_declarator.u.nested.type_declarator = $1;
2229 $$->u.type_declarator.u.nested.abstract_array = 1;
2233 alias_abstract_declarator_list:
2234 alias_abstract_declarator
2236 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2239 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2243 alias_abstract_declarator:
2244 direct_alias_abstract_declarator
2246 | pointer direct_alias_abstract_declarator
2249 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2253 direct_alias_abstract_declarator:
2256 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2257 $$->u.type_declarator.type = TYPEDEC_ID;
2260 | LPAREN alias_abstract_declarator RPAREN
2262 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2263 $$->u.type_declarator.type = TYPEDEC_NESTED;
2264 $$->u.type_declarator.u.nested.type_declarator = $2;
2266 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2268 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2269 $$->u.type_declarator.type = TYPEDEC_NESTED;
2270 $$->u.type_declarator.u.nested.type_declarator = $1;
2271 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2272 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2274 | direct_alias_abstract_declarator LSBRAC RSBRAC
2276 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2277 $$->u.type_declarator.type = TYPEDEC_NESTED;
2278 $$->u.type_declarator.u.nested.type_declarator = $1;
2279 $$->u.type_declarator.u.nested.abstract_array = 1;
2286 | pointer direct_declarator
2289 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2296 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2297 $$->u.type_declarator.type = TYPEDEC_ID;
2298 $$->u.type_declarator.u.id = $1->s;
2300 | LPAREN declarator RPAREN
2302 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2303 $$->u.type_declarator.type = TYPEDEC_NESTED;
2304 $$->u.type_declarator.u.nested.type_declarator = $2;
2306 | direct_declarator LSBRAC unary_expression RSBRAC
2308 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2309 $$->u.type_declarator.type = TYPEDEC_NESTED;
2310 $$->u.type_declarator.u.nested.type_declarator = $1;
2311 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2312 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2317 direct_type_declarator
2319 | pointer direct_type_declarator
2322 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2326 direct_type_declarator:
2329 add_type(scanner, $1);
2330 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2331 $$->u.type_declarator.type = TYPEDEC_ID;
2332 $$->u.type_declarator.u.id = $1->s;
2334 | LPAREN type_declarator RPAREN
2336 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2337 $$->u.type_declarator.type = TYPEDEC_NESTED;
2338 $$->u.type_declarator.u.nested.type_declarator = $2;
2340 | direct_type_declarator LSBRAC unary_expression RSBRAC
2342 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2343 $$->u.type_declarator.type = TYPEDEC_NESTED;
2344 $$->u.type_declarator.u.nested.type_declarator = $1;
2345 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2346 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2353 $$ = make_node(scanner, NODE_POINTER);
2357 $$ = make_node(scanner, NODE_POINTER);
2358 cds_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2360 | STAR type_qualifier_list pointer
2362 $$ = make_node(scanner, NODE_POINTER);
2363 $$->u.pointer.const_qualifier = 1;
2364 cds_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2368 type_qualifier_list:
2369 /* pointer assumes only const type qualifier */
2371 | type_qualifier_list CONST
2374 /* 2.3: CTF-specific declarations */
2376 ctf_assignment_expression_list:
2377 ctf_assignment_expression SEMICOLON
2379 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2382 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2386 ctf_assignment_expression:
2387 unary_expression EQUAL unary_expression
2390 * Because we have left and right, cannot use
2393 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2394 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2395 if ($1->u.unary_expression.type != UNARY_STRING)
2396 reparent_error(scanner, "ctf_assignment_expression left expects string");
2397 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2399 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2402 * Because we have left and right, cannot use
2405 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2406 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2407 if ($1->u.unary_expression.type != UNARY_STRING)
2408 reparent_error(scanner, "ctf_assignment_expression left expects string");
2409 cds_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2411 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2413 struct ctf_node *list;
2415 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2416 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2417 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2418 $$ = make_node(scanner, NODE_TYPEDEF);
2419 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2420 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2422 | TYPEDEF declaration_specifiers type_declarator_list
2424 struct ctf_node *list;
2426 $$ = make_node(scanner, NODE_TYPEDEF);
2427 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2428 $$->u._typedef.type_specifier_list = list;
2429 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2430 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2432 | declaration_specifiers TYPEDEF type_declarator_list
2434 struct ctf_node *list;
2436 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2437 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2438 $$ = make_node(scanner, NODE_TYPEDEF);
2439 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2440 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2442 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2444 struct ctf_node *list;
2446 $$ = make_node(scanner, NODE_TYPEALIAS);
2447 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2448 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2450 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2451 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2452 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2453 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2455 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2456 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2457 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2458 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);