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.
25 #include <helpers/list.h>
28 #include "ctf-scanner.h"
29 #include "ctf-parser.h"
32 /* Join two lists, put "add" at the end of "head". */
34 _cds_list_splice_tail (struct cds_list_head *add, struct cds_list_head *head)
36 /* Do nothing if the list which gets added is empty. */
37 if (add != add->next) {
38 add->next->prev = head->prev;
39 add->prev->next = head;
40 head->prev->next = add->next;
41 head->prev = add->prev;
45 #define printf_dbg(fmt, args...) fprintf(stderr, "%s: " fmt, __func__, ## args)
47 int yyparse(struct ctf_scanner *scanner);
48 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
49 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
50 int yylex_destroy(yyscan_t yyscanner) ;
51 void yyset_in(FILE * in_str, yyscan_t scanner);
56 struct cds_list_head gc;
61 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
64 struct gc_string *gstr;
67 /* TODO: could be faster with find first bit or glib Gstring */
68 /* sizeof long to account for malloc header (int or long ?) */
69 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
72 gstr = malloc(alloclen);
73 cds_list_add(&gstr->gc, &scanner->allocated_strings);
74 gstr->alloclen = alloclen;
79 * note: never use gc_string_append on a string that has external references.
80 * gsrc will be garbage collected immediately, and gstr might be.
81 * Should only be used to append characters to a string literal or constant.
83 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
84 struct gc_string *gstr,
85 struct gc_string *gsrc)
87 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
90 /* TODO: could be faster with find first bit or glib Gstring */
91 /* sizeof long to account for malloc header (int or long ?) */
92 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
95 if (alloclen > gstr->alloclen) {
96 struct gc_string *newgstr;
98 newgstr = gc_string_alloc(scanner, newlen);
99 strcpy(newgstr->s, gstr->s);
100 strcat(newgstr->s, gsrc->s);
101 cds_list_del(&gstr->gc);
105 strcat(gstr->s, gsrc->s);
107 cds_list_del(&gsrc->gc);
112 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
114 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
115 strcpy(lvalp->gs->s, src);
118 static void init_scope(struct ctf_scanner_scope *scope,
119 struct ctf_scanner_scope *parent)
121 scope->parent = parent;
122 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
126 static void finalize_scope(struct ctf_scanner_scope *scope)
128 g_hash_table_destroy(scope->types);
131 static void push_scope(struct ctf_scanner *scanner)
133 struct ctf_scanner_scope *ns;
135 printf_dbg("push scope\n");
136 ns = malloc(sizeof(struct ctf_scanner_scope));
137 init_scope(ns, scanner->cs);
141 static void pop_scope(struct ctf_scanner *scanner)
143 struct ctf_scanner_scope *os;
145 printf_dbg("pop scope\n");
147 scanner->cs = os->parent;
152 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
156 ret = (int) g_hash_table_lookup(s->types, id);
157 printf_dbg("lookup %p %s %d\n", s, id, ret);
161 int is_type(struct ctf_scanner *scanner, const char *id)
163 struct ctf_scanner_scope *it;
166 for (it = scanner->cs; it != NULL; it = it->parent) {
167 if (lookup_type(it, id)) {
172 printf_dbg("is type %s %d\n", id, ret);
176 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
178 printf_dbg("add type %s\n", id->s);
179 if (lookup_type(scanner->cs, id->s))
181 g_hash_table_insert(scanner->cs->types, id->s, id->s);
184 static struct ctf_node *make_node(struct ctf_scanner *scanner,
187 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
188 struct ctf_node *node;
190 node = malloc(sizeof(*node));
193 memset(node, 0, sizeof(*node));
195 CDS_INIT_LIST_HEAD(&node->tmp_head);
196 cds_list_add(&node->gc, &ast->allocated_nodes);
197 cds_list_add(&node->siblings, &node->tmp_head);
201 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
205 CDS_INIT_LIST_HEAD(&node->u.event.declaration_list);
208 CDS_INIT_LIST_HEAD(&node->u.stream.declaration_list);
211 CDS_INIT_LIST_HEAD(&node->u.trace.declaration_list);
214 case NODE_CTF_EXPRESSION:
215 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.left);
216 CDS_INIT_LIST_HEAD(&node->u.ctf_expression.right);
218 case NODE_UNARY_EXPRESSION:
222 CDS_INIT_LIST_HEAD(&node->u._typedef.declaration_specifier);
223 CDS_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
225 case NODE_TYPEALIAS_TARGET:
226 CDS_INIT_LIST_HEAD(&node->u.typealias_target.declaration_specifier);
227 CDS_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
229 case NODE_TYPEALIAS_ALIAS:
230 CDS_INIT_LIST_HEAD(&node->u.typealias_alias.declaration_specifier);
231 CDS_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
236 case NODE_TYPE_SPECIFIER:
240 case NODE_TYPE_DECLARATOR:
241 CDS_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
244 case NODE_FLOATING_POINT:
245 CDS_INIT_LIST_HEAD(&node->u.floating_point.expressions);
248 CDS_INIT_LIST_HEAD(&node->u.integer.expressions);
251 CDS_INIT_LIST_HEAD(&node->u.string.expressions);
253 case NODE_ENUMERATOR:
254 CDS_INIT_LIST_HEAD(&node->u.enumerator.values);
257 CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
259 case NODE_STRUCT_OR_VARIANT_DECLARATION:
260 CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.declaration_specifier);
261 CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
264 CDS_INIT_LIST_HEAD(&node->u.variant.declaration_list);
267 CDS_INIT_LIST_HEAD(&node->u._struct.declaration_list);
272 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
280 static int reparent_ctf_expression(struct ctf_node *node,
281 struct ctf_node *parent)
283 switch (parent->type) {
285 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
288 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
291 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
293 case NODE_FLOATING_POINT:
294 _cds_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
297 _cds_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
300 _cds_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
304 case NODE_CTF_EXPRESSION:
306 case NODE_TYPEALIAS_TARGET:
307 case NODE_TYPEALIAS_ALIAS:
309 case NODE_TYPE_SPECIFIER:
311 case NODE_TYPE_DECLARATOR:
312 case NODE_ENUMERATOR:
314 case NODE_STRUCT_OR_VARIANT_DECLARATION:
317 case NODE_UNARY_EXPRESSION:
322 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
329 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
331 switch (parent->type) {
333 _cds_list_splice_tail(&node->tmp_head, &parent->u.root._typedef);
336 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
339 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
342 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
345 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
348 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
351 case NODE_FLOATING_POINT:
354 case NODE_CTF_EXPRESSION:
356 case NODE_TYPEALIAS_TARGET:
357 case NODE_TYPEALIAS_ALIAS:
359 case NODE_TYPE_SPECIFIER:
361 case NODE_TYPE_DECLARATOR:
362 case NODE_ENUMERATOR:
364 case NODE_STRUCT_OR_VARIANT_DECLARATION:
365 case NODE_UNARY_EXPRESSION:
370 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
377 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
379 switch (parent->type) {
381 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.typealias);
384 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
387 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
390 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
393 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
396 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
399 case NODE_FLOATING_POINT:
402 case NODE_CTF_EXPRESSION:
404 case NODE_TYPEALIAS_TARGET:
405 case NODE_TYPEALIAS_ALIAS:
407 case NODE_TYPE_SPECIFIER:
409 case NODE_TYPE_DECLARATOR:
410 case NODE_ENUMERATOR:
412 case NODE_STRUCT_OR_VARIANT_DECLARATION:
413 case NODE_UNARY_EXPRESSION:
418 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
425 static int reparent_type_specifier(struct ctf_node *node,
426 struct ctf_node *parent)
428 switch (parent->type) {
430 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_specifier);
433 _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
436 _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
439 _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
442 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
445 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
448 _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.declaration_specifier);
450 case NODE_TYPEALIAS_TARGET:
451 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.declaration_specifier);
453 case NODE_TYPEALIAS_ALIAS:
454 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.declaration_specifier);
456 case NODE_TYPE_DECLARATOR:
457 parent->u.type_declarator.type = TYPEDEC_NESTED;
458 parent->u.type_declarator.u.nested.length = node;
461 parent->u._enum.container_type = node;
463 case NODE_STRUCT_OR_VARIANT_DECLARATION:
464 _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.declaration_specifier);
467 case NODE_FLOATING_POINT:
470 case NODE_CTF_EXPRESSION:
471 case NODE_TYPE_SPECIFIER:
473 case NODE_ENUMERATOR:
474 case NODE_UNARY_EXPRESSION:
479 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
486 static int reparent_type_declarator(struct ctf_node *node,
487 struct ctf_node *parent)
489 switch (parent->type) {
490 case NODE_TYPE_DECLARATOR:
491 parent->u.type_declarator.type = TYPEDEC_NESTED;
492 parent->u.type_declarator.u.nested.type_declarator = node;
494 case NODE_STRUCT_OR_VARIANT_DECLARATION:
495 _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
498 _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
500 case NODE_TYPEALIAS_TARGET:
501 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
503 case NODE_TYPEALIAS_ALIAS:
504 _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
515 case NODE_FLOATING_POINT:
518 case NODE_CTF_EXPRESSION:
519 case NODE_TYPE_SPECIFIER:
521 case NODE_ENUMERATOR:
522 case NODE_UNARY_EXPRESSION:
527 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
537 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
538 * create the link declared by the input, -ENOENT if node or parent is NULL,
539 * -EINVAL if there is an internal structure problem.
541 static int set_parent_node(struct ctf_node *node,
542 struct ctf_node *parent)
544 if (!node || !parent)
547 /* Note: Linking to parent will be done only by an external visitor */
549 switch (node->type) {
551 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
555 if (parent->type == NODE_ROOT) {
556 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.event);
561 if (parent->type == NODE_ROOT) {
562 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
567 if (parent->type == NODE_ROOT) {
568 _cds_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
573 case NODE_CTF_EXPRESSION:
574 return reparent_ctf_expression(node, parent);
575 case NODE_UNARY_EXPRESSION:
576 if (parent->type == NODE_TYPE_DECLARATOR)
577 parent->u.type_declarator.bitfield_len = node;
583 return reparent_typedef(node, parent);
584 case NODE_TYPEALIAS_TARGET:
585 if (parent->type == NODE_TYPEALIAS)
586 parent->u.typealias.target = node;
589 case NODE_TYPEALIAS_ALIAS:
590 if (parent->type == NODE_TYPEALIAS)
591 parent->u.typealias.alias = node;
595 return reparent_typealias(node, parent);
598 if (parent->type == NODE_TYPE_DECLARATOR) {
599 _cds_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
603 case NODE_TYPE_DECLARATOR:
604 return reparent_type_declarator(node, parent);
606 case NODE_TYPE_SPECIFIER:
607 case NODE_FLOATING_POINT:
613 return reparent_type_specifier(node, parent);
615 case NODE_ENUMERATOR:
616 if (parent->type == NODE_ENUM) {
617 _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
621 case NODE_STRUCT_OR_VARIANT_DECLARATION:
622 switch (parent->type) {
624 _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
627 _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
636 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
643 void yyerror(struct ctf_scanner *scanner, const char *str)
645 fprintf(stderr, "error %s\n", str);
653 #define reparent_error(scanner, str) \
655 yyerror(scanner, YY_("reparent_error: " str "\n")); \
659 static void free_strings(struct cds_list_head *list)
661 struct gc_string *gstr, *tmp;
663 cds_list_for_each_entry_safe(gstr, tmp, list, gc)
667 static struct ctf_ast *ctf_ast_alloc(void)
671 ast = malloc(sizeof(*ast));
674 memset(ast, 0, sizeof(*ast));
675 CDS_INIT_LIST_HEAD(&ast->allocated_nodes);
676 ast->root.type = NODE_ROOT;
677 CDS_INIT_LIST_HEAD(&ast->root.tmp_head);
678 CDS_INIT_LIST_HEAD(&ast->root.u.root._typedef);
679 CDS_INIT_LIST_HEAD(&ast->root.u.root.typealias);
680 CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_specifier);
681 CDS_INIT_LIST_HEAD(&ast->root.u.root.trace);
682 CDS_INIT_LIST_HEAD(&ast->root.u.root.stream);
683 CDS_INIT_LIST_HEAD(&ast->root.u.root.event);
687 static void ctf_ast_free(struct ctf_ast *ast)
689 struct ctf_node *node, *tmp;
691 cds_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
695 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
697 return yyparse(scanner);
700 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
702 struct ctf_scanner *scanner;
705 scanner = malloc(sizeof(*scanner));
708 memset(scanner, 0, sizeof(*scanner));
710 ret = yylex_init_extra(scanner, &scanner->scanner);
712 fprintf(stderr, "yylex_init error\n");
713 goto cleanup_scanner;
715 yyset_in(input, scanner);
717 scanner->ast = ctf_ast_alloc();
720 init_scope(&scanner->root_scope, NULL);
721 scanner->cs = &scanner->root_scope;
722 CDS_INIT_LIST_HEAD(&scanner->allocated_strings);
727 ret = yylex_destroy(scanner->scanner);
729 fprintf(stderr, "yylex_destroy error\n");
735 void ctf_scanner_free(struct ctf_scanner *scanner)
739 finalize_scope(&scanner->root_scope);
740 free_strings(&scanner->allocated_strings);
741 ctf_ast_free(scanner->ast);
742 ret = yylex_destroy(scanner->scanner);
744 fprintf(stderr, "yylex_destroy error\n");
752 %parse-param {struct ctf_scanner *scanner}
753 %lex-param {struct ctf_scanner *scanner}
755 %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
756 %token <gs> IDENTIFIER ID_TYPE
762 struct gc_string *gs;
767 %type <gs> s_char s_char_sequence c_char c_char_sequence
769 %type <n> postfix_expression unary_expression unary_expression_or_range
771 %type <n> declaration
772 %type <n> event_declaration
773 %type <n> stream_declaration
774 %type <n> trace_declaration
775 %type <n> declaration_specifiers
777 %type <n> type_declarator_list
778 %type <n> abstract_type_declarator_list
779 %type <n> type_specifier
780 %type <n> struct_type_specifier
781 %type <n> variant_type_specifier
782 %type <n> type_specifier_or_integer_constant
783 %type <n> enum_type_specifier
784 %type <n> struct_or_variant_declaration_list
785 %type <n> struct_or_variant_declaration
786 %type <n> specifier_qualifier_list
787 %type <n> struct_or_variant_declarator_list
788 %type <n> struct_or_variant_declarator
789 %type <n> enumerator_list
791 %type <n> abstract_declarator_list
792 %type <n> abstract_declarator
793 %type <n> direct_abstract_declarator
795 %type <n> direct_declarator
796 %type <n> type_declarator
797 %type <n> direct_type_declarator
798 %type <n> abstract_type_declarator
799 %type <n> direct_abstract_type_declarator
801 %type <n> ctf_assignment_expression_list
802 %type <n> ctf_assignment_expression
809 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
810 reparent_error(scanner, "error reparenting to root");
814 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
815 reparent_error(scanner, "error reparenting to root");
871 | c_char_sequence c_char
872 { $$ = gc_string_append(scanner, $1, $2); }
880 reparent_error(scanner, "escape sequences not supported yet");
884 /* 1.6 String literals */
889 | s_char_sequence s_char
890 { $$ = gc_string_append(scanner, $1, $2); }
898 reparent_error(scanner, "escape sequences not supported yet");
902 /* 2: Phrase structure grammar */
907 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
908 $$->u.unary_expression.type = UNARY_STRING;
909 $$->u.unary_expression.u.string = yylval.gs->s;
913 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
914 $$->u.unary_expression.type = UNARY_STRING;
915 $$->u.unary_expression.u.string = yylval.gs->s;
919 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
920 $$->u.unary_expression.type = UNARY_STRING;
921 $$->u.unary_expression.u.string = yylval.gs->s;
926 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
927 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
928 sscanf(yylval.gs->s, "%llu",
929 &$$->u.unary_expression.u.unsigned_constant);
933 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
934 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
935 sscanf(yylval.gs->s, "0%llo",
936 &$$->u.unary_expression.u.unsigned_constant);
938 | HEXADECIMAL_CONSTANT
940 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
941 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
942 sscanf(yylval.gs->s, "0x%llx",
943 &$$->u.unary_expression.u.unsigned_constant);
945 | STRING_LITERAL_START DQUOTE
947 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
948 $$->u.unary_expression.type = UNARY_STRING;
949 $$->u.unary_expression.u.string = "";
951 | STRING_LITERAL_START s_char_sequence DQUOTE
953 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
954 $$->u.unary_expression.type = UNARY_STRING;
955 $$->u.unary_expression.u.string = $2->s;
957 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
959 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
960 $$->u.unary_expression.type = UNARY_STRING;
961 $$->u.unary_expression.u.string = $2->s;
963 | LPAREN unary_expression RPAREN
965 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
966 $$->u.unary_expression.type = UNARY_NESTED;
967 $$->u.unary_expression.u.nested_exp = $2;
969 | postfix_expression LSBRAC unary_expression RSBRAC
971 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
972 $$->u.unary_expression.type = UNARY_SBRAC;
973 $$->u.unary_expression.u.sbrac_exp = $3;
974 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
975 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
977 | postfix_expression DOT IDENTIFIER
979 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
980 $$->u.unary_expression.type = UNARY_STRING;
981 $$->u.unary_expression.u.string = yylval.gs->s;
982 $$->u.unary_expression.link = UNARY_DOTLINK;
983 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
984 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
986 | postfix_expression DOT ID_TYPE
988 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
989 $$->u.unary_expression.type = UNARY_STRING;
990 $$->u.unary_expression.u.string = yylval.gs->s;
991 $$->u.unary_expression.link = UNARY_DOTLINK;
992 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
993 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
995 | postfix_expression RARROW IDENTIFIER
997 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
998 $$->u.unary_expression.type = UNARY_STRING;
999 $$->u.unary_expression.u.string = yylval.gs->s;
1000 $$->u.unary_expression.link = UNARY_ARROWLINK;
1001 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1002 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1004 | postfix_expression RARROW ID_TYPE
1006 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1007 $$->u.unary_expression.type = UNARY_STRING;
1008 $$->u.unary_expression.u.string = yylval.gs->s;
1009 $$->u.unary_expression.link = UNARY_ARROWLINK;
1010 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1011 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1018 | PLUS postfix_expression
1020 | MINUS postfix_expression
1023 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1024 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1025 reparent_error(scanner, "expecting numeric constant");
1027 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1028 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1029 $$->u.unary_expression.u.signed_constant =
1030 -($$->u.unary_expression.u.unsigned_constant);
1032 $$->u.unary_expression.u.signed_constant =
1033 -($$->u.unary_expression.u.signed_constant);
1038 unary_expression_or_range:
1039 unary_expression DOTDOTDOT unary_expression
1042 _cds_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1043 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1049 /* 2.2: Declarations */
1052 declaration_specifiers SEMICOLON
1056 | stream_declaration
1060 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1062 $$ = make_node(scanner, NODE_TYPEDEF);
1063 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
1064 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.declaration_specifier);
1065 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1067 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1069 $$ = make_node(scanner, NODE_TYPEDEF);
1070 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._typedef.declaration_specifier);
1071 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1073 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1075 $$ = make_node(scanner, NODE_TYPEDEF);
1076 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
1077 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1079 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON declaration_specifiers abstract_type_declarator_list SEMICOLON
1081 $$ = make_node(scanner, NODE_TYPEALIAS);
1082 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1083 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1084 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1085 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1086 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
1087 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1089 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON type_declarator_list SEMICOLON
1091 $$ = make_node(scanner, NODE_TYPEALIAS);
1092 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1093 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1094 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1095 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
1096 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1101 event_declaration_begin event_declaration_end
1103 $$ = make_node(scanner, NODE_EVENT);
1105 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1107 $$ = make_node(scanner, NODE_EVENT);
1108 if (set_parent_node($2, $$))
1109 reparent_error(scanner, "event_declaration");
1113 event_declaration_begin:
1115 { push_scope(scanner); }
1118 event_declaration_end:
1120 { pop_scope(scanner); }
1125 stream_declaration_begin stream_declaration_end
1127 $$ = make_node(scanner, NODE_STREAM);
1129 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1131 $$ = make_node(scanner, NODE_STREAM);
1132 if (set_parent_node($2, $$))
1133 reparent_error(scanner, "stream_declaration");
1137 stream_declaration_begin:
1139 { push_scope(scanner); }
1142 stream_declaration_end:
1144 { pop_scope(scanner); }
1149 trace_declaration_begin trace_declaration_end
1151 $$ = make_node(scanner, NODE_TRACE);
1153 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1155 $$ = make_node(scanner, NODE_TRACE);
1156 if (set_parent_node($2, $$))
1157 reparent_error(scanner, "trace_declaration");
1161 trace_declaration_begin:
1163 { push_scope(scanner); }
1166 trace_declaration_end:
1168 { pop_scope(scanner); }
1171 declaration_specifiers:
1174 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1175 $$->u.type_specifier.type = TYPESPEC_CONST;
1179 | declaration_specifiers CONST
1181 struct ctf_node *node;
1184 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1185 node->u.type_specifier.type = TYPESPEC_CONST;
1186 cds_list_add_tail(&node->siblings, &($$)->tmp_head);
1188 | declaration_specifiers type_specifier
1191 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1195 type_declarator_list:
1198 | type_declarator_list COMMA type_declarator
1201 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1205 abstract_type_declarator_list:
1206 abstract_type_declarator
1208 | abstract_type_declarator_list COMMA abstract_type_declarator
1211 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1218 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1219 $$->u.type_specifier.type = TYPESPEC_VOID;
1223 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1224 $$->u.type_specifier.type = TYPESPEC_CHAR;
1228 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1229 $$->u.type_specifier.type = TYPESPEC_SHORT;
1233 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1234 $$->u.type_specifier.type = TYPESPEC_INT;
1238 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1239 $$->u.type_specifier.type = TYPESPEC_LONG;
1243 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1244 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1248 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1249 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1253 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1254 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1258 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1259 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1263 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1264 $$->u.type_specifier.type = TYPESPEC_BOOL;
1268 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1269 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1273 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1274 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1275 $$->u.type_specifier.id_type = yylval.gs->s;
1277 | FLOATING_POINT LBRAC RBRAC
1279 $$ = make_node(scanner, NODE_FLOATING_POINT);
1281 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1283 $$ = make_node(scanner, NODE_FLOATING_POINT);
1284 if (set_parent_node($3, $$))
1285 reparent_error(scanner, "floating point reparent error");
1287 | INTEGER LBRAC RBRAC
1289 $$ = make_node(scanner, NODE_INTEGER);
1291 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1293 $$ = make_node(scanner, NODE_INTEGER);
1294 if (set_parent_node($3, $$))
1295 reparent_error(scanner, "integer reparent error");
1297 | STRING LBRAC RBRAC
1299 $$ = make_node(scanner, NODE_STRING);
1301 | STRING LBRAC ctf_assignment_expression_list RBRAC
1303 $$ = make_node(scanner, NODE_STRING);
1304 if (set_parent_node($3, $$))
1305 reparent_error(scanner, "string reparent error");
1307 | ENUM enum_type_specifier
1309 | VARIANT variant_type_specifier
1311 | STRUCT struct_type_specifier
1315 struct_type_specifier:
1316 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1318 $$ = make_node(scanner, NODE_STRUCT);
1319 if (set_parent_node($2, $$))
1320 reparent_error(scanner, "struct reparent error");
1322 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1324 $$ = make_node(scanner, NODE_STRUCT);
1325 $$->u._struct.name = $1->s;
1326 if (set_parent_node($3, $$))
1327 reparent_error(scanner, "struct reparent error");
1329 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1331 $$ = make_node(scanner, NODE_STRUCT);
1332 $$->u._struct.name = $1->s;
1333 if (set_parent_node($3, $$))
1334 reparent_error(scanner, "struct reparent error");
1338 $$ = make_node(scanner, NODE_STRUCT);
1339 $$->u._struct.name = $1->s;
1343 $$ = make_node(scanner, NODE_STRUCT);
1344 $$->u._struct.name = $1->s;
1348 struct_declaration_begin:
1350 { push_scope(scanner); }
1353 struct_declaration_end:
1355 { pop_scope(scanner); }
1358 variant_type_specifier:
1359 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1361 $$ = make_node(scanner, NODE_VARIANT);
1362 if (set_parent_node($2, $$))
1363 reparent_error(scanner, "variant reparent error");
1365 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1367 $$ = make_node(scanner, NODE_VARIANT);
1368 $$->u.variant.choice = $2->s;
1369 if (set_parent_node($5, $$))
1370 reparent_error(scanner, "variant reparent error");
1372 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1374 $$ = make_node(scanner, NODE_VARIANT);
1375 $$->u.variant.choice = $2->s;
1376 if (set_parent_node($5, $$))
1377 reparent_error(scanner, "variant reparent error");
1379 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1381 $$ = make_node(scanner, NODE_VARIANT);
1382 $$->u.variant.name = $1->s;
1383 if (set_parent_node($3, $$))
1384 reparent_error(scanner, "variant reparent error");
1386 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1388 $$ = make_node(scanner, NODE_VARIANT);
1389 $$->u.variant.name = $1->s;
1390 $$->u.variant.choice = $3->s;
1391 if (set_parent_node($6, $$))
1392 reparent_error(scanner, "variant reparent error");
1394 | IDENTIFIER LT IDENTIFIER GT
1396 $$ = make_node(scanner, NODE_VARIANT);
1397 $$->u.variant.name = $1->s;
1398 $$->u.variant.choice = $3->s;
1400 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1402 $$ = make_node(scanner, NODE_VARIANT);
1403 $$->u.variant.name = $1->s;
1404 $$->u.variant.choice = $3->s;
1405 if (set_parent_node($6, $$))
1406 reparent_error(scanner, "variant reparent error");
1408 | IDENTIFIER LT ID_TYPE GT
1410 $$ = make_node(scanner, NODE_VARIANT);
1411 $$->u.variant.name = $1->s;
1412 $$->u.variant.choice = $3->s;
1414 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1416 $$ = make_node(scanner, NODE_VARIANT);
1417 $$->u.variant.name = $1->s;
1418 if (set_parent_node($3, $$))
1419 reparent_error(scanner, "variant reparent error");
1421 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1423 $$ = make_node(scanner, NODE_VARIANT);
1424 $$->u.variant.name = $1->s;
1425 $$->u.variant.choice = $3->s;
1426 if (set_parent_node($6, $$))
1427 reparent_error(scanner, "variant reparent error");
1429 | ID_TYPE LT IDENTIFIER GT
1431 $$ = make_node(scanner, NODE_VARIANT);
1432 $$->u.variant.name = $1->s;
1433 $$->u.variant.choice = $3->s;
1435 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1437 $$ = make_node(scanner, NODE_VARIANT);
1438 $$->u.variant.name = $1->s;
1439 $$->u.variant.choice = $3->s;
1440 if (set_parent_node($6, $$))
1441 reparent_error(scanner, "variant reparent error");
1443 | ID_TYPE LT ID_TYPE GT
1445 $$ = make_node(scanner, NODE_VARIANT);
1446 $$->u.variant.name = $1->s;
1447 $$->u.variant.choice = $3->s;
1451 variant_declaration_begin:
1453 { push_scope(scanner); }
1456 variant_declaration_end:
1458 { pop_scope(scanner); }
1461 type_specifier_or_integer_constant:
1462 declaration_specifiers
1466 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1467 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1468 sscanf(yylval.gs->s, "%llu",
1469 &$$->u.unary_expression.u.unsigned_constant);
1473 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1474 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1475 sscanf(yylval.gs->s, "0%llo",
1476 &$$->u.unary_expression.u.unsigned_constant);
1478 | HEXADECIMAL_CONSTANT
1480 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1481 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1482 sscanf(yylval.gs->s, "0x%llx",
1483 &$$->u.unary_expression.u.unsigned_constant);
1487 enum_type_specifier:
1488 LBRAC enumerator_list RBRAC
1490 $$ = make_node(scanner, NODE_ENUM);
1491 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1493 | LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
1495 $$ = make_node(scanner, NODE_ENUM);
1496 $$->u._enum.container_type = $2;
1497 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1499 | IDENTIFIER LBRAC enumerator_list RBRAC
1501 $$ = make_node(scanner, NODE_ENUM);
1502 $$->u._enum.enum_id = $1->s;
1503 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1505 | IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
1507 $$ = make_node(scanner, NODE_ENUM);
1508 $$->u._enum.enum_id = $1->s;
1509 $$->u._enum.container_type = $3;
1510 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1512 | ID_TYPE LBRAC enumerator_list RBRAC
1514 $$ = make_node(scanner, NODE_ENUM);
1515 $$->u._enum.enum_id = $1->s;
1516 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1518 | ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
1520 $$ = make_node(scanner, NODE_ENUM);
1521 $$->u._enum.enum_id = $1->s;
1522 $$->u._enum.container_type = $3;
1523 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1525 | LBRAC enumerator_list COMMA RBRAC
1527 $$ = make_node(scanner, NODE_ENUM);
1528 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1530 | LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
1532 $$ = make_node(scanner, NODE_ENUM);
1533 $$->u._enum.container_type = $2;
1534 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1536 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1538 $$ = make_node(scanner, NODE_ENUM);
1539 $$->u._enum.enum_id = $1->s;
1540 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1542 | IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
1544 $$ = make_node(scanner, NODE_ENUM);
1545 $$->u._enum.enum_id = $1->s;
1546 $$->u._enum.container_type = $3;
1547 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1551 $$ = make_node(scanner, NODE_ENUM);
1552 $$->u._enum.enum_id = $1->s;
1554 | IDENTIFIER LT type_specifier_or_integer_constant GT
1556 $$ = make_node(scanner, NODE_ENUM);
1557 $$->u._enum.enum_id = $1->s;
1558 $$->u._enum.container_type = $3;
1560 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1562 $$ = make_node(scanner, NODE_ENUM);
1563 $$->u._enum.enum_id = $1->s;
1564 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1566 | ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
1568 $$ = make_node(scanner, NODE_ENUM);
1569 $$->u._enum.enum_id = $1->s;
1570 $$->u._enum.container_type = $3;
1571 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
1575 $$ = make_node(scanner, NODE_ENUM);
1576 $$->u._enum.enum_id = $1->s;
1578 | ID_TYPE LT type_specifier_or_integer_constant GT
1580 $$ = make_node(scanner, NODE_ENUM);
1581 $$->u._enum.enum_id = $1->s;
1582 $$->u._enum.container_type = $3;
1586 struct_or_variant_declaration_list:
1589 | struct_or_variant_declaration_list struct_or_variant_declaration
1593 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1596 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1601 struct_or_variant_declaration:
1602 specifier_qualifier_list struct_or_variant_declarator_list SEMICOLON
1604 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1605 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.struct_or_variant_declaration.declaration_specifier);
1606 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
1608 | specifier_qualifier_list TYPEDEF specifier_qualifier_list type_declarator_list SEMICOLON
1610 $$ = make_node(scanner, NODE_TYPEDEF);
1611 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
1612 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.declaration_specifier);
1613 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1615 | TYPEDEF specifier_qualifier_list type_declarator_list SEMICOLON
1617 $$ = make_node(scanner, NODE_TYPEDEF);
1618 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._typedef.declaration_specifier);
1619 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1621 | specifier_qualifier_list TYPEDEF type_declarator_list SEMICOLON
1623 $$ = make_node(scanner, NODE_TYPEDEF);
1624 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
1625 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1627 | TYPEALIAS specifier_qualifier_list abstract_declarator_list COLON specifier_qualifier_list abstract_type_declarator_list SEMICOLON
1629 $$ = make_node(scanner, NODE_TYPEALIAS);
1630 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1631 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1632 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1633 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1634 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
1635 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1637 | TYPEALIAS specifier_qualifier_list abstract_declarator_list COLON type_declarator_list SEMICOLON
1639 $$ = make_node(scanner, NODE_TYPEALIAS);
1640 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1641 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1642 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1643 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
1644 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1648 specifier_qualifier_list:
1651 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1652 $$->u.type_specifier.type = TYPESPEC_CONST;
1656 | specifier_qualifier_list CONST
1658 struct ctf_node *node;
1661 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1662 node->u.type_specifier.type = TYPESPEC_CONST;
1663 cds_list_add_tail(&node->siblings, &($$)->tmp_head);
1665 | specifier_qualifier_list type_specifier
1668 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1672 struct_or_variant_declarator_list:
1673 struct_or_variant_declarator
1675 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
1678 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1682 struct_or_variant_declarator:
1685 | COLON unary_expression
1687 | declarator COLON unary_expression
1690 if (set_parent_node($3, $1))
1691 reparent_error(scanner, "struct_or_variant_declarator");
1698 | enumerator_list COMMA enumerator
1701 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1708 $$ = make_node(scanner, NODE_ENUMERATOR);
1709 $$->u.enumerator.id = $1->s;
1713 $$ = make_node(scanner, NODE_ENUMERATOR);
1714 $$->u.enumerator.id = $1->s;
1718 $$ = make_node(scanner, NODE_ENUMERATOR);
1719 $$->u.enumerator.id = $1->s;
1721 | STRING_LITERAL_START DQUOTE
1723 $$ = make_node(scanner, NODE_ENUMERATOR);
1724 $$->u.enumerator.id = "";
1726 | STRING_LITERAL_START s_char_sequence DQUOTE
1728 $$ = make_node(scanner, NODE_ENUMERATOR);
1729 $$->u.enumerator.id = $2->s;
1731 | IDENTIFIER EQUAL unary_expression_or_range
1733 $$ = make_node(scanner, NODE_ENUMERATOR);
1734 $$->u.enumerator.id = $1->s;
1735 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
1737 | ID_TYPE EQUAL unary_expression_or_range
1739 $$ = make_node(scanner, NODE_ENUMERATOR);
1740 $$->u.enumerator.id = $1->s;
1741 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
1743 | keywords EQUAL unary_expression_or_range
1745 $$ = make_node(scanner, NODE_ENUMERATOR);
1746 $$->u.enumerator.id = $1->s;
1747 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
1749 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
1751 $$ = make_node(scanner, NODE_ENUMERATOR);
1752 $$->u.enumerator.id = "";
1753 cds_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
1755 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
1757 $$ = make_node(scanner, NODE_ENUMERATOR);
1758 $$->u.enumerator.id = $2->s;
1759 cds_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
1763 abstract_declarator_list:
1766 | abstract_declarator_list COMMA abstract_declarator
1769 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1773 abstract_declarator:
1774 direct_abstract_declarator
1776 | pointer direct_abstract_declarator
1779 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
1783 direct_abstract_declarator:
1786 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1787 $$->u.type_declarator.type = TYPEDEC_ID;
1792 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1793 $$->u.type_declarator.type = TYPEDEC_ID;
1794 $$->u.type_declarator.u.id = $1->s;
1796 | LPAREN abstract_declarator RPAREN
1798 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1799 $$->u.type_declarator.type = TYPEDEC_NESTED;
1800 $$->u.type_declarator.u.nested.type_declarator = $2;
1802 | direct_abstract_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
1804 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1805 $$->u.type_declarator.type = TYPEDEC_NESTED;
1806 $$->u.type_declarator.u.nested.type_declarator = $1;
1807 $$->u.type_declarator.u.nested.length = $3;
1809 | direct_abstract_declarator LSBRAC RSBRAC
1811 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1812 $$->u.type_declarator.type = TYPEDEC_NESTED;
1813 $$->u.type_declarator.u.nested.type_declarator = $1;
1814 $$->u.type_declarator.u.nested.abstract_array = 1;
1821 | pointer direct_declarator
1824 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
1831 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1832 $$->u.type_declarator.type = TYPEDEC_ID;
1833 $$->u.type_declarator.u.id = $1->s;
1835 | LPAREN declarator RPAREN
1837 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1838 $$->u.type_declarator.type = TYPEDEC_NESTED;
1839 $$->u.type_declarator.u.nested.type_declarator = $2;
1841 | direct_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
1843 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1844 $$->u.type_declarator.type = TYPEDEC_NESTED;
1845 $$->u.type_declarator.u.nested.type_declarator = $1;
1846 $$->u.type_declarator.u.nested.length = $3;
1851 direct_type_declarator
1853 | pointer direct_type_declarator
1856 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
1860 direct_type_declarator:
1863 add_type(scanner, $1);
1864 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1865 $$->u.type_declarator.type = TYPEDEC_ID;
1866 $$->u.type_declarator.u.id = $1->s;
1868 | LPAREN type_declarator RPAREN
1870 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1871 $$->u.type_declarator.type = TYPEDEC_NESTED;
1872 $$->u.type_declarator.u.nested.type_declarator = $2;
1874 | direct_type_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
1876 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1877 $$->u.type_declarator.type = TYPEDEC_NESTED;
1878 $$->u.type_declarator.u.nested.type_declarator = $1;
1879 $$->u.type_declarator.u.nested.length = $3;
1883 abstract_type_declarator:
1884 direct_abstract_type_declarator
1886 | pointer direct_abstract_type_declarator
1889 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
1893 direct_abstract_type_declarator:
1896 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1897 $$->u.type_declarator.type = TYPEDEC_ID;
1902 add_type(scanner, $1);
1903 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1904 $$->u.type_declarator.type = TYPEDEC_ID;
1905 $$->u.type_declarator.u.id = $1->s;
1907 | LPAREN abstract_type_declarator RPAREN
1909 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1910 $$->u.type_declarator.type = TYPEDEC_NESTED;
1911 $$->u.type_declarator.u.nested.type_declarator = $2;
1913 | direct_abstract_type_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
1915 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1916 $$->u.type_declarator.type = TYPEDEC_NESTED;
1917 $$->u.type_declarator.u.nested.type_declarator = $1;
1918 $$->u.type_declarator.u.nested.length = $3;
1920 | direct_abstract_type_declarator LSBRAC RSBRAC
1922 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1923 $$->u.type_declarator.type = TYPEDEC_NESTED;
1924 $$->u.type_declarator.u.nested.type_declarator = $1;
1925 $$->u.type_declarator.u.nested.abstract_array = 1;
1932 $$ = make_node(scanner, NODE_POINTER);
1936 $$ = make_node(scanner, NODE_POINTER);
1937 cds_list_splice(&($2)->tmp_head, &($$)->tmp_head);
1939 | STAR type_qualifier_list pointer
1941 $$ = make_node(scanner, NODE_POINTER);
1942 $$->u.pointer.const_qualifier = 1;
1943 cds_list_splice(&($3)->tmp_head, &($$)->tmp_head);
1947 type_qualifier_list:
1948 /* pointer assumes only const type qualifier */
1950 | type_qualifier_list CONST
1953 /* 2.3: CTF-specific declarations */
1955 ctf_assignment_expression_list:
1956 ctf_assignment_expression SEMICOLON
1958 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
1961 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1965 ctf_assignment_expression:
1966 unary_expression EQUAL unary_expression
1969 * Because we have left and right, cannot use
1972 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
1973 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
1974 if ($1->u.unary_expression.type != UNARY_STRING)
1975 reparent_error(scanner, "ctf_assignment_expression left expects string");
1976 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
1978 | unary_expression TYPEASSIGN type_specifier
1981 * Because we have left and right, cannot use
1984 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
1985 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
1986 if ($1->u.unary_expression.type != UNARY_STRING)
1987 reparent_error(scanner, "ctf_assignment_expression left expects string");
1988 cds_list_add(&($3)->siblings, &($3)->tmp_head);
1989 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
1991 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
1993 $$ = make_node(scanner, NODE_TYPEDEF);
1994 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.declaration_specifier);
1995 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
1996 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1998 | TYPEDEF declaration_specifiers type_declarator_list
2000 $$ = make_node(scanner, NODE_TYPEDEF);
2001 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._typedef.declaration_specifier);
2002 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2004 | declaration_specifiers TYPEDEF type_declarator_list
2006 $$ = make_node(scanner, NODE_TYPEDEF);
2007 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
2008 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2010 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON declaration_specifiers abstract_type_declarator_list
2012 $$ = make_node(scanner, NODE_TYPEALIAS);
2013 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2014 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2015 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
2016 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2017 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
2018 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2020 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON type_declarator_list
2022 $$ = make_node(scanner, NODE_TYPEALIAS);
2023 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2024 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2025 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
2026 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
2027 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);