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 "ctf-scanner.h"
30 #include "ctf-parser.h"
34 * TODO: support enum, variant and struct declarations in scopes.
37 /* Join two lists, put "add" at the end of "head". */
39 _cds_list_splice_tail (struct cds_list_head *add, struct cds_list_head *head)
41 /* Do nothing if the list which gets added is empty. */
42 if (add != add->next) {
43 add->next->prev = head->prev;
44 add->prev->next = head;
45 head->prev->next = add->next;
46 head->prev = add->prev;
50 #define printf_dbg(fmt, args...) fprintf(stderr, "%s: " fmt, __func__, ## args)
52 int yyparse(struct ctf_scanner *scanner);
53 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
54 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
55 int yylex_destroy(yyscan_t yyscanner) ;
56 void yyset_in(FILE * in_str, yyscan_t scanner);
61 struct cds_list_head gc;
66 static const char *node_type_to_str[] = {
67 [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
68 [ NODE_ROOT ] = "NODE_ROOT",
69 [ NODE_EVENT ] = "NODE_EVENT",
70 [ NODE_STREAM ] = "NODE_STREAM",
71 [ NODE_TRACE ] = "NODE_TRACE",
72 [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
73 [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
74 [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
75 [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
76 [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
77 [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
78 [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
79 [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
80 [ NODE_POINTER ] = "NODE_POINTER",
81 [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
82 [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
83 [ NODE_INTEGER ] = "NODE_INTEGER",
84 [ NODE_STRING ] = "NODE_STRING",
85 [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
86 [ NODE_ENUM ] = "NODE_ENUM",
87 [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
88 [ NODE_VARIANT ] = "NODE_VARIANT",
89 [ NODE_STRUCT ] = "NODE_STRUCT",
92 const char *node_type(struct ctf_node *node)
94 if (node->type < NR_NODE_TYPES)
95 return node_type_to_str[node->type];
100 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
103 struct gc_string *gstr;
106 /* TODO: could be faster with find first bit or glib Gstring */
107 /* sizeof long to account for malloc header (int or long ?) */
108 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
111 gstr = malloc(alloclen);
112 cds_list_add(&gstr->gc, &scanner->allocated_strings);
113 gstr->alloclen = alloclen;
118 * note: never use gc_string_append on a string that has external references.
119 * gsrc will be garbage collected immediately, and gstr might be.
120 * Should only be used to append characters to a string literal or constant.
122 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
123 struct gc_string *gstr,
124 struct gc_string *gsrc)
126 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
129 /* TODO: could be faster with find first bit or glib Gstring */
130 /* sizeof long to account for malloc header (int or long ?) */
131 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
134 if (alloclen > gstr->alloclen) {
135 struct gc_string *newgstr;
137 newgstr = gc_string_alloc(scanner, newlen);
138 strcpy(newgstr->s, gstr->s);
139 strcat(newgstr->s, gsrc->s);
140 cds_list_del(&gstr->gc);
144 strcat(gstr->s, gsrc->s);
146 cds_list_del(&gsrc->gc);
151 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
153 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
154 strcpy(lvalp->gs->s, src);
157 static void init_scope(struct ctf_scanner_scope *scope,
158 struct ctf_scanner_scope *parent)
160 scope->parent = parent;
161 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
165 static void finalize_scope(struct ctf_scanner_scope *scope)
167 g_hash_table_destroy(scope->types);
170 static void push_scope(struct ctf_scanner *scanner)
172 struct ctf_scanner_scope *ns;
174 printf_dbg("push scope\n");
175 ns = malloc(sizeof(struct ctf_scanner_scope));
176 init_scope(ns, scanner->cs);
180 static void pop_scope(struct ctf_scanner *scanner)
182 struct ctf_scanner_scope *os;
184 printf_dbg("pop scope\n");
186 scanner->cs = os->parent;
191 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
195 ret = (int) (long) g_hash_table_lookup(s->types, id);
196 printf_dbg("lookup %p %s %d\n", s, id, ret);
200 int is_type(struct ctf_scanner *scanner, const char *id)
202 struct ctf_scanner_scope *it;
205 for (it = scanner->cs; it != NULL; it = it->parent) {
206 if (lookup_type(it, id)) {
211 printf_dbg("is type %s %d\n", id, ret);
215 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
217 printf_dbg("add type %s\n", id->s);
218 if (lookup_type(scanner->cs, id->s))
220 g_hash_table_insert(scanner->cs->types, id->s, id->s);
223 static struct ctf_node *make_node(struct ctf_scanner *scanner,
226 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
227 struct ctf_node *node;
229 node = malloc(sizeof(*node));
232 memset(node, 0, sizeof(*node));
234 CDS_INIT_LIST_HEAD(&node->tmp_head);
235 cds_list_add(&node->gc, &ast->allocated_nodes);
236 cds_list_add(&node->siblings, &node->tmp_head);
240 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
244 CDS_INIT_LIST_HEAD(&node->u.event.declaration_list);
247 CDS_INIT_LIST_HEAD(&node->u.stream.declaration_list);
250 CDS_INIT_LIST_HEAD(&node->u.trace.declaration_list);
253 case NODE_CTF_EXPRESSION:
254 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.left);
255 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.right);
257 case NODE_UNARY_EXPRESSION:
261 CDS_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
263 case NODE_TYPEALIAS_TARGET:
264 CDS_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
266 case NODE_TYPEALIAS_ALIAS:
267 CDS_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
272 case NODE_TYPE_SPECIFIER:
274 case NODE_TYPE_SPECIFIER_LIST:
275 CDS_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
279 case NODE_TYPE_DECLARATOR:
280 CDS_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
283 case NODE_FLOATING_POINT:
284 CDS_INIT_LIST_HEAD(&node->u.floating_point.expressions);
287 CDS_INIT_LIST_HEAD(&node->u.integer.expressions);
290 CDS_INIT_LIST_HEAD(&node->u.string.expressions);
292 case NODE_ENUMERATOR:
293 CDS_INIT_LIST_HEAD(&node->u.enumerator.values);
296 CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
298 case NODE_STRUCT_OR_VARIANT_DECLARATION:
299 CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
302 CDS_INIT_LIST_HEAD(&node->u.variant.declaration_list);
305 CDS_INIT_LIST_HEAD(&node->u._struct.declaration_list);
310 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
318 static int reparent_ctf_expression(struct ctf_node *node,
319 struct ctf_node *parent)
321 switch (parent->type) {
323 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
326 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
329 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
331 case NODE_FLOATING_POINT:
332 _cds_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
335 _cds_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
338 _cds_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
342 case NODE_CTF_EXPRESSION:
344 case NODE_TYPEALIAS_TARGET:
345 case NODE_TYPEALIAS_ALIAS:
347 case NODE_TYPE_SPECIFIER:
348 case NODE_TYPE_SPECIFIER_LIST:
350 case NODE_TYPE_DECLARATOR:
351 case NODE_ENUMERATOR:
353 case NODE_STRUCT_OR_VARIANT_DECLARATION:
356 case NODE_UNARY_EXPRESSION:
361 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
368 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
370 switch (parent->type) {
372 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
375 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
378 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
381 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
384 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
387 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
390 case NODE_FLOATING_POINT:
393 case NODE_CTF_EXPRESSION:
395 case NODE_TYPEALIAS_TARGET:
396 case NODE_TYPEALIAS_ALIAS:
398 case NODE_TYPE_SPECIFIER:
399 case NODE_TYPE_SPECIFIER_LIST:
401 case NODE_TYPE_DECLARATOR:
402 case NODE_ENUMERATOR:
404 case NODE_STRUCT_OR_VARIANT_DECLARATION:
405 case NODE_UNARY_EXPRESSION:
410 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
417 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
419 switch (parent->type) {
421 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
424 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
427 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
430 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
433 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
436 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
439 case NODE_FLOATING_POINT:
442 case NODE_CTF_EXPRESSION:
444 case NODE_TYPEALIAS_TARGET:
445 case NODE_TYPEALIAS_ALIAS:
447 case NODE_TYPE_SPECIFIER:
448 case NODE_TYPE_SPECIFIER_LIST:
450 case NODE_TYPE_DECLARATOR:
451 case NODE_ENUMERATOR:
453 case NODE_STRUCT_OR_VARIANT_DECLARATION:
454 case NODE_UNARY_EXPRESSION:
459 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
466 static int reparent_type_specifier(struct ctf_node *node,
467 struct ctf_node *parent)
469 switch (parent->type) {
470 case NODE_TYPE_SPECIFIER_LIST:
471 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
474 case NODE_TYPE_SPECIFIER:
481 case NODE_TYPEALIAS_TARGET:
482 case NODE_TYPEALIAS_ALIAS:
483 case NODE_TYPE_DECLARATOR:
485 case NODE_STRUCT_OR_VARIANT_DECLARATION:
487 case NODE_FLOATING_POINT:
490 case NODE_CTF_EXPRESSION:
492 case NODE_ENUMERATOR:
493 case NODE_UNARY_EXPRESSION:
498 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
505 static int reparent_type_specifier_list(struct ctf_node *node,
506 struct ctf_node *parent)
508 switch (parent->type) {
510 cds_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
513 cds_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
516 cds_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
519 cds_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
522 cds_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
525 cds_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
528 parent->u._typedef.type_specifier_list = node;
530 case NODE_TYPEALIAS_TARGET:
531 parent->u.typealias_target.type_specifier_list = node;
533 case NODE_TYPEALIAS_ALIAS:
534 parent->u.typealias_alias.type_specifier_list = node;
536 case NODE_TYPE_DECLARATOR:
537 parent->u.type_declarator.type = TYPEDEC_NESTED;
538 parent->u.type_declarator.u.nested.length = node;
541 parent->u._enum.container_type = node;
543 case NODE_STRUCT_OR_VARIANT_DECLARATION:
544 parent->u.struct_or_variant_declaration.type_specifier_list = node;
546 case NODE_TYPE_SPECIFIER:
548 case NODE_FLOATING_POINT:
551 case NODE_CTF_EXPRESSION:
553 case NODE_ENUMERATOR:
554 case NODE_UNARY_EXPRESSION:
559 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
566 static int reparent_type_declarator(struct ctf_node *node,
567 struct ctf_node *parent)
569 switch (parent->type) {
570 case NODE_TYPE_DECLARATOR:
571 parent->u.type_declarator.type = TYPEDEC_NESTED;
572 parent->u.type_declarator.u.nested.type_declarator = node;
574 case NODE_STRUCT_OR_VARIANT_DECLARATION:
575 _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
578 _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
580 case NODE_TYPEALIAS_TARGET:
581 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
583 case NODE_TYPEALIAS_ALIAS:
584 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
595 case NODE_FLOATING_POINT:
598 case NODE_CTF_EXPRESSION:
599 case NODE_TYPE_SPECIFIER:
600 case NODE_TYPE_SPECIFIER_LIST:
602 case NODE_ENUMERATOR:
603 case NODE_UNARY_EXPRESSION:
608 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
618 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
619 * create the link declared by the input, -ENOENT if node or parent is NULL,
620 * -EINVAL if there is an internal structure problem.
622 static int set_parent_node(struct ctf_node *node,
623 struct ctf_node *parent)
625 if (!node || !parent)
628 /* Note: Linking to parent will be done only by an external visitor */
630 switch (node->type) {
632 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
636 if (parent->type == NODE_ROOT) {
637 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.event);
643 if (parent->type == NODE_ROOT) {
644 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
650 if (parent->type == NODE_ROOT) {
651 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
657 case NODE_CTF_EXPRESSION:
658 return reparent_ctf_expression(node, parent);
659 case NODE_UNARY_EXPRESSION:
660 if (parent->type == NODE_TYPE_DECLARATOR)
661 parent->u.type_declarator.bitfield_len = node;
667 return reparent_typedef(node, parent);
668 case NODE_TYPEALIAS_TARGET:
669 if (parent->type == NODE_TYPEALIAS)
670 parent->u.typealias.target = node;
673 case NODE_TYPEALIAS_ALIAS:
674 if (parent->type == NODE_TYPEALIAS)
675 parent->u.typealias.alias = node;
679 return reparent_typealias(node, parent);
682 if (parent->type == NODE_TYPE_DECLARATOR) {
683 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
687 case NODE_TYPE_DECLARATOR:
688 return reparent_type_declarator(node, parent);
690 case NODE_TYPE_SPECIFIER_LIST:
691 return reparent_type_specifier_list(node, parent);
693 case NODE_TYPE_SPECIFIER:
694 return reparent_type_specifier(node, parent);
696 case NODE_FLOATING_POINT:
702 return -EINVAL; /* Dealt with internally within grammar */
704 case NODE_ENUMERATOR:
705 if (parent->type == NODE_ENUM) {
706 _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
711 case NODE_STRUCT_OR_VARIANT_DECLARATION:
712 switch (parent->type) {
714 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
717 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
726 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
733 void yyerror(struct ctf_scanner *scanner, const char *str)
735 fprintf(stderr, "error %s\n", str);
743 #define reparent_error(scanner, str) \
745 yyerror(scanner, YY_("reparent_error: " str "\n")); \
749 static void free_strings(struct cds_list_head *list)
751 struct gc_string *gstr, *tmp;
753 cds_list_for_each_entry_safe(gstr, tmp, list, gc)
757 static struct ctf_ast *ctf_ast_alloc(void)
761 ast = malloc(sizeof(*ast));
764 memset(ast, 0, sizeof(*ast));
765 CDS_INIT_LIST_HEAD(&ast->allocated_nodes);
766 ast->root.type = NODE_ROOT;
767 CDS_INIT_LIST_HEAD(&ast->root.tmp_head);
768 CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
769 CDS_INIT_LIST_HEAD(&ast->root.u.root.trace);
770 CDS_INIT_LIST_HEAD(&ast->root.u.root.stream);
771 CDS_INIT_LIST_HEAD(&ast->root.u.root.event);
775 static void ctf_ast_free(struct ctf_ast *ast)
777 struct ctf_node *node, *tmp;
779 cds_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
783 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
785 return yyparse(scanner);
788 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
790 struct ctf_scanner *scanner;
793 scanner = malloc(sizeof(*scanner));
796 memset(scanner, 0, sizeof(*scanner));
798 ret = yylex_init_extra(scanner, &scanner->scanner);
800 fprintf(stderr, "yylex_init error\n");
801 goto cleanup_scanner;
803 yyset_in(input, scanner);
805 scanner->ast = ctf_ast_alloc();
808 init_scope(&scanner->root_scope, NULL);
809 scanner->cs = &scanner->root_scope;
810 CDS_INIT_LIST_HEAD(&scanner->allocated_strings);
815 ret = yylex_destroy(scanner->scanner);
817 fprintf(stderr, "yylex_destroy error\n");
823 void ctf_scanner_free(struct ctf_scanner *scanner)
827 finalize_scope(&scanner->root_scope);
828 free_strings(&scanner->allocated_strings);
829 ctf_ast_free(scanner->ast);
830 ret = yylex_destroy(scanner->scanner);
832 fprintf(stderr, "yylex_destroy error\n");
840 %parse-param {struct ctf_scanner *scanner}
841 %lex-param {struct ctf_scanner *scanner}
843 %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
844 %token <gs> IDENTIFIER ID_TYPE
850 struct gc_string *gs;
855 %type <gs> s_char s_char_sequence c_char c_char_sequence
857 %type <n> postfix_expression unary_expression unary_expression_or_range
859 %type <n> declaration
860 %type <n> event_declaration
861 %type <n> stream_declaration
862 %type <n> trace_declaration
863 %type <n> declaration_specifiers
864 %type <n> alias_declaration_specifiers
866 %type <n> type_declarator_list
867 %type <n> type_specifier
868 %type <n> struct_type_specifier
869 %type <n> variant_type_specifier
870 %type <n> declaration_specifiers_or_integer_constant
871 %type <n> enum_type_specifier
872 %type <n> struct_or_variant_declaration_list
873 %type <n> struct_or_variant_declaration
874 %type <n> struct_or_variant_declarator_list
875 %type <n> struct_or_variant_declarator
876 %type <n> enumerator_list
878 %type <n> abstract_declarator_list
879 %type <n> abstract_declarator
880 %type <n> direct_abstract_declarator
881 %type <n> alias_abstract_declarator_list
882 %type <n> alias_abstract_declarator
883 %type <n> direct_alias_abstract_declarator
885 %type <n> direct_declarator
886 %type <n> type_declarator
887 %type <n> direct_type_declarator
889 %type <n> ctf_assignment_expression_list
890 %type <n> ctf_assignment_expression
897 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
898 reparent_error(scanner, "error reparenting to root");
902 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
903 reparent_error(scanner, "error reparenting to root");
961 | c_char_sequence c_char
962 { $$ = gc_string_append(scanner, $1, $2); }
970 reparent_error(scanner, "escape sequences not supported yet");
974 /* 1.6 String literals */
979 | s_char_sequence s_char
980 { $$ = gc_string_append(scanner, $1, $2); }
988 reparent_error(scanner, "escape sequences not supported yet");
992 /* 2: Phrase structure grammar */
997 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
998 $$->u.unary_expression.type = UNARY_STRING;
999 $$->u.unary_expression.u.string = yylval.gs->s;
1003 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1004 $$->u.unary_expression.type = UNARY_STRING;
1005 $$->u.unary_expression.u.string = yylval.gs->s;
1009 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1010 $$->u.unary_expression.type = UNARY_STRING;
1011 $$->u.unary_expression.u.string = yylval.gs->s;
1016 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1017 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1018 sscanf(yylval.gs->s, "%" PRIu64,
1019 &$$->u.unary_expression.u.unsigned_constant);
1023 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1024 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1025 sscanf(yylval.gs->s, "0%" PRIo64,
1026 &$$->u.unary_expression.u.unsigned_constant);
1028 | HEXADECIMAL_CONSTANT
1030 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1031 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1032 sscanf(yylval.gs->s, "0x%" PRIx64,
1033 &$$->u.unary_expression.u.unsigned_constant);
1035 | STRING_LITERAL_START DQUOTE
1037 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1038 $$->u.unary_expression.type = UNARY_STRING;
1039 $$->u.unary_expression.u.string = "";
1041 | STRING_LITERAL_START s_char_sequence DQUOTE
1043 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1044 $$->u.unary_expression.type = UNARY_STRING;
1045 $$->u.unary_expression.u.string = $2->s;
1047 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1049 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1050 $$->u.unary_expression.type = UNARY_STRING;
1051 $$->u.unary_expression.u.string = $2->s;
1053 | LPAREN unary_expression RPAREN
1055 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1056 $$->u.unary_expression.type = UNARY_NESTED;
1057 $$->u.unary_expression.u.nested_exp = $2;
1059 | postfix_expression LSBRAC unary_expression RSBRAC
1061 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1062 $$->u.unary_expression.type = UNARY_SBRAC;
1063 $$->u.unary_expression.u.sbrac_exp = $3;
1064 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1065 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1067 | postfix_expression DOT IDENTIFIER
1069 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1070 $$->u.unary_expression.type = UNARY_STRING;
1071 $$->u.unary_expression.u.string = yylval.gs->s;
1072 $$->u.unary_expression.link = UNARY_DOTLINK;
1073 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1074 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1076 | postfix_expression DOT ID_TYPE
1078 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1079 $$->u.unary_expression.type = UNARY_STRING;
1080 $$->u.unary_expression.u.string = yylval.gs->s;
1081 $$->u.unary_expression.link = UNARY_DOTLINK;
1082 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1083 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1085 | postfix_expression RARROW IDENTIFIER
1087 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1088 $$->u.unary_expression.type = UNARY_STRING;
1089 $$->u.unary_expression.u.string = yylval.gs->s;
1090 $$->u.unary_expression.link = UNARY_ARROWLINK;
1091 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1092 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1094 | postfix_expression RARROW ID_TYPE
1096 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1097 $$->u.unary_expression.type = UNARY_STRING;
1098 $$->u.unary_expression.u.string = yylval.gs->s;
1099 $$->u.unary_expression.link = UNARY_ARROWLINK;
1100 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1101 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1108 | PLUS postfix_expression
1110 | MINUS postfix_expression
1113 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1114 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1115 reparent_error(scanner, "expecting numeric constant");
1117 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1118 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1119 $$->u.unary_expression.u.signed_constant =
1120 -($$->u.unary_expression.u.unsigned_constant);
1122 $$->u.unary_expression.u.signed_constant =
1123 -($$->u.unary_expression.u.signed_constant);
1128 unary_expression_or_range:
1129 unary_expression DOTDOTDOT unary_expression
1132 _cds_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1133 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1139 /* 2.2: Declarations */
1142 declaration_specifiers SEMICOLON
1146 | stream_declaration
1150 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1152 struct ctf_node *list;
1154 $$ = make_node(scanner, NODE_TYPEDEF);
1155 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1156 $$->u._typedef.type_specifier_list = list;
1157 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1158 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1159 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1161 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1163 struct ctf_node *list;
1165 $$ = make_node(scanner, NODE_TYPEDEF);
1166 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1167 $$->u._typedef.type_specifier_list = list;
1168 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1169 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1171 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1173 struct ctf_node *list;
1175 $$ = make_node(scanner, NODE_TYPEDEF);
1176 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1177 $$->u._typedef.type_specifier_list = list;
1178 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1179 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1181 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1183 struct ctf_node *list;
1185 $$ = make_node(scanner, NODE_TYPEALIAS);
1186 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1187 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1189 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1190 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1191 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1192 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1194 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1195 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1196 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1197 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1202 event_declaration_begin event_declaration_end
1204 $$ = make_node(scanner, NODE_EVENT);
1206 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1208 $$ = make_node(scanner, NODE_EVENT);
1209 if (set_parent_node($2, $$))
1210 reparent_error(scanner, "event_declaration");
1214 event_declaration_begin:
1216 { push_scope(scanner); }
1219 event_declaration_end:
1221 { pop_scope(scanner); }
1226 stream_declaration_begin stream_declaration_end
1228 $$ = make_node(scanner, NODE_STREAM);
1230 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1232 $$ = make_node(scanner, NODE_STREAM);
1233 if (set_parent_node($2, $$))
1234 reparent_error(scanner, "stream_declaration");
1238 stream_declaration_begin:
1240 { push_scope(scanner); }
1243 stream_declaration_end:
1245 { pop_scope(scanner); }
1250 trace_declaration_begin trace_declaration_end
1252 $$ = make_node(scanner, NODE_TRACE);
1254 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1256 $$ = make_node(scanner, NODE_TRACE);
1257 if (set_parent_node($2, $$))
1258 reparent_error(scanner, "trace_declaration");
1262 trace_declaration_begin:
1264 { push_scope(scanner); }
1267 trace_declaration_end:
1269 { pop_scope(scanner); }
1272 declaration_specifiers:
1275 struct ctf_node *node;
1277 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1278 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1279 node->u.type_specifier.type = TYPESPEC_CONST;
1280 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1284 struct ctf_node *node;
1286 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1288 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1290 | declaration_specifiers CONST
1292 struct ctf_node *node;
1295 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1296 node->u.type_specifier.type = TYPESPEC_CONST;
1297 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1299 | declaration_specifiers type_specifier
1302 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1306 type_declarator_list:
1309 | type_declarator_list COMMA type_declarator
1312 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1319 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1320 $$->u.type_specifier.type = TYPESPEC_VOID;
1324 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1325 $$->u.type_specifier.type = TYPESPEC_CHAR;
1329 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1330 $$->u.type_specifier.type = TYPESPEC_SHORT;
1334 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1335 $$->u.type_specifier.type = TYPESPEC_INT;
1339 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1340 $$->u.type_specifier.type = TYPESPEC_LONG;
1344 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1345 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1349 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1350 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1354 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1355 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1359 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1360 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1364 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1365 $$->u.type_specifier.type = TYPESPEC_BOOL;
1369 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1370 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1374 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1375 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1379 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1380 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1381 $$->u.type_specifier.id_type = yylval.gs->s;
1383 | FLOATING_POINT LBRAC RBRAC
1385 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1386 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1387 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1389 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1391 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1392 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1393 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1394 if (set_parent_node($3, $$->u.type_specifier.node))
1395 reparent_error(scanner, "floating point reparent error");
1397 | INTEGER LBRAC RBRAC
1399 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1400 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1401 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1403 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1405 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1406 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1407 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1408 if (set_parent_node($3, $$->u.type_specifier.node))
1409 reparent_error(scanner, "integer reparent error");
1411 | STRING LBRAC RBRAC
1413 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1414 $$->u.type_specifier.type = TYPESPEC_STRING;
1415 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1417 | STRING LBRAC ctf_assignment_expression_list RBRAC
1419 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1420 $$->u.type_specifier.type = TYPESPEC_STRING;
1421 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1422 if (set_parent_node($3, $$->u.type_specifier.node))
1423 reparent_error(scanner, "string reparent error");
1425 | ENUM enum_type_specifier
1427 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1428 $$->u.type_specifier.type = TYPESPEC_ENUM;
1429 $$->u.type_specifier.node = $2;
1431 | VARIANT variant_type_specifier
1433 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1434 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1435 $$->u.type_specifier.node = $2;
1438 | STRUCT struct_type_specifier
1440 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1441 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1442 $$->u.type_specifier.node = $2;
1447 struct_type_specifier:
1448 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1450 $$ = make_node(scanner, NODE_STRUCT);
1451 $$->u._struct.has_body = 1;
1452 if (set_parent_node($2, $$))
1453 reparent_error(scanner, "struct reparent error");
1455 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1457 $$ = make_node(scanner, NODE_STRUCT);
1458 $$->u._struct.has_body = 1;
1459 $$->u._struct.name = $1->s;
1460 if (set_parent_node($3, $$))
1461 reparent_error(scanner, "struct reparent error");
1463 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1465 $$ = make_node(scanner, NODE_STRUCT);
1466 $$->u._struct.has_body = 1;
1467 $$->u._struct.name = $1->s;
1468 if (set_parent_node($3, $$))
1469 reparent_error(scanner, "struct reparent error");
1473 $$ = make_node(scanner, NODE_STRUCT);
1474 $$->u._struct.has_body = 0;
1475 $$->u._struct.name = $1->s;
1479 $$ = make_node(scanner, NODE_STRUCT);
1480 $$->u._struct.has_body = 0;
1481 $$->u._struct.name = $1->s;
1485 struct_declaration_begin:
1487 { push_scope(scanner); }
1490 struct_declaration_end:
1492 { pop_scope(scanner); }
1495 variant_type_specifier:
1496 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1498 $$ = make_node(scanner, NODE_VARIANT);
1499 $$->u.variant.has_body = 1;
1500 if (set_parent_node($2, $$))
1501 reparent_error(scanner, "variant reparent error");
1503 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1505 $$ = make_node(scanner, NODE_VARIANT);
1506 $$->u.variant.has_body = 1;
1507 $$->u.variant.choice = $2->s;
1508 if (set_parent_node($5, $$))
1509 reparent_error(scanner, "variant reparent error");
1511 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1513 $$ = make_node(scanner, NODE_VARIANT);
1514 $$->u.variant.has_body = 1;
1515 $$->u.variant.choice = $2->s;
1516 if (set_parent_node($5, $$))
1517 reparent_error(scanner, "variant reparent error");
1519 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1521 $$ = make_node(scanner, NODE_VARIANT);
1522 $$->u.variant.has_body = 1;
1523 $$->u.variant.name = $1->s;
1524 if (set_parent_node($3, $$))
1525 reparent_error(scanner, "variant reparent error");
1527 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1529 $$ = make_node(scanner, NODE_VARIANT);
1530 $$->u.variant.has_body = 1;
1531 $$->u.variant.name = $1->s;
1532 $$->u.variant.choice = $3->s;
1533 if (set_parent_node($6, $$))
1534 reparent_error(scanner, "variant reparent error");
1536 | IDENTIFIER LT IDENTIFIER GT
1538 $$ = make_node(scanner, NODE_VARIANT);
1539 $$->u.variant.has_body = 0;
1540 $$->u.variant.name = $1->s;
1541 $$->u.variant.choice = $3->s;
1543 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1545 $$ = make_node(scanner, NODE_VARIANT);
1546 $$->u.variant.has_body = 1;
1547 $$->u.variant.name = $1->s;
1548 $$->u.variant.choice = $3->s;
1549 if (set_parent_node($6, $$))
1550 reparent_error(scanner, "variant reparent error");
1552 | IDENTIFIER LT ID_TYPE GT
1554 $$ = make_node(scanner, NODE_VARIANT);
1555 $$->u.variant.has_body = 0;
1556 $$->u.variant.name = $1->s;
1557 $$->u.variant.choice = $3->s;
1559 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1561 $$ = make_node(scanner, NODE_VARIANT);
1562 $$->u.variant.has_body = 1;
1563 $$->u.variant.name = $1->s;
1564 if (set_parent_node($3, $$))
1565 reparent_error(scanner, "variant reparent error");
1567 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1569 $$ = make_node(scanner, NODE_VARIANT);
1570 $$->u.variant.has_body = 1;
1571 $$->u.variant.name = $1->s;
1572 $$->u.variant.choice = $3->s;
1573 if (set_parent_node($6, $$))
1574 reparent_error(scanner, "variant reparent error");
1576 | ID_TYPE LT IDENTIFIER GT
1578 $$ = make_node(scanner, NODE_VARIANT);
1579 $$->u.variant.has_body = 0;
1580 $$->u.variant.name = $1->s;
1581 $$->u.variant.choice = $3->s;
1583 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1585 $$ = make_node(scanner, NODE_VARIANT);
1586 $$->u.variant.has_body = 1;
1587 $$->u.variant.name = $1->s;
1588 $$->u.variant.choice = $3->s;
1589 if (set_parent_node($6, $$))
1590 reparent_error(scanner, "variant reparent error");
1592 | ID_TYPE LT ID_TYPE GT
1594 $$ = make_node(scanner, NODE_VARIANT);
1595 $$->u.variant.has_body = 0;
1596 $$->u.variant.name = $1->s;
1597 $$->u.variant.choice = $3->s;
1601 variant_declaration_begin:
1603 { push_scope(scanner); }
1606 variant_declaration_end:
1608 { pop_scope(scanner); }
1611 declaration_specifiers_or_integer_constant:
1612 declaration_specifiers
1616 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1617 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1618 sscanf(yylval.gs->s, "%" PRIu64,
1619 &$$->u.unary_expression.u.unsigned_constant);
1623 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1624 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1625 sscanf(yylval.gs->s, "0%" PRIo64,
1626 &$$->u.unary_expression.u.unsigned_constant);
1628 | HEXADECIMAL_CONSTANT
1630 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1631 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1632 sscanf(yylval.gs->s, "0x%" PRIx64,
1633 &$$->u.unary_expression.u.unsigned_constant);
1637 enum_type_specifier:
1638 LBRAC enumerator_list RBRAC
1640 $$ = make_node(scanner, NODE_ENUM);
1641 $$->u._enum.has_body = 1;
1642 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1644 | LT declaration_specifiers GT LBRAC enumerator_list RBRAC
1646 $$ = make_node(scanner, NODE_ENUM);
1647 $$->u._enum.has_body = 1;
1648 ($$)->u._enum.container_type = $2;
1649 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1651 | IDENTIFIER LBRAC enumerator_list RBRAC
1653 $$ = make_node(scanner, NODE_ENUM);
1654 $$->u._enum.has_body = 1;
1655 $$->u._enum.enum_id = $1->s;
1656 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1658 | IDENTIFIER LT declaration_specifiers GT LBRAC enumerator_list RBRAC
1660 $$ = make_node(scanner, NODE_ENUM);
1661 $$->u._enum.has_body = 1;
1662 $$->u._enum.enum_id = $1->s;
1663 ($$)->u._enum.container_type = $3;
1664 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1666 | ID_TYPE LBRAC enumerator_list RBRAC
1668 $$ = make_node(scanner, NODE_ENUM);
1669 $$->u._enum.has_body = 1;
1670 $$->u._enum.enum_id = $1->s;
1671 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1673 | ID_TYPE LT declaration_specifiers GT LBRAC enumerator_list RBRAC
1675 $$ = make_node(scanner, NODE_ENUM);
1676 $$->u._enum.has_body = 1;
1677 $$->u._enum.enum_id = $1->s;
1678 ($$)->u._enum.container_type = $3;
1679 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1681 | LBRAC enumerator_list COMMA RBRAC
1683 $$ = make_node(scanner, NODE_ENUM);
1684 $$->u._enum.has_body = 1;
1685 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1687 | LT declaration_specifiers GT LBRAC enumerator_list COMMA RBRAC
1689 $$ = make_node(scanner, NODE_ENUM);
1690 $$->u._enum.has_body = 1;
1691 ($$)->u._enum.container_type = $2;
1692 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1694 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1696 $$ = make_node(scanner, NODE_ENUM);
1697 $$->u._enum.has_body = 1;
1698 $$->u._enum.enum_id = $1->s;
1699 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1701 | IDENTIFIER LT declaration_specifiers GT LBRAC enumerator_list COMMA RBRAC
1703 $$ = make_node(scanner, NODE_ENUM);
1704 $$->u._enum.has_body = 1;
1705 $$->u._enum.enum_id = $1->s;
1706 ($$)->u._enum.container_type = $3;
1707 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1711 $$ = make_node(scanner, NODE_ENUM);
1712 $$->u._enum.has_body = 0;
1713 $$->u._enum.enum_id = $1->s;
1715 | IDENTIFIER LT declaration_specifiers GT
1717 $$ = make_node(scanner, NODE_ENUM);
1718 $$->u._enum.has_body = 0;
1719 $$->u._enum.enum_id = $1->s;
1720 ($$)->u._enum.container_type = $3;
1722 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1724 $$ = make_node(scanner, NODE_ENUM);
1725 $$->u._enum.has_body = 1;
1726 $$->u._enum.enum_id = $1->s;
1727 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1729 | ID_TYPE LT declaration_specifiers GT LBRAC enumerator_list COMMA RBRAC
1731 $$ = make_node(scanner, NODE_ENUM);
1732 $$->u._enum.has_body = 1;
1733 $$->u._enum.enum_id = $1->s;
1734 ($$)->u._enum.container_type = $3;
1735 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1739 $$ = make_node(scanner, NODE_ENUM);
1740 $$->u._enum.has_body = 0;
1741 $$->u._enum.enum_id = $1->s;
1743 | ID_TYPE LT declaration_specifiers GT
1745 $$ = make_node(scanner, NODE_ENUM);
1746 $$->u._enum.has_body = 0;
1747 $$->u._enum.enum_id = $1->s;
1748 ($$)->u._enum.container_type = $3;
1752 struct_or_variant_declaration_list:
1755 | struct_or_variant_declaration_list struct_or_variant_declaration
1759 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1762 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1767 struct_or_variant_declaration:
1768 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
1770 struct ctf_node *list;
1772 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1773 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1774 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1775 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1776 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
1778 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1780 struct ctf_node *list;
1782 $$ = make_node(scanner, NODE_TYPEDEF);
1783 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1784 $$->u._typedef.type_specifier_list = list;
1785 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1786 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1787 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1789 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1791 struct ctf_node *list;
1793 $$ = make_node(scanner, NODE_TYPEDEF);
1794 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1795 $$->u._typedef.type_specifier_list = list;
1796 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1797 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1799 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1801 struct ctf_node *list;
1803 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1804 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1805 $$ = make_node(scanner, NODE_TYPEDEF);
1806 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1807 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1809 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1811 struct ctf_node *list;
1813 $$ = make_node(scanner, NODE_TYPEALIAS);
1814 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1815 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1817 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1818 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1819 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1820 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1822 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1823 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1824 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1825 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1829 alias_declaration_specifiers:
1832 struct ctf_node *node;
1834 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1835 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1836 node->u.type_specifier.type = TYPESPEC_CONST;
1837 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1841 struct ctf_node *node;
1843 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1845 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1849 struct ctf_node *node;
1851 add_type(scanner, $1);
1852 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1853 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1854 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
1855 node->u.type_specifier.id_type = yylval.gs->s;
1856 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1858 | alias_declaration_specifiers CONST
1860 struct ctf_node *node;
1863 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1864 node->u.type_specifier.type = TYPESPEC_CONST;
1865 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1867 | alias_declaration_specifiers type_specifier
1870 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1872 | alias_declaration_specifiers IDENTIFIER
1874 struct ctf_node *node;
1876 add_type(scanner, $2);
1878 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1879 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
1880 node->u.type_specifier.id_type = yylval.gs->s;
1881 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1885 struct_or_variant_declarator_list:
1886 struct_or_variant_declarator
1888 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
1891 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1895 struct_or_variant_declarator:
1898 | COLON unary_expression
1900 | declarator COLON unary_expression
1903 if (set_parent_node($3, $1))
1904 reparent_error(scanner, "struct_or_variant_declarator");
1911 | enumerator_list COMMA enumerator
1914 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1921 $$ = make_node(scanner, NODE_ENUMERATOR);
1922 $$->u.enumerator.id = $1->s;
1926 $$ = make_node(scanner, NODE_ENUMERATOR);
1927 $$->u.enumerator.id = $1->s;
1931 $$ = make_node(scanner, NODE_ENUMERATOR);
1932 $$->u.enumerator.id = $1->s;
1934 | STRING_LITERAL_START DQUOTE
1936 $$ = make_node(scanner, NODE_ENUMERATOR);
1937 $$->u.enumerator.id = "";
1939 | STRING_LITERAL_START s_char_sequence DQUOTE
1941 $$ = make_node(scanner, NODE_ENUMERATOR);
1942 $$->u.enumerator.id = $2->s;
1944 | IDENTIFIER EQUAL unary_expression_or_range
1946 $$ = make_node(scanner, NODE_ENUMERATOR);
1947 $$->u.enumerator.id = $1->s;
1948 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
1950 | ID_TYPE EQUAL unary_expression_or_range
1952 $$ = make_node(scanner, NODE_ENUMERATOR);
1953 $$->u.enumerator.id = $1->s;
1954 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
1956 | keywords EQUAL unary_expression_or_range
1958 $$ = make_node(scanner, NODE_ENUMERATOR);
1959 $$->u.enumerator.id = $1->s;
1960 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
1962 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
1964 $$ = make_node(scanner, NODE_ENUMERATOR);
1965 $$->u.enumerator.id = "";
1966 cds_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
1968 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
1970 $$ = make_node(scanner, NODE_ENUMERATOR);
1971 $$->u.enumerator.id = $2->s;
1972 cds_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
1976 abstract_declarator_list:
1979 | abstract_declarator_list COMMA abstract_declarator
1982 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1986 abstract_declarator:
1987 direct_abstract_declarator
1989 | pointer direct_abstract_declarator
1992 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
1996 direct_abstract_declarator:
1999 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2000 $$->u.type_declarator.type = TYPEDEC_ID;
2005 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2006 $$->u.type_declarator.type = TYPEDEC_ID;
2007 $$->u.type_declarator.u.id = $1->s;
2009 | LPAREN abstract_declarator RPAREN
2011 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2012 $$->u.type_declarator.type = TYPEDEC_NESTED;
2013 $$->u.type_declarator.u.nested.type_declarator = $2;
2015 | direct_abstract_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2017 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2018 $$->u.type_declarator.type = TYPEDEC_NESTED;
2019 $$->u.type_declarator.u.nested.type_declarator = $1;
2020 ($$)->u.type_declarator.u.nested.length = $3;
2022 | direct_abstract_declarator LSBRAC RSBRAC
2024 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2025 $$->u.type_declarator.type = TYPEDEC_NESTED;
2026 $$->u.type_declarator.u.nested.type_declarator = $1;
2027 $$->u.type_declarator.u.nested.abstract_array = 1;
2031 alias_abstract_declarator_list:
2032 alias_abstract_declarator
2034 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2037 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2041 alias_abstract_declarator:
2042 direct_alias_abstract_declarator
2044 | pointer direct_alias_abstract_declarator
2047 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2051 direct_alias_abstract_declarator:
2054 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2055 $$->u.type_declarator.type = TYPEDEC_ID;
2058 | LPAREN alias_abstract_declarator RPAREN
2060 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2061 $$->u.type_declarator.type = TYPEDEC_NESTED;
2062 $$->u.type_declarator.u.nested.type_declarator = $2;
2064 | direct_alias_abstract_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2066 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2067 $$->u.type_declarator.type = TYPEDEC_NESTED;
2068 $$->u.type_declarator.u.nested.type_declarator = $1;
2069 ($$)->u.type_declarator.u.nested.length = $3;
2071 | direct_alias_abstract_declarator LSBRAC RSBRAC
2073 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2074 $$->u.type_declarator.type = TYPEDEC_NESTED;
2075 $$->u.type_declarator.u.nested.type_declarator = $1;
2076 $$->u.type_declarator.u.nested.abstract_array = 1;
2083 | pointer direct_declarator
2086 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2093 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2094 $$->u.type_declarator.type = TYPEDEC_ID;
2095 $$->u.type_declarator.u.id = $1->s;
2097 | LPAREN declarator RPAREN
2099 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2100 $$->u.type_declarator.type = TYPEDEC_NESTED;
2101 $$->u.type_declarator.u.nested.type_declarator = $2;
2103 | direct_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2105 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2106 $$->u.type_declarator.type = TYPEDEC_NESTED;
2107 $$->u.type_declarator.u.nested.type_declarator = $1;
2108 ($$)->u.type_declarator.u.nested.length = $3;
2113 direct_type_declarator
2115 | pointer direct_type_declarator
2118 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2122 direct_type_declarator:
2125 add_type(scanner, $1);
2126 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2127 $$->u.type_declarator.type = TYPEDEC_ID;
2128 $$->u.type_declarator.u.id = $1->s;
2130 | LPAREN type_declarator RPAREN
2132 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2133 $$->u.type_declarator.type = TYPEDEC_NESTED;
2134 $$->u.type_declarator.u.nested.type_declarator = $2;
2136 | direct_type_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2138 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2139 $$->u.type_declarator.type = TYPEDEC_NESTED;
2140 $$->u.type_declarator.u.nested.type_declarator = $1;
2141 ($$)->u.type_declarator.u.nested.length = $3;
2148 $$ = make_node(scanner, NODE_POINTER);
2152 $$ = make_node(scanner, NODE_POINTER);
2153 cds_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2155 | STAR type_qualifier_list pointer
2157 $$ = make_node(scanner, NODE_POINTER);
2158 $$->u.pointer.const_qualifier = 1;
2159 cds_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2163 type_qualifier_list:
2164 /* pointer assumes only const type qualifier */
2166 | type_qualifier_list CONST
2169 /* 2.3: CTF-specific declarations */
2171 ctf_assignment_expression_list:
2172 ctf_assignment_expression SEMICOLON
2174 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2177 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2181 ctf_assignment_expression:
2182 unary_expression EQUAL unary_expression
2185 * Because we have left and right, cannot use
2188 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2189 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2190 if ($1->u.unary_expression.type != UNARY_STRING)
2191 reparent_error(scanner, "ctf_assignment_expression left expects string");
2192 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2194 | unary_expression TYPEASSIGN type_specifier /* Only allow struct */
2196 struct ctf_node *list;
2198 * Because we have left and right, cannot use
2201 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2202 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2203 if ($1->u.unary_expression.type != UNARY_STRING)
2204 reparent_error(scanner, "ctf_assignment_expression left expects string");
2205 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2206 cds_list_add_tail(&($3)->siblings, &list->u.type_specifier_list.head);
2207 cds_list_add_tail(&list->siblings, &($$)->u.ctf_expression.right);
2209 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2211 struct ctf_node *list;
2213 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2214 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2215 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2216 $$ = make_node(scanner, NODE_TYPEDEF);
2217 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2218 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2220 | TYPEDEF declaration_specifiers type_declarator_list
2222 struct ctf_node *list;
2224 $$ = make_node(scanner, NODE_TYPEDEF);
2225 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2226 $$->u._typedef.type_specifier_list = list;
2227 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2228 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2230 | declaration_specifiers TYPEDEF type_declarator_list
2232 struct ctf_node *list;
2234 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2235 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2236 $$ = make_node(scanner, NODE_TYPEDEF);
2237 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2238 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2240 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON alias_declaration_specifiers alias_abstract_declarator_list
2242 struct ctf_node *list;
2244 $$ = make_node(scanner, NODE_TYPEALIAS);
2245 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2246 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2248 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2249 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2250 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2251 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2253 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2254 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2255 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2256 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);