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 #define printf_dbg(fmt, args...) fprintf(stderr, "%s: " fmt, __func__, ## args)
34 int yyparse(struct ctf_scanner *scanner);
35 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
36 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
37 int yylex_destroy(yyscan_t yyscanner) ;
38 void yyset_in(FILE * in_str, yyscan_t scanner);
43 struct cds_list_head gc;
48 static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
51 struct gc_string *gstr;
54 /* TODO: could be faster with find first bit or glib Gstring */
55 /* sizeof long to account for malloc header (int or long ?) */
56 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
59 gstr = malloc(alloclen);
60 cds_list_add(&gstr->gc, &scanner->allocated_strings);
61 gstr->alloclen = alloclen;
66 * note: never use gc_string_append on a string that has external references.
67 * gsrc will be garbage collected immediately, and gstr might be.
68 * Should only be used to append characters to a string literal or constant.
70 struct gc_string *gc_string_append(struct ctf_scanner *scanner,
71 struct gc_string *gstr,
72 struct gc_string *gsrc)
74 size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
77 /* TODO: could be faster with find first bit or glib Gstring */
78 /* sizeof long to account for malloc header (int or long ?) */
79 for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
82 if (alloclen > gstr->alloclen) {
83 struct gc_string *newgstr;
85 newgstr = gc_string_alloc(scanner, newlen);
86 strcpy(newgstr->s, gstr->s);
87 strcat(newgstr->s, gsrc->s);
88 cds_list_del(&gstr->gc);
92 strcat(gstr->s, gsrc->s);
94 cds_list_del(&gsrc->gc);
99 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
101 lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
102 strcpy(lvalp->gs->s, src);
105 static void init_scope(struct ctf_scanner_scope *scope,
106 struct ctf_scanner_scope *parent)
108 scope->parent = parent;
109 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
113 static void finalize_scope(struct ctf_scanner_scope *scope)
115 g_hash_table_destroy(scope->types);
118 static void push_scope(struct ctf_scanner *scanner)
120 struct ctf_scanner_scope *ns;
122 printf_dbg("push scope\n");
123 ns = malloc(sizeof(struct ctf_scanner_scope));
124 init_scope(ns, scanner->cs);
128 static void pop_scope(struct ctf_scanner *scanner)
130 struct ctf_scanner_scope *os;
132 printf_dbg("pop scope\n");
134 scanner->cs = os->parent;
139 static int lookup_type(struct ctf_scanner_scope *s, const char *id)
143 ret = (int) g_hash_table_lookup(s->types, id);
144 printf_dbg("lookup %p %s %d\n", s, id, ret);
148 int is_type(struct ctf_scanner *scanner, const char *id)
150 struct ctf_scanner_scope *it;
153 for (it = scanner->cs; it != NULL; it = it->parent) {
154 if (lookup_type(it, id)) {
159 printf_dbg("is type %s %d\n", id, ret);
163 static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
165 printf_dbg("add type %s\n", id->s);
166 if (lookup_type(scanner->cs, id->s))
168 g_hash_table_insert(scanner->cs->types, id->s, id->s);
171 static struct ctf_node *make_node(struct ctf_scanner *scanner,
174 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
175 struct ctf_node *node;
177 node = malloc(sizeof(*node));
180 memset(node, 0, sizeof(*node));
182 CDS_INIT_LIST_HEAD(&node->siblings);
183 cds_list_add(&node->gc, &ast->allocated_nodes);
187 fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
191 CDS_INIT_LIST_HEAD(&node->u.event.declaration_list);
194 CDS_INIT_LIST_HEAD(&node->u.stream.declaration_list);
197 CDS_INIT_LIST_HEAD(&node->u.trace.declaration_list);
200 case NODE_CTF_EXPRESSION:
202 case NODE_UNARY_EXPRESSION:
206 CDS_INIT_LIST_HEAD(&node->u._typedef.declaration_specifier);
207 CDS_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
209 case NODE_TYPEALIAS_TARGET:
210 CDS_INIT_LIST_HEAD(&node->u.typealias_target.declaration_specifier);
211 CDS_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
213 case NODE_TYPEALIAS_ALIAS:
214 CDS_INIT_LIST_HEAD(&node->u.typealias_alias.declaration_specifier);
215 CDS_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
220 case NODE_TYPE_SPECIFIER:
224 case NODE_TYPE_DECLARATOR:
225 CDS_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
228 case NODE_FLOATING_POINT:
229 CDS_INIT_LIST_HEAD(&node->u.floating_point.expressions);
232 CDS_INIT_LIST_HEAD(&node->u.integer.expressions);
235 CDS_INIT_LIST_HEAD(&node->u.string.expressions);
237 case NODE_ENUMERATOR:
240 CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
242 case NODE_STRUCT_OR_VARIANT_DECLARATION:
243 CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.declaration_specifier);
244 CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
247 CDS_INIT_LIST_HEAD(&node->u.variant.declaration_list);
250 CDS_INIT_LIST_HEAD(&node->u._struct.declaration_list);
255 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
263 static int reparent_ctf_expression(struct ctf_node *node,
264 struct ctf_node *parent)
266 switch (parent->type) {
268 cds_list_add(&node->siblings, &parent->u.event.declaration_list);
271 cds_list_add(&node->siblings, &parent->u.stream.declaration_list);
274 cds_list_add(&node->siblings, &parent->u.trace.declaration_list);
276 case NODE_FLOATING_POINT:
277 cds_list_add(&node->siblings, &parent->u.floating_point.expressions);
280 cds_list_add(&node->siblings, &parent->u.integer.expressions);
283 cds_list_add(&node->siblings, &parent->u.string.expressions);
287 case NODE_CTF_EXPRESSION:
289 case NODE_TYPEALIAS_TARGET:
290 case NODE_TYPEALIAS_ALIAS:
292 case NODE_TYPE_SPECIFIER:
294 case NODE_TYPE_DECLARATOR:
295 case NODE_ENUMERATOR:
297 case NODE_STRUCT_OR_VARIANT_DECLARATION:
300 case NODE_UNARY_EXPRESSION:
305 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
312 static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
314 switch (parent->type) {
316 cds_list_add(&node->siblings, &parent->u.root._typedef);
319 cds_list_add(&node->siblings, &parent->u.event.declaration_list);
322 cds_list_add(&node->siblings, &parent->u.stream.declaration_list);
325 cds_list_add(&node->siblings, &parent->u.trace.declaration_list);
328 cds_list_add(&node->siblings, &parent->u.variant.declaration_list);
331 cds_list_add(&node->siblings, &parent->u._struct.declaration_list);
334 case NODE_FLOATING_POINT:
337 case NODE_CTF_EXPRESSION:
339 case NODE_TYPEALIAS_TARGET:
340 case NODE_TYPEALIAS_ALIAS:
342 case NODE_TYPE_SPECIFIER:
344 case NODE_TYPE_DECLARATOR:
345 case NODE_ENUMERATOR:
347 case NODE_STRUCT_OR_VARIANT_DECLARATION:
348 case NODE_UNARY_EXPRESSION:
353 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
360 static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
362 switch (parent->type) {
364 cds_list_add(&node->siblings, &parent->u.root.typealias);
367 cds_list_add(&node->siblings, &parent->u.event.declaration_list);
370 cds_list_add(&node->siblings, &parent->u.stream.declaration_list);
373 cds_list_add(&node->siblings, &parent->u.trace.declaration_list);
376 cds_list_add(&node->siblings, &parent->u.variant.declaration_list);
379 cds_list_add(&node->siblings, &parent->u._struct.declaration_list);
382 case NODE_FLOATING_POINT:
385 case NODE_CTF_EXPRESSION:
387 case NODE_TYPEALIAS_TARGET:
388 case NODE_TYPEALIAS_ALIAS:
390 case NODE_TYPE_SPECIFIER:
392 case NODE_TYPE_DECLARATOR:
393 case NODE_ENUMERATOR:
395 case NODE_STRUCT_OR_VARIANT_DECLARATION:
396 case NODE_UNARY_EXPRESSION:
401 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
408 static int reparent_type_specifier(struct ctf_node *node,
409 struct ctf_node *parent)
411 switch (parent->type) {
413 cds_list_add(&node->siblings, &parent->u.root.declaration_specifier);
416 cds_list_add(&node->siblings, &parent->u.event.declaration_list);
419 cds_list_add(&node->siblings, &parent->u.stream.declaration_list);
422 cds_list_add(&node->siblings, &parent->u.trace.declaration_list);
425 cds_list_add(&node->siblings, &parent->u.variant.declaration_list);
428 cds_list_add(&node->siblings, &parent->u._struct.declaration_list);
431 cds_list_add(&node->siblings, &parent->u._typedef.declaration_specifier);
433 case NODE_TYPEALIAS_TARGET:
434 cds_list_add(&node->siblings, &parent->u.typealias_target.declaration_specifier);
436 case NODE_TYPEALIAS_ALIAS:
437 cds_list_add(&node->siblings, &parent->u.typealias_alias.declaration_specifier);
439 case NODE_TYPE_DECLARATOR:
440 parent->u.type_declarator.type = TYPEDEC_NESTED;
441 parent->u.type_declarator.u.nested.length = node;
444 parent->u._enum.container_type = node;
446 case NODE_STRUCT_OR_VARIANT_DECLARATION:
447 cds_list_add(&node->siblings, &parent->u.struct_or_variant_declaration.declaration_specifier);
450 case NODE_FLOATING_POINT:
453 case NODE_CTF_EXPRESSION:
454 case NODE_TYPE_SPECIFIER:
456 case NODE_ENUMERATOR:
457 case NODE_UNARY_EXPRESSION:
462 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
469 static int reparent_type_declarator(struct ctf_node *node,
470 struct ctf_node *parent)
472 switch (parent->type) {
473 case NODE_TYPE_DECLARATOR:
474 parent->u.type_declarator.type = TYPEDEC_NESTED;
475 parent->u.type_declarator.u.nested.type_declarator = node;
477 case NODE_STRUCT_OR_VARIANT_DECLARATION:
478 cds_list_add(&node->siblings, &parent->u.struct_or_variant_declaration.type_declarators);
481 cds_list_add(&node->siblings, &parent->u._typedef.type_declarators);
483 case NODE_TYPEALIAS_TARGET:
484 cds_list_add(&node->siblings, &parent->u.typealias_target.type_declarators);
486 case NODE_TYPEALIAS_ALIAS:
487 cds_list_add(&node->siblings, &parent->u.typealias_alias.type_declarators);
498 case NODE_FLOATING_POINT:
501 case NODE_CTF_EXPRESSION:
502 case NODE_TYPE_SPECIFIER:
504 case NODE_ENUMERATOR:
505 case NODE_UNARY_EXPRESSION:
510 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
520 * Relink node to new parent. Returns 0 on success, -EPERM if it is not
521 * permitted to create the link declared by the input, -ENOENT if node or parent
522 * is NULL, -EINVAL if there is an internal structure problem.
524 static int reparent_node(struct ctf_node *node,
525 struct ctf_node *parent)
527 if (!node || !parent)
530 /* Unlink from old parent */
531 cds_list_del(&node->siblings);
533 /* Note: Linking to parent will be done only by an external visitor */
535 switch (node->type) {
537 fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
541 if (parent->type == NODE_ROOT)
542 cds_list_add_tail(&node->siblings, &parent->u.root.event);
547 if (parent->type == NODE_ROOT)
548 cds_list_add_tail(&node->siblings, &parent->u.root.stream);
553 if (parent->type == NODE_ROOT)
554 cds_list_add_tail(&node->siblings, &parent->u.root.trace);
559 case NODE_CTF_EXPRESSION:
560 return reparent_ctf_expression(node, parent);
561 case NODE_UNARY_EXPRESSION:
562 if (parent->type == NODE_TYPE_DECLARATOR)
563 parent->u.type_declarator.bitfield_len = node;
569 return reparent_typedef(node, parent);
570 case NODE_TYPEALIAS_TARGET:
571 if (parent->type == NODE_TYPEALIAS)
572 parent->u.typealias.target = node;
575 case NODE_TYPEALIAS_ALIAS:
576 if (parent->type == NODE_TYPEALIAS)
577 parent->u.typealias.alias = node;
581 return reparent_typealias(node, parent);
584 if (parent->type == NODE_TYPE_DECLARATOR)
585 cds_list_add_tail(&node->siblings, &parent->u.type_declarator.pointers);
589 case NODE_TYPE_DECLARATOR:
590 return reparent_type_declarator(node, parent);
592 case NODE_TYPE_SPECIFIER:
593 case NODE_FLOATING_POINT:
599 return reparent_type_specifier(node, parent);
601 case NODE_ENUMERATOR:
602 if (parent->type == NODE_ENUM)
603 cds_list_add_tail(&node->siblings, &parent->u._enum.enumerator_list);
607 case NODE_STRUCT_OR_VARIANT_DECLARATION:
608 switch (parent->type) {
610 cds_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
613 cds_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
622 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
629 void yyerror(struct ctf_scanner *scanner, const char *str)
631 fprintf(stderr, "error %s\n", str);
639 #define reparent_error(scanner, str) \
641 yyerror(scanner, YY_("reparent_error: " str "\n")); \
645 static void free_strings(struct cds_list_head *list)
647 struct gc_string *gstr, *tmp;
649 cds_list_for_each_entry_safe(gstr, tmp, list, gc)
653 static struct ctf_ast *ctf_ast_alloc(void)
657 ast = malloc(sizeof(*ast));
660 memset(ast, 0, sizeof(*ast));
661 CDS_INIT_LIST_HEAD(&ast->allocated_nodes);
662 ast->root.type = NODE_ROOT;
663 CDS_INIT_LIST_HEAD(&ast->root.siblings);
664 CDS_INIT_LIST_HEAD(&ast->root.u.root._typedef);
665 CDS_INIT_LIST_HEAD(&ast->root.u.root.typealias);
666 CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_specifier);
667 CDS_INIT_LIST_HEAD(&ast->root.u.root.trace);
668 CDS_INIT_LIST_HEAD(&ast->root.u.root.stream);
669 CDS_INIT_LIST_HEAD(&ast->root.u.root.event);
673 static void ctf_ast_free(struct ctf_ast *ast)
675 struct ctf_node *node, *tmp;
677 cds_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
681 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
683 return yyparse(scanner);
686 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
688 struct ctf_scanner *scanner;
691 scanner = malloc(sizeof(*scanner));
694 memset(scanner, 0, sizeof(*scanner));
696 ret = yylex_init_extra(scanner, &scanner->scanner);
698 fprintf(stderr, "yylex_init error\n");
699 goto cleanup_scanner;
701 yyset_in(input, scanner);
703 scanner->ast = ctf_ast_alloc();
706 init_scope(&scanner->root_scope, NULL);
707 scanner->cs = &scanner->root_scope;
708 CDS_INIT_LIST_HEAD(&scanner->allocated_strings);
713 ret = yylex_destroy(scanner->scanner);
715 fprintf(stderr, "yylex_destroy error\n");
721 void ctf_scanner_free(struct ctf_scanner *scanner)
725 finalize_scope(&scanner->root_scope);
726 free_strings(&scanner->allocated_strings);
727 ctf_ast_free(scanner->ast);
728 ret = yylex_destroy(scanner->scanner);
730 fprintf(stderr, "yylex_destroy error\n");
738 %parse-param {struct ctf_scanner *scanner}
739 %lex-param {struct ctf_scanner *scanner}
741 %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
742 %token <gs> IDENTIFIER ID_TYPE
748 struct gc_string *gs;
753 %type <gs> s_char s_char_sequence c_char c_char_sequence
755 %type <n> postfix_expression unary_expression unary_expression_or_range
757 %type <n> declaration
758 %type <n> event_declaration
759 %type <n> stream_declaration
760 %type <n> trace_declaration
761 %type <n> declaration_specifiers
763 %type <n> type_declarator_list
764 %type <n> abstract_type_declarator_list
765 %type <n> type_specifier
766 %type <n> struct_type_specifier
767 %type <n> variant_type_specifier
768 %type <n> type_specifier_or_integer_constant
769 %type <n> enum_type_specifier
770 %type <n> struct_or_variant_declaration_list
771 %type <n> struct_or_variant_declaration
772 %type <n> specifier_qualifier_list
773 %type <n> struct_or_variant_declarator_list
774 %type <n> struct_or_variant_declarator
775 %type <n> enumerator_list
777 %type <n> abstract_declarator_list
778 %type <n> abstract_declarator
779 %type <n> direct_abstract_declarator
781 %type <n> direct_declarator
782 %type <n> type_declarator
783 %type <n> direct_type_declarator
784 %type <n> abstract_type_declarator
785 %type <n> direct_abstract_type_declarator
787 %type <n> ctf_assignment_expression_list
788 %type <n> ctf_assignment_expression
795 if (reparent_node($1, &ctf_scanner_get_ast(scanner)->root))
796 reparent_error(scanner, "error reparenting to root");
800 if (reparent_node($2, &ctf_scanner_get_ast(scanner)->root))
801 reparent_error(scanner, "error reparenting to root");
857 | c_char_sequence c_char
858 { $$ = gc_string_append(scanner, $1, $2); }
866 reparent_error(scanner, "escape sequences not supported yet");
870 /* 1.6 String literals */
875 | s_char_sequence s_char
876 { $$ = gc_string_append(scanner, $1, $2); }
884 reparent_error(scanner, "escape sequences not supported yet");
888 /* 2: Phrase structure grammar */
893 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
894 $$->u.unary_expression.type = UNARY_STRING;
895 $$->u.unary_expression.u.string = yylval.gs->s;
899 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
900 $$->u.unary_expression.type = UNARY_STRING;
901 $$->u.unary_expression.u.string = yylval.gs->s;
906 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
907 $$->u.unary_expression.type = UNARY_STRING;
908 $$->u.unary_expression.u.string = yylval.gs->s;
913 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
914 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
915 sscanf(yylval.gs->s, "%llu",
916 &$$->u.unary_expression.u.unsigned_constant);
920 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
921 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
922 sscanf(yylval.gs->s, "0%llo",
923 &$$->u.unary_expression.u.unsigned_constant);
925 | HEXADECIMAL_CONSTANT
927 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
928 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
929 sscanf(yylval.gs->s, "0x%llx",
930 &$$->u.unary_expression.u.unsigned_constant);
932 | STRING_LITERAL_START DQUOTE
934 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
935 $$->u.unary_expression.type = UNARY_STRING;
936 $$->u.unary_expression.u.string = "";
938 | STRING_LITERAL_START s_char_sequence DQUOTE
940 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
941 $$->u.unary_expression.type = UNARY_STRING;
942 $$->u.unary_expression.u.string = $2->s;
944 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
946 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
947 $$->u.unary_expression.type = UNARY_STRING;
948 $$->u.unary_expression.u.string = $2->s;
950 | LPAREN unary_expression RPAREN
954 | postfix_expression LSBRAC unary_expression RSBRAC
956 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
957 $$->u.unary_expression.type = UNARY_SBRAC;
958 $$->u.unary_expression.u.sbrac_exp = $3;
959 cds_list_add(&($$)->siblings, &($1)->siblings);
961 | postfix_expression DOT IDENTIFIER
963 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
964 $$->u.unary_expression.type = UNARY_STRING;
965 $$->u.unary_expression.u.string = yylval.gs->s;
966 $$->u.unary_expression.link = UNARY_DOTLINK;
967 cds_list_add(&($$)->siblings, &($1)->siblings);
969 | postfix_expression DOT ID_TYPE
971 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
972 $$->u.unary_expression.type = UNARY_STRING;
973 $$->u.unary_expression.u.string = yylval.gs->s;
974 $$->u.unary_expression.link = UNARY_DOTLINK;
975 cds_list_add(&($$)->siblings, &($1)->siblings);
977 | postfix_expression RARROW 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_ARROWLINK;
983 cds_list_add(&($$)->siblings, &($1)->siblings);
985 | postfix_expression RARROW ID_TYPE
987 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
988 $$->u.unary_expression.type = UNARY_STRING;
989 $$->u.unary_expression.u.string = yylval.gs->s;
990 $$->u.unary_expression.link = UNARY_ARROWLINK;
991 cds_list_add(&($$)->siblings, &($1)->siblings);
998 | PLUS postfix_expression
1000 | MINUS postfix_expression
1003 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1004 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1005 reparent_error(scanner, "expecting numeric constant");
1007 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1008 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1009 $$->u.unary_expression.u.signed_constant =
1010 -($$->u.unary_expression.u.unsigned_constant);
1012 $$->u.unary_expression.u.signed_constant =
1013 -($$->u.unary_expression.u.signed_constant);
1018 unary_expression_or_range:
1019 unary_expression DOTDOTDOT unary_expression
1022 cds_list_add(&($3)->siblings, &($$)->siblings);
1028 /* 2.2: Declarations */
1031 declaration_specifiers SEMICOLON
1035 | stream_declaration
1039 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1041 $$ = make_node(scanner, NODE_TYPEDEF);
1042 cds_list_add(&($3)->siblings, &($$)->u._typedef.declaration_specifier);
1043 cds_list_add(&($1)->siblings, &($$)->u._typedef.declaration_specifier);
1044 cds_list_add(&($4)->siblings, &($$)->u._typedef.type_declarators);
1046 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1048 $$ = make_node(scanner, NODE_TYPEDEF);
1049 cds_list_add(&($2)->siblings, &($$)->u._typedef.declaration_specifier);
1050 cds_list_add(&($3)->siblings, &($$)->u._typedef.type_declarators);
1052 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1054 $$ = make_node(scanner, NODE_TYPEDEF);
1055 cds_list_add(&($1)->siblings, &($$)->u._typedef.declaration_specifier);
1056 cds_list_add(&($3)->siblings, &($$)->u._typedef.type_declarators);
1058 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON declaration_specifiers abstract_type_declarator_list SEMICOLON
1060 $$ = make_node(scanner, NODE_TYPEALIAS);
1061 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1062 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1063 cds_list_add(&($2)->siblings, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1064 cds_list_add(&($3)->siblings, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1065 cds_list_add(&($5)->siblings, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
1066 cds_list_add(&($6)->siblings, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1068 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON type_declarator_list SEMICOLON
1070 $$ = make_node(scanner, NODE_TYPEALIAS);
1071 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1072 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1073 cds_list_add(&($2)->siblings, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1074 cds_list_add(&($3)->siblings, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1075 cds_list_add(&($5)->siblings, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1080 event_declaration_begin event_declaration_end
1081 { $$ = make_node(scanner, NODE_EVENT); }
1082 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1084 $$ = make_node(scanner, NODE_EVENT);
1085 if (reparent_node($2, $$))
1086 reparent_error(scanner, "event_declaration");
1090 event_declaration_begin:
1092 { push_scope(scanner); }
1095 event_declaration_end:
1097 { pop_scope(scanner); }
1102 stream_declaration_begin stream_declaration_end
1103 { $$ = make_node(scanner, NODE_STREAM); }
1104 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1106 $$ = make_node(scanner, NODE_STREAM);
1107 if (reparent_node($2, $$))
1108 reparent_error(scanner, "stream_declaration");
1112 stream_declaration_begin:
1114 { push_scope(scanner); }
1117 stream_declaration_end:
1119 { pop_scope(scanner); }
1124 trace_declaration_begin trace_declaration_end
1125 { $$ = make_node(scanner, NODE_TRACE); }
1126 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1128 $$ = make_node(scanner, NODE_TRACE);
1129 if (reparent_node($2, $$))
1130 reparent_error(scanner, "trace_declaration");
1134 trace_declaration_begin:
1136 { push_scope(scanner); }
1139 trace_declaration_end:
1141 { pop_scope(scanner); }
1144 declaration_specifiers:
1147 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1148 $$->u.type_specifier.type = TYPESPEC_CONST;
1152 | declaration_specifiers CONST
1154 struct ctf_node *node;
1156 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1157 node->u.type_specifier.type = TYPESPEC_CONST;
1158 cds_list_add(&node->siblings, &($1)->siblings);
1161 | declaration_specifiers type_specifier
1164 cds_list_add(&($2)->siblings, &($1)->siblings);
1168 type_declarator_list:
1171 | type_declarator_list COMMA type_declarator
1174 cds_list_add(&($3)->siblings, &($$)->siblings);
1178 abstract_type_declarator_list:
1179 abstract_type_declarator
1181 | abstract_type_declarator_list COMMA abstract_type_declarator
1184 cds_list_add(&($3)->siblings, &($$)->siblings);
1191 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1192 $$->u.type_specifier.type = TYPESPEC_VOID;
1196 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1197 $$->u.type_specifier.type = TYPESPEC_CHAR;
1201 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1202 $$->u.type_specifier.type = TYPESPEC_SHORT;
1206 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1207 $$->u.type_specifier.type = TYPESPEC_INT;
1211 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1212 $$->u.type_specifier.type = TYPESPEC_LONG;
1216 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1217 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1221 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1222 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1226 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1227 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1231 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1232 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1236 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1237 $$->u.type_specifier.type = TYPESPEC_BOOL;
1241 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1242 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1246 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1247 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1248 $$->u.type_specifier.id_type = yylval.gs->s;
1250 | FLOATING_POINT LBRAC RBRAC
1252 $$ = make_node(scanner, NODE_FLOATING_POINT);
1254 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1256 $$ = make_node(scanner, NODE_FLOATING_POINT);
1257 if (reparent_node($3, $$))
1258 reparent_error(scanner, "floating point reparent error");
1260 | INTEGER LBRAC RBRAC
1262 $$ = make_node(scanner, NODE_INTEGER);
1264 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1266 $$ = make_node(scanner, NODE_INTEGER);
1267 if (reparent_node($3, $$))
1268 reparent_error(scanner, "integer reparent error");
1270 | STRING LBRAC RBRAC
1272 $$ = make_node(scanner, NODE_STRING);
1274 | STRING LBRAC ctf_assignment_expression_list RBRAC
1276 $$ = make_node(scanner, NODE_STRING);
1277 if (reparent_node($3, $$))
1278 reparent_error(scanner, "string reparent error");
1280 | ENUM enum_type_specifier
1282 | VARIANT variant_type_specifier
1284 | STRUCT struct_type_specifier
1288 struct_type_specifier:
1289 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1291 $$ = make_node(scanner, NODE_STRUCT);
1292 if (reparent_node($2, $$))
1293 reparent_error(scanner, "struct reparent error");
1295 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1297 $$ = make_node(scanner, NODE_STRUCT);
1298 $$->u._struct.name = $1->s;
1299 if (reparent_node($3, $$))
1300 reparent_error(scanner, "struct reparent error");
1302 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1304 $$ = make_node(scanner, NODE_STRUCT);
1305 $$->u._struct.name = $1->s;
1306 if (reparent_node($3, $$))
1307 reparent_error(scanner, "struct reparent error");
1311 $$ = make_node(scanner, NODE_STRUCT);
1312 $$->u._struct.name = $1->s;
1316 $$ = make_node(scanner, NODE_STRUCT);
1317 $$->u._struct.name = $1->s;
1321 struct_declaration_begin:
1323 { push_scope(scanner); }
1326 struct_declaration_end:
1328 { pop_scope(scanner); }
1331 variant_type_specifier:
1332 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1334 $$ = make_node(scanner, NODE_VARIANT);
1335 if (reparent_node($2, $$))
1336 reparent_error(scanner, "variant reparent error");
1338 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1340 $$ = make_node(scanner, NODE_VARIANT);
1341 $$->u.variant.choice = $2->s;
1342 if (reparent_node($5, $$))
1343 reparent_error(scanner, "variant reparent error");
1345 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1347 $$ = make_node(scanner, NODE_VARIANT);
1348 $$->u.variant.choice = $2->s;
1349 if (reparent_node($5, $$))
1350 reparent_error(scanner, "variant reparent error");
1352 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1354 $$ = make_node(scanner, NODE_VARIANT);
1355 $$->u.variant.name = $1->s;
1356 if (reparent_node($3, $$))
1357 reparent_error(scanner, "variant reparent error");
1359 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1361 $$ = make_node(scanner, NODE_VARIANT);
1362 $$->u.variant.name = $1->s;
1363 $$->u.variant.choice = $3->s;
1364 if (reparent_node($6, $$))
1365 reparent_error(scanner, "variant reparent error");
1367 | IDENTIFIER LT IDENTIFIER GT
1369 $$ = make_node(scanner, NODE_VARIANT);
1370 $$->u.variant.name = $1->s;
1371 $$->u.variant.choice = $3->s;
1373 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1375 $$ = make_node(scanner, NODE_VARIANT);
1376 $$->u.variant.name = $1->s;
1377 $$->u.variant.choice = $3->s;
1378 if (reparent_node($6, $$))
1379 reparent_error(scanner, "variant reparent error");
1381 | IDENTIFIER LT ID_TYPE GT
1383 $$ = make_node(scanner, NODE_VARIANT);
1384 $$->u.variant.name = $1->s;
1385 $$->u.variant.choice = $3->s;
1387 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1389 $$ = make_node(scanner, NODE_VARIANT);
1390 $$->u.variant.name = $1->s;
1391 if (reparent_node($3, $$))
1392 reparent_error(scanner, "variant reparent error");
1394 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1396 $$ = make_node(scanner, NODE_VARIANT);
1397 $$->u.variant.name = $1->s;
1398 $$->u.variant.choice = $3->s;
1399 if (reparent_node($6, $$))
1400 reparent_error(scanner, "variant reparent error");
1402 | ID_TYPE LT IDENTIFIER GT
1404 $$ = make_node(scanner, NODE_VARIANT);
1405 $$->u.variant.name = $1->s;
1406 $$->u.variant.choice = $3->s;
1408 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1410 $$ = make_node(scanner, NODE_VARIANT);
1411 $$->u.variant.name = $1->s;
1412 $$->u.variant.choice = $3->s;
1413 if (reparent_node($6, $$))
1414 reparent_error(scanner, "variant reparent error");
1416 | ID_TYPE LT ID_TYPE GT
1418 $$ = make_node(scanner, NODE_VARIANT);
1419 $$->u.variant.name = $1->s;
1420 $$->u.variant.choice = $3->s;
1424 variant_declaration_begin:
1426 { push_scope(scanner); }
1429 variant_declaration_end:
1431 { pop_scope(scanner); }
1434 type_specifier_or_integer_constant:
1435 declaration_specifiers
1439 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1440 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1441 sscanf(yylval.gs->s, "%llu",
1442 &$$->u.unary_expression.u.unsigned_constant);
1446 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1447 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1448 sscanf(yylval.gs->s, "0%llo",
1449 &$$->u.unary_expression.u.unsigned_constant);
1451 | HEXADECIMAL_CONSTANT
1453 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1454 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1455 sscanf(yylval.gs->s, "0x%llx",
1456 &$$->u.unary_expression.u.unsigned_constant);
1460 enum_type_specifier:
1461 LBRAC enumerator_list RBRAC
1463 $$ = make_node(scanner, NODE_ENUM);
1464 cds_list_add(&($2)->siblings, &($$)->u._enum.enumerator_list);
1466 | LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
1468 $$ = make_node(scanner, NODE_ENUM);
1469 $$->u._enum.container_type = $2;
1470 cds_list_add(&($5)->siblings, &($$)->u._enum.enumerator_list);
1472 | IDENTIFIER LBRAC enumerator_list RBRAC
1474 $$ = make_node(scanner, NODE_ENUM);
1475 $$->u._enum.enum_id = $1->s;
1476 cds_list_add(&($3)->siblings, &($$)->u._enum.enumerator_list);
1478 | IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
1480 $$ = make_node(scanner, NODE_ENUM);
1481 $$->u._enum.enum_id = $1->s;
1482 $$->u._enum.container_type = $3;
1483 cds_list_add(&($6)->siblings, &($$)->u._enum.enumerator_list);
1485 | ID_TYPE LBRAC enumerator_list RBRAC
1487 $$ = make_node(scanner, NODE_ENUM);
1488 $$->u._enum.enum_id = $1->s;
1489 cds_list_add(&($3)->siblings, &($$)->u._enum.enumerator_list);
1491 | ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
1493 $$ = make_node(scanner, NODE_ENUM);
1494 $$->u._enum.enum_id = $1->s;
1495 $$->u._enum.container_type = $3;
1496 cds_list_add(&($6)->siblings, &($$)->u._enum.enumerator_list);
1498 | LBRAC enumerator_list COMMA RBRAC
1500 $$ = make_node(scanner, NODE_ENUM);
1501 cds_list_add(&($2)->siblings, &($$)->u._enum.enumerator_list);
1503 | LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
1505 $$ = make_node(scanner, NODE_ENUM);
1506 $$->u._enum.container_type = $2;
1507 cds_list_add(&($5)->siblings, &($$)->u._enum.enumerator_list);
1509 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1511 $$ = make_node(scanner, NODE_ENUM);
1512 $$->u._enum.enum_id = $1->s;
1513 cds_list_add(&($3)->siblings, &($$)->u._enum.enumerator_list);
1515 | IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
1517 $$ = make_node(scanner, NODE_ENUM);
1518 $$->u._enum.enum_id = $1->s;
1519 $$->u._enum.container_type = $3;
1520 cds_list_add(&($6)->siblings, &($$)->u._enum.enumerator_list);
1524 $$ = make_node(scanner, NODE_ENUM);
1525 $$->u._enum.enum_id = $1->s;
1527 | IDENTIFIER LT type_specifier_or_integer_constant GT
1529 $$ = make_node(scanner, NODE_ENUM);
1530 $$->u._enum.enum_id = $1->s;
1531 $$->u._enum.container_type = $3;
1533 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1535 $$ = make_node(scanner, NODE_ENUM);
1536 $$->u._enum.enum_id = $1->s;
1537 cds_list_add(&($3)->siblings, &($$)->u._enum.enumerator_list);
1539 | ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
1541 $$ = make_node(scanner, NODE_ENUM);
1542 $$->u._enum.enum_id = $1->s;
1543 $$->u._enum.container_type = $3;
1544 cds_list_add(&($6)->siblings, &($$)->u._enum.enumerator_list);
1548 $$ = make_node(scanner, NODE_ENUM);
1549 $$->u._enum.enum_id = $1->s;
1551 | ID_TYPE LT type_specifier_or_integer_constant GT
1553 $$ = make_node(scanner, NODE_ENUM);
1554 $$->u._enum.enum_id = $1->s;
1555 $$->u._enum.container_type = $3;
1559 struct_or_variant_declaration_list:
1562 | struct_or_variant_declaration_list struct_or_variant_declaration
1566 cds_list_add(&($2)->siblings, &($1)->siblings);
1573 struct_or_variant_declaration:
1574 specifier_qualifier_list struct_or_variant_declarator_list SEMICOLON
1576 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1577 cds_list_add(&($1)->siblings, &($$)->u.struct_or_variant_declaration.declaration_specifier);
1578 cds_list_add(&($2)->siblings, &($$)->u.struct_or_variant_declaration.type_declarators);
1580 | specifier_qualifier_list TYPEDEF specifier_qualifier_list type_declarator_list SEMICOLON
1582 $$ = make_node(scanner, NODE_TYPEDEF);
1583 cds_list_add(&($3)->siblings, &($$)->u._typedef.declaration_specifier);
1584 cds_list_add(&($1)->siblings, &($$)->u._typedef.declaration_specifier);
1585 cds_list_add(&($4)->siblings, &($$)->u._typedef.type_declarators);
1587 | TYPEDEF specifier_qualifier_list type_declarator_list SEMICOLON
1589 $$ = make_node(scanner, NODE_TYPEDEF);
1590 cds_list_add(&($2)->siblings, &($$)->u._typedef.declaration_specifier);
1591 cds_list_add(&($3)->siblings, &($$)->u._typedef.type_declarators);
1593 | specifier_qualifier_list TYPEDEF type_declarator_list SEMICOLON
1595 $$ = make_node(scanner, NODE_TYPEDEF);
1596 cds_list_add(&($1)->siblings, &($$)->u._typedef.declaration_specifier);
1597 cds_list_add(&($3)->siblings, &($$)->u._typedef.type_declarators);
1599 | TYPEALIAS specifier_qualifier_list abstract_declarator_list COLON specifier_qualifier_list abstract_type_declarator_list SEMICOLON
1601 $$ = make_node(scanner, NODE_TYPEALIAS);
1602 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1603 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1604 cds_list_add(&($2)->siblings, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1605 cds_list_add(&($3)->siblings, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1606 cds_list_add(&($5)->siblings, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
1607 cds_list_add(&($6)->siblings, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1609 | TYPEALIAS specifier_qualifier_list abstract_declarator_list COLON type_declarator_list SEMICOLON
1611 $$ = make_node(scanner, NODE_TYPEALIAS);
1612 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1613 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1614 cds_list_add(&($2)->siblings, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1615 cds_list_add(&($3)->siblings, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1616 cds_list_add(&($5)->siblings, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1620 specifier_qualifier_list:
1623 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1624 $$->u.type_specifier.type = TYPESPEC_CONST;
1628 | specifier_qualifier_list CONST
1630 struct ctf_node *node;
1633 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1634 node->u.type_specifier.type = TYPESPEC_CONST;
1635 cds_list_add(&node->siblings, &($$)->siblings);
1637 | specifier_qualifier_list type_specifier
1640 cds_list_add(&($2)->siblings, &($$)->siblings);
1644 struct_or_variant_declarator_list:
1645 struct_or_variant_declarator
1647 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
1650 cds_list_add(&($3)->siblings, &($$)->siblings);
1654 struct_or_variant_declarator:
1657 | COLON unary_expression
1659 | declarator COLON unary_expression
1662 if (reparent_node($3, $1))
1663 reparent_error(scanner, "struct_or_variant_declarator");
1670 | enumerator_list COMMA enumerator
1673 cds_list_add(&($3)->siblings, &($$)->siblings);
1680 $$ = make_node(scanner, NODE_ENUMERATOR);
1681 $$->u.enumerator.id = $1->s;
1685 $$ = make_node(scanner, NODE_ENUMERATOR);
1686 $$->u.enumerator.id = $1->s;
1690 $$ = make_node(scanner, NODE_ENUMERATOR);
1691 $$->u.enumerator.id = $1->s;
1693 | STRING_LITERAL_START DQUOTE
1695 $$ = make_node(scanner, NODE_ENUMERATOR);
1696 $$->u.enumerator.id = "";
1698 | STRING_LITERAL_START s_char_sequence DQUOTE
1700 $$ = make_node(scanner, NODE_ENUMERATOR);
1701 $$->u.enumerator.id = $2->s;
1703 | IDENTIFIER EQUAL unary_expression_or_range
1705 $$ = make_node(scanner, NODE_ENUMERATOR);
1706 $$->u.enumerator.id = $1->s;
1707 $$->u.enumerator.values = $3;
1709 | ID_TYPE EQUAL unary_expression_or_range
1711 $$ = make_node(scanner, NODE_ENUMERATOR);
1712 $$->u.enumerator.id = $1->s;
1713 $$->u.enumerator.values = $3;
1715 | keywords EQUAL unary_expression_or_range
1717 $$ = make_node(scanner, NODE_ENUMERATOR);
1718 $$->u.enumerator.id = $1->s;
1719 $$->u.enumerator.values = $3;
1721 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
1723 $$ = make_node(scanner, NODE_ENUMERATOR);
1724 $$->u.enumerator.id = "";
1725 $$->u.enumerator.values = $4;
1727 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
1729 $$ = make_node(scanner, NODE_ENUMERATOR);
1730 $$->u.enumerator.id = $2->s;
1731 $$->u.enumerator.values = $5;
1735 abstract_declarator_list:
1738 | abstract_declarator_list COMMA abstract_declarator
1741 cds_list_add(&($3)->siblings, &($$)->siblings);
1745 abstract_declarator:
1746 direct_abstract_declarator
1748 | pointer direct_abstract_declarator
1751 cds_list_add(&($1)->siblings, &($$)->u.type_declarator.pointers);
1755 direct_abstract_declarator:
1758 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1759 $$->u.type_declarator.type = TYPEDEC_ID;
1764 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1765 $$->u.type_declarator.type = TYPEDEC_ID;
1766 $$->u.type_declarator.u.id = $1->s;
1768 | LPAREN abstract_declarator RPAREN
1770 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1771 $$->u.type_declarator.type = TYPEDEC_NESTED;
1772 $$->u.type_declarator.u.nested.type_declarator = $2;
1774 | direct_abstract_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
1776 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1777 $$->u.type_declarator.type = TYPEDEC_NESTED;
1778 $$->u.type_declarator.u.nested.type_declarator = $1;
1779 $$->u.type_declarator.u.nested.length = $3;
1781 | direct_abstract_declarator LSBRAC RSBRAC
1783 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1784 $$->u.type_declarator.type = TYPEDEC_NESTED;
1785 $$->u.type_declarator.u.nested.type_declarator = $1;
1786 $$->u.type_declarator.u.nested.abstract_array = 1;
1793 | pointer direct_declarator
1796 cds_list_add(&($1)->siblings, &($$)->u.type_declarator.pointers);
1803 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1804 $$->u.type_declarator.type = TYPEDEC_ID;
1805 $$->u.type_declarator.u.id = $1->s;
1807 | LPAREN declarator RPAREN
1809 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1810 $$->u.type_declarator.type = TYPEDEC_NESTED;
1811 $$->u.type_declarator.u.nested.type_declarator = $2;
1813 | direct_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
1815 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1816 $$->u.type_declarator.type = TYPEDEC_NESTED;
1817 $$->u.type_declarator.u.nested.type_declarator = $1;
1818 $$->u.type_declarator.u.nested.length = $3;
1823 direct_type_declarator
1825 | pointer direct_type_declarator
1828 cds_list_add(&($1)->siblings, &($$)->u.type_declarator.pointers);
1832 direct_type_declarator:
1835 add_type(scanner, $1);
1836 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1837 $$->u.type_declarator.type = TYPEDEC_ID;
1838 $$->u.type_declarator.u.id = $1->s;
1840 | LPAREN type_declarator RPAREN
1842 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1843 $$->u.type_declarator.type = TYPEDEC_NESTED;
1844 $$->u.type_declarator.u.nested.type_declarator = $2;
1846 | direct_type_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
1848 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1849 $$->u.type_declarator.type = TYPEDEC_NESTED;
1850 $$->u.type_declarator.u.nested.type_declarator = $1;
1851 $$->u.type_declarator.u.nested.length = $3;
1855 abstract_type_declarator:
1856 direct_abstract_type_declarator
1858 | pointer direct_abstract_type_declarator
1861 cds_list_add(&($1)->siblings, &($$)->u.type_declarator.pointers);
1865 direct_abstract_type_declarator:
1868 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1869 $$->u.type_declarator.type = TYPEDEC_ID;
1874 add_type(scanner, $1);
1875 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1876 $$->u.type_declarator.type = TYPEDEC_ID;
1877 $$->u.type_declarator.u.id = $1->s;
1879 | LPAREN abstract_type_declarator RPAREN
1881 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1882 $$->u.type_declarator.type = TYPEDEC_NESTED;
1883 $$->u.type_declarator.u.nested.type_declarator = $2;
1885 | direct_abstract_type_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
1887 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1888 $$->u.type_declarator.type = TYPEDEC_NESTED;
1889 $$->u.type_declarator.u.nested.type_declarator = $1;
1890 $$->u.type_declarator.u.nested.length = $3;
1892 | direct_abstract_type_declarator LSBRAC RSBRAC
1894 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
1895 $$->u.type_declarator.type = TYPEDEC_NESTED;
1896 $$->u.type_declarator.u.nested.type_declarator = $1;
1897 $$->u.type_declarator.u.nested.abstract_array = 1;
1903 { $$ = make_node(scanner, NODE_POINTER); }
1906 $$ = make_node(scanner, NODE_POINTER);
1907 cds_list_add(&($2)->siblings, &($$)->siblings);
1909 | STAR type_qualifier_list pointer
1911 $$ = make_node(scanner, NODE_POINTER);
1912 $$->u.pointer.const_qualifier = 1;
1913 cds_list_add(&($3)->siblings, &($$)->siblings);
1917 type_qualifier_list:
1918 /* pointer assumes only const type qualifier */
1920 | type_qualifier_list CONST
1923 /* 2.3: CTF-specific declarations */
1925 ctf_assignment_expression_list:
1926 ctf_assignment_expression SEMICOLON
1928 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
1931 cds_list_add(&($2)->siblings, &($1)->siblings);
1935 ctf_assignment_expression:
1936 unary_expression EQUAL unary_expression
1939 * Because we have left and right, cannot use
1942 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
1943 $$->u.ctf_expression.left = $1;
1944 if ($1->u.unary_expression.type != UNARY_STRING)
1945 reparent_error(scanner, "ctf_assignment_expression left expects string");
1946 $$->u.ctf_expression.right = $3;
1948 | unary_expression TYPEASSIGN type_specifier
1951 * Because we have left and right, cannot use
1954 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
1955 $$->u.ctf_expression.left = $1;
1956 if ($1->u.unary_expression.type != UNARY_STRING)
1957 reparent_error(scanner, "ctf_assignment_expression left expects string");
1958 $$->u.ctf_expression.right = $3;
1960 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
1962 $$ = make_node(scanner, NODE_TYPEDEF);
1963 cds_list_add(&($3)->siblings, &($$)->u._typedef.declaration_specifier);
1964 cds_list_add(&($1)->siblings, &($$)->u._typedef.declaration_specifier);
1965 cds_list_add(&($4)->siblings, &($$)->u._typedef.type_declarators);
1967 | TYPEDEF declaration_specifiers type_declarator_list
1969 $$ = make_node(scanner, NODE_TYPEDEF);
1970 cds_list_add(&($2)->siblings, &($$)->u._typedef.declaration_specifier);
1971 cds_list_add(&($3)->siblings, &($$)->u._typedef.type_declarators);
1973 | declaration_specifiers TYPEDEF type_declarator_list
1975 $$ = make_node(scanner, NODE_TYPEDEF);
1976 cds_list_add(&($1)->siblings, &($$)->u._typedef.declaration_specifier);
1977 cds_list_add(&($3)->siblings, &($$)->u._typedef.type_declarators);
1979 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON declaration_specifiers abstract_type_declarator_list
1981 $$ = make_node(scanner, NODE_TYPEALIAS);
1982 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1983 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1984 cds_list_add(&($2)->siblings, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1985 cds_list_add(&($3)->siblings, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1986 cds_list_add(&($5)->siblings, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
1987 cds_list_add(&($6)->siblings, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1989 | TYPEALIAS declaration_specifiers abstract_declarator_list COLON type_declarator_list
1991 $$ = make_node(scanner, NODE_TYPEALIAS);
1992 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1993 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1994 cds_list_add(&($2)->siblings, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
1995 cds_list_add(&($3)->siblings, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1996 cds_list_add(&($5)->siblings, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);