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"
33 /* Join two lists, put "add" at the end of "head". */
35 _cds_list_splice_tail (struct cds_list_head *add, struct cds_list_head *head)
37 /* Do nothing if the list which gets added is empty. */
38 if (add != add->next) {
39 add->next->prev = head->prev;
40 add->prev->next = head;
41 head->prev->next = add->next;
42 head->prev = add->prev;
46 #define printf_dbg(fmt, args...) fprintf(stderr, "%s: " fmt, __func__, ## args)
48 int yyparse(struct ctf_scanner *scanner);
49 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
50 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
51 int yylex_destroy(yyscan_t yyscanner) ;
52 void yyset_in(FILE * in_str, yyscan_t scanner);
57 struct cds_list_head gc;
62 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
65 struct gc_string *gstr;
68 /* TODO: could be faster with find first bit or glib Gstring */
69 /* sizeof long to account for malloc header (int or long ?) */
70 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
73 gstr = malloc(alloclen);
74 cds_list_add(&gstr->gc, &scanner->allocated_strings);
75 gstr->alloclen = alloclen;
80 * note: never use gc_string_append on a string that has external references.
81 * gsrc will be garbage collected immediately, and gstr might be.
82 * Should only be used to append characters to a string literal or constant.
84 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
85 struct gc_string *gstr,
86 struct gc_string *gsrc)
88 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
91 /* TODO: could be faster with find first bit or glib Gstring */
92 /* sizeof long to account for malloc header (int or long ?) */
93 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
96 if (alloclen > gstr->alloclen) {
97 struct gc_string *newgstr;
99 newgstr = gc_string_alloc(scanner, newlen);
100 strcpy(newgstr->s, gstr->s);
101 strcat(newgstr->s, gsrc->s);
102 cds_list_del(&gstr->gc);
106 strcat(gstr->s, gsrc->s);
108 cds_list_del(&gsrc->gc);
113 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
115 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
116 strcpy(lvalp->gs->s, src);
119 static void init_scope(struct ctf_scanner_scope *scope,
120 struct ctf_scanner_scope *parent)
122 scope->parent = parent;
123 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
127 static void finalize_scope(struct ctf_scanner_scope *scope)
129 g_hash_table_destroy(scope->types);
132 static void push_scope(struct ctf_scanner *scanner)
134 struct ctf_scanner_scope *ns;
136 printf_dbg("push scope\n");
137 ns = malloc(sizeof(struct ctf_scanner_scope));
138 init_scope(ns, scanner->cs);
142 static void pop_scope(struct ctf_scanner *scanner)
144 struct ctf_scanner_scope *os;
146 printf_dbg("pop scope\n");
148 scanner->cs = os->parent;
153 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
157 ret = (int) (long) g_hash_table_lookup(s->types, id);
158 printf_dbg("lookup %p %s %d\n", s, id, ret);
162 int is_type(struct ctf_scanner *scanner, const char *id)
164 struct ctf_scanner_scope *it;
167 for (it = scanner->cs; it != NULL; it = it->parent) {
168 if (lookup_type(it, id)) {
173 printf_dbg("is type %s %d\n", id, ret);
177 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
179 printf_dbg("add type %s\n", id->s);
180 if (lookup_type(scanner->cs, id->s))
182 g_hash_table_insert(scanner->cs->types, id->s, id->s);
185 static struct ctf_node *make_node(struct ctf_scanner *scanner,
188 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
189 struct ctf_node *node;
191 node = malloc(sizeof(*node));
194 memset(node, 0, sizeof(*node));
196 CDS_INIT_LIST_HEAD(&node->tmp_head);
197 cds_list_add(&node->gc, &ast->allocated_nodes);
198 cds_list_add(&node->siblings, &node->tmp_head);
202 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
206 CDS_INIT_LIST_HEAD(&node->u.event.declaration_list);
209 CDS_INIT_LIST_HEAD(&node->u.stream.declaration_list);
212 CDS_INIT_LIST_HEAD(&node->u.trace.declaration_list);
215 case NODE_CTF_EXPRESSION:
216 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.left);
217 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.right);
219 case NODE_UNARY_EXPRESSION:
223 CDS_INIT_LIST_HEAD(&node->u._typedef.declaration_specifier);
224 CDS_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
226 case NODE_TYPEALIAS_TARGET:
227 CDS_INIT_LIST_HEAD(&node->u.typealias_target.declaration_specifier);
228 CDS_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
230 case NODE_TYPEALIAS_ALIAS:
231 CDS_INIT_LIST_HEAD(&node->u.typealias_alias.declaration_specifier);
232 CDS_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
237 case NODE_TYPE_SPECIFIER:
241 case NODE_TYPE_DECLARATOR:
242 CDS_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
245 case NODE_FLOATING_POINT:
246 CDS_INIT_LIST_HEAD(&node->u.floating_point.expressions);
249 CDS_INIT_LIST_HEAD(&node->u.integer.expressions);
252 CDS_INIT_LIST_HEAD(&node->u.string.expressions);
254 case NODE_ENUMERATOR:
255 CDS_INIT_LIST_HEAD(&node->u.enumerator.values);
258 CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
260 case NODE_STRUCT_OR_VARIANT_DECLARATION:
261 CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.declaration_specifier);
262 CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
265 CDS_INIT_LIST_HEAD(&node->u.variant.declaration_list);
268 CDS_INIT_LIST_HEAD(&node->u._struct.declaration_list);
273 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
281 static int reparent_ctf_expression(struct ctf_node *node,
282 struct ctf_node *parent)
284 switch (parent->type) {
286 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
289 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
292 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
294 case NODE_FLOATING_POINT:
295 _cds_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
298 _cds_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
301 _cds_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
305 case NODE_CTF_EXPRESSION:
307 case NODE_TYPEALIAS_TARGET:
308 case NODE_TYPEALIAS_ALIAS:
310 case NODE_TYPE_SPECIFIER:
312 case NODE_TYPE_DECLARATOR:
313 case NODE_ENUMERATOR:
315 case NODE_STRUCT_OR_VARIANT_DECLARATION:
318 case NODE_UNARY_EXPRESSION:
323 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
330 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
332 switch (parent->type) {
334 _cds_list_splice_tail(&node->tmp_head, &parent->u.root._typedef);
337 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
340 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
343 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
346 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
349 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
352 case NODE_FLOATING_POINT:
355 case NODE_CTF_EXPRESSION:
357 case NODE_TYPEALIAS_TARGET:
358 case NODE_TYPEALIAS_ALIAS:
360 case NODE_TYPE_SPECIFIER:
362 case NODE_TYPE_DECLARATOR:
363 case NODE_ENUMERATOR:
365 case NODE_STRUCT_OR_VARIANT_DECLARATION:
366 case NODE_UNARY_EXPRESSION:
371 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
378 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
380 switch (parent->type) {
382 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.typealias);
385 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
388 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
391 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
394 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
397 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
400 case NODE_FLOATING_POINT:
403 case NODE_CTF_EXPRESSION:
405 case NODE_TYPEALIAS_TARGET:
406 case NODE_TYPEALIAS_ALIAS:
408 case NODE_TYPE_SPECIFIER:
410 case NODE_TYPE_DECLARATOR:
411 case NODE_ENUMERATOR:
413 case NODE_STRUCT_OR_VARIANT_DECLARATION:
414 case NODE_UNARY_EXPRESSION:
419 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
426 static int reparent_type_specifier(struct ctf_node *node,
427 struct ctf_node *parent)
429 switch (parent->type) {
431 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_specifier);
434 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
437 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
440 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
443 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
446 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
449 _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.declaration_specifier);
451 case NODE_TYPEALIAS_TARGET:
452 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.declaration_specifier);
454 case NODE_TYPEALIAS_ALIAS:
455 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.declaration_specifier);
457 case NODE_TYPE_DECLARATOR:
458 parent->u.type_declarator.type = TYPEDEC_NESTED;
459 parent->u.type_declarator.u.nested.length = node;
462 parent->u._enum.container_type = node;
464 case NODE_STRUCT_OR_VARIANT_DECLARATION:
465 _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.declaration_specifier);
468 case NODE_FLOATING_POINT:
471 case NODE_CTF_EXPRESSION:
472 case NODE_TYPE_SPECIFIER:
474 case NODE_ENUMERATOR:
475 case NODE_UNARY_EXPRESSION:
480 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
487 static int reparent_type_declarator(struct ctf_node *node,
488 struct ctf_node *parent)
490 switch (parent->type) {
491 case NODE_TYPE_DECLARATOR:
492 parent->u.type_declarator.type = TYPEDEC_NESTED;
493 parent->u.type_declarator.u.nested.type_declarator = node;
495 case NODE_STRUCT_OR_VARIANT_DECLARATION:
496 _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
499 _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
501 case NODE_TYPEALIAS_TARGET:
502 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
504 case NODE_TYPEALIAS_ALIAS:
505 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
516 case NODE_FLOATING_POINT:
519 case NODE_CTF_EXPRESSION:
520 case NODE_TYPE_SPECIFIER:
522 case NODE_ENUMERATOR:
523 case NODE_UNARY_EXPRESSION:
528 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
538 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
539 * create the link declared by the input, -ENOENT if node or parent is NULL,
540 * -EINVAL if there is an internal structure problem.
542 static int set_parent_node(struct ctf_node *node,
543 struct ctf_node *parent)
545 if (!node || !parent)
548 /* Note: Linking to parent will be done only by an external visitor */
550 switch (node->type) {
552 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
556 if (parent->type == NODE_ROOT) {
557 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.event);
562 if (parent->type == NODE_ROOT) {
563 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
568 if (parent->type == NODE_ROOT) {
569 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
574 case NODE_CTF_EXPRESSION:
575 return reparent_ctf_expression(node, parent);
576 case NODE_UNARY_EXPRESSION:
577 if (parent->type == NODE_TYPE_DECLARATOR)
578 parent->u.type_declarator.bitfield_len = node;
584 return reparent_typedef(node, parent);
585 case NODE_TYPEALIAS_TARGET:
586 if (parent->type == NODE_TYPEALIAS)
587 parent->u.typealias.target = node;
590 case NODE_TYPEALIAS_ALIAS:
591 if (parent->type == NODE_TYPEALIAS)
592 parent->u.typealias.alias = node;
596 return reparent_typealias(node, parent);
599 if (parent->type == NODE_TYPE_DECLARATOR) {
600 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
604 case NODE_TYPE_DECLARATOR:
605 return reparent_type_declarator(node, parent);
607 case NODE_TYPE_SPECIFIER:
608 case NODE_FLOATING_POINT:
614 return reparent_type_specifier(node, parent);
616 case NODE_ENUMERATOR:
617 if (parent->type == NODE_ENUM) {
618 _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
622 case NODE_STRUCT_OR_VARIANT_DECLARATION:
623 switch (parent->type) {
625 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
628 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
637 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
644 void yyerror(struct ctf_scanner *scanner, const char *str)
646 fprintf(stderr, "error %s\n", str);
654 #define reparent_error(scanner, str) \
656 yyerror(scanner, YY_("reparent_error: " str "\n")); \
660 static void free_strings(struct cds_list_head *list)
662 struct gc_string *gstr, *tmp;
664 cds_list_for_each_entry_safe(gstr, tmp, list, gc)
668 static struct ctf_ast *ctf_ast_alloc(void)
672 ast = malloc(sizeof(*ast));
675 memset(ast, 0, sizeof(*ast));
676 CDS_INIT_LIST_HEAD(&ast->allocated_nodes);
677 ast->root.type = NODE_ROOT;
678 CDS_INIT_LIST_HEAD(&ast->root.tmp_head);
679 CDS_INIT_LIST_HEAD(&ast->root.u.root._typedef);
680 CDS_INIT_LIST_HEAD(&ast->root.u.root.typealias);
681 CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_specifier);
682 CDS_INIT_LIST_HEAD(&ast->root.u.root.trace);
683 CDS_INIT_LIST_HEAD(&ast->root.u.root.stream);
684 CDS_INIT_LIST_HEAD(&ast->root.u.root.event);
688 static void ctf_ast_free(struct ctf_ast *ast)
690 struct ctf_node *node, *tmp;
692 cds_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
696 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
698 return yyparse(scanner);
701 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
703 struct ctf_scanner *scanner;
706 scanner = malloc(sizeof(*scanner));
709 memset(scanner, 0, sizeof(*scanner));
711 ret = yylex_init_extra(scanner, &scanner->scanner);
713 fprintf(stderr, "yylex_init error\n");
714 goto cleanup_scanner;
716 yyset_in(input, scanner);
718 scanner->ast = ctf_ast_alloc();
721 init_scope(&scanner->root_scope, NULL);
722 scanner->cs = &scanner->root_scope;
723 CDS_INIT_LIST_HEAD(&scanner->allocated_strings);
728 ret = yylex_destroy(scanner->scanner);
730 fprintf(stderr, "yylex_destroy error\n");
736 void ctf_scanner_free(struct ctf_scanner *scanner)
740 finalize_scope(&scanner->root_scope);
741 free_strings(&scanner->allocated_strings);
742 ctf_ast_free(scanner->ast);
743 ret = yylex_destroy(scanner->scanner);
745 fprintf(stderr, "yylex_destroy error\n");
753 %parse-param {struct ctf_scanner *scanner}
754 %lex-param {struct ctf_scanner *scanner}
756 %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
757 %token <gs> IDENTIFIER ID_TYPE
763 struct gc_string *gs;
768 %type <gs> s_char s_char_sequence c_char c_char_sequence
770 %type <n> postfix_expression unary_expression unary_expression_or_range
772 %type <n> declaration
773 %type <n> event_declaration
774 %type <n> stream_declaration
775 %type <n> trace_declaration
776 %type <n> declaration_specifiers
778 %type <n> type_declarator_list
779 %type <n> abstract_type_declarator_list
780 %type <n> type_specifier
781 %type <n> struct_type_specifier
782 %type <n> variant_type_specifier
783 %type <n> type_specifier_or_integer_constant
784 %type <n> enum_type_specifier
785 %type <n> struct_or_variant_declaration_list
786 %type <n> struct_or_variant_declaration
787 %type <n> specifier_qualifier_list
788 %type <n> struct_or_variant_declarator_list
789 %type <n> struct_or_variant_declarator
790 %type <n> enumerator_list
792 %type <n> abstract_declarator_list
793 %type <n> abstract_declarator
794 %type <n> direct_abstract_declarator
796 %type <n> direct_declarator
797 %type <n> type_declarator
798 %type <n> direct_type_declarator
799 %type <n> abstract_type_declarator
800 %type <n> direct_abstract_type_declarator
802 %type <n> ctf_assignment_expression_list
803 %type <n> ctf_assignment_expression
810 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
811 reparent_error(scanner, "error reparenting to root");
815 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
816 reparent_error(scanner, "error reparenting to root");
872 | c_char_sequence c_char
873 { $$ = gc_string_append(scanner, $1, $2); }
881 reparent_error(scanner, "escape sequences not supported yet");
885 /* 1.6 String literals */
890 | s_char_sequence s_char
891 { $$ = gc_string_append(scanner, $1, $2); }
899 reparent_error(scanner, "escape sequences not supported yet");
903 /* 2: Phrase structure grammar */
908 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
909 $$->u.unary_expression.type = UNARY_STRING;
910 $$->u.unary_expression.u.string = yylval.gs->s;
914 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
915 $$->u.unary_expression.type = UNARY_STRING;
916 $$->u.unary_expression.u.string = yylval.gs->s;
920 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
921 $$->u.unary_expression.type = UNARY_STRING;
922 $$->u.unary_expression.u.string = yylval.gs->s;
927 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
928 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
929 sscanf(yylval.gs->s, "%" PRIu64,
930 &$$->u.unary_expression.u.unsigned_constant);
934 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
935 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
936 sscanf(yylval.gs->s, "0%" PRIo64,
937 &$$->u.unary_expression.u.unsigned_constant);
939 | HEXADECIMAL_CONSTANT
941 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
942 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
943 sscanf(yylval.gs->s, "0x%" PRIx64,
944 &$$->u.unary_expression.u.unsigned_constant);
946 | STRING_LITERAL_START DQUOTE
948 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
949 $$->u.unary_expression.type = UNARY_STRING;
950 $$->u.unary_expression.u.string = "";
952 | STRING_LITERAL_START s_char_sequence DQUOTE
954 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
955 $$->u.unary_expression.type = UNARY_STRING;
956 $$->u.unary_expression.u.string = $2->s;
958 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
960 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
961 $$->u.unary_expression.type = UNARY_STRING;
962 $$->u.unary_expression.u.string = $2->s;
964 | LPAREN unary_expression RPAREN
966 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
967 $$->u.unary_expression.type = UNARY_NESTED;
968 $$->u.unary_expression.u.nested_exp = $2;
970 | postfix_expression LSBRAC unary_expression RSBRAC
972 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
973 $$->u.unary_expression.type = UNARY_SBRAC;
974 $$->u.unary_expression.u.sbrac_exp = $3;
975 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
976 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
978 | postfix_expression DOT IDENTIFIER
980 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
981 $$->u.unary_expression.type = UNARY_STRING;
982 $$->u.unary_expression.u.string = yylval.gs->s;
983 $$->u.unary_expression.link = UNARY_DOTLINK;
984 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
985 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
987 | postfix_expression DOT ID_TYPE
989 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
990 $$->u.unary_expression.type = UNARY_STRING;
991 $$->u.unary_expression.u.string = yylval.gs->s;
992 $$->u.unary_expression.link = UNARY_DOTLINK;
993 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
994 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
996 | postfix_expression RARROW IDENTIFIER
998 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
999 $$->u.unary_expression.type = UNARY_STRING;
1000 $$->u.unary_expression.u.string = yylval.gs->s;
1001 $$->u.unary_expression.link = UNARY_ARROWLINK;
1002 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1003 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1005 | postfix_expression RARROW ID_TYPE
1007 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1008 $$->u.unary_expression.type = UNARY_STRING;
1009 $$->u.unary_expression.u.string = yylval.gs->s;
1010 $$->u.unary_expression.link = UNARY_ARROWLINK;
1011 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1012 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1019 | PLUS postfix_expression
1021 | MINUS postfix_expression
1024 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1025 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1026 reparent_error(scanner, "expecting numeric constant");
1028 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1029 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1030 $$->u.unary_expression.u.signed_constant =
1031 -($$->u.unary_expression.u.unsigned_constant);
1033 $$->u.unary_expression.u.signed_constant =
1034 -($$->u.unary_expression.u.signed_constant);
1039 unary_expression_or_range:
1040 unary_expression DOTDOTDOT unary_expression
1043 _cds_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1044 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1050 /* 2.2: Declarations */
1053 declaration_specifiers SEMICOLON
1057 | stream_declaration
1061 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1063 $$ = make_node(scanner, NODE_TYPEDEF);
1064 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
1065 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.declaration_specifier);
1066 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1068 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1070 $$ = make_node(scanner, NODE_TYPEDEF);
1071 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._typedef.declaration_specifier);
1072 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1074 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1076 $$ = make_node(scanner, NODE_TYPEDEF);
1077 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
1078 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1080 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON declaration_specifiers abstract_type_declarator_list SEMICOLON
1082 $$ = make_node(scanner, NODE_TYPEALIAS);
1083 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1084 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1085 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1086 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1087 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
1088 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1090 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON type_declarator_list SEMICOLON
1092 $$ = make_node(scanner, NODE_TYPEALIAS);
1093 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1094 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1095 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1096 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
1097 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1102 event_declaration_begin event_declaration_end
1104 $$ = make_node(scanner, NODE_EVENT);
1106 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1108 $$ = make_node(scanner, NODE_EVENT);
1109 if (set_parent_node($2, $$))
1110 reparent_error(scanner, "event_declaration");
1114 event_declaration_begin:
1116 { push_scope(scanner); }
1119 event_declaration_end:
1121 { pop_scope(scanner); }
1126 stream_declaration_begin stream_declaration_end
1128 $$ = make_node(scanner, NODE_STREAM);
1130 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1132 $$ = make_node(scanner, NODE_STREAM);
1133 if (set_parent_node($2, $$))
1134 reparent_error(scanner, "stream_declaration");
1138 stream_declaration_begin:
1140 { push_scope(scanner); }
1143 stream_declaration_end:
1145 { pop_scope(scanner); }
1150 trace_declaration_begin trace_declaration_end
1152 $$ = make_node(scanner, NODE_TRACE);
1154 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1156 $$ = make_node(scanner, NODE_TRACE);
1157 if (set_parent_node($2, $$))
1158 reparent_error(scanner, "trace_declaration");
1162 trace_declaration_begin:
1164 { push_scope(scanner); }
1167 trace_declaration_end:
1169 { pop_scope(scanner); }
1172 declaration_specifiers:
1175 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1176 $$->u.type_specifier.type = TYPESPEC_CONST;
1180 | declaration_specifiers CONST
1182 struct ctf_node *node;
1185 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1186 node->u.type_specifier.type = TYPESPEC_CONST;
1187 cds_list_add_tail(&node->siblings, &($$)->tmp_head);
1189 | declaration_specifiers type_specifier
1192 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1196 type_declarator_list:
1199 | type_declarator_list COMMA type_declarator
1202 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1206 abstract_type_declarator_list:
1207 abstract_type_declarator
1209 | abstract_type_declarator_list COMMA abstract_type_declarator
1212 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1219 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1220 $$->u.type_specifier.type = TYPESPEC_VOID;
1224 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1225 $$->u.type_specifier.type = TYPESPEC_CHAR;
1229 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1230 $$->u.type_specifier.type = TYPESPEC_SHORT;
1234 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1235 $$->u.type_specifier.type = TYPESPEC_INT;
1239 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1240 $$->u.type_specifier.type = TYPESPEC_LONG;
1244 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1245 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1249 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1250 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1254 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1255 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1259 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1260 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1264 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1265 $$->u.type_specifier.type = TYPESPEC_BOOL;
1269 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1270 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1274 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1275 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1276 $$->u.type_specifier.id_type = yylval.gs->s;
1278 | FLOATING_POINT LBRAC RBRAC
1280 $$ = make_node(scanner, NODE_FLOATING_POINT);
1282 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1284 $$ = make_node(scanner, NODE_FLOATING_POINT);
1285 if (set_parent_node($3, $$))
1286 reparent_error(scanner, "floating point reparent error");
1288 | INTEGER LBRAC RBRAC
1290 $$ = make_node(scanner, NODE_INTEGER);
1292 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1294 $$ = make_node(scanner, NODE_INTEGER);
1295 if (set_parent_node($3, $$))
1296 reparent_error(scanner, "integer reparent error");
1298 | STRING LBRAC RBRAC
1300 $$ = make_node(scanner, NODE_STRING);
1302 | STRING LBRAC ctf_assignment_expression_list RBRAC
1304 $$ = make_node(scanner, NODE_STRING);
1305 if (set_parent_node($3, $$))
1306 reparent_error(scanner, "string reparent error");
1308 | ENUM enum_type_specifier
1310 | VARIANT variant_type_specifier
1312 | STRUCT struct_type_specifier
1316 struct_type_specifier:
1317 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1319 $$ = make_node(scanner, NODE_STRUCT);
1320 if (set_parent_node($2, $$))
1321 reparent_error(scanner, "struct reparent error");
1323 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1325 $$ = make_node(scanner, NODE_STRUCT);
1326 $$->u._struct.name = $1->s;
1327 if (set_parent_node($3, $$))
1328 reparent_error(scanner, "struct reparent error");
1330 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1332 $$ = make_node(scanner, NODE_STRUCT);
1333 $$->u._struct.name = $1->s;
1334 if (set_parent_node($3, $$))
1335 reparent_error(scanner, "struct reparent error");
1339 $$ = make_node(scanner, NODE_STRUCT);
1340 $$->u._struct.name = $1->s;
1344 $$ = make_node(scanner, NODE_STRUCT);
1345 $$->u._struct.name = $1->s;
1349 struct_declaration_begin:
1351 { push_scope(scanner); }
1354 struct_declaration_end:
1356 { pop_scope(scanner); }
1359 variant_type_specifier:
1360 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1362 $$ = make_node(scanner, NODE_VARIANT);
1363 if (set_parent_node($2, $$))
1364 reparent_error(scanner, "variant reparent error");
1366 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1368 $$ = make_node(scanner, NODE_VARIANT);
1369 $$->u.variant.choice = $2->s;
1370 if (set_parent_node($5, $$))
1371 reparent_error(scanner, "variant reparent error");
1373 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1375 $$ = make_node(scanner, NODE_VARIANT);
1376 $$->u.variant.choice = $2->s;
1377 if (set_parent_node($5, $$))
1378 reparent_error(scanner, "variant reparent error");
1380 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1382 $$ = make_node(scanner, NODE_VARIANT);
1383 $$->u.variant.name = $1->s;
1384 if (set_parent_node($3, $$))
1385 reparent_error(scanner, "variant reparent error");
1387 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1389 $$ = make_node(scanner, NODE_VARIANT);
1390 $$->u.variant.name = $1->s;
1391 $$->u.variant.choice = $3->s;
1392 if (set_parent_node($6, $$))
1393 reparent_error(scanner, "variant reparent error");
1395 | IDENTIFIER LT IDENTIFIER GT
1397 $$ = make_node(scanner, NODE_VARIANT);
1398 $$->u.variant.name = $1->s;
1399 $$->u.variant.choice = $3->s;
1401 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1403 $$ = make_node(scanner, NODE_VARIANT);
1404 $$->u.variant.name = $1->s;
1405 $$->u.variant.choice = $3->s;
1406 if (set_parent_node($6, $$))
1407 reparent_error(scanner, "variant reparent error");
1409 | IDENTIFIER LT ID_TYPE GT
1411 $$ = make_node(scanner, NODE_VARIANT);
1412 $$->u.variant.name = $1->s;
1413 $$->u.variant.choice = $3->s;
1415 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1417 $$ = make_node(scanner, NODE_VARIANT);
1418 $$->u.variant.name = $1->s;
1419 if (set_parent_node($3, $$))
1420 reparent_error(scanner, "variant reparent error");
1422 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1424 $$ = make_node(scanner, NODE_VARIANT);
1425 $$->u.variant.name = $1->s;
1426 $$->u.variant.choice = $3->s;
1427 if (set_parent_node($6, $$))
1428 reparent_error(scanner, "variant reparent error");
1430 | ID_TYPE LT IDENTIFIER GT
1432 $$ = make_node(scanner, NODE_VARIANT);
1433 $$->u.variant.name = $1->s;
1434 $$->u.variant.choice = $3->s;
1436 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1438 $$ = make_node(scanner, NODE_VARIANT);
1439 $$->u.variant.name = $1->s;
1440 $$->u.variant.choice = $3->s;
1441 if (set_parent_node($6, $$))
1442 reparent_error(scanner, "variant reparent error");
1444 | ID_TYPE LT ID_TYPE GT
1446 $$ = make_node(scanner, NODE_VARIANT);
1447 $$->u.variant.name = $1->s;
1448 $$->u.variant.choice = $3->s;
1452 variant_declaration_begin:
1454 { push_scope(scanner); }
1457 variant_declaration_end:
1459 { pop_scope(scanner); }
1462 type_specifier_or_integer_constant:
1463 declaration_specifiers
1467 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1468 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1469 sscanf(yylval.gs->s, "%" PRIu64,
1470 &$$->u.unary_expression.u.unsigned_constant);
1474 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1475 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1476 sscanf(yylval.gs->s, "0%" PRIo64,
1477 &$$->u.unary_expression.u.unsigned_constant);
1479 | HEXADECIMAL_CONSTANT
1481 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1482 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1483 sscanf(yylval.gs->s, "0x%" PRIx64,
1484 &$$->u.unary_expression.u.unsigned_constant);
1488 enum_type_specifier:
1489 LBRAC enumerator_list RBRAC
1491 $$ = make_node(scanner, NODE_ENUM);
1492 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1494 | LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
1496 $$ = make_node(scanner, NODE_ENUM);
1497 $$->u._enum.container_type = $2;
1498 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1500 | IDENTIFIER LBRAC enumerator_list RBRAC
1502 $$ = make_node(scanner, NODE_ENUM);
1503 $$->u._enum.enum_id = $1->s;
1504 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1506 | IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
1508 $$ = make_node(scanner, NODE_ENUM);
1509 $$->u._enum.enum_id = $1->s;
1510 $$->u._enum.container_type = $3;
1511 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1513 | ID_TYPE LBRAC enumerator_list RBRAC
1515 $$ = make_node(scanner, NODE_ENUM);
1516 $$->u._enum.enum_id = $1->s;
1517 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1519 | ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
1521 $$ = make_node(scanner, NODE_ENUM);
1522 $$->u._enum.enum_id = $1->s;
1523 $$->u._enum.container_type = $3;
1524 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1526 | LBRAC enumerator_list COMMA RBRAC
1528 $$ = make_node(scanner, NODE_ENUM);
1529 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1531 | LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
1533 $$ = make_node(scanner, NODE_ENUM);
1534 $$->u._enum.container_type = $2;
1535 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1537 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1539 $$ = make_node(scanner, NODE_ENUM);
1540 $$->u._enum.enum_id = $1->s;
1541 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1543 | IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
1545 $$ = make_node(scanner, NODE_ENUM);
1546 $$->u._enum.enum_id = $1->s;
1547 $$->u._enum.container_type = $3;
1548 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1552 $$ = make_node(scanner, NODE_ENUM);
1553 $$->u._enum.enum_id = $1->s;
1555 | IDENTIFIER LT type_specifier_or_integer_constant GT
1557 $$ = make_node(scanner, NODE_ENUM);
1558 $$->u._enum.enum_id = $1->s;
1559 $$->u._enum.container_type = $3;
1561 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1563 $$ = make_node(scanner, NODE_ENUM);
1564 $$->u._enum.enum_id = $1->s;
1565 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1567 | ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
1569 $$ = make_node(scanner, NODE_ENUM);
1570 $$->u._enum.enum_id = $1->s;
1571 $$->u._enum.container_type = $3;
1572 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1576 $$ = make_node(scanner, NODE_ENUM);
1577 $$->u._enum.enum_id = $1->s;
1579 | ID_TYPE LT type_specifier_or_integer_constant GT
1581 $$ = make_node(scanner, NODE_ENUM);
1582 $$->u._enum.enum_id = $1->s;
1583 $$->u._enum.container_type = $3;
1587 struct_or_variant_declaration_list:
1590 | struct_or_variant_declaration_list struct_or_variant_declaration
1594 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1597 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1602 struct_or_variant_declaration:
1603 specifier_qualifier_list struct_or_variant_declarator_list SEMICOLON
1605 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1606 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.struct_or_variant_declaration.declaration_specifier);
1607 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
1609 | specifier_qualifier_list TYPEDEF specifier_qualifier_list type_declarator_list SEMICOLON
1611 $$ = make_node(scanner, NODE_TYPEDEF);
1612 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
1613 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.declaration_specifier);
1614 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1616 | TYPEDEF specifier_qualifier_list type_declarator_list SEMICOLON
1618 $$ = make_node(scanner, NODE_TYPEDEF);
1619 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._typedef.declaration_specifier);
1620 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1622 | specifier_qualifier_list TYPEDEF type_declarator_list SEMICOLON
1624 $$ = make_node(scanner, NODE_TYPEDEF);
1625 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
1626 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1628 | TYPEALIAS specifier_qualifier_list abstract_declarator_list COLON specifier_qualifier_list abstract_type_declarator_list SEMICOLON
1630 $$ = make_node(scanner, NODE_TYPEALIAS);
1631 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1632 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1633 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1634 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1635 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
1636 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1638 | TYPEALIAS specifier_qualifier_list abstract_declarator_list COLON type_declarator_list SEMICOLON
1640 $$ = make_node(scanner, NODE_TYPEALIAS);
1641 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1642 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1643 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1644 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
1645 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1649 specifier_qualifier_list:
1652 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1653 $$->u.type_specifier.type = TYPESPEC_CONST;
1657 | specifier_qualifier_list CONST
1659 struct ctf_node *node;
1662 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1663 node->u.type_specifier.type = TYPESPEC_CONST;
1664 cds_list_add_tail(&node->siblings, &($$)->tmp_head);
1666 | specifier_qualifier_list type_specifier
1669 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1673 struct_or_variant_declarator_list:
1674 struct_or_variant_declarator
1676 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
1679 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1683 struct_or_variant_declarator:
1686 | COLON unary_expression
1688 | declarator COLON unary_expression
1691 if (set_parent_node($3, $1))
1692 reparent_error(scanner, "struct_or_variant_declarator");
1699 | enumerator_list COMMA enumerator
1702 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1709 $$ = make_node(scanner, NODE_ENUMERATOR);
1710 $$->u.enumerator.id = $1->s;
1714 $$ = make_node(scanner, NODE_ENUMERATOR);
1715 $$->u.enumerator.id = $1->s;
1719 $$ = make_node(scanner, NODE_ENUMERATOR);
1720 $$->u.enumerator.id = $1->s;
1722 | STRING_LITERAL_START DQUOTE
1724 $$ = make_node(scanner, NODE_ENUMERATOR);
1725 $$->u.enumerator.id = "";
1727 | STRING_LITERAL_START s_char_sequence DQUOTE
1729 $$ = make_node(scanner, NODE_ENUMERATOR);
1730 $$->u.enumerator.id = $2->s;
1732 | IDENTIFIER EQUAL unary_expression_or_range
1734 $$ = make_node(scanner, NODE_ENUMERATOR);
1735 $$->u.enumerator.id = $1->s;
1736 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
1738 | ID_TYPE EQUAL unary_expression_or_range
1740 $$ = make_node(scanner, NODE_ENUMERATOR);
1741 $$->u.enumerator.id = $1->s;
1742 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
1744 | keywords EQUAL unary_expression_or_range
1746 $$ = make_node(scanner, NODE_ENUMERATOR);
1747 $$->u.enumerator.id = $1->s;
1748 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
1750 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
1752 $$ = make_node(scanner, NODE_ENUMERATOR);
1753 $$->u.enumerator.id = "";
1754 cds_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
1756 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
1758 $$ = make_node(scanner, NODE_ENUMERATOR);
1759 $$->u.enumerator.id = $2->s;
1760 cds_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
1764 abstract_declarator_list:
1767 | abstract_declarator_list COMMA abstract_declarator
1770 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1774 abstract_declarator:
1775 direct_abstract_declarator
1777 | pointer direct_abstract_declarator
1780 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
1784 direct_abstract_declarator:
1787 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1788 $$->u.type_declarator.type = TYPEDEC_ID;
1793 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1794 $$->u.type_declarator.type = TYPEDEC_ID;
1795 $$->u.type_declarator.u.id = $1->s;
1797 | LPAREN abstract_declarator RPAREN
1799 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1800 $$->u.type_declarator.type = TYPEDEC_NESTED;
1801 $$->u.type_declarator.u.nested.type_declarator = $2;
1803 | direct_abstract_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
1805 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1806 $$->u.type_declarator.type = TYPEDEC_NESTED;
1807 $$->u.type_declarator.u.nested.type_declarator = $1;
1808 $$->u.type_declarator.u.nested.length = $3;
1810 | direct_abstract_declarator LSBRAC RSBRAC
1812 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1813 $$->u.type_declarator.type = TYPEDEC_NESTED;
1814 $$->u.type_declarator.u.nested.type_declarator = $1;
1815 $$->u.type_declarator.u.nested.abstract_array = 1;
1822 | pointer direct_declarator
1825 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
1832 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1833 $$->u.type_declarator.type = TYPEDEC_ID;
1834 $$->u.type_declarator.u.id = $1->s;
1836 | LPAREN declarator RPAREN
1838 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1839 $$->u.type_declarator.type = TYPEDEC_NESTED;
1840 $$->u.type_declarator.u.nested.type_declarator = $2;
1842 | direct_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
1844 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1845 $$->u.type_declarator.type = TYPEDEC_NESTED;
1846 $$->u.type_declarator.u.nested.type_declarator = $1;
1847 $$->u.type_declarator.u.nested.length = $3;
1852 direct_type_declarator
1854 | pointer direct_type_declarator
1857 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
1861 direct_type_declarator:
1864 add_type(scanner, $1);
1865 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1866 $$->u.type_declarator.type = TYPEDEC_ID;
1867 $$->u.type_declarator.u.id = $1->s;
1869 | LPAREN type_declarator RPAREN
1871 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1872 $$->u.type_declarator.type = TYPEDEC_NESTED;
1873 $$->u.type_declarator.u.nested.type_declarator = $2;
1875 | direct_type_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
1877 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1878 $$->u.type_declarator.type = TYPEDEC_NESTED;
1879 $$->u.type_declarator.u.nested.type_declarator = $1;
1880 $$->u.type_declarator.u.nested.length = $3;
1884 abstract_type_declarator:
1885 direct_abstract_type_declarator
1887 | pointer direct_abstract_type_declarator
1890 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
1894 direct_abstract_type_declarator:
1897 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1898 $$->u.type_declarator.type = TYPEDEC_ID;
1903 add_type(scanner, $1);
1904 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1905 $$->u.type_declarator.type = TYPEDEC_ID;
1906 $$->u.type_declarator.u.id = $1->s;
1908 | LPAREN abstract_type_declarator RPAREN
1910 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1911 $$->u.type_declarator.type = TYPEDEC_NESTED;
1912 $$->u.type_declarator.u.nested.type_declarator = $2;
1914 | direct_abstract_type_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
1916 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1917 $$->u.type_declarator.type = TYPEDEC_NESTED;
1918 $$->u.type_declarator.u.nested.type_declarator = $1;
1919 $$->u.type_declarator.u.nested.length = $3;
1921 | direct_abstract_type_declarator LSBRAC RSBRAC
1923 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1924 $$->u.type_declarator.type = TYPEDEC_NESTED;
1925 $$->u.type_declarator.u.nested.type_declarator = $1;
1926 $$->u.type_declarator.u.nested.abstract_array = 1;
1933 $$ = make_node(scanner, NODE_POINTER);
1937 $$ = make_node(scanner, NODE_POINTER);
1938 cds_list_splice(&($2)->tmp_head, &($$)->tmp_head);
1940 | STAR type_qualifier_list pointer
1942 $$ = make_node(scanner, NODE_POINTER);
1943 $$->u.pointer.const_qualifier = 1;
1944 cds_list_splice(&($3)->tmp_head, &($$)->tmp_head);
1948 type_qualifier_list:
1949 /* pointer assumes only const type qualifier */
1951 | type_qualifier_list CONST
1954 /* 2.3: CTF-specific declarations */
1956 ctf_assignment_expression_list:
1957 ctf_assignment_expression SEMICOLON
1959 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
1962 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1966 ctf_assignment_expression:
1967 unary_expression EQUAL unary_expression
1970 * Because we have left and right, cannot use
1973 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
1974 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
1975 if ($1->u.unary_expression.type != UNARY_STRING)
1976 reparent_error(scanner, "ctf_assignment_expression left expects string");
1977 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
1979 | unary_expression TYPEASSIGN type_specifier
1982 * Because we have left and right, cannot use
1985 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
1986 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
1987 if ($1->u.unary_expression.type != UNARY_STRING)
1988 reparent_error(scanner, "ctf_assignment_expression left expects string");
1989 cds_list_add(&($3)->siblings, &($3)->tmp_head);
1990 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
1992 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
1994 $$ = make_node(scanner, NODE_TYPEDEF);
1995 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.declaration_specifier);
1996 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
1997 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1999 | TYPEDEF declaration_specifiers type_declarator_list
2001 $$ = make_node(scanner, NODE_TYPEDEF);
2002 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._typedef.declaration_specifier);
2003 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2005 | declaration_specifiers TYPEDEF type_declarator_list
2007 $$ = make_node(scanner, NODE_TYPEDEF);
2008 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
2009 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2011 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON declaration_specifiers abstract_type_declarator_list
2013 $$ = make_node(scanner, NODE_TYPEALIAS);
2014 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2015 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2016 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
2017 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2018 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
2019 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2021 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON type_declarator_list
2023 $$ = make_node(scanner, NODE_TYPEALIAS);
2024 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2025 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2026 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
2027 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
2028 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);