Use objstack for strings
[babeltrace.git] / formats / ctf / metadata / ctf-parser.y
CommitLineData
8b9d5b5e
MD
1%{
2/*
c59a87f5 3 * ctf-parser.y
8b9d5b5e
MD
4 *
5 * Common Trace Format Metadata Grammar.
c59a87f5
MD
6 *
7 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
c462e188
MD
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
8b9d5b5e
MD
26 */
27
28#include <stdio.h>
d876a5ba 29#include <ctype.h>
8b9d5b5e
MD
30#include <unistd.h>
31#include <string.h>
32#include <stdlib.h>
33#include <assert.h>
8b9d5b5e 34#include <glib.h>
02b234c4 35#include <errno.h>
380d60b1 36#include <inttypes.h>
fe41395a 37#include <babeltrace/list.h>
70bd0a12 38#include <babeltrace/babeltrace-internal.h>
34d3acc4 39#include "ctf-scanner.h"
8b9d5b5e
MD
40#include "ctf-parser.h"
41#include "ctf-ast.h"
8aa95b17 42#include "objstack.h"
8b9d5b5e 43
5d6c80a5 44BT_HIDDEN
a3983482
MD
45int yydebug;
46
48a01768
MD
47/* Join two lists, put "add" at the end of "head". */
48static inline void
3122e6f0 49_bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
48a01768
MD
50{
51 /* Do nothing if the list which gets added is empty. */
52 if (add != add->next) {
53 add->next->prev = head->prev;
54 add->prev->next = head;
55 head->prev->next = add->next;
56 head->prev = add->prev;
57 }
58}
59
5d6c80a5 60BT_HIDDEN
34d3acc4 61int yyparse(struct ctf_scanner *scanner);
5d6c80a5 62BT_HIDDEN
34d3acc4 63int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
5d6c80a5 64BT_HIDDEN
34d3acc4 65int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
5d6c80a5 66BT_HIDDEN
61e9d0ce 67int yylex_destroy(yyscan_t yyscanner);
5d6c80a5 68BT_HIDDEN
65102a8c 69void yyrestart(FILE * in_str, yyscan_t scanner);
8c834e5a
MD
70BT_HIDDEN
71int yyget_lineno(yyscan_t yyscanner);
740aad26
MD
72BT_HIDDEN
73char *yyget_text(yyscan_t yyscanner);
8b9d5b5e 74
34f7b02c 75static const char *node_type_to_str[] = {
590ca879
EB
76#define ENTRY(S) [S] = #S,
77 FOREACH_CTF_NODES(ENTRY)
78#undef ENTRY
34f7b02c
MD
79};
80
ff201942
MD
81/*
82 * Static node for out of memory errors. Only "type" is used. lineno is
83 * always left at 0. The rest of the node content can be overwritten,
84 * but is never used.
85 */
86static struct ctf_node error_node = {
bdb55bcb
MD
87 .type = NODE_ERROR,
88};
89
5d6c80a5 90BT_HIDDEN
34f7b02c
MD
91const char *node_type(struct ctf_node *node)
92{
93 if (node->type < NR_NODE_TYPES)
94 return node_type_to_str[node->type];
95 else
96 return NULL;
97}
98
34d3acc4 99void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
8b9d5b5e 100{
8aa95b17
MD
101 lvalp->s = objstack_alloc(scanner->objstack, strlen(src) + 1);
102 strcpy(lvalp->s, src);
8b9d5b5e
MD
103}
104
d876a5ba
EB
105static
106int str_check(size_t str_len, size_t offset, size_t len)
107{
108 /* check overflow */
109 if (offset + len < offset)
110 return -1;
111 if (offset + len > str_len)
112 return -1;
113 return 0;
114}
115
697b1050
MD
116static
117int bt_isodigit(int c)
118{
119 switch (c) {
120 case '0':
121 case '1':
122 case '2':
123 case '3':
124 case '4':
125 case '5':
126 case '6':
127 case '7':
128 return 1;
129 default:
130 return 0;
131 }
132}
133
134static
135int parse_base_sequence(const char *src, size_t len, size_t pos,
136 char *buffer, size_t *buf_len, int base)
137{
138 const size_t max_char = 3;
139 int nr_char = 0;
140
141 while (!str_check(len, pos, 1) && nr_char < max_char) {
142 char c = src[pos++];
143
144 if (base == 8) {
145 if (bt_isodigit(c))
146 buffer[nr_char++] = c;
147 else
148 break;
149 } else if (base == 16) {
150 if (isxdigit(c))
151 buffer[nr_char++] = c;
152 else
153 break;
154
155 } else {
156 /* Unsupported base */
157 return -1;
158 }
159 }
160 assert(nr_char > 0);
161 buffer[nr_char] = '\0';
162 *buf_len = nr_char;
163 return 0;
164}
165
d876a5ba
EB
166static
167int import_basic_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
168 size_t len, const char *src, char delim)
169{
170 size_t pos = 0, dpos = 0;
171
172 if (str_check(len, pos, 1))
173 return -1;
174 if (src[pos++] != delim)
175 return -1;
176
177 while (src[pos] != delim) {
178 char c;
179
180 if (str_check(len, pos, 1))
181 return -1;
182 c = src[pos++];
183 if (c == '\\') {
184 if (str_check(len, pos, 1))
185 return -1;
186 c = src[pos++];
187
188 switch (c) {
d876a5ba
EB
189 case 'a':
190 c = '\a';
191 break;
192 case 'b':
193 c = '\b';
194 break;
195 case 'f':
196 c = '\f';
197 break;
198 case 'n':
199 c = '\n';
200 break;
201 case 'r':
202 c = '\r';
203 break;
204 case 't':
205 c = '\t';
206 break;
207 case 'v':
208 c = '\v';
209 break;
210 case '\\':
211 c = '\\';
212 break;
213 case '\'':
214 c = '\'';
215 break;
216 case '\"':
217 c = '\"';
218 break;
219 case '?':
220 c = '?';
221 break;
697b1050
MD
222 case '0':
223 case '1':
224 case '2':
225 case '3':
226 case '4':
227 case '5':
228 case '6':
229 case '7':
d876a5ba 230 {
697b1050
MD
231 char oct_buffer[4];
232 size_t oct_len;
d876a5ba 233
697b1050
MD
234 if (parse_base_sequence(src, len, pos - 1,
235 oct_buffer, &oct_len, 8))
d876a5ba 236 return -1;
d876a5ba 237 c = strtoul(&oct_buffer[0], NULL, 8);
697b1050 238 pos += oct_len - 1;
d876a5ba
EB
239 break;
240 }
241 case 'x':
242 {
697b1050
MD
243 char hex_buffer[4];
244 size_t hex_len;
d876a5ba 245
697b1050
MD
246 if (parse_base_sequence(src, len, pos,
247 hex_buffer, &hex_len, 16))
d876a5ba 248 return -1;
d876a5ba
EB
249 c = strtoul(&hex_buffer[0], NULL, 16);
250 pos += hex_len;
251 break;
252 }
253 default:
254 return -1;
255 }
256 }
257 if (str_check(len, dpos, 1))
258 return -1;
8aa95b17 259 lvalp->s[dpos++] = c;
d876a5ba
EB
260 }
261
262 if (str_check(len, dpos, 1))
263 return -1;
8aa95b17 264 lvalp->s[dpos++] = '\0';
d876a5ba
EB
265
266 if (str_check(len, pos, 1))
267 return -1;
268 if (src[pos++] != delim)
269 return -1;
270
271 if (str_check(len, pos, 1))
272 return -1;
273 if (src[pos] != '\0')
274 return -1;
275 return 0;
276}
277
278int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
279 const char *src, char delim)
280{
281 size_t len;
282
283 len = strlen(src) + 1;
8aa95b17 284 lvalp->s = objstack_alloc(scanner->objstack, len);
d876a5ba
EB
285 if (src[0] == 'L') {
286 // TODO: import wide string
287 printfl_error(yyget_lineno(scanner),
288 "Wide string not supported yet.");
289 return -1;
290 } else {
291 return import_basic_string(scanner, lvalp, len, src, delim);
292 }
293}
294
609bd1bf
MD
295static void init_scope(struct ctf_scanner_scope *scope,
296 struct ctf_scanner_scope *parent)
8b9d5b5e
MD
297{
298 scope->parent = parent;
299 scope->types = g_hash_table_new_full(g_str_hash, g_str_equal,
6dc474b8 300 NULL, NULL);
8b9d5b5e
MD
301}
302
609bd1bf 303static void finalize_scope(struct ctf_scanner_scope *scope)
8b9d5b5e
MD
304{
305 g_hash_table_destroy(scope->types);
306}
307
34d3acc4 308static void push_scope(struct ctf_scanner *scanner)
8b9d5b5e 309{
609bd1bf 310 struct ctf_scanner_scope *ns;
8b9d5b5e 311
a3983482 312 printf_debug("push scope\n");
609bd1bf 313 ns = malloc(sizeof(struct ctf_scanner_scope));
34d3acc4
MD
314 init_scope(ns, scanner->cs);
315 scanner->cs = ns;
8b9d5b5e
MD
316}
317
34d3acc4 318static void pop_scope(struct ctf_scanner *scanner)
8b9d5b5e 319{
609bd1bf 320 struct ctf_scanner_scope *os;
8b9d5b5e 321
a3983482 322 printf_debug("pop scope\n");
34d3acc4
MD
323 os = scanner->cs;
324 scanner->cs = os->parent;
8b9d5b5e
MD
325 finalize_scope(os);
326 free(os);
327}
328
609bd1bf 329static int lookup_type(struct ctf_scanner_scope *s, const char *id)
8b9d5b5e
MD
330{
331 int ret;
332
380d60b1 333 ret = (int) (long) g_hash_table_lookup(s->types, id);
a3983482 334 printf_debug("lookup %p %s %d\n", s, id, ret);
8b9d5b5e
MD
335 return ret;
336}
337
5d6c80a5 338BT_HIDDEN
34d3acc4 339int is_type(struct ctf_scanner *scanner, const char *id)
8b9d5b5e 340{
609bd1bf 341 struct ctf_scanner_scope *it;
8b9d5b5e
MD
342 int ret = 0;
343
34d3acc4 344 for (it = scanner->cs; it != NULL; it = it->parent) {
8b9d5b5e
MD
345 if (lookup_type(it, id)) {
346 ret = 1;
347 break;
348 }
349 }
a3983482 350 printf_debug("is type %s %d\n", id, ret);
8b9d5b5e
MD
351 return ret;
352}
353
8aa95b17 354static void add_type(struct ctf_scanner *scanner, char *id)
8b9d5b5e 355{
8aa95b17
MD
356 printf_debug("add type %s\n", id);
357 if (lookup_type(scanner->cs, id))
8b9d5b5e 358 return;
8aa95b17 359 g_hash_table_insert(scanner->cs->types, id, id);
8b9d5b5e
MD
360}
361
02b234c4
MD
362static struct ctf_node *make_node(struct ctf_scanner *scanner,
363 enum node_type type)
364{
365 struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
366 struct ctf_node *node;
367
368 node = malloc(sizeof(*node));
bdb55bcb 369 if (!node) {
ff201942 370 printfl_fatal(yyget_lineno(scanner->scanner), "out of memory");
bdb55bcb
MD
371 return &error_node;
372 }
02b234c4
MD
373 memset(node, 0, sizeof(*node));
374 node->type = type;
5c5c3455 375 node->lineno = yyget_lineno(scanner->scanner);
3122e6f0
JD
376 BT_INIT_LIST_HEAD(&node->tmp_head);
377 bt_list_add(&node->gc, &ast->allocated_nodes);
378 bt_list_add(&node->siblings, &node->tmp_head);
02b234c4
MD
379
380 switch (type) {
381 case NODE_ROOT:
bdb55bcb 382 node->type = NODE_ERROR;
c55adfb9 383 printfn_fatal(node, "trying to create root node");
02b234c4
MD
384 break;
385
386 case NODE_EVENT:
3122e6f0 387 BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
02b234c4
MD
388 break;
389 case NODE_STREAM:
3122e6f0 390 BT_INIT_LIST_HEAD(&node->u.stream.declaration_list);
02b234c4 391 break;
e2c76a4d 392 case NODE_ENV:
3122e6f0 393 BT_INIT_LIST_HEAD(&node->u.env.declaration_list);
e2c76a4d 394 break;
02b234c4 395 case NODE_TRACE:
3122e6f0 396 BT_INIT_LIST_HEAD(&node->u.trace.declaration_list);
02b234c4 397 break;
73d15916 398 case NODE_CLOCK:
3122e6f0 399 BT_INIT_LIST_HEAD(&node->u.clock.declaration_list);
73d15916 400 break;
f133896d
MD
401 case NODE_CALLSITE:
402 BT_INIT_LIST_HEAD(&node->u.callsite.declaration_list);
403 break;
02b234c4
MD
404
405 case NODE_CTF_EXPRESSION:
3122e6f0
JD
406 BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
407 BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
02b234c4 408 break;
6dc474b8
MD
409 case NODE_UNARY_EXPRESSION:
410 break;
02b234c4
MD
411
412 case NODE_TYPEDEF:
3122e6f0 413 BT_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
02b234c4
MD
414 break;
415 case NODE_TYPEALIAS_TARGET:
3122e6f0 416 BT_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
02b234c4
MD
417 break;
418 case NODE_TYPEALIAS_ALIAS:
3122e6f0 419 BT_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
02b234c4
MD
420 break;
421 case NODE_TYPEALIAS:
422 break;
423
424 case NODE_TYPE_SPECIFIER:
425 break;
3e11b713 426 case NODE_TYPE_SPECIFIER_LIST:
3122e6f0 427 BT_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
3e11b713 428 break;
02b234c4
MD
429 case NODE_POINTER:
430 break;
431 case NODE_TYPE_DECLARATOR:
3122e6f0 432 BT_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
02b234c4
MD
433 break;
434
435 case NODE_FLOATING_POINT:
3122e6f0 436 BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
02b234c4
MD
437 break;
438 case NODE_INTEGER:
3122e6f0 439 BT_INIT_LIST_HEAD(&node->u.integer.expressions);
02b234c4
MD
440 break;
441 case NODE_STRING:
3122e6f0 442 BT_INIT_LIST_HEAD(&node->u.string.expressions);
02b234c4
MD
443 break;
444 case NODE_ENUMERATOR:
3122e6f0 445 BT_INIT_LIST_HEAD(&node->u.enumerator.values);
02b234c4
MD
446 break;
447 case NODE_ENUM:
3122e6f0 448 BT_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
02b234c4
MD
449 break;
450 case NODE_STRUCT_OR_VARIANT_DECLARATION:
3122e6f0 451 BT_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
02b234c4
MD
452 break;
453 case NODE_VARIANT:
3122e6f0 454 BT_INIT_LIST_HEAD(&node->u.variant.declaration_list);
02b234c4
MD
455 break;
456 case NODE_STRUCT:
3122e6f0
JD
457 BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
458 BT_INIT_LIST_HEAD(&node->u._struct.min_align);
02b234c4
MD
459 break;
460
461 case NODE_UNKNOWN:
462 default:
bdb55bcb 463 node->type = NODE_ERROR;
c55adfb9 464 printfn_fatal(node, "unknown node type '%d'", (int) type);
02b234c4
MD
465 break;
466 }
467
468 return node;
469}
470
471static int reparent_ctf_expression(struct ctf_node *node,
472 struct ctf_node *parent)
473{
474 switch (parent->type) {
475 case NODE_EVENT:
3122e6f0 476 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
02b234c4
MD
477 break;
478 case NODE_STREAM:
3122e6f0 479 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
02b234c4 480 break;
e2c76a4d 481 case NODE_ENV:
3122e6f0 482 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
e2c76a4d 483 break;
02b234c4 484 case NODE_TRACE:
3122e6f0 485 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
02b234c4 486 break;
73d15916 487 case NODE_CLOCK:
3122e6f0 488 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
73d15916 489 break;
f133896d
MD
490 case NODE_CALLSITE:
491 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
492 break;
02b234c4 493 case NODE_FLOATING_POINT:
3122e6f0 494 _bt_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions);
02b234c4
MD
495 break;
496 case NODE_INTEGER:
3122e6f0 497 _bt_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions);
02b234c4
MD
498 break;
499 case NODE_STRING:
3122e6f0 500 _bt_list_splice_tail(&node->tmp_head, &parent->u.string.expressions);
02b234c4
MD
501 break;
502
503 case NODE_ROOT:
504 case NODE_CTF_EXPRESSION:
505 case NODE_TYPEDEF:
506 case NODE_TYPEALIAS_TARGET:
507 case NODE_TYPEALIAS_ALIAS:
508 case NODE_TYPEALIAS:
509 case NODE_TYPE_SPECIFIER:
3e11b713 510 case NODE_TYPE_SPECIFIER_LIST:
02b234c4
MD
511 case NODE_POINTER:
512 case NODE_TYPE_DECLARATOR:
513 case NODE_ENUMERATOR:
514 case NODE_ENUM:
515 case NODE_STRUCT_OR_VARIANT_DECLARATION:
516 case NODE_VARIANT:
517 case NODE_STRUCT:
6dc474b8 518 case NODE_UNARY_EXPRESSION:
02b234c4
MD
519 return -EPERM;
520
521 case NODE_UNKNOWN:
522 default:
c55adfb9 523 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
02b234c4
MD
524 return -EINVAL;
525 }
526 return 0;
527}
528
529static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
530{
531 switch (parent->type) {
532 case NODE_ROOT:
3122e6f0 533 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
02b234c4
MD
534 break;
535 case NODE_EVENT:
3122e6f0 536 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
02b234c4
MD
537 break;
538 case NODE_STREAM:
3122e6f0 539 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
02b234c4 540 break;
e2c76a4d 541 case NODE_ENV:
3122e6f0 542 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
e2c76a4d 543 break;
02b234c4 544 case NODE_TRACE:
3122e6f0 545 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
02b234c4 546 break;
73d15916 547 case NODE_CLOCK:
3122e6f0 548 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
73d15916 549 break;
f133896d
MD
550 case NODE_CALLSITE:
551 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
552 break;
02b234c4 553 case NODE_VARIANT:
3122e6f0 554 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
02b234c4
MD
555 break;
556 case NODE_STRUCT:
3122e6f0 557 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
02b234c4
MD
558 break;
559
560 case NODE_FLOATING_POINT:
561 case NODE_INTEGER:
562 case NODE_STRING:
563 case NODE_CTF_EXPRESSION:
564 case NODE_TYPEDEF:
565 case NODE_TYPEALIAS_TARGET:
566 case NODE_TYPEALIAS_ALIAS:
567 case NODE_TYPEALIAS:
568 case NODE_TYPE_SPECIFIER:
3e11b713 569 case NODE_TYPE_SPECIFIER_LIST:
02b234c4
MD
570 case NODE_POINTER:
571 case NODE_TYPE_DECLARATOR:
572 case NODE_ENUMERATOR:
573 case NODE_ENUM:
574 case NODE_STRUCT_OR_VARIANT_DECLARATION:
6dc474b8 575 case NODE_UNARY_EXPRESSION:
02b234c4
MD
576 return -EPERM;
577
578 case NODE_UNKNOWN:
579 default:
c55adfb9 580 printfn_fatal(node, "unknown node type %d", parent->type);
02b234c4
MD
581 return -EINVAL;
582 }
583 return 0;
584}
585
586static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
587{
588 switch (parent->type) {
589 case NODE_ROOT:
3122e6f0 590 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
02b234c4
MD
591 break;
592 case NODE_EVENT:
3122e6f0 593 _bt_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
02b234c4
MD
594 break;
595 case NODE_STREAM:
3122e6f0 596 _bt_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
02b234c4 597 break;
e2c76a4d 598 case NODE_ENV:
3122e6f0 599 _bt_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
e2c76a4d 600 break;
02b234c4 601 case NODE_TRACE:
3122e6f0 602 _bt_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
02b234c4 603 break;
73d15916 604 case NODE_CLOCK:
3122e6f0 605 _bt_list_splice_tail(&node->tmp_head, &parent->u.clock.declaration_list);
73d15916 606 break;
f133896d
MD
607 case NODE_CALLSITE:
608 _bt_list_splice_tail(&node->tmp_head, &parent->u.callsite.declaration_list);
609 break;
02b234c4 610 case NODE_VARIANT:
3122e6f0 611 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
02b234c4
MD
612 break;
613 case NODE_STRUCT:
3122e6f0 614 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
02b234c4
MD
615 break;
616
617 case NODE_FLOATING_POINT:
618 case NODE_INTEGER:
619 case NODE_STRING:
620 case NODE_CTF_EXPRESSION:
621 case NODE_TYPEDEF:
622 case NODE_TYPEALIAS_TARGET:
623 case NODE_TYPEALIAS_ALIAS:
624 case NODE_TYPEALIAS:
625 case NODE_TYPE_SPECIFIER:
3e11b713 626 case NODE_TYPE_SPECIFIER_LIST:
02b234c4
MD
627 case NODE_POINTER:
628 case NODE_TYPE_DECLARATOR:
629 case NODE_ENUMERATOR:
630 case NODE_ENUM:
631 case NODE_STRUCT_OR_VARIANT_DECLARATION:
6dc474b8 632 case NODE_UNARY_EXPRESSION:
02b234c4
MD
633 return -EPERM;
634
635 case NODE_UNKNOWN:
636 default:
c55adfb9 637 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
02b234c4
MD
638 return -EINVAL;
639 }
640 return 0;
641}
642
6dc474b8
MD
643static int reparent_type_specifier(struct ctf_node *node,
644 struct ctf_node *parent)
3e11b713
MD
645{
646 switch (parent->type) {
647 case NODE_TYPE_SPECIFIER_LIST:
3122e6f0 648 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
3e11b713
MD
649 break;
650
651 case NODE_TYPE_SPECIFIER:
652 case NODE_EVENT:
653 case NODE_STREAM:
e2c76a4d 654 case NODE_ENV:
3e11b713 655 case NODE_TRACE:
73d15916 656 case NODE_CLOCK:
f133896d 657 case NODE_CALLSITE:
3e11b713
MD
658 case NODE_VARIANT:
659 case NODE_STRUCT:
660 case NODE_TYPEDEF:
661 case NODE_TYPEALIAS_TARGET:
662 case NODE_TYPEALIAS_ALIAS:
663 case NODE_TYPE_DECLARATOR:
664 case NODE_ENUM:
665 case NODE_STRUCT_OR_VARIANT_DECLARATION:
666 case NODE_TYPEALIAS:
667 case NODE_FLOATING_POINT:
668 case NODE_INTEGER:
669 case NODE_STRING:
670 case NODE_CTF_EXPRESSION:
671 case NODE_POINTER:
672 case NODE_ENUMERATOR:
673 case NODE_UNARY_EXPRESSION:
674 return -EPERM;
675
676 case NODE_UNKNOWN:
677 default:
c55adfb9 678 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
3e11b713
MD
679 return -EINVAL;
680 }
681 return 0;
682}
683
684static int reparent_type_specifier_list(struct ctf_node *node,
685 struct ctf_node *parent)
02b234c4
MD
686{
687 switch (parent->type) {
688 case NODE_ROOT:
3122e6f0 689 bt_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
02b234c4
MD
690 break;
691 case NODE_EVENT:
3122e6f0 692 bt_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
02b234c4
MD
693 break;
694 case NODE_STREAM:
3122e6f0 695 bt_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
02b234c4 696 break;
e2c76a4d 697 case NODE_ENV:
3122e6f0 698 bt_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
e2c76a4d 699 break;
02b234c4 700 case NODE_TRACE:
3122e6f0 701 bt_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
02b234c4 702 break;
73d15916 703 case NODE_CLOCK:
3122e6f0 704 bt_list_add_tail(&node->siblings, &parent->u.clock.declaration_list);
73d15916 705 break;
f133896d
MD
706 case NODE_CALLSITE:
707 bt_list_add_tail(&node->siblings, &parent->u.callsite.declaration_list);
708 break;
02b234c4 709 case NODE_VARIANT:
3122e6f0 710 bt_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
02b234c4
MD
711 break;
712 case NODE_STRUCT:
3122e6f0 713 bt_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
02b234c4
MD
714 break;
715 case NODE_TYPEDEF:
3e11b713 716 parent->u._typedef.type_specifier_list = node;
02b234c4
MD
717 break;
718 case NODE_TYPEALIAS_TARGET:
3e11b713 719 parent->u.typealias_target.type_specifier_list = node;
02b234c4
MD
720 break;
721 case NODE_TYPEALIAS_ALIAS:
3e11b713 722 parent->u.typealias_alias.type_specifier_list = node;
02b234c4 723 break;
02b234c4 724 case NODE_ENUM:
3e11b713 725 parent->u._enum.container_type = node;
02b234c4
MD
726 break;
727 case NODE_STRUCT_OR_VARIANT_DECLARATION:
3e11b713 728 parent->u.struct_or_variant_declaration.type_specifier_list = node;
02b234c4 729 break;
98df1c9f 730 case NODE_TYPE_DECLARATOR:
3e11b713 731 case NODE_TYPE_SPECIFIER:
02b234c4
MD
732 case NODE_TYPEALIAS:
733 case NODE_FLOATING_POINT:
734 case NODE_INTEGER:
735 case NODE_STRING:
736 case NODE_CTF_EXPRESSION:
02b234c4
MD
737 case NODE_POINTER:
738 case NODE_ENUMERATOR:
6dc474b8 739 case NODE_UNARY_EXPRESSION:
02b234c4
MD
740 return -EPERM;
741
742 case NODE_UNKNOWN:
743 default:
c55adfb9 744 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
02b234c4
MD
745 return -EINVAL;
746 }
747 return 0;
748}
749
750static int reparent_type_declarator(struct ctf_node *node,
751 struct ctf_node *parent)
752{
753 switch (parent->type) {
754 case NODE_TYPE_DECLARATOR:
755 parent->u.type_declarator.type = TYPEDEC_NESTED;
756 parent->u.type_declarator.u.nested.type_declarator = node;
757 break;
758 case NODE_STRUCT_OR_VARIANT_DECLARATION:
3122e6f0 759 _bt_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators);
02b234c4
MD
760 break;
761 case NODE_TYPEDEF:
3122e6f0 762 _bt_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators);
02b234c4
MD
763 break;
764 case NODE_TYPEALIAS_TARGET:
3122e6f0 765 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators);
02b234c4
MD
766 break;
767 case NODE_TYPEALIAS_ALIAS:
3122e6f0 768 _bt_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators);
02b234c4
MD
769 break;
770
771 case NODE_ROOT:
772 case NODE_EVENT:
773 case NODE_STREAM:
e2c76a4d 774 case NODE_ENV:
02b234c4 775 case NODE_TRACE:
73d15916 776 case NODE_CLOCK:
f133896d 777 case NODE_CALLSITE:
02b234c4
MD
778 case NODE_VARIANT:
779 case NODE_STRUCT:
780 case NODE_TYPEALIAS:
781 case NODE_ENUM:
782 case NODE_FLOATING_POINT:
783 case NODE_INTEGER:
784 case NODE_STRING:
785 case NODE_CTF_EXPRESSION:
786 case NODE_TYPE_SPECIFIER:
3e11b713 787 case NODE_TYPE_SPECIFIER_LIST:
02b234c4
MD
788 case NODE_POINTER:
789 case NODE_ENUMERATOR:
6dc474b8 790 case NODE_UNARY_EXPRESSION:
02b234c4
MD
791 return -EPERM;
792
793 case NODE_UNKNOWN:
794 default:
c55adfb9 795 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
02b234c4
MD
796 return -EINVAL;
797 }
798 return 0;
799}
800
801/*
48a01768 802 * set_parent_node
02b234c4 803 *
48a01768
MD
804 * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to
805 * create the link declared by the input, -ENOENT if node or parent is NULL,
806 * -EINVAL if there is an internal structure problem.
02b234c4 807 */
48a01768 808static int set_parent_node(struct ctf_node *node,
02b234c4
MD
809 struct ctf_node *parent)
810{
811 if (!node || !parent)
812 return -ENOENT;
813
6dc474b8 814 /* Note: Linking to parent will be done only by an external visitor */
02b234c4
MD
815
816 switch (node->type) {
817 case NODE_ROOT:
c55adfb9 818 printfn_fatal(node, "trying to reparent root node");
02b234c4
MD
819 return -EINVAL;
820
821 case NODE_EVENT:
48a01768 822 if (parent->type == NODE_ROOT) {
3122e6f0 823 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.event);
3e11b713 824 } else {
02b234c4 825 return -EPERM;
3e11b713 826 }
02b234c4
MD
827 break;
828 case NODE_STREAM:
48a01768 829 if (parent->type == NODE_ROOT) {
3122e6f0 830 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
3e11b713 831 } else {
02b234c4 832 return -EPERM;
3e11b713 833 }
02b234c4 834 break;
e2c76a4d
MD
835 case NODE_ENV:
836 if (parent->type == NODE_ROOT) {
3122e6f0 837 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.env);
e2c76a4d
MD
838 } else {
839 return -EPERM;
840 }
841 break;
02b234c4 842 case NODE_TRACE:
48a01768 843 if (parent->type == NODE_ROOT) {
3122e6f0 844 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
3e11b713 845 } else {
02b234c4 846 return -EPERM;
3e11b713 847 }
02b234c4 848 break;
73d15916
MD
849 case NODE_CLOCK:
850 if (parent->type == NODE_ROOT) {
3122e6f0 851 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.clock);
73d15916
MD
852 } else {
853 return -EPERM;
854 }
855 break;
f133896d
MD
856 case NODE_CALLSITE:
857 if (parent->type == NODE_ROOT) {
858 _bt_list_splice_tail(&node->tmp_head, &parent->u.root.callsite);
859 } else {
860 return -EPERM;
861 }
862 break;
02b234c4
MD
863
864 case NODE_CTF_EXPRESSION:
865 return reparent_ctf_expression(node, parent);
6dc474b8
MD
866 case NODE_UNARY_EXPRESSION:
867 if (parent->type == NODE_TYPE_DECLARATOR)
868 parent->u.type_declarator.bitfield_len = node;
869 else
870 return -EPERM;
871 break;
02b234c4
MD
872
873 case NODE_TYPEDEF:
874 return reparent_typedef(node, parent);
875 case NODE_TYPEALIAS_TARGET:
876 if (parent->type == NODE_TYPEALIAS)
877 parent->u.typealias.target = node;
878 else
879 return -EINVAL;
880 case NODE_TYPEALIAS_ALIAS:
881 if (parent->type == NODE_TYPEALIAS)
882 parent->u.typealias.alias = node;
883 else
884 return -EINVAL;
885 case NODE_TYPEALIAS:
886 return reparent_typealias(node, parent);
887
02b234c4 888 case NODE_POINTER:
48a01768 889 if (parent->type == NODE_TYPE_DECLARATOR) {
3122e6f0 890 _bt_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers);
48a01768 891 } else
02b234c4
MD
892 return -EPERM;
893 break;
894 case NODE_TYPE_DECLARATOR:
895 return reparent_type_declarator(node, parent);
896
3e11b713
MD
897 case NODE_TYPE_SPECIFIER_LIST:
898 return reparent_type_specifier_list(node, parent);
899
6dc474b8 900 case NODE_TYPE_SPECIFIER:
3e11b713
MD
901 return reparent_type_specifier(node, parent);
902
02b234c4 903 case NODE_FLOATING_POINT:
02b234c4 904 case NODE_INTEGER:
02b234c4 905 case NODE_STRING:
6dc474b8
MD
906 case NODE_ENUM:
907 case NODE_VARIANT:
908 case NODE_STRUCT:
3e11b713 909 return -EINVAL; /* Dealt with internally within grammar */
6dc474b8 910
02b234c4 911 case NODE_ENUMERATOR:
48a01768 912 if (parent->type == NODE_ENUM) {
3122e6f0 913 _bt_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
3e11b713 914 } else {
02b234c4 915 return -EPERM;
3e11b713 916 }
02b234c4 917 break;
02b234c4
MD
918 case NODE_STRUCT_OR_VARIANT_DECLARATION:
919 switch (parent->type) {
920 case NODE_STRUCT:
3122e6f0 921 _bt_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
02b234c4
MD
922 break;
923 case NODE_VARIANT:
3122e6f0 924 _bt_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
02b234c4
MD
925 break;
926 default:
927 return -EINVAL;
928 }
929 break;
02b234c4
MD
930
931 case NODE_UNKNOWN:
932 default:
c55adfb9 933 printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
02b234c4
MD
934 return -EINVAL;
935 }
936 return 0;
937}
938
5d6c80a5 939BT_HIDDEN
34d3acc4 940void yyerror(struct ctf_scanner *scanner, const char *str)
8b9d5b5e 941{
c55adfb9
EB
942 printfl_error(yyget_lineno(scanner->scanner),
943 "token \"%s\": %s\n",
740aad26 944 yyget_text(scanner->scanner), str);
8b9d5b5e
MD
945}
946
5d6c80a5 947BT_HIDDEN
8b9d5b5e
MD
948int yywrap(void)
949{
950 return 1;
951}
952
6dc474b8
MD
953#define reparent_error(scanner, str) \
954do { \
c55adfb9 955 yyerror(scanner, YY_("reparent_error: " str)); \
6dc474b8
MD
956 YYERROR; \
957} while (0)
958
34d3acc4 959static struct ctf_ast *ctf_ast_alloc(void)
8b9d5b5e 960{
34d3acc4
MD
961 struct ctf_ast *ast;
962
963 ast = malloc(sizeof(*ast));
964 if (!ast)
965 return NULL;
966 memset(ast, 0, sizeof(*ast));
3122e6f0 967 BT_INIT_LIST_HEAD(&ast->allocated_nodes);
02b234c4 968 ast->root.type = NODE_ROOT;
3122e6f0
JD
969 BT_INIT_LIST_HEAD(&ast->root.tmp_head);
970 BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
971 BT_INIT_LIST_HEAD(&ast->root.u.root.trace);
972 BT_INIT_LIST_HEAD(&ast->root.u.root.env);
973 BT_INIT_LIST_HEAD(&ast->root.u.root.stream);
974 BT_INIT_LIST_HEAD(&ast->root.u.root.event);
975 BT_INIT_LIST_HEAD(&ast->root.u.root.clock);
f133896d 976 BT_INIT_LIST_HEAD(&ast->root.u.root.callsite);
34d3acc4
MD
977 return ast;
978}
979
980static void ctf_ast_free(struct ctf_ast *ast)
981{
02b234c4
MD
982 struct ctf_node *node, *tmp;
983
3122e6f0 984 bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
02b234c4 985 free(node);
15d4fe3c 986 free(ast);
34d3acc4
MD
987}
988
989int ctf_scanner_append_ast(struct ctf_scanner *scanner)
990{
991 return yyparse(scanner);
992}
993
994struct ctf_scanner *ctf_scanner_alloc(FILE *input)
995{
996 struct ctf_scanner *scanner;
997 int ret;
998
a3983482
MD
999 yydebug = babeltrace_debug;
1000
34d3acc4
MD
1001 scanner = malloc(sizeof(*scanner));
1002 if (!scanner)
1003 return NULL;
1004 memset(scanner, 0, sizeof(*scanner));
1005
1006 ret = yylex_init_extra(scanner, &scanner->scanner);
1007 if (ret) {
c55adfb9 1008 printf_fatal("yylex_init error");
34d3acc4
MD
1009 goto cleanup_scanner;
1010 }
65102a8c
MD
1011 /* Start processing new stream */
1012 yyrestart(input, scanner->scanner);
34d3acc4
MD
1013
1014 scanner->ast = ctf_ast_alloc();
1015 if (!scanner->ast)
1016 goto cleanup_lexer;
8aa95b17
MD
1017 scanner->objstack = objstack_create();
1018 if (!scanner->objstack)
1019 goto cleanup_ast;
34d3acc4 1020 init_scope(&scanner->root_scope, NULL);
19d96da7 1021 scanner->cs = &scanner->root_scope;
34d3acc4 1022
65102a8c
MD
1023 if (yydebug)
1024 fprintf(stdout, "Scanner input is a%s.\n",
1025 isatty(fileno(input)) ? "n interactive tty" :
1026 " noninteractive file");
1027
34d3acc4
MD
1028 return scanner;
1029
8aa95b17
MD
1030cleanup_ast:
1031 ctf_ast_free(scanner->ast);
34d3acc4
MD
1032cleanup_lexer:
1033 ret = yylex_destroy(scanner->scanner);
1034 if (!ret)
c55adfb9 1035 printf_fatal("yylex_destroy error");
34d3acc4
MD
1036cleanup_scanner:
1037 free(scanner);
1038 return NULL;
1039}
1040
1041void ctf_scanner_free(struct ctf_scanner *scanner)
1042{
1043 int ret;
1044
1045 finalize_scope(&scanner->root_scope);
8aa95b17 1046 objstack_destroy(scanner->objstack);
34d3acc4
MD
1047 ctf_ast_free(scanner->ast);
1048 ret = yylex_destroy(scanner->scanner);
1049 if (ret)
c55adfb9 1050 printf_error("yylex_destroy error");
34d3acc4
MD
1051 free(scanner);
1052}
8b9d5b5e
MD
1053
1054%}
1055
34d3acc4
MD
1056%define api.pure
1057 /* %locations */
8c834e5a 1058%error-verbose
34d3acc4
MD
1059%parse-param {struct ctf_scanner *scanner}
1060%lex-param {struct ctf_scanner *scanner}
0fbb34a5
MD
1061/*
1062 * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
1063 * vs struct { int :value; } (unnamed bit-field). The default is to
1064 * shift, so whenever we encounter an enumeration, we are doing the
1065 * proper thing (shift). It is illegal to declare an enumeration
1066 * "bit-field", so it is OK if this situation ends up in a parsing
1067 * error.
1068 */
1069%expect 2
8b9d5b5e 1070%start file
80b07bd7 1071%token INTEGER_LITERAL STRING_LITERAL CHARACTER_LITERAL LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM ENV EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE CALLSITE CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY TOK_ALIGN
8aa95b17 1072%token <s> IDENTIFIER ID_TYPE
8b9d5b5e
MD
1073%token ERROR
1074%union
1075{
1076 long long ll;
80b07bd7 1077 unsigned long long ull;
8b9d5b5e 1078 char c;
8aa95b17 1079 char *s;
8b9d5b5e
MD
1080 struct ctf_node *n;
1081}
1082
8aa95b17 1083%type <s> STRING_LITERAL CHARACTER_LITERAL
d876a5ba 1084
8aa95b17 1085%type <s> keywords
6dc474b8 1086
80b07bd7 1087%type <ull> INTEGER_LITERAL
6dc474b8
MD
1088%type <n> postfix_expression unary_expression unary_expression_or_range
1089
1090%type <n> declaration
02b234c4 1091%type <n> event_declaration
6dc474b8 1092%type <n> stream_declaration
e2c76a4d 1093%type <n> env_declaration
6dc474b8 1094%type <n> trace_declaration
73d15916 1095%type <n> clock_declaration
f133896d 1096%type <n> callsite_declaration
0fbb34a5 1097%type <n> integer_declaration_specifiers
6dc474b8 1098%type <n> declaration_specifiers
1ee8e81d 1099%type <n> alias_declaration_specifiers
6dc474b8
MD
1100
1101%type <n> type_declarator_list
0fbb34a5 1102%type <n> integer_type_specifier
6dc474b8
MD
1103%type <n> type_specifier
1104%type <n> struct_type_specifier
1105%type <n> variant_type_specifier
6dc474b8
MD
1106%type <n> enum_type_specifier
1107%type <n> struct_or_variant_declaration_list
1108%type <n> struct_or_variant_declaration
6dc474b8
MD
1109%type <n> struct_or_variant_declarator_list
1110%type <n> struct_or_variant_declarator
1111%type <n> enumerator_list
1112%type <n> enumerator
1113%type <n> abstract_declarator_list
1114%type <n> abstract_declarator
1115%type <n> direct_abstract_declarator
e0c14875
MD
1116%type <n> alias_abstract_declarator_list
1117%type <n> alias_abstract_declarator
1118%type <n> direct_alias_abstract_declarator
6dc474b8
MD
1119%type <n> declarator
1120%type <n> direct_declarator
1121%type <n> type_declarator
1122%type <n> direct_type_declarator
6dc474b8 1123%type <n> pointer
02b234c4
MD
1124%type <n> ctf_assignment_expression_list
1125%type <n> ctf_assignment_expression
1126
8b9d5b5e
MD
1127%%
1128
1129file:
1130 declaration
6dc474b8 1131 {
48a01768 1132 if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root))
6dc474b8
MD
1133 reparent_error(scanner, "error reparenting to root");
1134 }
8b9d5b5e 1135 | file declaration
6dc474b8 1136 {
48a01768 1137 if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root))
6dc474b8
MD
1138 reparent_error(scanner, "error reparenting to root");
1139 }
8b9d5b5e
MD
1140 ;
1141
1142keywords:
1143 VOID
8aa95b17 1144 { $$ = yylval.s; }
8b9d5b5e 1145 | CHAR
8aa95b17 1146 { $$ = yylval.s; }
8b9d5b5e 1147 | SHORT
8aa95b17 1148 { $$ = yylval.s; }
8b9d5b5e 1149 | INT
8aa95b17 1150 { $$ = yylval.s; }
8b9d5b5e 1151 | LONG
8aa95b17 1152 { $$ = yylval.s; }
8b9d5b5e 1153 | FLOAT
8aa95b17 1154 { $$ = yylval.s; }
8b9d5b5e 1155 | DOUBLE
8aa95b17 1156 { $$ = yylval.s; }
8b9d5b5e 1157 | SIGNED
8aa95b17 1158 { $$ = yylval.s; }
8b9d5b5e 1159 | UNSIGNED
8aa95b17 1160 { $$ = yylval.s; }
8b9d5b5e 1161 | _BOOL
8aa95b17 1162 { $$ = yylval.s; }
8b9d5b5e 1163 | _COMPLEX
8aa95b17 1164 { $$ = yylval.s; }
3888a159 1165 | _IMAGINARY
8aa95b17 1166 { $$ = yylval.s; }
8b9d5b5e 1167 | FLOATING_POINT
8aa95b17 1168 { $$ = yylval.s; }
8b9d5b5e 1169 | INTEGER
8aa95b17 1170 { $$ = yylval.s; }
8b9d5b5e 1171 | STRING
8aa95b17 1172 { $$ = yylval.s; }
8b9d5b5e 1173 | ENUM
8aa95b17 1174 { $$ = yylval.s; }
8b9d5b5e 1175 | VARIANT
8aa95b17 1176 { $$ = yylval.s; }
8b9d5b5e 1177 | STRUCT
8aa95b17 1178 { $$ = yylval.s; }
8b9d5b5e 1179 | CONST
8aa95b17 1180 { $$ = yylval.s; }
8b9d5b5e 1181 | TYPEDEF
8aa95b17 1182 { $$ = yylval.s; }
8b9d5b5e 1183 | EVENT
8aa95b17 1184 { $$ = yylval.s; }
8b9d5b5e 1185 | STREAM
8aa95b17 1186 { $$ = yylval.s; }
d2ea163b 1187 | ENV
8aa95b17 1188 { $$ = yylval.s; }
8b9d5b5e 1189 | TRACE
8aa95b17 1190 { $$ = yylval.s; }
73d15916 1191 | CLOCK
8aa95b17 1192 { $$ = yylval.s; }
f133896d 1193 | CALLSITE
8aa95b17 1194 { $$ = yylval.s; }
b7e35bad 1195 | TOK_ALIGN
8aa95b17 1196 { $$ = yylval.s; }
8b9d5b5e
MD
1197 ;
1198
8b9d5b5e
MD
1199
1200/* 2: Phrase structure grammar */
1201
1202postfix_expression:
1203 IDENTIFIER
6dc474b8
MD
1204 {
1205 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1206 $$->u.unary_expression.type = UNARY_STRING;
8aa95b17 1207 $$->u.unary_expression.u.string = yylval.s;
6dc474b8 1208 }
8b9d5b5e 1209 | ID_TYPE
6dc474b8
MD
1210 {
1211 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1212 $$->u.unary_expression.type = UNARY_STRING;
8aa95b17 1213 $$->u.unary_expression.u.string = yylval.s;
6dc474b8 1214 }
8b9d5b5e 1215 | keywords
6dc474b8
MD
1216 {
1217 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1218 $$->u.unary_expression.type = UNARY_STRING;
8aa95b17 1219 $$->u.unary_expression.u.string = yylval.s;
6dc474b8 1220 }
80b07bd7 1221 | INTEGER_LITERAL
6dc474b8
MD
1222 {
1223 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1224 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
80b07bd7 1225 $$->u.unary_expression.u.unsigned_constant = $1;
6dc474b8 1226 }
d876a5ba 1227 | STRING_LITERAL
6dc474b8
MD
1228 {
1229 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1230 $$->u.unary_expression.type = UNARY_STRING;
8aa95b17 1231 $$->u.unary_expression.u.string = $1;
6dc474b8 1232 }
d876a5ba 1233 | CHARACTER_LITERAL
6dc474b8
MD
1234 {
1235 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1236 $$->u.unary_expression.type = UNARY_STRING;
8aa95b17 1237 $$->u.unary_expression.u.string = $1;
6dc474b8 1238 }
8b9d5b5e 1239 | LPAREN unary_expression RPAREN
6dc474b8 1240 {
104147cd 1241 $$ = $2;
6dc474b8 1242 }
8b9d5b5e 1243 | postfix_expression LSBRAC unary_expression RSBRAC
6dc474b8
MD
1244 {
1245 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1246 $$->u.unary_expression.type = UNARY_SBRAC;
1247 $$->u.unary_expression.u.sbrac_exp = $3;
3122e6f0
JD
1248 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1249 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
6dc474b8 1250 }
8b9d5b5e 1251 | postfix_expression DOT IDENTIFIER
6dc474b8
MD
1252 {
1253 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1254 $$->u.unary_expression.type = UNARY_STRING;
8aa95b17 1255 $$->u.unary_expression.u.string = yylval.s;
6dc474b8 1256 $$->u.unary_expression.link = UNARY_DOTLINK;
3122e6f0
JD
1257 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1258 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
6dc474b8 1259 }
8b9d5b5e 1260 | postfix_expression DOT ID_TYPE
6dc474b8
MD
1261 {
1262 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1263 $$->u.unary_expression.type = UNARY_STRING;
8aa95b17 1264 $$->u.unary_expression.u.string = yylval.s;
6dc474b8 1265 $$->u.unary_expression.link = UNARY_DOTLINK;
3122e6f0
JD
1266 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1267 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
6dc474b8 1268 }
8b9d5b5e 1269 | postfix_expression RARROW IDENTIFIER
6dc474b8
MD
1270 {
1271 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1272 $$->u.unary_expression.type = UNARY_STRING;
8aa95b17 1273 $$->u.unary_expression.u.string = yylval.s;
6dc474b8 1274 $$->u.unary_expression.link = UNARY_ARROWLINK;
3122e6f0
JD
1275 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1276 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
6dc474b8 1277 }
8b9d5b5e 1278 | postfix_expression RARROW ID_TYPE
6dc474b8
MD
1279 {
1280 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1281 $$->u.unary_expression.type = UNARY_STRING;
8aa95b17 1282 $$->u.unary_expression.u.string = yylval.s;
6dc474b8 1283 $$->u.unary_expression.link = UNARY_ARROWLINK;
3122e6f0
JD
1284 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1285 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
6dc474b8 1286 }
8b9d5b5e
MD
1287 ;
1288
1289unary_expression:
1290 postfix_expression
6dc474b8 1291 { $$ = $1; }
8b9d5b5e 1292 | PLUS postfix_expression
f9c67088
EB
1293 {
1294 $$ = $2;
1295 if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
1296 && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
1297 reparent_error(scanner, "expecting numeric constant");
1298 }
1299 }
8b9d5b5e 1300 | MINUS postfix_expression
6dc474b8
MD
1301 {
1302 $$ = $2;
6dc474b8
MD
1303 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1304 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1305 $$->u.unary_expression.u.signed_constant =
1306 -($$->u.unary_expression.u.unsigned_constant);
ca3de390 1307 } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
6dc474b8
MD
1308 $$->u.unary_expression.u.signed_constant =
1309 -($$->u.unary_expression.u.signed_constant);
ca3de390
EB
1310 } else {
1311 reparent_error(scanner, "expecting numeric constant");
6dc474b8
MD
1312 }
1313 }
8b9d5b5e
MD
1314 ;
1315
1316unary_expression_or_range:
1317 unary_expression DOTDOTDOT unary_expression
6dc474b8
MD
1318 {
1319 $$ = $1;
3122e6f0 1320 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
48a01768 1321 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
6dc474b8 1322 }
8b9d5b5e 1323 | unary_expression
6dc474b8 1324 { $$ = $1; }
8b9d5b5e
MD
1325 ;
1326
1327/* 2.2: Declarations */
1328
1329declaration:
1330 declaration_specifiers SEMICOLON
6dc474b8 1331 { $$ = $1; }
8b9d5b5e 1332 | event_declaration
6dc474b8 1333 { $$ = $1; }
8b9d5b5e 1334 | stream_declaration
6dc474b8 1335 { $$ = $1; }
e2c76a4d
MD
1336 | env_declaration
1337 { $$ = $1; }
8b9d5b5e 1338 | trace_declaration
6dc474b8 1339 { $$ = $1; }
73d15916
MD
1340 | clock_declaration
1341 { $$ = $1; }
f133896d
MD
1342 | callsite_declaration
1343 { $$ = $1; }
8b9d5b5e 1344 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
6dc474b8 1345 {
3e11b713
MD
1346 struct ctf_node *list;
1347
6dc474b8 1348 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713
MD
1349 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1350 $$->u._typedef.type_specifier_list = list;
3122e6f0
JD
1351 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1352 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1353 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 1354 }
8b9d5b5e 1355 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
6dc474b8 1356 {
3e11b713
MD
1357 struct ctf_node *list;
1358
6dc474b8 1359 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713
MD
1360 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1361 $$->u._typedef.type_specifier_list = list;
3122e6f0
JD
1362 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1363 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 1364 }
8b9d5b5e 1365 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
6dc474b8 1366 {
3e11b713
MD
1367 struct ctf_node *list;
1368
6dc474b8 1369 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713
MD
1370 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1371 $$->u._typedef.type_specifier_list = list;
3122e6f0
JD
1372 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1373 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 1374 }
a030d084 1375 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
6dc474b8 1376 {
3e11b713
MD
1377 struct ctf_node *list;
1378
6dc474b8
MD
1379 $$ = make_node(scanner, NODE_TYPEALIAS);
1380 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1381 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
3e11b713
MD
1382
1383 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1384 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
3122e6f0
JD
1385 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1386 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
3e11b713
MD
1387
1388 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1389 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
3122e6f0
JD
1390 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1391 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
6dc474b8 1392 }
8b9d5b5e
MD
1393 ;
1394
1395event_declaration:
1396 event_declaration_begin event_declaration_end
48a01768
MD
1397 {
1398 $$ = make_node(scanner, NODE_EVENT);
48a01768 1399 }
8b9d5b5e 1400 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
02b234c4
MD
1401 {
1402 $$ = make_node(scanner, NODE_EVENT);
48a01768 1403 if (set_parent_node($2, $$))
6dc474b8 1404 reparent_error(scanner, "event_declaration");
02b234c4 1405 }
8b9d5b5e
MD
1406 ;
1407
1408event_declaration_begin:
1409 EVENT LBRAC
fce8006d 1410 { push_scope(scanner); }
8b9d5b5e
MD
1411 ;
1412
1413event_declaration_end:
1414 RBRAC SEMICOLON
fce8006d 1415 { pop_scope(scanner); }
8b9d5b5e
MD
1416 ;
1417
1418
1419stream_declaration:
1420 stream_declaration_begin stream_declaration_end
48a01768
MD
1421 {
1422 $$ = make_node(scanner, NODE_STREAM);
48a01768 1423 }
8b9d5b5e 1424 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
6dc474b8
MD
1425 {
1426 $$ = make_node(scanner, NODE_STREAM);
48a01768 1427 if (set_parent_node($2, $$))
6dc474b8
MD
1428 reparent_error(scanner, "stream_declaration");
1429 }
8b9d5b5e
MD
1430 ;
1431
1432stream_declaration_begin:
1433 STREAM LBRAC
fce8006d 1434 { push_scope(scanner); }
8b9d5b5e
MD
1435 ;
1436
1437stream_declaration_end:
1438 RBRAC SEMICOLON
fce8006d 1439 { pop_scope(scanner); }
8b9d5b5e
MD
1440 ;
1441
e2c76a4d
MD
1442env_declaration:
1443 env_declaration_begin env_declaration_end
1444 {
1445 $$ = make_node(scanner, NODE_ENV);
1446 }
1447 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1448 {
1449 $$ = make_node(scanner, NODE_ENV);
1450 if (set_parent_node($2, $$))
1451 reparent_error(scanner, "env declaration");
1452 }
1453 ;
1454
1455env_declaration_begin:
1456 ENV LBRAC
1457 { push_scope(scanner); }
1458 ;
1459
1460env_declaration_end:
1461 RBRAC SEMICOLON
1462 { pop_scope(scanner); }
1463 ;
1464
8b9d5b5e
MD
1465trace_declaration:
1466 trace_declaration_begin trace_declaration_end
48a01768
MD
1467 {
1468 $$ = make_node(scanner, NODE_TRACE);
48a01768 1469 }
8b9d5b5e 1470 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
6dc474b8
MD
1471 {
1472 $$ = make_node(scanner, NODE_TRACE);
48a01768 1473 if (set_parent_node($2, $$))
6dc474b8
MD
1474 reparent_error(scanner, "trace_declaration");
1475 }
8b9d5b5e
MD
1476 ;
1477
1478trace_declaration_begin:
1479 TRACE LBRAC
fce8006d 1480 { push_scope(scanner); }
8b9d5b5e
MD
1481 ;
1482
1483trace_declaration_end:
1484 RBRAC SEMICOLON
fce8006d 1485 { pop_scope(scanner); }
8b9d5b5e
MD
1486 ;
1487
73d15916
MD
1488clock_declaration:
1489 CLOCK clock_declaration_begin clock_declaration_end
1490 {
1491 $$ = make_node(scanner, NODE_CLOCK);
1492 }
1493 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1494 {
1495 $$ = make_node(scanner, NODE_CLOCK);
1496 if (set_parent_node($3, $$))
1497 reparent_error(scanner, "trace_declaration");
1498 }
1499 ;
1500
1501clock_declaration_begin:
1502 LBRAC
1503 { push_scope(scanner); }
1504 ;
1505
1506clock_declaration_end:
1507 RBRAC SEMICOLON
1508 { pop_scope(scanner); }
1509 ;
1510
f133896d
MD
1511callsite_declaration:
1512 CALLSITE callsite_declaration_begin callsite_declaration_end
1513 {
1514 $$ = make_node(scanner, NODE_CALLSITE);
1515 }
1516 | CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1517 {
1518 $$ = make_node(scanner, NODE_CALLSITE);
1519 if (set_parent_node($3, $$))
1520 reparent_error(scanner, "trace_declaration");
1521 }
1522 ;
1523
1524callsite_declaration_begin:
1525 LBRAC
1526 { push_scope(scanner); }
1527 ;
1528
1529callsite_declaration_end:
1530 RBRAC SEMICOLON
1531 { pop_scope(scanner); }
1532 ;
1533
0fbb34a5
MD
1534integer_declaration_specifiers:
1535 CONST
1536 {
1537 struct ctf_node *node;
1538
1539 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1540 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1541 node->u.type_specifier.type = TYPESPEC_CONST;
3122e6f0 1542 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
0fbb34a5
MD
1543 }
1544 | integer_type_specifier
1545 {
1546 struct ctf_node *node;
1547
1548 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1549 node = $1;
3122e6f0 1550 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
0fbb34a5
MD
1551 }
1552 | integer_declaration_specifiers CONST
1553 {
1554 struct ctf_node *node;
1555
1556 $$ = $1;
1557 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1558 node->u.type_specifier.type = TYPESPEC_CONST;
3122e6f0 1559 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
0fbb34a5
MD
1560 }
1561 | integer_declaration_specifiers integer_type_specifier
1562 {
1563 $$ = $1;
3122e6f0 1564 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
0fbb34a5
MD
1565 }
1566 ;
1567
8b9d5b5e
MD
1568declaration_specifiers:
1569 CONST
6dc474b8 1570 {
3e11b713
MD
1571 struct ctf_node *node;
1572
1573 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1574 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1575 node->u.type_specifier.type = TYPESPEC_CONST;
3122e6f0 1576 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
6dc474b8 1577 }
8b9d5b5e 1578 | type_specifier
3e11b713
MD
1579 {
1580 struct ctf_node *node;
1581
1582 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1583 node = $1;
3122e6f0 1584 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
3e11b713 1585 }
8b9d5b5e 1586 | declaration_specifiers CONST
6dc474b8
MD
1587 {
1588 struct ctf_node *node;
1589
48a01768 1590 $$ = $1;
6dc474b8
MD
1591 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1592 node->u.type_specifier.type = TYPESPEC_CONST;
3122e6f0 1593 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
6dc474b8 1594 }
8b9d5b5e 1595 | declaration_specifiers type_specifier
6dc474b8
MD
1596 {
1597 $$ = $1;
3122e6f0 1598 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
6dc474b8 1599 }
8b9d5b5e
MD
1600 ;
1601
1602type_declarator_list:
1603 type_declarator
0009a725 1604 { $$ = $1; }
8b9d5b5e 1605 | type_declarator_list COMMA type_declarator
6dc474b8
MD
1606 {
1607 $$ = $1;
3122e6f0 1608 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
6dc474b8 1609 }
8b9d5b5e
MD
1610 ;
1611
0fbb34a5
MD
1612integer_type_specifier:
1613 CHAR
1614 {
1615 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1616 $$->u.type_specifier.type = TYPESPEC_CHAR;
1617 }
1618 | SHORT
1619 {
1620 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1621 $$->u.type_specifier.type = TYPESPEC_SHORT;
1622 }
1623 | INT
1624 {
1625 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1626 $$->u.type_specifier.type = TYPESPEC_INT;
1627 }
1628 | LONG
1629 {
1630 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1631 $$->u.type_specifier.type = TYPESPEC_LONG;
1632 }
1633 | SIGNED
1634 {
1635 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1636 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1637 }
1638 | UNSIGNED
1639 {
1640 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1641 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1642 }
1643 | _BOOL
1644 {
1645 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1646 $$->u.type_specifier.type = TYPESPEC_BOOL;
1647 }
1648 | ID_TYPE
1649 {
1650 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1651 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
8aa95b17 1652 $$->u.type_specifier.id_type = yylval.s;
0fbb34a5
MD
1653 }
1654 | INTEGER LBRAC RBRAC
1655 {
1656 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1657 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1658 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1659 }
1660 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1661 {
1662 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1663 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1664 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1665 if (set_parent_node($3, $$->u.type_specifier.node))
1666 reparent_error(scanner, "integer reparent error");
1667 }
1668 ;
1669
8b9d5b5e
MD
1670type_specifier:
1671 VOID
6dc474b8
MD
1672 {
1673 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1674 $$->u.type_specifier.type = TYPESPEC_VOID;
1675 }
8b9d5b5e 1676 | CHAR
6dc474b8
MD
1677 {
1678 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1679 $$->u.type_specifier.type = TYPESPEC_CHAR;
1680 }
8b9d5b5e 1681 | SHORT
6dc474b8
MD
1682 {
1683 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1684 $$->u.type_specifier.type = TYPESPEC_SHORT;
1685 }
8b9d5b5e 1686 | INT
6dc474b8
MD
1687 {
1688 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1689 $$->u.type_specifier.type = TYPESPEC_INT;
1690 }
8b9d5b5e 1691 | LONG
6dc474b8
MD
1692 {
1693 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1694 $$->u.type_specifier.type = TYPESPEC_LONG;
1695 }
8b9d5b5e 1696 | FLOAT
6dc474b8
MD
1697 {
1698 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1699 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1700 }
8b9d5b5e 1701 | DOUBLE
6dc474b8
MD
1702 {
1703 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1704 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1705 }
8b9d5b5e 1706 | SIGNED
6dc474b8
MD
1707 {
1708 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1709 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1710 }
8b9d5b5e 1711 | UNSIGNED
6dc474b8
MD
1712 {
1713 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1714 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1715 }
8b9d5b5e 1716 | _BOOL
6dc474b8
MD
1717 {
1718 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1719 $$->u.type_specifier.type = TYPESPEC_BOOL;
1720 }
8b9d5b5e 1721 | _COMPLEX
6dc474b8
MD
1722 {
1723 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1724 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1725 }
3888a159
MD
1726 | _IMAGINARY
1727 {
1728 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1729 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1730 }
8b9d5b5e 1731 | ID_TYPE
6dc474b8
MD
1732 {
1733 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1734 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
8aa95b17 1735 $$->u.type_specifier.id_type = yylval.s;
6dc474b8 1736 }
8b9d5b5e 1737 | FLOATING_POINT LBRAC RBRAC
6dc474b8 1738 {
3e11b713
MD
1739 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1740 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1741 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
6dc474b8 1742 }
8b9d5b5e 1743 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
6dc474b8 1744 {
3e11b713
MD
1745 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1746 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1747 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1748 if (set_parent_node($3, $$->u.type_specifier.node))
6dc474b8
MD
1749 reparent_error(scanner, "floating point reparent error");
1750 }
8b9d5b5e 1751 | INTEGER LBRAC RBRAC
6dc474b8 1752 {
3e11b713
MD
1753 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1754 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1755 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
6dc474b8 1756 }
8b9d5b5e 1757 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
6dc474b8 1758 {
3e11b713
MD
1759 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1760 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1761 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1762 if (set_parent_node($3, $$->u.type_specifier.node))
6dc474b8
MD
1763 reparent_error(scanner, "integer reparent error");
1764 }
b40c8090
MD
1765 | STRING
1766 {
1767 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1768 $$->u.type_specifier.type = TYPESPEC_STRING;
1769 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1770 }
8b9d5b5e 1771 | STRING LBRAC RBRAC
6dc474b8 1772 {
3e11b713
MD
1773 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1774 $$->u.type_specifier.type = TYPESPEC_STRING;
1775 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
6dc474b8 1776 }
8b9d5b5e 1777 | STRING LBRAC ctf_assignment_expression_list RBRAC
6dc474b8 1778 {
3e11b713
MD
1779 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1780 $$->u.type_specifier.type = TYPESPEC_STRING;
1781 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1782 if (set_parent_node($3, $$->u.type_specifier.node))
6dc474b8
MD
1783 reparent_error(scanner, "string reparent error");
1784 }
8b9d5b5e 1785 | ENUM enum_type_specifier
3e11b713
MD
1786 {
1787 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1788 $$->u.type_specifier.type = TYPESPEC_ENUM;
1789 $$->u.type_specifier.node = $2;
1790 }
8b9d5b5e 1791 | VARIANT variant_type_specifier
3e11b713
MD
1792 {
1793 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1794 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1795 $$->u.type_specifier.node = $2;
3e11b713 1796 }
8b9d5b5e 1797 | STRUCT struct_type_specifier
3e11b713
MD
1798 {
1799 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1800 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1801 $$->u.type_specifier.node = $2;
3e11b713 1802 }
8b9d5b5e
MD
1803 ;
1804
1805struct_type_specifier:
1806 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
6dc474b8
MD
1807 {
1808 $$ = make_node(scanner, NODE_STRUCT);
1ee8e81d 1809 $$->u._struct.has_body = 1;
5039b4cc 1810 if ($2 && set_parent_node($2, $$))
6dc474b8
MD
1811 reparent_error(scanner, "struct reparent error");
1812 }
8b9d5b5e 1813 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
6dc474b8
MD
1814 {
1815 $$ = make_node(scanner, NODE_STRUCT);
1ee8e81d 1816 $$->u._struct.has_body = 1;
8aa95b17 1817 $$->u._struct.name = $1;
5039b4cc 1818 if ($3 && set_parent_node($3, $$))
6dc474b8
MD
1819 reparent_error(scanner, "struct reparent error");
1820 }
8b9d5b5e 1821 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
6dc474b8
MD
1822 {
1823 $$ = make_node(scanner, NODE_STRUCT);
1ee8e81d 1824 $$->u._struct.has_body = 1;
8aa95b17 1825 $$->u._struct.name = $1;
5039b4cc 1826 if ($3 && set_parent_node($3, $$))
6dc474b8
MD
1827 reparent_error(scanner, "struct reparent error");
1828 }
8b9d5b5e 1829 | IDENTIFIER
6dc474b8
MD
1830 {
1831 $$ = make_node(scanner, NODE_STRUCT);
1ee8e81d 1832 $$->u._struct.has_body = 0;
8aa95b17 1833 $$->u._struct.name = $1;
6dc474b8 1834 }
8b9d5b5e 1835 | ID_TYPE
6dc474b8
MD
1836 {
1837 $$ = make_node(scanner, NODE_STRUCT);
1ee8e81d 1838 $$->u._struct.has_body = 0;
8aa95b17 1839 $$->u._struct.name = $1;
6dc474b8 1840 }
b7e35bad
MD
1841 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1842 {
1843 $$ = make_node(scanner, NODE_STRUCT);
1844 $$->u._struct.has_body = 1;
3122e6f0 1845 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
b7e35bad
MD
1846 if ($2 && set_parent_node($2, $$))
1847 reparent_error(scanner, "struct reparent error");
1848 }
1849 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1850 {
1851 $$ = make_node(scanner, NODE_STRUCT);
1852 $$->u._struct.has_body = 1;
8aa95b17 1853 $$->u._struct.name = $1;
3122e6f0 1854 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
b7e35bad
MD
1855 if ($3 && set_parent_node($3, $$))
1856 reparent_error(scanner, "struct reparent error");
1857 }
1858 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1859 {
1860 $$ = make_node(scanner, NODE_STRUCT);
1861 $$->u._struct.has_body = 1;
8aa95b17 1862 $$->u._struct.name = $1;
3122e6f0 1863 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
b7e35bad
MD
1864 if ($3 && set_parent_node($3, $$))
1865 reparent_error(scanner, "struct reparent error");
1866 }
8b9d5b5e
MD
1867 ;
1868
1869struct_declaration_begin:
1870 LBRAC
fce8006d 1871 { push_scope(scanner); }
8b9d5b5e
MD
1872 ;
1873
1874struct_declaration_end:
1875 RBRAC
fce8006d 1876 { pop_scope(scanner); }
8b9d5b5e
MD
1877 ;
1878
1879variant_type_specifier:
1880 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1881 {
1882 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1883 $$->u.variant.has_body = 1;
5039b4cc 1884 if ($2 && set_parent_node($2, $$))
6dc474b8
MD
1885 reparent_error(scanner, "variant reparent error");
1886 }
8b9d5b5e 1887 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1888 {
1889 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1890 $$->u.variant.has_body = 1;
8aa95b17 1891 $$->u.variant.choice = $2;
5039b4cc 1892 if ($5 && set_parent_node($5, $$))
6dc474b8
MD
1893 reparent_error(scanner, "variant reparent error");
1894 }
8b9d5b5e 1895 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1896 {
1897 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1898 $$->u.variant.has_body = 1;
8aa95b17 1899 $$->u.variant.choice = $2;
5039b4cc 1900 if ($5 && set_parent_node($5, $$))
6dc474b8
MD
1901 reparent_error(scanner, "variant reparent error");
1902 }
8b9d5b5e 1903 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1904 {
1905 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1906 $$->u.variant.has_body = 1;
8aa95b17 1907 $$->u.variant.name = $1;
5039b4cc 1908 if ($3 && set_parent_node($3, $$))
6dc474b8
MD
1909 reparent_error(scanner, "variant reparent error");
1910 }
8b9d5b5e 1911 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1912 {
1913 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1914 $$->u.variant.has_body = 1;
8aa95b17
MD
1915 $$->u.variant.name = $1;
1916 $$->u.variant.choice = $3;
5039b4cc 1917 if ($6 && set_parent_node($6, $$))
6dc474b8
MD
1918 reparent_error(scanner, "variant reparent error");
1919 }
8b9d5b5e 1920 | IDENTIFIER LT IDENTIFIER GT
6dc474b8
MD
1921 {
1922 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1923 $$->u.variant.has_body = 0;
8aa95b17
MD
1924 $$->u.variant.name = $1;
1925 $$->u.variant.choice = $3;
6dc474b8 1926 }
8b9d5b5e 1927 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1928 {
1929 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1930 $$->u.variant.has_body = 1;
8aa95b17
MD
1931 $$->u.variant.name = $1;
1932 $$->u.variant.choice = $3;
5039b4cc 1933 if ($6 && set_parent_node($6, $$))
6dc474b8
MD
1934 reparent_error(scanner, "variant reparent error");
1935 }
8b9d5b5e 1936 | IDENTIFIER LT ID_TYPE GT
6dc474b8
MD
1937 {
1938 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1939 $$->u.variant.has_body = 0;
8aa95b17
MD
1940 $$->u.variant.name = $1;
1941 $$->u.variant.choice = $3;
6dc474b8 1942 }
8b9d5b5e 1943 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1944 {
1945 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1946 $$->u.variant.has_body = 1;
8aa95b17 1947 $$->u.variant.name = $1;
5039b4cc 1948 if ($3 && set_parent_node($3, $$))
6dc474b8
MD
1949 reparent_error(scanner, "variant reparent error");
1950 }
8b9d5b5e 1951 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1952 {
1953 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1954 $$->u.variant.has_body = 1;
8aa95b17
MD
1955 $$->u.variant.name = $1;
1956 $$->u.variant.choice = $3;
5039b4cc 1957 if ($6 && set_parent_node($6, $$))
6dc474b8
MD
1958 reparent_error(scanner, "variant reparent error");
1959 }
8b9d5b5e 1960 | ID_TYPE LT IDENTIFIER GT
6dc474b8
MD
1961 {
1962 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1963 $$->u.variant.has_body = 0;
8aa95b17
MD
1964 $$->u.variant.name = $1;
1965 $$->u.variant.choice = $3;
6dc474b8 1966 }
8b9d5b5e 1967 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1968 {
1969 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1970 $$->u.variant.has_body = 1;
8aa95b17
MD
1971 $$->u.variant.name = $1;
1972 $$->u.variant.choice = $3;
5039b4cc 1973 if ($6 && set_parent_node($6, $$))
6dc474b8
MD
1974 reparent_error(scanner, "variant reparent error");
1975 }
8b9d5b5e 1976 | ID_TYPE LT ID_TYPE GT
6dc474b8
MD
1977 {
1978 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1979 $$->u.variant.has_body = 0;
8aa95b17
MD
1980 $$->u.variant.name = $1;
1981 $$->u.variant.choice = $3;
6dc474b8 1982 }
8b9d5b5e
MD
1983 ;
1984
1985variant_declaration_begin:
1986 LBRAC
fce8006d 1987 { push_scope(scanner); }
8b9d5b5e
MD
1988 ;
1989
1990variant_declaration_end:
1991 RBRAC
fce8006d 1992 { pop_scope(scanner); }
8b9d5b5e
MD
1993 ;
1994
8b9d5b5e
MD
1995enum_type_specifier:
1996 LBRAC enumerator_list RBRAC
6dc474b8
MD
1997 {
1998 $$ = make_node(scanner, NODE_ENUM);
add40b62 1999 $$->u._enum.has_body = 1;
3122e6f0 2000 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2001 }
0fbb34a5 2002 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
6dc474b8
MD
2003 {
2004 $$ = make_node(scanner, NODE_ENUM);
add40b62 2005 $$->u._enum.has_body = 1;
3e11b713 2006 ($$)->u._enum.container_type = $2;
3122e6f0 2007 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2008 }
8b9d5b5e 2009 | IDENTIFIER LBRAC enumerator_list RBRAC
6dc474b8
MD
2010 {
2011 $$ = make_node(scanner, NODE_ENUM);
add40b62 2012 $$->u._enum.has_body = 1;
8aa95b17 2013 $$->u._enum.enum_id = $1;
3122e6f0 2014 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2015 }
0fbb34a5 2016 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
6dc474b8
MD
2017 {
2018 $$ = make_node(scanner, NODE_ENUM);
add40b62 2019 $$->u._enum.has_body = 1;
8aa95b17 2020 $$->u._enum.enum_id = $1;
3e11b713 2021 ($$)->u._enum.container_type = $3;
3122e6f0 2022 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2023 }
8b9d5b5e 2024 | ID_TYPE LBRAC enumerator_list RBRAC
6dc474b8
MD
2025 {
2026 $$ = make_node(scanner, NODE_ENUM);
add40b62 2027 $$->u._enum.has_body = 1;
8aa95b17 2028 $$->u._enum.enum_id = $1;
3122e6f0 2029 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2030 }
0fbb34a5 2031 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
6dc474b8
MD
2032 {
2033 $$ = make_node(scanner, NODE_ENUM);
add40b62 2034 $$->u._enum.has_body = 1;
8aa95b17 2035 $$->u._enum.enum_id = $1;
3e11b713 2036 ($$)->u._enum.container_type = $3;
3122e6f0 2037 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2038 }
8b9d5b5e 2039 | LBRAC enumerator_list COMMA RBRAC
6dc474b8
MD
2040 {
2041 $$ = make_node(scanner, NODE_ENUM);
add40b62 2042 $$->u._enum.has_body = 1;
3122e6f0 2043 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2044 }
0fbb34a5 2045 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
6dc474b8
MD
2046 {
2047 $$ = make_node(scanner, NODE_ENUM);
add40b62 2048 $$->u._enum.has_body = 1;
3e11b713 2049 ($$)->u._enum.container_type = $2;
3122e6f0 2050 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2051 }
8b9d5b5e 2052 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
6dc474b8
MD
2053 {
2054 $$ = make_node(scanner, NODE_ENUM);
add40b62 2055 $$->u._enum.has_body = 1;
8aa95b17 2056 $$->u._enum.enum_id = $1;
3122e6f0 2057 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2058 }
0fbb34a5 2059 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
6dc474b8
MD
2060 {
2061 $$ = make_node(scanner, NODE_ENUM);
add40b62 2062 $$->u._enum.has_body = 1;
8aa95b17 2063 $$->u._enum.enum_id = $1;
3e11b713 2064 ($$)->u._enum.container_type = $3;
3122e6f0 2065 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2066 }
8b9d5b5e 2067 | IDENTIFIER
6dc474b8
MD
2068 {
2069 $$ = make_node(scanner, NODE_ENUM);
add40b62 2070 $$->u._enum.has_body = 0;
8aa95b17 2071 $$->u._enum.enum_id = $1;
6dc474b8 2072 }
8b9d5b5e 2073 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
6dc474b8
MD
2074 {
2075 $$ = make_node(scanner, NODE_ENUM);
add40b62 2076 $$->u._enum.has_body = 1;
8aa95b17 2077 $$->u._enum.enum_id = $1;
3122e6f0 2078 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2079 }
0fbb34a5 2080 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
6dc474b8
MD
2081 {
2082 $$ = make_node(scanner, NODE_ENUM);
add40b62 2083 $$->u._enum.has_body = 1;
8aa95b17 2084 $$->u._enum.enum_id = $1;
3e11b713 2085 ($$)->u._enum.container_type = $3;
3122e6f0 2086 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2087 }
8b9d5b5e 2088 | ID_TYPE
6dc474b8
MD
2089 {
2090 $$ = make_node(scanner, NODE_ENUM);
add40b62 2091 $$->u._enum.has_body = 0;
8aa95b17 2092 $$->u._enum.enum_id = $1;
6dc474b8 2093 }
8b9d5b5e
MD
2094 ;
2095
2096struct_or_variant_declaration_list:
2097 /* empty */
6dc474b8 2098 { $$ = NULL; }
8b9d5b5e 2099 | struct_or_variant_declaration_list struct_or_variant_declaration
6dc474b8
MD
2100 {
2101 if ($1) {
2102 $$ = $1;
3122e6f0 2103 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
6dc474b8
MD
2104 } else {
2105 $$ = $2;
3122e6f0 2106 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
6dc474b8
MD
2107 }
2108 }
8b9d5b5e
MD
2109 ;
2110
2111struct_or_variant_declaration:
1ee8e81d 2112 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
6dc474b8 2113 {
3e11b713
MD
2114 struct ctf_node *list;
2115
2116 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
3122e6f0 2117 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
6dc474b8 2118 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
3e11b713 2119 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
3122e6f0 2120 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
6dc474b8 2121 }
1ee8e81d 2122 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
6dc474b8 2123 {
3e11b713
MD
2124 struct ctf_node *list;
2125
6dc474b8 2126 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713
MD
2127 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2128 $$->u._typedef.type_specifier_list = list;
3122e6f0
JD
2129 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2130 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2131 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 2132 }
1ee8e81d 2133 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
6dc474b8 2134 {
3e11b713
MD
2135 struct ctf_node *list;
2136
6dc474b8 2137 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713
MD
2138 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2139 $$->u._typedef.type_specifier_list = list;
3122e6f0
JD
2140 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2141 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 2142 }
1ee8e81d 2143 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
6dc474b8 2144 {
3e11b713
MD
2145 struct ctf_node *list;
2146
2147 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
3122e6f0 2148 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
6dc474b8 2149 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713 2150 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
3122e6f0 2151 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 2152 }
a030d084 2153 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
6dc474b8 2154 {
3e11b713
MD
2155 struct ctf_node *list;
2156
6dc474b8
MD
2157 $$ = make_node(scanner, NODE_TYPEALIAS);
2158 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2159 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
3e11b713
MD
2160
2161 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2162 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
3122e6f0
JD
2163 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2164 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
3e11b713
MD
2165
2166 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2167 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
3122e6f0
JD
2168 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2169 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
6dc474b8 2170 }
8b9d5b5e
MD
2171 ;
2172
1ee8e81d 2173alias_declaration_specifiers:
8b9d5b5e 2174 CONST
6dc474b8 2175 {
3e11b713
MD
2176 struct ctf_node *node;
2177
2178 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2179 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2180 node->u.type_specifier.type = TYPESPEC_CONST;
3122e6f0 2181 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
6dc474b8 2182 }
8b9d5b5e 2183 | type_specifier
3e11b713
MD
2184 {
2185 struct ctf_node *node;
2186
2187 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2188 node = $1;
3122e6f0 2189 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
3e11b713 2190 }
1ee8e81d
MD
2191 | IDENTIFIER
2192 {
3e11b713
MD
2193 struct ctf_node *node;
2194
1ee8e81d 2195 add_type(scanner, $1);
3e11b713
MD
2196 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2197 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2198 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
8aa95b17 2199 node->u.type_specifier.id_type = yylval.s;
3122e6f0 2200 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1ee8e81d
MD
2201 }
2202 | alias_declaration_specifiers CONST
6dc474b8
MD
2203 {
2204 struct ctf_node *node;
2205
2206 $$ = $1;
2207 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2208 node->u.type_specifier.type = TYPESPEC_CONST;
3122e6f0 2209 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
6dc474b8 2210 }
1ee8e81d 2211 | alias_declaration_specifiers type_specifier
6dc474b8
MD
2212 {
2213 $$ = $1;
3122e6f0 2214 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
6dc474b8 2215 }
1ee8e81d
MD
2216 | alias_declaration_specifiers IDENTIFIER
2217 {
2218 struct ctf_node *node;
2219
2220 add_type(scanner, $2);
2221 $$ = $1;
2222 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2223 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
8aa95b17 2224 node->u.type_specifier.id_type = yylval.s;
3122e6f0 2225 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1ee8e81d 2226 }
8b9d5b5e
MD
2227 ;
2228
2229struct_or_variant_declarator_list:
2230 struct_or_variant_declarator
0009a725 2231 { $$ = $1; }
8b9d5b5e 2232 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
6dc474b8
MD
2233 {
2234 $$ = $1;
3122e6f0 2235 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
6dc474b8 2236 }
8b9d5b5e
MD
2237 ;
2238
2239struct_or_variant_declarator:
2240 declarator
6dc474b8 2241 { $$ = $1; }
8b9d5b5e 2242 | COLON unary_expression
6dc474b8 2243 { $$ = $2; }
8b9d5b5e 2244 | declarator COLON unary_expression
6dc474b8
MD
2245 {
2246 $$ = $1;
48a01768 2247 if (set_parent_node($3, $1))
6dc474b8
MD
2248 reparent_error(scanner, "struct_or_variant_declarator");
2249 }
8b9d5b5e
MD
2250 ;
2251
2252enumerator_list:
2253 enumerator
0009a725 2254 { $$ = $1; }
8b9d5b5e 2255 | enumerator_list COMMA enumerator
6dc474b8
MD
2256 {
2257 $$ = $1;
3122e6f0 2258 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
6dc474b8 2259 }
8b9d5b5e
MD
2260 ;
2261
2262enumerator:
2263 IDENTIFIER
6dc474b8
MD
2264 {
2265 $$ = make_node(scanner, NODE_ENUMERATOR);
8aa95b17 2266 $$->u.enumerator.id = $1;
6dc474b8 2267 }
8b9d5b5e 2268 | ID_TYPE
6dc474b8
MD
2269 {
2270 $$ = make_node(scanner, NODE_ENUMERATOR);
8aa95b17 2271 $$->u.enumerator.id = $1;
6dc474b8 2272 }
8b9d5b5e 2273 | keywords
6dc474b8
MD
2274 {
2275 $$ = make_node(scanner, NODE_ENUMERATOR);
8aa95b17 2276 $$->u.enumerator.id = $1;
6dc474b8 2277 }
d876a5ba 2278 | STRING_LITERAL
6dc474b8
MD
2279 {
2280 $$ = make_node(scanner, NODE_ENUMERATOR);
8aa95b17 2281 $$->u.enumerator.id = $1;
6dc474b8 2282 }
8b9d5b5e 2283 | IDENTIFIER EQUAL unary_expression_or_range
6dc474b8
MD
2284 {
2285 $$ = make_node(scanner, NODE_ENUMERATOR);
8aa95b17 2286 $$->u.enumerator.id = $1;
3122e6f0 2287 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
6dc474b8 2288 }
8b9d5b5e 2289 | ID_TYPE EQUAL unary_expression_or_range
6dc474b8
MD
2290 {
2291 $$ = make_node(scanner, NODE_ENUMERATOR);
8aa95b17 2292 $$->u.enumerator.id = $1;
3122e6f0 2293 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
6dc474b8 2294 }
8b9d5b5e 2295 | keywords EQUAL unary_expression_or_range
6dc474b8
MD
2296 {
2297 $$ = make_node(scanner, NODE_ENUMERATOR);
8aa95b17 2298 $$->u.enumerator.id = $1;
3122e6f0 2299 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
6dc474b8 2300 }
d876a5ba 2301 | STRING_LITERAL EQUAL unary_expression_or_range
6dc474b8
MD
2302 {
2303 $$ = make_node(scanner, NODE_ENUMERATOR);
8aa95b17 2304 $$->u.enumerator.id = $1;
d876a5ba 2305 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
6dc474b8 2306 }
8b9d5b5e
MD
2307 ;
2308
2309abstract_declarator_list:
2310 abstract_declarator
0009a725 2311 { $$ = $1; }
8b9d5b5e 2312 | abstract_declarator_list COMMA abstract_declarator
6dc474b8
MD
2313 {
2314 $$ = $1;
3122e6f0 2315 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
6dc474b8 2316 }
8b9d5b5e
MD
2317 ;
2318
2319abstract_declarator:
2320 direct_abstract_declarator
6dc474b8 2321 { $$ = $1; }
8b9d5b5e 2322 | pointer direct_abstract_declarator
6dc474b8
MD
2323 {
2324 $$ = $2;
3122e6f0 2325 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
6dc474b8 2326 }
8b9d5b5e
MD
2327 ;
2328
2329direct_abstract_declarator:
2330 /* empty */
6dc474b8
MD
2331 {
2332 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2333 $$->u.type_declarator.type = TYPEDEC_ID;
2334 /* id is NULL */
2335 }
8b9d5b5e 2336 | IDENTIFIER
6dc474b8
MD
2337 {
2338 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2339 $$->u.type_declarator.type = TYPEDEC_ID;
8aa95b17 2340 $$->u.type_declarator.u.id = $1;
6dc474b8 2341 }
8b9d5b5e 2342 | LPAREN abstract_declarator RPAREN
6dc474b8
MD
2343 {
2344 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2345 $$->u.type_declarator.type = TYPEDEC_NESTED;
2346 $$->u.type_declarator.u.nested.type_declarator = $2;
2347 }
98df1c9f 2348 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
6dc474b8
MD
2349 {
2350 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2351 $$->u.type_declarator.type = TYPEDEC_NESTED;
2352 $$->u.type_declarator.u.nested.type_declarator = $1;
3122e6f0
JD
2353 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2354 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
6dc474b8 2355 }
8b9d5b5e 2356 | direct_abstract_declarator LSBRAC RSBRAC
6dc474b8
MD
2357 {
2358 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2359 $$->u.type_declarator.type = TYPEDEC_NESTED;
2360 $$->u.type_declarator.u.nested.type_declarator = $1;
2361 $$->u.type_declarator.u.nested.abstract_array = 1;
2362 }
8b9d5b5e
MD
2363 ;
2364
e0c14875
MD
2365alias_abstract_declarator_list:
2366 alias_abstract_declarator
6dc474b8 2367 { $$ = $1; }
e0c14875
MD
2368 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2369 {
2370 $$ = $1;
3122e6f0 2371 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
e0c14875
MD
2372 }
2373 ;
2374
2375alias_abstract_declarator:
2376 direct_alias_abstract_declarator
2377 { $$ = $1; }
2378 | pointer direct_alias_abstract_declarator
6dc474b8
MD
2379 {
2380 $$ = $2;
3122e6f0 2381 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
6dc474b8 2382 }
8b9d5b5e
MD
2383 ;
2384
e0c14875
MD
2385direct_alias_abstract_declarator:
2386 /* empty */
6dc474b8
MD
2387 {
2388 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
e0c14875
MD
2389 $$->u.type_declarator.type = TYPEDEC_ID;
2390 /* id is NULL */
6dc474b8 2391 }
e0c14875 2392 | LPAREN alias_abstract_declarator RPAREN
6dc474b8
MD
2393 {
2394 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2395 $$->u.type_declarator.type = TYPEDEC_NESTED;
2396 $$->u.type_declarator.u.nested.type_declarator = $2;
2397 }
98df1c9f 2398 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
6dc474b8
MD
2399 {
2400 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2401 $$->u.type_declarator.type = TYPEDEC_NESTED;
2402 $$->u.type_declarator.u.nested.type_declarator = $1;
3122e6f0
JD
2403 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2404 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
6dc474b8 2405 }
e0c14875
MD
2406 | direct_alias_abstract_declarator LSBRAC RSBRAC
2407 {
2408 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2409 $$->u.type_declarator.type = TYPEDEC_NESTED;
2410 $$->u.type_declarator.u.nested.type_declarator = $1;
2411 $$->u.type_declarator.u.nested.abstract_array = 1;
2412 }
8b9d5b5e
MD
2413 ;
2414
e0c14875
MD
2415declarator:
2416 direct_declarator
6dc474b8 2417 { $$ = $1; }
e0c14875 2418 | pointer direct_declarator
6dc474b8
MD
2419 {
2420 $$ = $2;
3122e6f0 2421 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
6dc474b8 2422 }
8b9d5b5e
MD
2423 ;
2424
e0c14875 2425direct_declarator:
8b9d5b5e 2426 IDENTIFIER
6dc474b8 2427 {
6dc474b8
MD
2428 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2429 $$->u.type_declarator.type = TYPEDEC_ID;
8aa95b17 2430 $$->u.type_declarator.u.id = $1;
6dc474b8 2431 }
e0c14875 2432 | LPAREN declarator RPAREN
6dc474b8
MD
2433 {
2434 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2435 $$->u.type_declarator.type = TYPEDEC_NESTED;
2436 $$->u.type_declarator.u.nested.type_declarator = $2;
2437 }
98df1c9f 2438 | direct_declarator LSBRAC unary_expression RSBRAC
6dc474b8
MD
2439 {
2440 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2441 $$->u.type_declarator.type = TYPEDEC_NESTED;
2442 $$->u.type_declarator.u.nested.type_declarator = $1;
3122e6f0
JD
2443 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2444 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
6dc474b8 2445 }
8b9d5b5e
MD
2446 ;
2447
e0c14875
MD
2448type_declarator:
2449 direct_type_declarator
6dc474b8 2450 { $$ = $1; }
e0c14875 2451 | pointer direct_type_declarator
6dc474b8
MD
2452 {
2453 $$ = $2;
3122e6f0 2454 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
6dc474b8 2455 }
8b9d5b5e
MD
2456 ;
2457
e0c14875
MD
2458direct_type_declarator:
2459 IDENTIFIER
6dc474b8
MD
2460 {
2461 add_type(scanner, $1);
2462 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2463 $$->u.type_declarator.type = TYPEDEC_ID;
8aa95b17 2464 $$->u.type_declarator.u.id = $1;
6dc474b8 2465 }
e0c14875 2466 | LPAREN type_declarator RPAREN
6dc474b8
MD
2467 {
2468 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2469 $$->u.type_declarator.type = TYPEDEC_NESTED;
2470 $$->u.type_declarator.u.nested.type_declarator = $2;
2471 }
98df1c9f 2472 | direct_type_declarator LSBRAC unary_expression RSBRAC
6dc474b8
MD
2473 {
2474 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2475 $$->u.type_declarator.type = TYPEDEC_NESTED;
2476 $$->u.type_declarator.u.nested.type_declarator = $1;
3122e6f0
JD
2477 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2478 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
6dc474b8 2479 }
8b9d5b5e
MD
2480 ;
2481
2482pointer:
2483 STAR
48a01768
MD
2484 {
2485 $$ = make_node(scanner, NODE_POINTER);
48a01768 2486 }
8b9d5b5e 2487 | STAR pointer
6dc474b8
MD
2488 {
2489 $$ = make_node(scanner, NODE_POINTER);
3122e6f0 2490 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
6dc474b8 2491 }
8b9d5b5e 2492 | STAR type_qualifier_list pointer
6dc474b8
MD
2493 {
2494 $$ = make_node(scanner, NODE_POINTER);
2495 $$->u.pointer.const_qualifier = 1;
3122e6f0 2496 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
6dc474b8 2497 }
8b9d5b5e
MD
2498 ;
2499
2500type_qualifier_list:
6dc474b8 2501 /* pointer assumes only const type qualifier */
8b9d5b5e
MD
2502 CONST
2503 | type_qualifier_list CONST
2504 ;
2505
2506/* 2.3: CTF-specific declarations */
2507
2508ctf_assignment_expression_list:
2509 ctf_assignment_expression SEMICOLON
0009a725 2510 { $$ = $1; }
8b9d5b5e 2511 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
6dc474b8
MD
2512 {
2513 $$ = $1;
3122e6f0 2514 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
6dc474b8 2515 }
8b9d5b5e
MD
2516 ;
2517
2518ctf_assignment_expression:
2519 unary_expression EQUAL unary_expression
02b234c4 2520 {
6dc474b8
MD
2521 /*
2522 * Because we have left and right, cannot use
48a01768 2523 * set_parent_node.
6dc474b8 2524 */
02b234c4 2525 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
3122e6f0 2526 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
6dc474b8
MD
2527 if ($1->u.unary_expression.type != UNARY_STRING)
2528 reparent_error(scanner, "ctf_assignment_expression left expects string");
3122e6f0 2529 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
02b234c4 2530 }
427c09b7 2531 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
6dc474b8
MD
2532 {
2533 /*
2534 * Because we have left and right, cannot use
48a01768 2535 * set_parent_node.
6dc474b8
MD
2536 */
2537 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
3122e6f0 2538 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
6dc474b8
MD
2539 if ($1->u.unary_expression.type != UNARY_STRING)
2540 reparent_error(scanner, "ctf_assignment_expression left expects string");
3122e6f0 2541 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
6dc474b8 2542 }
8b9d5b5e 2543 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
6dc474b8 2544 {
3e11b713
MD
2545 struct ctf_node *list;
2546
2547 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
3122e6f0
JD
2548 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2549 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
6dc474b8 2550 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713 2551 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
3122e6f0 2552 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 2553 }
8b9d5b5e 2554 | TYPEDEF declaration_specifiers type_declarator_list
6dc474b8 2555 {
3e11b713
MD
2556 struct ctf_node *list;
2557
6dc474b8 2558 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713
MD
2559 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2560 $$->u._typedef.type_specifier_list = list;
3122e6f0
JD
2561 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2562 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 2563 }
8b9d5b5e 2564 | declaration_specifiers TYPEDEF type_declarator_list
6dc474b8 2565 {
3e11b713
MD
2566 struct ctf_node *list;
2567
2568 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
3122e6f0 2569 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
6dc474b8 2570 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713 2571 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
3122e6f0 2572 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 2573 }
a030d084 2574 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
6dc474b8 2575 {
3e11b713
MD
2576 struct ctf_node *list;
2577
6dc474b8
MD
2578 $$ = make_node(scanner, NODE_TYPEALIAS);
2579 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2580 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
3e11b713
MD
2581
2582 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2583 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
3122e6f0
JD
2584 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2585 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
3e11b713
MD
2586
2587 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2588 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
3122e6f0
JD
2589 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2590 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
6dc474b8 2591 }
8b9d5b5e 2592 ;
This page took 0.199831 seconds and 4 git commands to generate.