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