5 * Common Trace Format Metadata Grammar.
7 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
28 #include <babeltrace/list.h>
29 #include <babeltrace/babeltrace.h>
30 #include "ctf-scanner.h"
31 #include "ctf-parser.h"
37 * TODO: support enum, variant and struct declarations in scopes.
40 /* Join two lists, put "add" at the end of "head". */
42 _cds_list_splice_tail (struct cds_list_head *add, struct cds_list_head *head)
44 /* Do nothing if the list which gets added is empty. */
45 if (add != add->next) {
46 add->next->prev = head->prev;
47 add->prev->next = head;
48 head->prev->next = add->next;
49 head->prev = add->prev;
53 int yyparse(struct ctf_scanner *scanner);
54 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
55 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
56 int yylex_destroy(yyscan_t yyscanner);
57 void yyrestart(FILE * in_str, yyscan_t scanner);
62 struct cds_list_head gc;
67 static const char *node_type_to_str[] = {
68 [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
69 [ NODE_ROOT ] = "NODE_ROOT",
70 [ NODE_EVENT ] = "NODE_EVENT",
71 [ NODE_STREAM ] = "NODE_STREAM",
72 [ NODE_TRACE ] = "NODE_TRACE",
73 [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
74 [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
75 [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
76 [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
77 [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
78 [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
79 [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
80 [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
81 [ NODE_POINTER ] = "NODE_POINTER",
82 [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
83 [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
84 [ NODE_INTEGER ] = "NODE_INTEGER",
85 [ NODE_STRING ] = "NODE_STRING",
86 [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
87 [ NODE_ENUM ] = "NODE_ENUM",
88 [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
89 [ NODE_VARIANT ] = "NODE_VARIANT",
90 [ NODE_STRUCT ] = "NODE_STRUCT",
93 const char *node_type(struct ctf_node *node)
95 if (node->type < NR_NODE_TYPES)
96 return node_type_to_str[node->type];
101 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
104 struct gc_string *gstr;
107 /* TODO: could be faster with find first bit or glib Gstring */
108 /* sizeof long to account for malloc header (int or long ?) */
109 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
112 gstr = malloc(alloclen);
113 cds_list_add(&gstr->gc, &scanner->allocated_strings);
114 gstr->alloclen = alloclen;
119 * note: never use gc_string_append on a string that has external references.
120 * gsrc will be garbage collected immediately, and gstr might be.
121 * Should only be used to append characters to a string literal or constant.
123 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
124 struct gc_string *gstr,
125 struct gc_string *gsrc)
127 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
130 /* TODO: could be faster with find first bit or glib Gstring */
131 /* sizeof long to account for malloc header (int or long ?) */
132 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
135 if (alloclen > gstr->alloclen) {
136 struct gc_string *newgstr;
138 newgstr = gc_string_alloc(scanner, newlen);
139 strcpy(newgstr->s, gstr->s);
140 strcat(newgstr->s, gsrc->s);
141 cds_list_del(&gstr->gc);
145 strcat(gstr->s, gsrc->s);
147 cds_list_del(&gsrc->gc);
152 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
154 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
155 strcpy(lvalp->gs->s, src);
158 static void init_scope(struct ctf_scanner_scope *scope,
159 struct ctf_scanner_scope *parent)
161 scope->parent = parent;
162 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
166 static void finalize_scope(struct ctf_scanner_scope *scope)
168 g_hash_table_destroy(scope->types);
171 static void push_scope(struct ctf_scanner *scanner)
173 struct ctf_scanner_scope *ns;
175 printf_debug("push scope\n");
176 ns = malloc(sizeof(struct ctf_scanner_scope));
177 init_scope(ns, scanner->cs);
181 static void pop_scope(struct ctf_scanner *scanner)
183 struct ctf_scanner_scope *os;
185 printf_debug("pop scope\n");
187 scanner->cs = os->parent;
192 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
196 ret = (int) (long) g_hash_table_lookup(s->types, id);
197 printf_debug("lookup %p %s %d\n", s, id, ret);
201 int is_type(struct ctf_scanner *scanner, const char *id)
203 struct ctf_scanner_scope *it;
206 for (it = scanner->cs; it != NULL; it = it->parent) {
207 if (lookup_type(it, id)) {
212 printf_debug("is type %s %d\n", id, ret);
216 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
218 printf_debug("add type %s\n", id->s);
219 if (lookup_type(scanner->cs, id->s))
221 g_hash_table_insert(scanner->cs->types, id->s, id->s);
224 static struct ctf_node *make_node(struct ctf_scanner *scanner,
227 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
228 struct ctf_node *node;
230 node = malloc(sizeof(*node));
233 memset(node, 0, sizeof(*node));
235 CDS_INIT_LIST_HEAD(&node->tmp_head);
236 cds_list_add(&node->gc, &ast->allocated_nodes);
237 cds_list_add(&node->siblings, &node->tmp_head);
241 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
245 CDS_INIT_LIST_HEAD(&node->u.event.declaration_list);
248 CDS_INIT_LIST_HEAD(&node->u.stream.declaration_list);
251 CDS_INIT_LIST_HEAD(&node->u.trace.declaration_list);
254 case NODE_CTF_EXPRESSION:
255 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.left);
256 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.right);
258 case NODE_UNARY_EXPRESSION:
262 CDS_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
264 case NODE_TYPEALIAS_TARGET:
265 CDS_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
267 case NODE_TYPEALIAS_ALIAS:
268 CDS_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
273 case NODE_TYPE_SPECIFIER:
275 case NODE_TYPE_SPECIFIER_LIST:
276 CDS_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
280 case NODE_TYPE_DECLARATOR:
281 CDS_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
284 case NODE_FLOATING_POINT:
285 CDS_INIT_LIST_HEAD(&node->u.floating_point.expressions);
288 CDS_INIT_LIST_HEAD(&node->u.integer.expressions);
291 CDS_INIT_LIST_HEAD(&node->u.string.expressions);
293 case NODE_ENUMERATOR:
294 CDS_INIT_LIST_HEAD(&node->u.enumerator.values);
297 CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
299 case NODE_STRUCT_OR_VARIANT_DECLARATION:
300 CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
303 CDS_INIT_LIST_HEAD(&node->u.variant.declaration_list);
306 CDS_INIT_LIST_HEAD(&node->u._struct.declaration_list);
307 CDS_INIT_LIST_HEAD(&node->u._struct.min_align);
312 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
320 static int reparent_ctf_expression(struct ctf_node *node,
321 struct ctf_node *parent)
323 switch (parent->type) {
325 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
328 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
331 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
333 case NODE_FLOATING_POINT:
334 _cds_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
337 _cds_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
340 _cds_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
344 case NODE_CTF_EXPRESSION:
346 case NODE_TYPEALIAS_TARGET:
347 case NODE_TYPEALIAS_ALIAS:
349 case NODE_TYPE_SPECIFIER:
350 case NODE_TYPE_SPECIFIER_LIST:
352 case NODE_TYPE_DECLARATOR:
353 case NODE_ENUMERATOR:
355 case NODE_STRUCT_OR_VARIANT_DECLARATION:
358 case NODE_UNARY_EXPRESSION:
363 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
370 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
372 switch (parent->type) {
374 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
377 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
380 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
383 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
386 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
389 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
392 case NODE_FLOATING_POINT:
395 case NODE_CTF_EXPRESSION:
397 case NODE_TYPEALIAS_TARGET:
398 case NODE_TYPEALIAS_ALIAS:
400 case NODE_TYPE_SPECIFIER:
401 case NODE_TYPE_SPECIFIER_LIST:
403 case NODE_TYPE_DECLARATOR:
404 case NODE_ENUMERATOR:
406 case NODE_STRUCT_OR_VARIANT_DECLARATION:
407 case NODE_UNARY_EXPRESSION:
412 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
419 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
421 switch (parent->type) {
423 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
426 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
429 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
432 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
435 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
438 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
441 case NODE_FLOATING_POINT:
444 case NODE_CTF_EXPRESSION:
446 case NODE_TYPEALIAS_TARGET:
447 case NODE_TYPEALIAS_ALIAS:
449 case NODE_TYPE_SPECIFIER:
450 case NODE_TYPE_SPECIFIER_LIST:
452 case NODE_TYPE_DECLARATOR:
453 case NODE_ENUMERATOR:
455 case NODE_STRUCT_OR_VARIANT_DECLARATION:
456 case NODE_UNARY_EXPRESSION:
461 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
468 static int reparent_type_specifier(struct ctf_node *node,
469 struct ctf_node *parent)
471 switch (parent->type) {
472 case NODE_TYPE_SPECIFIER_LIST:
473 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
476 case NODE_TYPE_SPECIFIER:
483 case NODE_TYPEALIAS_TARGET:
484 case NODE_TYPEALIAS_ALIAS:
485 case NODE_TYPE_DECLARATOR:
487 case NODE_STRUCT_OR_VARIANT_DECLARATION:
489 case NODE_FLOATING_POINT:
492 case NODE_CTF_EXPRESSION:
494 case NODE_ENUMERATOR:
495 case NODE_UNARY_EXPRESSION:
500 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
507 static int reparent_type_specifier_list(struct ctf_node *node,
508 struct ctf_node *parent)
510 switch (parent->type) {
512 cds_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
515 cds_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
518 cds_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
521 cds_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
524 cds_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
527 cds_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
530 parent->u._typedef.type_specifier_list = node;
532 case NODE_TYPEALIAS_TARGET:
533 parent->u.typealias_target.type_specifier_list = node;
535 case NODE_TYPEALIAS_ALIAS:
536 parent->u.typealias_alias.type_specifier_list = node;
538 case NODE_TYPE_DECLARATOR:
539 parent->u.type_declarator.type = TYPEDEC_NESTED;
540 parent->u.type_declarator.u.nested.length = node;
543 parent->u._enum.container_type = node;
545 case NODE_STRUCT_OR_VARIANT_DECLARATION:
546 parent->u.struct_or_variant_declaration.type_specifier_list = node;
548 case NODE_TYPE_SPECIFIER:
550 case NODE_FLOATING_POINT:
553 case NODE_CTF_EXPRESSION:
555 case NODE_ENUMERATOR:
556 case NODE_UNARY_EXPRESSION:
561 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
568 static int reparent_type_declarator(struct ctf_node *node,
569 struct ctf_node *parent)
571 switch (parent->type) {
572 case NODE_TYPE_DECLARATOR:
573 parent->u.type_declarator.type = TYPEDEC_NESTED;
574 parent->u.type_declarator.u.nested.type_declarator = node;
576 case NODE_STRUCT_OR_VARIANT_DECLARATION:
577 _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
580 _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
582 case NODE_TYPEALIAS_TARGET:
583 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
585 case NODE_TYPEALIAS_ALIAS:
586 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
597 case NODE_FLOATING_POINT:
600 case NODE_CTF_EXPRESSION:
601 case NODE_TYPE_SPECIFIER:
602 case NODE_TYPE_SPECIFIER_LIST:
604 case NODE_ENUMERATOR:
605 case NODE_UNARY_EXPRESSION:
610 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
620 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
621 * create the link declared by the input, -ENOENT if node or parent is NULL,
622 * -EINVAL if there is an internal structure problem.
624 static int set_parent_node(struct ctf_node *node,
625 struct ctf_node *parent)
627 if (!node || !parent)
630 /* Note: Linking to parent will be done only by an external visitor */
632 switch (node->type) {
634 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
638 if (parent->type == NODE_ROOT) {
639 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.event);
645 if (parent->type == NODE_ROOT) {
646 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
652 if (parent->type == NODE_ROOT) {
653 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
659 case NODE_CTF_EXPRESSION:
660 return reparent_ctf_expression(node, parent);
661 case NODE_UNARY_EXPRESSION:
662 if (parent->type == NODE_TYPE_DECLARATOR)
663 parent->u.type_declarator.bitfield_len = node;
669 return reparent_typedef(node, parent);
670 case NODE_TYPEALIAS_TARGET:
671 if (parent->type == NODE_TYPEALIAS)
672 parent->u.typealias.target = node;
675 case NODE_TYPEALIAS_ALIAS:
676 if (parent->type == NODE_TYPEALIAS)
677 parent->u.typealias.alias = node;
681 return reparent_typealias(node, parent);
684 if (parent->type == NODE_TYPE_DECLARATOR) {
685 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
689 case NODE_TYPE_DECLARATOR:
690 return reparent_type_declarator(node, parent);
692 case NODE_TYPE_SPECIFIER_LIST:
693 return reparent_type_specifier_list(node, parent);
695 case NODE_TYPE_SPECIFIER:
696 return reparent_type_specifier(node, parent);
698 case NODE_FLOATING_POINT:
704 return -EINVAL; /* Dealt with internally within grammar */
706 case NODE_ENUMERATOR:
707 if (parent->type == NODE_ENUM) {
708 _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
713 case NODE_STRUCT_OR_VARIANT_DECLARATION:
714 switch (parent->type) {
716 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
719 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
728 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
735 void yyerror(struct ctf_scanner *scanner, const char *str)
737 fprintf(stderr, "error %s\n", str);
745 #define reparent_error(scanner, str) \
747 yyerror(scanner, YY_("reparent_error: " str "\n")); \
751 static void free_strings(struct cds_list_head *list)
753 struct gc_string *gstr, *tmp;
755 cds_list_for_each_entry_safe(gstr, tmp, list, gc)
759 static struct ctf_ast *ctf_ast_alloc(void)
763 ast = malloc(sizeof(*ast));
766 memset(ast, 0, sizeof(*ast));
767 CDS_INIT_LIST_HEAD(&ast->allocated_nodes);
768 ast->root.type = NODE_ROOT;
769 CDS_INIT_LIST_HEAD(&ast->root.tmp_head);
770 CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
771 CDS_INIT_LIST_HEAD(&ast->root.u.root.trace);
772 CDS_INIT_LIST_HEAD(&ast->root.u.root.stream);
773 CDS_INIT_LIST_HEAD(&ast->root.u.root.event);
777 static void ctf_ast_free(struct ctf_ast *ast)
779 struct ctf_node *node, *tmp;
781 cds_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
785 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
787 return yyparse(scanner);
790 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
792 struct ctf_scanner *scanner;
795 yydebug = babeltrace_debug;
797 scanner = malloc(sizeof(*scanner));
800 memset(scanner, 0, sizeof(*scanner));
802 ret = yylex_init_extra(scanner, &scanner->scanner);
804 fprintf(stderr, "yylex_init error\n");
805 goto cleanup_scanner;
807 /* Start processing new stream */
808 yyrestart(input, scanner->scanner);
810 scanner->ast = ctf_ast_alloc();
813 init_scope(&scanner->root_scope, NULL);
814 scanner->cs = &scanner->root_scope;
815 CDS_INIT_LIST_HEAD(&scanner->allocated_strings);
818 fprintf(stdout, "Scanner input is a%s.\n",
819 isatty(fileno(input)) ? "n interactive tty" :
820 " noninteractive file");
825 ret = yylex_destroy(scanner->scanner);
827 fprintf(stderr, "yylex_destroy error\n");
833 void ctf_scanner_free(struct ctf_scanner *scanner)
837 finalize_scope(&scanner->root_scope);
838 free_strings(&scanner->allocated_strings);
839 ctf_ast_free(scanner->ast);
840 ret = yylex_destroy(scanner->scanner);
842 fprintf(stderr, "yylex_destroy error\n");
850 %parse-param {struct ctf_scanner *scanner}
851 %lex-param {struct ctf_scanner *scanner}
853 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
854 * vs struct { int :value; } (unnamed bit-field). The default is to
855 * shift, so whenever we encounter an enumeration, we are doing the
856 * proper thing (shift). It is illegal to declare an enumeration
857 * "bit-field", so it is OK if this situation ends up in a parsing
862 %token CHARACTER_CONSTANT_START SQUOTE STRING_LITERAL_START DQUOTE ESCSEQ CHAR_STRING_TOKEN LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT TOK_ALIGN
863 %token <gs> IDENTIFIER ID_TYPE
869 struct gc_string *gs;
874 %type <gs> s_char s_char_sequence c_char c_char_sequence
876 %type <n> postfix_expression unary_expression unary_expression_or_range
878 %type <n> declaration
879 %type <n> event_declaration
880 %type <n> stream_declaration
881 %type <n> trace_declaration
882 %type <n> integer_declaration_specifiers
883 %type <n> declaration_specifiers
884 %type <n> alias_declaration_specifiers
886 %type <n> type_declarator_list
887 %type <n> integer_type_specifier
888 %type <n> type_specifier
889 %type <n> struct_type_specifier
890 %type <n> variant_type_specifier
891 %type <n> declaration_specifiers_or_integer_constant
892 %type <n> enum_type_specifier
893 %type <n> struct_or_variant_declaration_list
894 %type <n> struct_or_variant_declaration
895 %type <n> struct_or_variant_declarator_list
896 %type <n> struct_or_variant_declarator
897 %type <n> enumerator_list
899 %type <n> abstract_declarator_list
900 %type <n> abstract_declarator
901 %type <n> direct_abstract_declarator
902 %type <n> alias_abstract_declarator_list
903 %type <n> alias_abstract_declarator
904 %type <n> direct_alias_abstract_declarator
906 %type <n> direct_declarator
907 %type <n> type_declarator
908 %type <n> direct_type_declarator
910 %type <n> ctf_assignment_expression_list
911 %type <n> ctf_assignment_expression
918 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
919 reparent_error(scanner, "error reparenting to root");
923 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
924 reparent_error(scanner, "error reparenting to root");
984 | c_char_sequence c_char
985 { $$ = gc_string_append(scanner, $1, $2); }
993 reparent_error(scanner, "escape sequences not supported yet");
997 /* 1.6 String literals */
1002 | s_char_sequence s_char
1003 { $$ = gc_string_append(scanner, $1, $2); }
1011 reparent_error(scanner, "escape sequences not supported yet");
1015 /* 2: Phrase structure grammar */
1020 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1021 $$->u.unary_expression.type = UNARY_STRING;
1022 $$->u.unary_expression.u.string = yylval.gs->s;
1026 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1027 $$->u.unary_expression.type = UNARY_STRING;
1028 $$->u.unary_expression.u.string = yylval.gs->s;
1032 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1033 $$->u.unary_expression.type = UNARY_STRING;
1034 $$->u.unary_expression.u.string = yylval.gs->s;
1038 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1039 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1040 sscanf(yylval.gs->s, "%" PRIu64,
1041 &$$->u.unary_expression.u.unsigned_constant);
1045 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1046 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1047 sscanf(yylval.gs->s, "0%" PRIo64,
1048 &$$->u.unary_expression.u.unsigned_constant);
1050 | HEXADECIMAL_CONSTANT
1052 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1053 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1054 sscanf(yylval.gs->s, "0x%" PRIx64,
1055 &$$->u.unary_expression.u.unsigned_constant);
1057 | STRING_LITERAL_START DQUOTE
1059 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1060 $$->u.unary_expression.type = UNARY_STRING;
1061 $$->u.unary_expression.u.string = "";
1063 | STRING_LITERAL_START s_char_sequence DQUOTE
1065 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1066 $$->u.unary_expression.type = UNARY_STRING;
1067 $$->u.unary_expression.u.string = $2->s;
1069 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1071 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1072 $$->u.unary_expression.type = UNARY_STRING;
1073 $$->u.unary_expression.u.string = $2->s;
1075 | LPAREN unary_expression RPAREN
1077 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1078 $$->u.unary_expression.type = UNARY_NESTED;
1079 $$->u.unary_expression.u.nested_exp = $2;
1081 | postfix_expression LSBRAC unary_expression RSBRAC
1083 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1084 $$->u.unary_expression.type = UNARY_SBRAC;
1085 $$->u.unary_expression.u.sbrac_exp = $3;
1086 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1087 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1089 | postfix_expression DOT IDENTIFIER
1091 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1092 $$->u.unary_expression.type = UNARY_STRING;
1093 $$->u.unary_expression.u.string = yylval.gs->s;
1094 $$->u.unary_expression.link = UNARY_DOTLINK;
1095 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1096 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1098 | postfix_expression DOT ID_TYPE
1100 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1101 $$->u.unary_expression.type = UNARY_STRING;
1102 $$->u.unary_expression.u.string = yylval.gs->s;
1103 $$->u.unary_expression.link = UNARY_DOTLINK;
1104 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1105 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1107 | postfix_expression RARROW IDENTIFIER
1109 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1110 $$->u.unary_expression.type = UNARY_STRING;
1111 $$->u.unary_expression.u.string = yylval.gs->s;
1112 $$->u.unary_expression.link = UNARY_ARROWLINK;
1113 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1114 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1116 | postfix_expression RARROW ID_TYPE
1118 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1119 $$->u.unary_expression.type = UNARY_STRING;
1120 $$->u.unary_expression.u.string = yylval.gs->s;
1121 $$->u.unary_expression.link = UNARY_ARROWLINK;
1122 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1123 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1130 | PLUS postfix_expression
1132 | MINUS postfix_expression
1135 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1136 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1137 reparent_error(scanner, "expecting numeric constant");
1139 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1140 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1141 $$->u.unary_expression.u.signed_constant =
1142 -($$->u.unary_expression.u.unsigned_constant);
1144 $$->u.unary_expression.u.signed_constant =
1145 -($$->u.unary_expression.u.signed_constant);
1150 unary_expression_or_range:
1151 unary_expression DOTDOTDOT unary_expression
1154 _cds_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1155 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1161 /* 2.2: Declarations */
1164 declaration_specifiers SEMICOLON
1168 | stream_declaration
1172 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1174 struct ctf_node *list;
1176 $$ = make_node(scanner, NODE_TYPEDEF);
1177 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1178 $$->u._typedef.type_specifier_list = list;
1179 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1180 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1181 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1183 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1185 struct ctf_node *list;
1187 $$ = make_node(scanner, NODE_TYPEDEF);
1188 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1189 $$->u._typedef.type_specifier_list = list;
1190 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1191 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1193 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1195 struct ctf_node *list;
1197 $$ = make_node(scanner, NODE_TYPEDEF);
1198 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1199 $$->u._typedef.type_specifier_list = list;
1200 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1201 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1203 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1205 struct ctf_node *list;
1207 $$ = make_node(scanner, NODE_TYPEALIAS);
1208 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1209 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1211 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1212 $$->u.typealias.target->u.typealias_target.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.typealias.target->u.typealias_target.type_declarators);
1216 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1217 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1218 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1219 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1224 event_declaration_begin event_declaration_end
1226 $$ = make_node(scanner, NODE_EVENT);
1228 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1230 $$ = make_node(scanner, NODE_EVENT);
1231 if (set_parent_node($2, $$))
1232 reparent_error(scanner, "event_declaration");
1236 event_declaration_begin:
1238 { push_scope(scanner); }
1241 event_declaration_end:
1243 { pop_scope(scanner); }
1248 stream_declaration_begin stream_declaration_end
1250 $$ = make_node(scanner, NODE_STREAM);
1252 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1254 $$ = make_node(scanner, NODE_STREAM);
1255 if (set_parent_node($2, $$))
1256 reparent_error(scanner, "stream_declaration");
1260 stream_declaration_begin:
1262 { push_scope(scanner); }
1265 stream_declaration_end:
1267 { pop_scope(scanner); }
1272 trace_declaration_begin trace_declaration_end
1274 $$ = make_node(scanner, NODE_TRACE);
1276 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1278 $$ = make_node(scanner, NODE_TRACE);
1279 if (set_parent_node($2, $$))
1280 reparent_error(scanner, "trace_declaration");
1284 trace_declaration_begin:
1286 { push_scope(scanner); }
1289 trace_declaration_end:
1291 { pop_scope(scanner); }
1294 integer_declaration_specifiers:
1297 struct ctf_node *node;
1299 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1300 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1301 node->u.type_specifier.type = TYPESPEC_CONST;
1302 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1304 | integer_type_specifier
1306 struct ctf_node *node;
1308 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1310 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1312 | integer_declaration_specifiers CONST
1314 struct ctf_node *node;
1317 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1318 node->u.type_specifier.type = TYPESPEC_CONST;
1319 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1321 | integer_declaration_specifiers integer_type_specifier
1324 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1328 declaration_specifiers:
1331 struct ctf_node *node;
1333 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1334 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1335 node->u.type_specifier.type = TYPESPEC_CONST;
1336 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1340 struct ctf_node *node;
1342 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1344 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1346 | declaration_specifiers CONST
1348 struct ctf_node *node;
1351 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1352 node->u.type_specifier.type = TYPESPEC_CONST;
1353 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1355 | declaration_specifiers type_specifier
1358 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1362 type_declarator_list:
1365 | type_declarator_list COMMA type_declarator
1368 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1372 integer_type_specifier:
1375 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1376 $$->u.type_specifier.type = TYPESPEC_CHAR;
1380 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1381 $$->u.type_specifier.type = TYPESPEC_SHORT;
1385 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1386 $$->u.type_specifier.type = TYPESPEC_INT;
1390 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1391 $$->u.type_specifier.type = TYPESPEC_LONG;
1395 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1396 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1400 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1401 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1405 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1406 $$->u.type_specifier.type = TYPESPEC_BOOL;
1410 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1411 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1412 $$->u.type_specifier.id_type = yylval.gs->s;
1414 | INTEGER LBRAC RBRAC
1416 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1417 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1418 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1420 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1422 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1423 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1424 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1425 if (set_parent_node($3, $$->u.type_specifier.node))
1426 reparent_error(scanner, "integer reparent error");
1433 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1434 $$->u.type_specifier.type = TYPESPEC_VOID;
1438 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1439 $$->u.type_specifier.type = TYPESPEC_CHAR;
1443 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1444 $$->u.type_specifier.type = TYPESPEC_SHORT;
1448 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1449 $$->u.type_specifier.type = TYPESPEC_INT;
1453 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1454 $$->u.type_specifier.type = TYPESPEC_LONG;
1458 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1459 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1463 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1464 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1468 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1469 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1473 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1474 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1478 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1479 $$->u.type_specifier.type = TYPESPEC_BOOL;
1483 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1484 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1488 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1489 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1493 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1494 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1495 $$->u.type_specifier.id_type = yylval.gs->s;
1497 | FLOATING_POINT LBRAC RBRAC
1499 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1500 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1501 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1503 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1505 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1506 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1507 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1508 if (set_parent_node($3, $$->u.type_specifier.node))
1509 reparent_error(scanner, "floating point reparent error");
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");
1527 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1528 $$->u.type_specifier.type = TYPESPEC_STRING;
1529 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1531 | STRING LBRAC RBRAC
1533 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1534 $$->u.type_specifier.type = TYPESPEC_STRING;
1535 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1537 | STRING LBRAC ctf_assignment_expression_list RBRAC
1539 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1540 $$->u.type_specifier.type = TYPESPEC_STRING;
1541 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1542 if (set_parent_node($3, $$->u.type_specifier.node))
1543 reparent_error(scanner, "string reparent error");
1545 | ENUM enum_type_specifier
1547 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1548 $$->u.type_specifier.type = TYPESPEC_ENUM;
1549 $$->u.type_specifier.node = $2;
1551 | VARIANT variant_type_specifier
1553 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1554 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1555 $$->u.type_specifier.node = $2;
1557 | STRUCT struct_type_specifier
1559 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1560 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1561 $$->u.type_specifier.node = $2;
1565 struct_type_specifier:
1566 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1568 $$ = make_node(scanner, NODE_STRUCT);
1569 $$->u._struct.has_body = 1;
1570 if ($2 && set_parent_node($2, $$))
1571 reparent_error(scanner, "struct reparent error");
1573 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1575 $$ = make_node(scanner, NODE_STRUCT);
1576 $$->u._struct.has_body = 1;
1577 $$->u._struct.name = $1->s;
1578 if ($3 && set_parent_node($3, $$))
1579 reparent_error(scanner, "struct reparent error");
1581 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1583 $$ = make_node(scanner, NODE_STRUCT);
1584 $$->u._struct.has_body = 1;
1585 $$->u._struct.name = $1->s;
1586 if ($3 && set_parent_node($3, $$))
1587 reparent_error(scanner, "struct reparent error");
1591 $$ = make_node(scanner, NODE_STRUCT);
1592 $$->u._struct.has_body = 0;
1593 $$->u._struct.name = $1->s;
1597 $$ = make_node(scanner, NODE_STRUCT);
1598 $$->u._struct.has_body = 0;
1599 $$->u._struct.name = $1->s;
1601 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1603 $$ = make_node(scanner, NODE_STRUCT);
1604 $$->u._struct.has_body = 1;
1605 cds_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1606 if ($2 && set_parent_node($2, $$))
1607 reparent_error(scanner, "struct reparent error");
1609 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1611 $$ = make_node(scanner, NODE_STRUCT);
1612 $$->u._struct.has_body = 1;
1613 $$->u._struct.name = $1->s;
1614 cds_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1615 if ($3 && set_parent_node($3, $$))
1616 reparent_error(scanner, "struct reparent error");
1618 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1620 $$ = make_node(scanner, NODE_STRUCT);
1621 $$->u._struct.has_body = 1;
1622 $$->u._struct.name = $1->s;
1623 cds_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1624 if ($3 && set_parent_node($3, $$))
1625 reparent_error(scanner, "struct reparent error");
1629 struct_declaration_begin:
1631 { push_scope(scanner); }
1634 struct_declaration_end:
1636 { pop_scope(scanner); }
1639 variant_type_specifier:
1640 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1642 $$ = make_node(scanner, NODE_VARIANT);
1643 $$->u.variant.has_body = 1;
1644 if ($2 && set_parent_node($2, $$))
1645 reparent_error(scanner, "variant reparent error");
1647 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1649 $$ = make_node(scanner, NODE_VARIANT);
1650 $$->u.variant.has_body = 1;
1651 $$->u.variant.choice = $2->s;
1652 if ($5 && set_parent_node($5, $$))
1653 reparent_error(scanner, "variant reparent error");
1655 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1657 $$ = make_node(scanner, NODE_VARIANT);
1658 $$->u.variant.has_body = 1;
1659 $$->u.variant.choice = $2->s;
1660 if ($5 && set_parent_node($5, $$))
1661 reparent_error(scanner, "variant reparent error");
1663 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1665 $$ = make_node(scanner, NODE_VARIANT);
1666 $$->u.variant.has_body = 1;
1667 $$->u.variant.name = $1->s;
1668 if ($3 && set_parent_node($3, $$))
1669 reparent_error(scanner, "variant reparent error");
1671 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1673 $$ = make_node(scanner, NODE_VARIANT);
1674 $$->u.variant.has_body = 1;
1675 $$->u.variant.name = $1->s;
1676 $$->u.variant.choice = $3->s;
1677 if ($6 && set_parent_node($6, $$))
1678 reparent_error(scanner, "variant reparent error");
1680 | IDENTIFIER LT IDENTIFIER GT
1682 $$ = make_node(scanner, NODE_VARIANT);
1683 $$->u.variant.has_body = 0;
1684 $$->u.variant.name = $1->s;
1685 $$->u.variant.choice = $3->s;
1687 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1689 $$ = make_node(scanner, NODE_VARIANT);
1690 $$->u.variant.has_body = 1;
1691 $$->u.variant.name = $1->s;
1692 $$->u.variant.choice = $3->s;
1693 if ($6 && set_parent_node($6, $$))
1694 reparent_error(scanner, "variant reparent error");
1696 | IDENTIFIER LT ID_TYPE GT
1698 $$ = make_node(scanner, NODE_VARIANT);
1699 $$->u.variant.has_body = 0;
1700 $$->u.variant.name = $1->s;
1701 $$->u.variant.choice = $3->s;
1703 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1705 $$ = make_node(scanner, NODE_VARIANT);
1706 $$->u.variant.has_body = 1;
1707 $$->u.variant.name = $1->s;
1708 if ($3 && set_parent_node($3, $$))
1709 reparent_error(scanner, "variant reparent error");
1711 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1713 $$ = make_node(scanner, NODE_VARIANT);
1714 $$->u.variant.has_body = 1;
1715 $$->u.variant.name = $1->s;
1716 $$->u.variant.choice = $3->s;
1717 if ($6 && set_parent_node($6, $$))
1718 reparent_error(scanner, "variant reparent error");
1720 | ID_TYPE LT IDENTIFIER GT
1722 $$ = make_node(scanner, NODE_VARIANT);
1723 $$->u.variant.has_body = 0;
1724 $$->u.variant.name = $1->s;
1725 $$->u.variant.choice = $3->s;
1727 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1729 $$ = make_node(scanner, NODE_VARIANT);
1730 $$->u.variant.has_body = 1;
1731 $$->u.variant.name = $1->s;
1732 $$->u.variant.choice = $3->s;
1733 if ($6 && set_parent_node($6, $$))
1734 reparent_error(scanner, "variant reparent error");
1736 | ID_TYPE LT ID_TYPE GT
1738 $$ = make_node(scanner, NODE_VARIANT);
1739 $$->u.variant.has_body = 0;
1740 $$->u.variant.name = $1->s;
1741 $$->u.variant.choice = $3->s;
1745 variant_declaration_begin:
1747 { push_scope(scanner); }
1750 variant_declaration_end:
1752 { pop_scope(scanner); }
1755 declaration_specifiers_or_integer_constant:
1756 declaration_specifiers
1760 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1761 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1762 sscanf(yylval.gs->s, "%" PRIu64,
1763 &$$->u.unary_expression.u.unsigned_constant);
1767 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1768 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1769 sscanf(yylval.gs->s, "0%" PRIo64,
1770 &$$->u.unary_expression.u.unsigned_constant);
1772 | HEXADECIMAL_CONSTANT
1774 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1775 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1776 sscanf(yylval.gs->s, "0x%" PRIx64,
1777 &$$->u.unary_expression.u.unsigned_constant);
1781 enum_type_specifier:
1782 LBRAC enumerator_list RBRAC
1784 $$ = make_node(scanner, NODE_ENUM);
1785 $$->u._enum.has_body = 1;
1786 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1788 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1790 $$ = make_node(scanner, NODE_ENUM);
1791 $$->u._enum.has_body = 1;
1792 ($$)->u._enum.container_type = $2;
1793 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1795 | IDENTIFIER LBRAC enumerator_list RBRAC
1797 $$ = make_node(scanner, NODE_ENUM);
1798 $$->u._enum.has_body = 1;
1799 $$->u._enum.enum_id = $1->s;
1800 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1802 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1804 $$ = make_node(scanner, NODE_ENUM);
1805 $$->u._enum.has_body = 1;
1806 $$->u._enum.enum_id = $1->s;
1807 ($$)->u._enum.container_type = $3;
1808 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1810 | ID_TYPE LBRAC enumerator_list RBRAC
1812 $$ = make_node(scanner, NODE_ENUM);
1813 $$->u._enum.has_body = 1;
1814 $$->u._enum.enum_id = $1->s;
1815 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1817 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1819 $$ = make_node(scanner, NODE_ENUM);
1820 $$->u._enum.has_body = 1;
1821 $$->u._enum.enum_id = $1->s;
1822 ($$)->u._enum.container_type = $3;
1823 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1825 | LBRAC enumerator_list COMMA RBRAC
1827 $$ = make_node(scanner, NODE_ENUM);
1828 $$->u._enum.has_body = 1;
1829 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1831 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1833 $$ = make_node(scanner, NODE_ENUM);
1834 $$->u._enum.has_body = 1;
1835 ($$)->u._enum.container_type = $2;
1836 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1838 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1840 $$ = make_node(scanner, NODE_ENUM);
1841 $$->u._enum.has_body = 1;
1842 $$->u._enum.enum_id = $1->s;
1843 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1845 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1847 $$ = make_node(scanner, NODE_ENUM);
1848 $$->u._enum.has_body = 1;
1849 $$->u._enum.enum_id = $1->s;
1850 ($$)->u._enum.container_type = $3;
1851 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1855 $$ = make_node(scanner, NODE_ENUM);
1856 $$->u._enum.has_body = 0;
1857 $$->u._enum.enum_id = $1->s;
1859 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1861 $$ = make_node(scanner, NODE_ENUM);
1862 $$->u._enum.has_body = 1;
1863 $$->u._enum.enum_id = $1->s;
1864 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1866 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1868 $$ = make_node(scanner, NODE_ENUM);
1869 $$->u._enum.has_body = 1;
1870 $$->u._enum.enum_id = $1->s;
1871 ($$)->u._enum.container_type = $3;
1872 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1876 $$ = make_node(scanner, NODE_ENUM);
1877 $$->u._enum.has_body = 0;
1878 $$->u._enum.enum_id = $1->s;
1882 struct_or_variant_declaration_list:
1885 | struct_or_variant_declaration_list struct_or_variant_declaration
1889 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1892 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1897 struct_or_variant_declaration:
1898 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
1900 struct ctf_node *list;
1902 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1903 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1904 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1905 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1906 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
1908 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1910 struct ctf_node *list;
1912 $$ = make_node(scanner, NODE_TYPEDEF);
1913 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1914 $$->u._typedef.type_specifier_list = list;
1915 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1916 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1917 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1919 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1921 struct ctf_node *list;
1923 $$ = make_node(scanner, NODE_TYPEDEF);
1924 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1925 $$->u._typedef.type_specifier_list = list;
1926 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1927 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1929 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1931 struct ctf_node *list;
1933 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1934 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1935 $$ = make_node(scanner, NODE_TYPEDEF);
1936 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1937 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1939 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1941 struct ctf_node *list;
1943 $$ = make_node(scanner, NODE_TYPEALIAS);
1944 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1945 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1947 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1948 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1949 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1950 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1952 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1953 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1954 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1955 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1959 alias_declaration_specifiers:
1962 struct ctf_node *node;
1964 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1965 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1966 node->u.type_specifier.type = TYPESPEC_CONST;
1967 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1971 struct ctf_node *node;
1973 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1975 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1979 struct ctf_node *node;
1981 add_type(scanner, $1);
1982 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1983 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1984 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
1985 node->u.type_specifier.id_type = yylval.gs->s;
1986 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1988 | alias_declaration_specifiers CONST
1990 struct ctf_node *node;
1993 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1994 node->u.type_specifier.type = TYPESPEC_CONST;
1995 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1997 | alias_declaration_specifiers type_specifier
2000 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2002 | alias_declaration_specifiers IDENTIFIER
2004 struct ctf_node *node;
2006 add_type(scanner, $2);
2008 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2009 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2010 node->u.type_specifier.id_type = yylval.gs->s;
2011 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2015 struct_or_variant_declarator_list:
2016 struct_or_variant_declarator
2018 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2021 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2025 struct_or_variant_declarator:
2028 | COLON unary_expression
2030 | declarator COLON unary_expression
2033 if (set_parent_node($3, $1))
2034 reparent_error(scanner, "struct_or_variant_declarator");
2041 | enumerator_list COMMA enumerator
2044 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2051 $$ = make_node(scanner, NODE_ENUMERATOR);
2052 $$->u.enumerator.id = $1->s;
2056 $$ = make_node(scanner, NODE_ENUMERATOR);
2057 $$->u.enumerator.id = $1->s;
2061 $$ = make_node(scanner, NODE_ENUMERATOR);
2062 $$->u.enumerator.id = $1->s;
2064 | STRING_LITERAL_START DQUOTE
2066 $$ = make_node(scanner, NODE_ENUMERATOR);
2067 $$->u.enumerator.id = "";
2069 | STRING_LITERAL_START s_char_sequence DQUOTE
2071 $$ = make_node(scanner, NODE_ENUMERATOR);
2072 $$->u.enumerator.id = $2->s;
2074 | IDENTIFIER EQUAL unary_expression_or_range
2076 $$ = make_node(scanner, NODE_ENUMERATOR);
2077 $$->u.enumerator.id = $1->s;
2078 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2080 | ID_TYPE EQUAL unary_expression_or_range
2082 $$ = make_node(scanner, NODE_ENUMERATOR);
2083 $$->u.enumerator.id = $1->s;
2084 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2086 | keywords EQUAL unary_expression_or_range
2088 $$ = make_node(scanner, NODE_ENUMERATOR);
2089 $$->u.enumerator.id = $1->s;
2090 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2092 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
2094 $$ = make_node(scanner, NODE_ENUMERATOR);
2095 $$->u.enumerator.id = "";
2096 cds_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
2098 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
2100 $$ = make_node(scanner, NODE_ENUMERATOR);
2101 $$->u.enumerator.id = $2->s;
2102 cds_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
2106 abstract_declarator_list:
2109 | abstract_declarator_list COMMA abstract_declarator
2112 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2116 abstract_declarator:
2117 direct_abstract_declarator
2119 | pointer direct_abstract_declarator
2122 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2126 direct_abstract_declarator:
2129 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2130 $$->u.type_declarator.type = TYPEDEC_ID;
2135 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2136 $$->u.type_declarator.type = TYPEDEC_ID;
2137 $$->u.type_declarator.u.id = $1->s;
2139 | LPAREN abstract_declarator RPAREN
2141 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2142 $$->u.type_declarator.type = TYPEDEC_NESTED;
2143 $$->u.type_declarator.u.nested.type_declarator = $2;
2145 | direct_abstract_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2147 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2148 $$->u.type_declarator.type = TYPEDEC_NESTED;
2149 $$->u.type_declarator.u.nested.type_declarator = $1;
2150 ($$)->u.type_declarator.u.nested.length = $3;
2152 | direct_abstract_declarator LSBRAC RSBRAC
2154 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2155 $$->u.type_declarator.type = TYPEDEC_NESTED;
2156 $$->u.type_declarator.u.nested.type_declarator = $1;
2157 $$->u.type_declarator.u.nested.abstract_array = 1;
2161 alias_abstract_declarator_list:
2162 alias_abstract_declarator
2164 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2167 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2171 alias_abstract_declarator:
2172 direct_alias_abstract_declarator
2174 | pointer direct_alias_abstract_declarator
2177 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2181 direct_alias_abstract_declarator:
2184 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2185 $$->u.type_declarator.type = TYPEDEC_ID;
2188 | LPAREN alias_abstract_declarator RPAREN
2190 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2191 $$->u.type_declarator.type = TYPEDEC_NESTED;
2192 $$->u.type_declarator.u.nested.type_declarator = $2;
2194 | direct_alias_abstract_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2196 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2197 $$->u.type_declarator.type = TYPEDEC_NESTED;
2198 $$->u.type_declarator.u.nested.type_declarator = $1;
2199 ($$)->u.type_declarator.u.nested.length = $3;
2201 | direct_alias_abstract_declarator LSBRAC RSBRAC
2203 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2204 $$->u.type_declarator.type = TYPEDEC_NESTED;
2205 $$->u.type_declarator.u.nested.type_declarator = $1;
2206 $$->u.type_declarator.u.nested.abstract_array = 1;
2213 | pointer direct_declarator
2216 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2223 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2224 $$->u.type_declarator.type = TYPEDEC_ID;
2225 $$->u.type_declarator.u.id = $1->s;
2227 | LPAREN declarator RPAREN
2229 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2230 $$->u.type_declarator.type = TYPEDEC_NESTED;
2231 $$->u.type_declarator.u.nested.type_declarator = $2;
2233 | direct_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2235 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2236 $$->u.type_declarator.type = TYPEDEC_NESTED;
2237 $$->u.type_declarator.u.nested.type_declarator = $1;
2238 ($$)->u.type_declarator.u.nested.length = $3;
2243 direct_type_declarator
2245 | pointer direct_type_declarator
2248 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2252 direct_type_declarator:
2255 add_type(scanner, $1);
2256 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2257 $$->u.type_declarator.type = TYPEDEC_ID;
2258 $$->u.type_declarator.u.id = $1->s;
2260 | LPAREN type_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_type_declarator LSBRAC declaration_specifiers_or_integer_constant 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 ($$)->u.type_declarator.u.nested.length = $3;
2278 $$ = make_node(scanner, NODE_POINTER);
2282 $$ = make_node(scanner, NODE_POINTER);
2283 cds_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2285 | STAR type_qualifier_list pointer
2287 $$ = make_node(scanner, NODE_POINTER);
2288 $$->u.pointer.const_qualifier = 1;
2289 cds_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2293 type_qualifier_list:
2294 /* pointer assumes only const type qualifier */
2296 | type_qualifier_list CONST
2299 /* 2.3: CTF-specific declarations */
2301 ctf_assignment_expression_list:
2302 ctf_assignment_expression SEMICOLON
2304 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2307 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2311 ctf_assignment_expression:
2312 unary_expression EQUAL unary_expression
2315 * Because we have left and right, cannot use
2318 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2319 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2320 if ($1->u.unary_expression.type != UNARY_STRING)
2321 reparent_error(scanner, "ctf_assignment_expression left expects string");
2322 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2324 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2327 * Because we have left and right, cannot use
2330 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2331 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2332 if ($1->u.unary_expression.type != UNARY_STRING)
2333 reparent_error(scanner, "ctf_assignment_expression left expects string");
2334 cds_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2336 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2338 struct ctf_node *list;
2340 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2341 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2342 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2343 $$ = make_node(scanner, NODE_TYPEDEF);
2344 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2345 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2347 | TYPEDEF declaration_specifiers type_declarator_list
2349 struct ctf_node *list;
2351 $$ = make_node(scanner, NODE_TYPEDEF);
2352 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2353 $$->u._typedef.type_specifier_list = list;
2354 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2355 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2357 | declaration_specifiers TYPEDEF type_declarator_list
2359 struct ctf_node *list;
2361 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2362 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2363 $$ = make_node(scanner, NODE_TYPEDEF);
2364 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2365 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2367 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2369 struct ctf_node *list;
2371 $$ = make_node(scanner, NODE_TYPEALIAS);
2372 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2373 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2375 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2376 $$->u.typealias.target->u.typealias_target.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.typealias.target->u.typealias_target.type_declarators);
2380 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2381 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2382 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2383 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);