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;
1015 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1016 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1017 sscanf(yylval.gs->s, "%" PRIu64,
1018 &$$->u.unary_expression.u.unsigned_constant);
1022 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1023 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1024 sscanf(yylval.gs->s, "0%" PRIo64,
1025 &$$->u.unary_expression.u.unsigned_constant);
1027 | HEXADECIMAL_CONSTANT
1029 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1030 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1031 sscanf(yylval.gs->s, "0x%" PRIx64,
1032 &$$->u.unary_expression.u.unsigned_constant);
1034 | STRING_LITERAL_START DQUOTE
1036 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1037 $$->u.unary_expression.type = UNARY_STRING;
1038 $$->u.unary_expression.u.string = "";
1040 | STRING_LITERAL_START s_char_sequence DQUOTE
1042 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1043 $$->u.unary_expression.type = UNARY_STRING;
1044 $$->u.unary_expression.u.string = $2->s;
1046 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1048 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1049 $$->u.unary_expression.type = UNARY_STRING;
1050 $$->u.unary_expression.u.string = $2->s;
1052 | LPAREN unary_expression RPAREN
1054 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1055 $$->u.unary_expression.type = UNARY_NESTED;
1056 $$->u.unary_expression.u.nested_exp = $2;
1058 | postfix_expression LSBRAC unary_expression RSBRAC
1060 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1061 $$->u.unary_expression.type = UNARY_SBRAC;
1062 $$->u.unary_expression.u.sbrac_exp = $3;
1063 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1064 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1066 | postfix_expression DOT IDENTIFIER
1068 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1069 $$->u.unary_expression.type = UNARY_STRING;
1070 $$->u.unary_expression.u.string = yylval.gs->s;
1071 $$->u.unary_expression.link = UNARY_DOTLINK;
1072 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1073 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1075 | postfix_expression DOT ID_TYPE
1077 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1078 $$->u.unary_expression.type = UNARY_STRING;
1079 $$->u.unary_expression.u.string = yylval.gs->s;
1080 $$->u.unary_expression.link = UNARY_DOTLINK;
1081 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1082 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1084 | postfix_expression RARROW IDENTIFIER
1086 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1087 $$->u.unary_expression.type = UNARY_STRING;
1088 $$->u.unary_expression.u.string = yylval.gs->s;
1089 $$->u.unary_expression.link = UNARY_ARROWLINK;
1090 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1091 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1093 | postfix_expression RARROW ID_TYPE
1095 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1096 $$->u.unary_expression.type = UNARY_STRING;
1097 $$->u.unary_expression.u.string = yylval.gs->s;
1098 $$->u.unary_expression.link = UNARY_ARROWLINK;
1099 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1100 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1107 | PLUS postfix_expression
1109 | MINUS postfix_expression
1112 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1113 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1114 reparent_error(scanner, "expecting numeric constant");
1116 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1117 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1118 $$->u.unary_expression.u.signed_constant =
1119 -($$->u.unary_expression.u.unsigned_constant);
1121 $$->u.unary_expression.u.signed_constant =
1122 -($$->u.unary_expression.u.signed_constant);
1127 unary_expression_or_range:
1128 unary_expression DOTDOTDOT unary_expression
1131 _cds_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1132 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1138 /* 2.2: Declarations */
1141 declaration_specifiers SEMICOLON
1145 | stream_declaration
1149 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1151 struct ctf_node *list;
1153 $$ = make_node(scanner, NODE_TYPEDEF);
1154 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1155 $$->u._typedef.type_specifier_list = list;
1156 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1157 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1158 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1160 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1162 struct ctf_node *list;
1164 $$ = make_node(scanner, NODE_TYPEDEF);
1165 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1166 $$->u._typedef.type_specifier_list = list;
1167 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1168 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1170 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1172 struct ctf_node *list;
1174 $$ = make_node(scanner, NODE_TYPEDEF);
1175 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1176 $$->u._typedef.type_specifier_list = list;
1177 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1178 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1180 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1182 struct ctf_node *list;
1184 $$ = make_node(scanner, NODE_TYPEALIAS);
1185 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1186 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1188 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1189 $$->u.typealias.target->u.typealias_target.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.typealias.target->u.typealias_target.type_declarators);
1193 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1194 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1195 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1196 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1201 event_declaration_begin event_declaration_end
1203 $$ = make_node(scanner, NODE_EVENT);
1205 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1207 $$ = make_node(scanner, NODE_EVENT);
1208 if (set_parent_node($2, $$))
1209 reparent_error(scanner, "event_declaration");
1213 event_declaration_begin:
1215 { push_scope(scanner); }
1218 event_declaration_end:
1220 { pop_scope(scanner); }
1225 stream_declaration_begin stream_declaration_end
1227 $$ = make_node(scanner, NODE_STREAM);
1229 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1231 $$ = make_node(scanner, NODE_STREAM);
1232 if (set_parent_node($2, $$))
1233 reparent_error(scanner, "stream_declaration");
1237 stream_declaration_begin:
1239 { push_scope(scanner); }
1242 stream_declaration_end:
1244 { pop_scope(scanner); }
1249 trace_declaration_begin trace_declaration_end
1251 $$ = make_node(scanner, NODE_TRACE);
1253 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1255 $$ = make_node(scanner, NODE_TRACE);
1256 if (set_parent_node($2, $$))
1257 reparent_error(scanner, "trace_declaration");
1261 trace_declaration_begin:
1263 { push_scope(scanner); }
1266 trace_declaration_end:
1268 { pop_scope(scanner); }
1271 declaration_specifiers:
1274 struct ctf_node *node;
1276 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1277 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1278 node->u.type_specifier.type = TYPESPEC_CONST;
1279 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1283 struct ctf_node *node;
1285 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1287 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1289 | declaration_specifiers CONST
1291 struct ctf_node *node;
1294 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1295 node->u.type_specifier.type = TYPESPEC_CONST;
1296 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1298 | declaration_specifiers type_specifier
1301 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1305 type_declarator_list:
1308 | type_declarator_list COMMA type_declarator
1311 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1318 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1319 $$->u.type_specifier.type = TYPESPEC_VOID;
1323 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1324 $$->u.type_specifier.type = TYPESPEC_CHAR;
1328 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1329 $$->u.type_specifier.type = TYPESPEC_SHORT;
1333 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1334 $$->u.type_specifier.type = TYPESPEC_INT;
1338 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1339 $$->u.type_specifier.type = TYPESPEC_LONG;
1343 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1344 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1348 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1349 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1353 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1354 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1358 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1359 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1363 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1364 $$->u.type_specifier.type = TYPESPEC_BOOL;
1368 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1369 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1373 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1374 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1378 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1379 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1380 $$->u.type_specifier.id_type = yylval.gs->s;
1382 | FLOATING_POINT LBRAC RBRAC
1384 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1385 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1386 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1388 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1390 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1391 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1392 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1393 if (set_parent_node($3, $$->u.type_specifier.node))
1394 reparent_error(scanner, "floating point reparent error");
1396 | INTEGER LBRAC RBRAC
1398 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1399 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1400 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1402 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1404 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1405 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1406 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1407 if (set_parent_node($3, $$->u.type_specifier.node))
1408 reparent_error(scanner, "integer reparent error");
1410 | STRING LBRAC RBRAC
1412 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1413 $$->u.type_specifier.type = TYPESPEC_STRING;
1414 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1416 | STRING LBRAC ctf_assignment_expression_list RBRAC
1418 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1419 $$->u.type_specifier.type = TYPESPEC_STRING;
1420 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1421 if (set_parent_node($3, $$->u.type_specifier.node))
1422 reparent_error(scanner, "string reparent error");
1424 | ENUM enum_type_specifier
1426 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1427 $$->u.type_specifier.type = TYPESPEC_ENUM;
1428 $$->u.type_specifier.node = $2;
1430 | VARIANT variant_type_specifier
1432 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1433 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1434 $$->u.type_specifier.node = $2;
1436 | STRUCT struct_type_specifier
1438 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1439 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1440 $$->u.type_specifier.node = $2;
1444 struct_type_specifier:
1445 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1447 $$ = make_node(scanner, NODE_STRUCT);
1448 $$->u._struct.has_body = 1;
1449 if ($2 && set_parent_node($2, $$))
1450 reparent_error(scanner, "struct reparent error");
1452 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1454 $$ = make_node(scanner, NODE_STRUCT);
1455 $$->u._struct.has_body = 1;
1456 $$->u._struct.name = $1->s;
1457 if ($3 && set_parent_node($3, $$))
1458 reparent_error(scanner, "struct reparent error");
1460 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1462 $$ = make_node(scanner, NODE_STRUCT);
1463 $$->u._struct.has_body = 1;
1464 $$->u._struct.name = $1->s;
1465 if ($3 && set_parent_node($3, $$))
1466 reparent_error(scanner, "struct reparent error");
1470 $$ = make_node(scanner, NODE_STRUCT);
1471 $$->u._struct.has_body = 0;
1472 $$->u._struct.name = $1->s;
1476 $$ = make_node(scanner, NODE_STRUCT);
1477 $$->u._struct.has_body = 0;
1478 $$->u._struct.name = $1->s;
1482 struct_declaration_begin:
1484 { push_scope(scanner); }
1487 struct_declaration_end:
1489 { pop_scope(scanner); }
1492 variant_type_specifier:
1493 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1495 $$ = make_node(scanner, NODE_VARIANT);
1496 $$->u.variant.has_body = 1;
1497 if ($2 && set_parent_node($2, $$))
1498 reparent_error(scanner, "variant reparent error");
1500 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1502 $$ = make_node(scanner, NODE_VARIANT);
1503 $$->u.variant.has_body = 1;
1504 $$->u.variant.choice = $2->s;
1505 if ($5 && set_parent_node($5, $$))
1506 reparent_error(scanner, "variant reparent error");
1508 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1510 $$ = make_node(scanner, NODE_VARIANT);
1511 $$->u.variant.has_body = 1;
1512 $$->u.variant.choice = $2->s;
1513 if ($5 && set_parent_node($5, $$))
1514 reparent_error(scanner, "variant reparent error");
1516 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1518 $$ = make_node(scanner, NODE_VARIANT);
1519 $$->u.variant.has_body = 1;
1520 $$->u.variant.name = $1->s;
1521 if ($3 && set_parent_node($3, $$))
1522 reparent_error(scanner, "variant reparent error");
1524 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1526 $$ = make_node(scanner, NODE_VARIANT);
1527 $$->u.variant.has_body = 1;
1528 $$->u.variant.name = $1->s;
1529 $$->u.variant.choice = $3->s;
1530 if ($6 && set_parent_node($6, $$))
1531 reparent_error(scanner, "variant reparent error");
1533 | IDENTIFIER LT IDENTIFIER GT
1535 $$ = make_node(scanner, NODE_VARIANT);
1536 $$->u.variant.has_body = 0;
1537 $$->u.variant.name = $1->s;
1538 $$->u.variant.choice = $3->s;
1540 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1542 $$ = make_node(scanner, NODE_VARIANT);
1543 $$->u.variant.has_body = 1;
1544 $$->u.variant.name = $1->s;
1545 $$->u.variant.choice = $3->s;
1546 if ($6 && set_parent_node($6, $$))
1547 reparent_error(scanner, "variant reparent error");
1549 | IDENTIFIER LT ID_TYPE GT
1551 $$ = make_node(scanner, NODE_VARIANT);
1552 $$->u.variant.has_body = 0;
1553 $$->u.variant.name = $1->s;
1554 $$->u.variant.choice = $3->s;
1556 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1558 $$ = make_node(scanner, NODE_VARIANT);
1559 $$->u.variant.has_body = 1;
1560 $$->u.variant.name = $1->s;
1561 if ($3 && set_parent_node($3, $$))
1562 reparent_error(scanner, "variant reparent error");
1564 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1566 $$ = make_node(scanner, NODE_VARIANT);
1567 $$->u.variant.has_body = 1;
1568 $$->u.variant.name = $1->s;
1569 $$->u.variant.choice = $3->s;
1570 if ($6 && set_parent_node($6, $$))
1571 reparent_error(scanner, "variant reparent error");
1573 | ID_TYPE LT IDENTIFIER GT
1575 $$ = make_node(scanner, NODE_VARIANT);
1576 $$->u.variant.has_body = 0;
1577 $$->u.variant.name = $1->s;
1578 $$->u.variant.choice = $3->s;
1580 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1582 $$ = make_node(scanner, NODE_VARIANT);
1583 $$->u.variant.has_body = 1;
1584 $$->u.variant.name = $1->s;
1585 $$->u.variant.choice = $3->s;
1586 if ($6 && set_parent_node($6, $$))
1587 reparent_error(scanner, "variant reparent error");
1589 | ID_TYPE LT ID_TYPE GT
1591 $$ = make_node(scanner, NODE_VARIANT);
1592 $$->u.variant.has_body = 0;
1593 $$->u.variant.name = $1->s;
1594 $$->u.variant.choice = $3->s;
1598 variant_declaration_begin:
1600 { push_scope(scanner); }
1603 variant_declaration_end:
1605 { pop_scope(scanner); }
1608 declaration_specifiers_or_integer_constant:
1609 declaration_specifiers
1613 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1614 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1615 sscanf(yylval.gs->s, "%" PRIu64,
1616 &$$->u.unary_expression.u.unsigned_constant);
1620 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1621 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1622 sscanf(yylval.gs->s, "0%" PRIo64,
1623 &$$->u.unary_expression.u.unsigned_constant);
1625 | HEXADECIMAL_CONSTANT
1627 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1628 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1629 sscanf(yylval.gs->s, "0x%" PRIx64,
1630 &$$->u.unary_expression.u.unsigned_constant);
1634 enum_type_specifier:
1635 LBRAC enumerator_list RBRAC
1637 $$ = make_node(scanner, NODE_ENUM);
1638 $$->u._enum.has_body = 1;
1639 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1641 | LT declaration_specifiers GT LBRAC enumerator_list RBRAC
1643 $$ = make_node(scanner, NODE_ENUM);
1644 $$->u._enum.has_body = 1;
1645 ($$)->u._enum.container_type = $2;
1646 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1648 | IDENTIFIER LBRAC enumerator_list RBRAC
1650 $$ = make_node(scanner, NODE_ENUM);
1651 $$->u._enum.has_body = 1;
1652 $$->u._enum.enum_id = $1->s;
1653 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1655 | IDENTIFIER LT declaration_specifiers GT LBRAC enumerator_list RBRAC
1657 $$ = make_node(scanner, NODE_ENUM);
1658 $$->u._enum.has_body = 1;
1659 $$->u._enum.enum_id = $1->s;
1660 ($$)->u._enum.container_type = $3;
1661 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1663 | ID_TYPE LBRAC enumerator_list RBRAC
1665 $$ = make_node(scanner, NODE_ENUM);
1666 $$->u._enum.has_body = 1;
1667 $$->u._enum.enum_id = $1->s;
1668 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1670 | ID_TYPE LT declaration_specifiers GT LBRAC enumerator_list RBRAC
1672 $$ = make_node(scanner, NODE_ENUM);
1673 $$->u._enum.has_body = 1;
1674 $$->u._enum.enum_id = $1->s;
1675 ($$)->u._enum.container_type = $3;
1676 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1678 | LBRAC enumerator_list COMMA RBRAC
1680 $$ = make_node(scanner, NODE_ENUM);
1681 $$->u._enum.has_body = 1;
1682 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1684 | LT declaration_specifiers GT LBRAC enumerator_list COMMA RBRAC
1686 $$ = make_node(scanner, NODE_ENUM);
1687 $$->u._enum.has_body = 1;
1688 ($$)->u._enum.container_type = $2;
1689 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1691 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1693 $$ = make_node(scanner, NODE_ENUM);
1694 $$->u._enum.has_body = 1;
1695 $$->u._enum.enum_id = $1->s;
1696 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1698 | IDENTIFIER LT declaration_specifiers GT LBRAC enumerator_list COMMA RBRAC
1700 $$ = make_node(scanner, NODE_ENUM);
1701 $$->u._enum.has_body = 1;
1702 $$->u._enum.enum_id = $1->s;
1703 ($$)->u._enum.container_type = $3;
1704 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1708 $$ = make_node(scanner, NODE_ENUM);
1709 $$->u._enum.has_body = 0;
1710 $$->u._enum.enum_id = $1->s;
1712 | IDENTIFIER LT declaration_specifiers GT
1714 $$ = make_node(scanner, NODE_ENUM);
1715 $$->u._enum.has_body = 0;
1716 $$->u._enum.enum_id = $1->s;
1717 ($$)->u._enum.container_type = $3;
1719 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1721 $$ = make_node(scanner, NODE_ENUM);
1722 $$->u._enum.has_body = 1;
1723 $$->u._enum.enum_id = $1->s;
1724 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1726 | ID_TYPE LT declaration_specifiers GT LBRAC enumerator_list COMMA RBRAC
1728 $$ = make_node(scanner, NODE_ENUM);
1729 $$->u._enum.has_body = 1;
1730 $$->u._enum.enum_id = $1->s;
1731 ($$)->u._enum.container_type = $3;
1732 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1736 $$ = make_node(scanner, NODE_ENUM);
1737 $$->u._enum.has_body = 0;
1738 $$->u._enum.enum_id = $1->s;
1740 | ID_TYPE LT declaration_specifiers GT
1742 $$ = make_node(scanner, NODE_ENUM);
1743 $$->u._enum.has_body = 0;
1744 $$->u._enum.enum_id = $1->s;
1745 ($$)->u._enum.container_type = $3;
1749 struct_or_variant_declaration_list:
1752 | struct_or_variant_declaration_list struct_or_variant_declaration
1756 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1759 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1764 struct_or_variant_declaration:
1765 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
1767 struct ctf_node *list;
1769 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1770 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1771 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1772 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1773 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
1775 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1777 struct ctf_node *list;
1779 $$ = make_node(scanner, NODE_TYPEDEF);
1780 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1781 $$->u._typedef.type_specifier_list = list;
1782 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1783 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1784 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1786 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1788 struct ctf_node *list;
1790 $$ = make_node(scanner, NODE_TYPEDEF);
1791 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1792 $$->u._typedef.type_specifier_list = list;
1793 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1794 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1796 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1798 struct ctf_node *list;
1800 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1801 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1802 $$ = make_node(scanner, NODE_TYPEDEF);
1803 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1804 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1806 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1808 struct ctf_node *list;
1810 $$ = make_node(scanner, NODE_TYPEALIAS);
1811 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1812 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1814 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1815 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1816 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1817 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1819 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1820 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1821 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1822 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1826 alias_declaration_specifiers:
1829 struct ctf_node *node;
1831 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1832 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1833 node->u.type_specifier.type = TYPESPEC_CONST;
1834 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1838 struct ctf_node *node;
1840 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1842 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1846 struct ctf_node *node;
1848 add_type(scanner, $1);
1849 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1850 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1851 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
1852 node->u.type_specifier.id_type = yylval.gs->s;
1853 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1855 | alias_declaration_specifiers CONST
1857 struct ctf_node *node;
1860 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1861 node->u.type_specifier.type = TYPESPEC_CONST;
1862 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1864 | alias_declaration_specifiers type_specifier
1867 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1869 | alias_declaration_specifiers IDENTIFIER
1871 struct ctf_node *node;
1873 add_type(scanner, $2);
1875 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1876 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
1877 node->u.type_specifier.id_type = yylval.gs->s;
1878 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1882 struct_or_variant_declarator_list:
1883 struct_or_variant_declarator
1885 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
1888 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1892 struct_or_variant_declarator:
1895 | COLON unary_expression
1897 | declarator COLON unary_expression
1900 if (set_parent_node($3, $1))
1901 reparent_error(scanner, "struct_or_variant_declarator");
1908 | enumerator_list COMMA enumerator
1911 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1918 $$ = make_node(scanner, NODE_ENUMERATOR);
1919 $$->u.enumerator.id = $1->s;
1923 $$ = make_node(scanner, NODE_ENUMERATOR);
1924 $$->u.enumerator.id = $1->s;
1928 $$ = make_node(scanner, NODE_ENUMERATOR);
1929 $$->u.enumerator.id = $1->s;
1931 | STRING_LITERAL_START DQUOTE
1933 $$ = make_node(scanner, NODE_ENUMERATOR);
1934 $$->u.enumerator.id = "";
1936 | STRING_LITERAL_START s_char_sequence DQUOTE
1938 $$ = make_node(scanner, NODE_ENUMERATOR);
1939 $$->u.enumerator.id = $2->s;
1941 | IDENTIFIER EQUAL unary_expression_or_range
1943 $$ = make_node(scanner, NODE_ENUMERATOR);
1944 $$->u.enumerator.id = $1->s;
1945 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
1947 | ID_TYPE EQUAL unary_expression_or_range
1949 $$ = make_node(scanner, NODE_ENUMERATOR);
1950 $$->u.enumerator.id = $1->s;
1951 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
1953 | keywords EQUAL unary_expression_or_range
1955 $$ = make_node(scanner, NODE_ENUMERATOR);
1956 $$->u.enumerator.id = $1->s;
1957 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
1959 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
1961 $$ = make_node(scanner, NODE_ENUMERATOR);
1962 $$->u.enumerator.id = "";
1963 cds_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
1965 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
1967 $$ = make_node(scanner, NODE_ENUMERATOR);
1968 $$->u.enumerator.id = $2->s;
1969 cds_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
1973 abstract_declarator_list:
1976 | abstract_declarator_list COMMA abstract_declarator
1979 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1983 abstract_declarator:
1984 direct_abstract_declarator
1986 | pointer direct_abstract_declarator
1989 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
1993 direct_abstract_declarator:
1996 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1997 $$->u.type_declarator.type = TYPEDEC_ID;
2002 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2003 $$->u.type_declarator.type = TYPEDEC_ID;
2004 $$->u.type_declarator.u.id = $1->s;
2006 | LPAREN abstract_declarator RPAREN
2008 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2009 $$->u.type_declarator.type = TYPEDEC_NESTED;
2010 $$->u.type_declarator.u.nested.type_declarator = $2;
2012 | direct_abstract_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2014 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2015 $$->u.type_declarator.type = TYPEDEC_NESTED;
2016 $$->u.type_declarator.u.nested.type_declarator = $1;
2017 ($$)->u.type_declarator.u.nested.length = $3;
2019 | direct_abstract_declarator LSBRAC RSBRAC
2021 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2022 $$->u.type_declarator.type = TYPEDEC_NESTED;
2023 $$->u.type_declarator.u.nested.type_declarator = $1;
2024 $$->u.type_declarator.u.nested.abstract_array = 1;
2028 alias_abstract_declarator_list:
2029 alias_abstract_declarator
2031 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2034 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2038 alias_abstract_declarator:
2039 direct_alias_abstract_declarator
2041 | pointer direct_alias_abstract_declarator
2044 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2048 direct_alias_abstract_declarator:
2051 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2052 $$->u.type_declarator.type = TYPEDEC_ID;
2055 | LPAREN alias_abstract_declarator RPAREN
2057 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2058 $$->u.type_declarator.type = TYPEDEC_NESTED;
2059 $$->u.type_declarator.u.nested.type_declarator = $2;
2061 | direct_alias_abstract_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2063 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2064 $$->u.type_declarator.type = TYPEDEC_NESTED;
2065 $$->u.type_declarator.u.nested.type_declarator = $1;
2066 ($$)->u.type_declarator.u.nested.length = $3;
2068 | direct_alias_abstract_declarator LSBRAC RSBRAC
2070 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2071 $$->u.type_declarator.type = TYPEDEC_NESTED;
2072 $$->u.type_declarator.u.nested.type_declarator = $1;
2073 $$->u.type_declarator.u.nested.abstract_array = 1;
2080 | pointer direct_declarator
2083 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2090 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2091 $$->u.type_declarator.type = TYPEDEC_ID;
2092 $$->u.type_declarator.u.id = $1->s;
2094 | LPAREN declarator RPAREN
2096 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2097 $$->u.type_declarator.type = TYPEDEC_NESTED;
2098 $$->u.type_declarator.u.nested.type_declarator = $2;
2100 | direct_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2102 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2103 $$->u.type_declarator.type = TYPEDEC_NESTED;
2104 $$->u.type_declarator.u.nested.type_declarator = $1;
2105 ($$)->u.type_declarator.u.nested.length = $3;
2110 direct_type_declarator
2112 | pointer direct_type_declarator
2115 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2119 direct_type_declarator:
2122 add_type(scanner, $1);
2123 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2124 $$->u.type_declarator.type = TYPEDEC_ID;
2125 $$->u.type_declarator.u.id = $1->s;
2127 | LPAREN type_declarator RPAREN
2129 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2130 $$->u.type_declarator.type = TYPEDEC_NESTED;
2131 $$->u.type_declarator.u.nested.type_declarator = $2;
2133 | direct_type_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
2135 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2136 $$->u.type_declarator.type = TYPEDEC_NESTED;
2137 $$->u.type_declarator.u.nested.type_declarator = $1;
2138 ($$)->u.type_declarator.u.nested.length = $3;
2145 $$ = make_node(scanner, NODE_POINTER);
2149 $$ = make_node(scanner, NODE_POINTER);
2150 cds_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2152 | STAR type_qualifier_list pointer
2154 $$ = make_node(scanner, NODE_POINTER);
2155 $$->u.pointer.const_qualifier = 1;
2156 cds_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2160 type_qualifier_list:
2161 /* pointer assumes only const type qualifier */
2163 | type_qualifier_list CONST
2166 /* 2.3: CTF-specific declarations */
2168 ctf_assignment_expression_list:
2169 ctf_assignment_expression SEMICOLON
2171 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2174 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2178 ctf_assignment_expression:
2179 unary_expression EQUAL unary_expression
2182 * Because we have left and right, cannot use
2185 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2186 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2187 if ($1->u.unary_expression.type != UNARY_STRING)
2188 reparent_error(scanner, "ctf_assignment_expression left expects string");
2189 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2191 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2194 * Because we have left and right, cannot use
2197 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2198 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2199 if ($1->u.unary_expression.type != UNARY_STRING)
2200 reparent_error(scanner, "ctf_assignment_expression left expects string");
2201 cds_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2203 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2205 struct ctf_node *list;
2207 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2208 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2209 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2210 $$ = make_node(scanner, NODE_TYPEDEF);
2211 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2212 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2214 | TYPEDEF declaration_specifiers type_declarator_list
2216 struct ctf_node *list;
2218 $$ = make_node(scanner, NODE_TYPEDEF);
2219 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2220 $$->u._typedef.type_specifier_list = list;
2221 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2222 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2224 | declaration_specifiers TYPEDEF type_declarator_list
2226 struct ctf_node *list;
2228 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2229 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2230 $$ = make_node(scanner, NODE_TYPEDEF);
2231 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2232 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2234 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2236 struct ctf_node *list;
2238 $$ = make_node(scanner, NODE_TYPEALIAS);
2239 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2240 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2242 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2243 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2244 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2245 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2247 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2248 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2249 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2250 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);