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