Remove nested expressions
[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 {
104147cd 1202 $$ = $2;
6dc474b8 1203 }
8b9d5b5e 1204 | postfix_expression LSBRAC unary_expression RSBRAC
6dc474b8
MD
1205 {
1206 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1207 $$->u.unary_expression.type = UNARY_SBRAC;
1208 $$->u.unary_expression.u.sbrac_exp = $3;
3122e6f0
JD
1209 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1210 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
6dc474b8 1211 }
8b9d5b5e 1212 | postfix_expression DOT IDENTIFIER
6dc474b8
MD
1213 {
1214 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1215 $$->u.unary_expression.type = UNARY_STRING;
1216 $$->u.unary_expression.u.string = yylval.gs->s;
1217 $$->u.unary_expression.link = UNARY_DOTLINK;
3122e6f0
JD
1218 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1219 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
6dc474b8 1220 }
8b9d5b5e 1221 | postfix_expression DOT ID_TYPE
6dc474b8
MD
1222 {
1223 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1224 $$->u.unary_expression.type = UNARY_STRING;
1225 $$->u.unary_expression.u.string = yylval.gs->s;
1226 $$->u.unary_expression.link = UNARY_DOTLINK;
3122e6f0
JD
1227 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1228 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
6dc474b8 1229 }
8b9d5b5e 1230 | postfix_expression RARROW IDENTIFIER
6dc474b8
MD
1231 {
1232 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1233 $$->u.unary_expression.type = UNARY_STRING;
1234 $$->u.unary_expression.u.string = yylval.gs->s;
1235 $$->u.unary_expression.link = UNARY_ARROWLINK;
3122e6f0
JD
1236 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1237 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
6dc474b8 1238 }
8b9d5b5e 1239 | postfix_expression RARROW ID_TYPE
6dc474b8
MD
1240 {
1241 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1242 $$->u.unary_expression.type = UNARY_STRING;
1243 $$->u.unary_expression.u.string = yylval.gs->s;
1244 $$->u.unary_expression.link = UNARY_ARROWLINK;
3122e6f0
JD
1245 bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1246 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
6dc474b8 1247 }
8b9d5b5e
MD
1248 ;
1249
1250unary_expression:
1251 postfix_expression
6dc474b8 1252 { $$ = $1; }
8b9d5b5e 1253 | PLUS postfix_expression
f9c67088
EB
1254 {
1255 $$ = $2;
1256 if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
1257 && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
1258 reparent_error(scanner, "expecting numeric constant");
1259 }
1260 }
8b9d5b5e 1261 | MINUS postfix_expression
6dc474b8
MD
1262 {
1263 $$ = $2;
6dc474b8
MD
1264 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1265 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1266 $$->u.unary_expression.u.signed_constant =
1267 -($$->u.unary_expression.u.unsigned_constant);
ca3de390 1268 } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
6dc474b8
MD
1269 $$->u.unary_expression.u.signed_constant =
1270 -($$->u.unary_expression.u.signed_constant);
ca3de390
EB
1271 } else {
1272 reparent_error(scanner, "expecting numeric constant");
6dc474b8
MD
1273 }
1274 }
8b9d5b5e
MD
1275 ;
1276
1277unary_expression_or_range:
1278 unary_expression DOTDOTDOT unary_expression
6dc474b8
MD
1279 {
1280 $$ = $1;
3122e6f0 1281 _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
48a01768 1282 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
6dc474b8 1283 }
8b9d5b5e 1284 | unary_expression
6dc474b8 1285 { $$ = $1; }
8b9d5b5e
MD
1286 ;
1287
1288/* 2.2: Declarations */
1289
1290declaration:
1291 declaration_specifiers SEMICOLON
6dc474b8 1292 { $$ = $1; }
8b9d5b5e 1293 | event_declaration
6dc474b8 1294 { $$ = $1; }
8b9d5b5e 1295 | stream_declaration
6dc474b8 1296 { $$ = $1; }
e2c76a4d
MD
1297 | env_declaration
1298 { $$ = $1; }
8b9d5b5e 1299 | trace_declaration
6dc474b8 1300 { $$ = $1; }
73d15916
MD
1301 | clock_declaration
1302 { $$ = $1; }
f133896d
MD
1303 | callsite_declaration
1304 { $$ = $1; }
8b9d5b5e 1305 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
6dc474b8 1306 {
3e11b713
MD
1307 struct ctf_node *list;
1308
6dc474b8 1309 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713
MD
1310 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1311 $$->u._typedef.type_specifier_list = list;
3122e6f0
JD
1312 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1313 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1314 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 1315 }
8b9d5b5e 1316 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
6dc474b8 1317 {
3e11b713
MD
1318 struct ctf_node *list;
1319
6dc474b8 1320 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713
MD
1321 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1322 $$->u._typedef.type_specifier_list = list;
3122e6f0
JD
1323 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1324 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 1325 }
8b9d5b5e 1326 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
6dc474b8 1327 {
3e11b713
MD
1328 struct ctf_node *list;
1329
6dc474b8 1330 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713
MD
1331 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1332 $$->u._typedef.type_specifier_list = list;
3122e6f0
JD
1333 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1334 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 1335 }
a030d084 1336 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
6dc474b8 1337 {
3e11b713
MD
1338 struct ctf_node *list;
1339
6dc474b8
MD
1340 $$ = make_node(scanner, NODE_TYPEALIAS);
1341 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1342 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
3e11b713
MD
1343
1344 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1345 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
3122e6f0
JD
1346 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1347 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
3e11b713
MD
1348
1349 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1350 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
3122e6f0
JD
1351 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1352 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
6dc474b8 1353 }
8b9d5b5e
MD
1354 ;
1355
1356event_declaration:
1357 event_declaration_begin event_declaration_end
48a01768
MD
1358 {
1359 $$ = make_node(scanner, NODE_EVENT);
48a01768 1360 }
8b9d5b5e 1361 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
02b234c4
MD
1362 {
1363 $$ = make_node(scanner, NODE_EVENT);
48a01768 1364 if (set_parent_node($2, $$))
6dc474b8 1365 reparent_error(scanner, "event_declaration");
02b234c4 1366 }
8b9d5b5e
MD
1367 ;
1368
1369event_declaration_begin:
1370 EVENT LBRAC
fce8006d 1371 { push_scope(scanner); }
8b9d5b5e
MD
1372 ;
1373
1374event_declaration_end:
1375 RBRAC SEMICOLON
fce8006d 1376 { pop_scope(scanner); }
8b9d5b5e
MD
1377 ;
1378
1379
1380stream_declaration:
1381 stream_declaration_begin stream_declaration_end
48a01768
MD
1382 {
1383 $$ = make_node(scanner, NODE_STREAM);
48a01768 1384 }
8b9d5b5e 1385 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
6dc474b8
MD
1386 {
1387 $$ = make_node(scanner, NODE_STREAM);
48a01768 1388 if (set_parent_node($2, $$))
6dc474b8
MD
1389 reparent_error(scanner, "stream_declaration");
1390 }
8b9d5b5e
MD
1391 ;
1392
1393stream_declaration_begin:
1394 STREAM LBRAC
fce8006d 1395 { push_scope(scanner); }
8b9d5b5e
MD
1396 ;
1397
1398stream_declaration_end:
1399 RBRAC SEMICOLON
fce8006d 1400 { pop_scope(scanner); }
8b9d5b5e
MD
1401 ;
1402
e2c76a4d
MD
1403env_declaration:
1404 env_declaration_begin env_declaration_end
1405 {
1406 $$ = make_node(scanner, NODE_ENV);
1407 }
1408 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1409 {
1410 $$ = make_node(scanner, NODE_ENV);
1411 if (set_parent_node($2, $$))
1412 reparent_error(scanner, "env declaration");
1413 }
1414 ;
1415
1416env_declaration_begin:
1417 ENV LBRAC
1418 { push_scope(scanner); }
1419 ;
1420
1421env_declaration_end:
1422 RBRAC SEMICOLON
1423 { pop_scope(scanner); }
1424 ;
1425
8b9d5b5e
MD
1426trace_declaration:
1427 trace_declaration_begin trace_declaration_end
48a01768
MD
1428 {
1429 $$ = make_node(scanner, NODE_TRACE);
48a01768 1430 }
8b9d5b5e 1431 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
6dc474b8
MD
1432 {
1433 $$ = make_node(scanner, NODE_TRACE);
48a01768 1434 if (set_parent_node($2, $$))
6dc474b8
MD
1435 reparent_error(scanner, "trace_declaration");
1436 }
8b9d5b5e
MD
1437 ;
1438
1439trace_declaration_begin:
1440 TRACE LBRAC
fce8006d 1441 { push_scope(scanner); }
8b9d5b5e
MD
1442 ;
1443
1444trace_declaration_end:
1445 RBRAC SEMICOLON
fce8006d 1446 { pop_scope(scanner); }
8b9d5b5e
MD
1447 ;
1448
73d15916
MD
1449clock_declaration:
1450 CLOCK clock_declaration_begin clock_declaration_end
1451 {
1452 $$ = make_node(scanner, NODE_CLOCK);
1453 }
1454 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1455 {
1456 $$ = make_node(scanner, NODE_CLOCK);
1457 if (set_parent_node($3, $$))
1458 reparent_error(scanner, "trace_declaration");
1459 }
1460 ;
1461
1462clock_declaration_begin:
1463 LBRAC
1464 { push_scope(scanner); }
1465 ;
1466
1467clock_declaration_end:
1468 RBRAC SEMICOLON
1469 { pop_scope(scanner); }
1470 ;
1471
f133896d
MD
1472callsite_declaration:
1473 CALLSITE callsite_declaration_begin callsite_declaration_end
1474 {
1475 $$ = make_node(scanner, NODE_CALLSITE);
1476 }
1477 | CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end
1478 {
1479 $$ = make_node(scanner, NODE_CALLSITE);
1480 if (set_parent_node($3, $$))
1481 reparent_error(scanner, "trace_declaration");
1482 }
1483 ;
1484
1485callsite_declaration_begin:
1486 LBRAC
1487 { push_scope(scanner); }
1488 ;
1489
1490callsite_declaration_end:
1491 RBRAC SEMICOLON
1492 { pop_scope(scanner); }
1493 ;
1494
0fbb34a5
MD
1495integer_declaration_specifiers:
1496 CONST
1497 {
1498 struct ctf_node *node;
1499
1500 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1501 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1502 node->u.type_specifier.type = TYPESPEC_CONST;
3122e6f0 1503 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
0fbb34a5
MD
1504 }
1505 | integer_type_specifier
1506 {
1507 struct ctf_node *node;
1508
1509 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1510 node = $1;
3122e6f0 1511 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
0fbb34a5
MD
1512 }
1513 | integer_declaration_specifiers CONST
1514 {
1515 struct ctf_node *node;
1516
1517 $$ = $1;
1518 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1519 node->u.type_specifier.type = TYPESPEC_CONST;
3122e6f0 1520 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
0fbb34a5
MD
1521 }
1522 | integer_declaration_specifiers integer_type_specifier
1523 {
1524 $$ = $1;
3122e6f0 1525 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
0fbb34a5
MD
1526 }
1527 ;
1528
8b9d5b5e
MD
1529declaration_specifiers:
1530 CONST
6dc474b8 1531 {
3e11b713
MD
1532 struct ctf_node *node;
1533
1534 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1535 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1536 node->u.type_specifier.type = TYPESPEC_CONST;
3122e6f0 1537 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
6dc474b8 1538 }
8b9d5b5e 1539 | type_specifier
3e11b713
MD
1540 {
1541 struct ctf_node *node;
1542
1543 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1544 node = $1;
3122e6f0 1545 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
3e11b713 1546 }
8b9d5b5e 1547 | declaration_specifiers CONST
6dc474b8
MD
1548 {
1549 struct ctf_node *node;
1550
48a01768 1551 $$ = $1;
6dc474b8
MD
1552 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1553 node->u.type_specifier.type = TYPESPEC_CONST;
3122e6f0 1554 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
6dc474b8 1555 }
8b9d5b5e 1556 | declaration_specifiers type_specifier
6dc474b8
MD
1557 {
1558 $$ = $1;
3122e6f0 1559 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
6dc474b8 1560 }
8b9d5b5e
MD
1561 ;
1562
1563type_declarator_list:
1564 type_declarator
0009a725 1565 { $$ = $1; }
8b9d5b5e 1566 | type_declarator_list COMMA type_declarator
6dc474b8
MD
1567 {
1568 $$ = $1;
3122e6f0 1569 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
6dc474b8 1570 }
8b9d5b5e
MD
1571 ;
1572
0fbb34a5
MD
1573integer_type_specifier:
1574 CHAR
1575 {
1576 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1577 $$->u.type_specifier.type = TYPESPEC_CHAR;
1578 }
1579 | SHORT
1580 {
1581 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1582 $$->u.type_specifier.type = TYPESPEC_SHORT;
1583 }
1584 | INT
1585 {
1586 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1587 $$->u.type_specifier.type = TYPESPEC_INT;
1588 }
1589 | LONG
1590 {
1591 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1592 $$->u.type_specifier.type = TYPESPEC_LONG;
1593 }
1594 | SIGNED
1595 {
1596 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1597 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1598 }
1599 | UNSIGNED
1600 {
1601 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1602 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1603 }
1604 | _BOOL
1605 {
1606 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1607 $$->u.type_specifier.type = TYPESPEC_BOOL;
1608 }
1609 | ID_TYPE
1610 {
1611 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1612 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1613 $$->u.type_specifier.id_type = yylval.gs->s;
1614 }
1615 | INTEGER LBRAC RBRAC
1616 {
1617 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1618 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1619 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1620 }
1621 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1622 {
1623 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1624 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1625 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1626 if (set_parent_node($3, $$->u.type_specifier.node))
1627 reparent_error(scanner, "integer reparent error");
1628 }
1629 ;
1630
8b9d5b5e
MD
1631type_specifier:
1632 VOID
6dc474b8
MD
1633 {
1634 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1635 $$->u.type_specifier.type = TYPESPEC_VOID;
1636 }
8b9d5b5e 1637 | CHAR
6dc474b8
MD
1638 {
1639 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1640 $$->u.type_specifier.type = TYPESPEC_CHAR;
1641 }
8b9d5b5e 1642 | SHORT
6dc474b8
MD
1643 {
1644 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1645 $$->u.type_specifier.type = TYPESPEC_SHORT;
1646 }
8b9d5b5e 1647 | INT
6dc474b8
MD
1648 {
1649 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1650 $$->u.type_specifier.type = TYPESPEC_INT;
1651 }
8b9d5b5e 1652 | LONG
6dc474b8
MD
1653 {
1654 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1655 $$->u.type_specifier.type = TYPESPEC_LONG;
1656 }
8b9d5b5e 1657 | FLOAT
6dc474b8
MD
1658 {
1659 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1660 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1661 }
8b9d5b5e 1662 | DOUBLE
6dc474b8
MD
1663 {
1664 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1665 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1666 }
8b9d5b5e 1667 | SIGNED
6dc474b8
MD
1668 {
1669 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1670 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1671 }
8b9d5b5e 1672 | UNSIGNED
6dc474b8
MD
1673 {
1674 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1675 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1676 }
8b9d5b5e 1677 | _BOOL
6dc474b8
MD
1678 {
1679 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1680 $$->u.type_specifier.type = TYPESPEC_BOOL;
1681 }
8b9d5b5e 1682 | _COMPLEX
6dc474b8
MD
1683 {
1684 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1685 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1686 }
3888a159
MD
1687 | _IMAGINARY
1688 {
1689 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1690 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1691 }
8b9d5b5e 1692 | ID_TYPE
6dc474b8
MD
1693 {
1694 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1695 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1696 $$->u.type_specifier.id_type = yylval.gs->s;
1697 }
8b9d5b5e 1698 | FLOATING_POINT LBRAC RBRAC
6dc474b8 1699 {
3e11b713
MD
1700 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1701 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1702 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
6dc474b8 1703 }
8b9d5b5e 1704 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
6dc474b8 1705 {
3e11b713
MD
1706 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1707 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1708 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1709 if (set_parent_node($3, $$->u.type_specifier.node))
6dc474b8
MD
1710 reparent_error(scanner, "floating point reparent error");
1711 }
8b9d5b5e 1712 | INTEGER LBRAC RBRAC
6dc474b8 1713 {
3e11b713
MD
1714 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1715 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1716 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
6dc474b8 1717 }
8b9d5b5e 1718 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
6dc474b8 1719 {
3e11b713
MD
1720 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1721 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1722 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1723 if (set_parent_node($3, $$->u.type_specifier.node))
6dc474b8
MD
1724 reparent_error(scanner, "integer reparent error");
1725 }
b40c8090
MD
1726 | STRING
1727 {
1728 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1729 $$->u.type_specifier.type = TYPESPEC_STRING;
1730 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1731 }
8b9d5b5e 1732 | STRING LBRAC RBRAC
6dc474b8 1733 {
3e11b713
MD
1734 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1735 $$->u.type_specifier.type = TYPESPEC_STRING;
1736 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
6dc474b8 1737 }
8b9d5b5e 1738 | STRING LBRAC ctf_assignment_expression_list RBRAC
6dc474b8 1739 {
3e11b713
MD
1740 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1741 $$->u.type_specifier.type = TYPESPEC_STRING;
1742 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1743 if (set_parent_node($3, $$->u.type_specifier.node))
6dc474b8
MD
1744 reparent_error(scanner, "string reparent error");
1745 }
8b9d5b5e 1746 | ENUM enum_type_specifier
3e11b713
MD
1747 {
1748 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1749 $$->u.type_specifier.type = TYPESPEC_ENUM;
1750 $$->u.type_specifier.node = $2;
1751 }
8b9d5b5e 1752 | VARIANT variant_type_specifier
3e11b713
MD
1753 {
1754 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1755 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1756 $$->u.type_specifier.node = $2;
3e11b713 1757 }
8b9d5b5e 1758 | STRUCT struct_type_specifier
3e11b713
MD
1759 {
1760 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1761 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1762 $$->u.type_specifier.node = $2;
3e11b713 1763 }
8b9d5b5e
MD
1764 ;
1765
1766struct_type_specifier:
1767 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
6dc474b8
MD
1768 {
1769 $$ = make_node(scanner, NODE_STRUCT);
1ee8e81d 1770 $$->u._struct.has_body = 1;
5039b4cc 1771 if ($2 && set_parent_node($2, $$))
6dc474b8
MD
1772 reparent_error(scanner, "struct reparent error");
1773 }
8b9d5b5e 1774 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
6dc474b8
MD
1775 {
1776 $$ = make_node(scanner, NODE_STRUCT);
1ee8e81d 1777 $$->u._struct.has_body = 1;
6dc474b8 1778 $$->u._struct.name = $1->s;
5039b4cc 1779 if ($3 && set_parent_node($3, $$))
6dc474b8
MD
1780 reparent_error(scanner, "struct reparent error");
1781 }
8b9d5b5e 1782 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
6dc474b8
MD
1783 {
1784 $$ = make_node(scanner, NODE_STRUCT);
1ee8e81d 1785 $$->u._struct.has_body = 1;
6dc474b8 1786 $$->u._struct.name = $1->s;
5039b4cc 1787 if ($3 && set_parent_node($3, $$))
6dc474b8
MD
1788 reparent_error(scanner, "struct reparent error");
1789 }
8b9d5b5e 1790 | IDENTIFIER
6dc474b8
MD
1791 {
1792 $$ = make_node(scanner, NODE_STRUCT);
1ee8e81d 1793 $$->u._struct.has_body = 0;
6dc474b8
MD
1794 $$->u._struct.name = $1->s;
1795 }
8b9d5b5e 1796 | ID_TYPE
6dc474b8
MD
1797 {
1798 $$ = make_node(scanner, NODE_STRUCT);
1ee8e81d 1799 $$->u._struct.has_body = 0;
6dc474b8
MD
1800 $$->u._struct.name = $1->s;
1801 }
b7e35bad
MD
1802 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1803 {
1804 $$ = make_node(scanner, NODE_STRUCT);
1805 $$->u._struct.has_body = 1;
3122e6f0 1806 bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
b7e35bad
MD
1807 if ($2 && set_parent_node($2, $$))
1808 reparent_error(scanner, "struct reparent error");
1809 }
1810 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1811 {
1812 $$ = make_node(scanner, NODE_STRUCT);
1813 $$->u._struct.has_body = 1;
1814 $$->u._struct.name = $1->s;
3122e6f0 1815 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
b7e35bad
MD
1816 if ($3 && set_parent_node($3, $$))
1817 reparent_error(scanner, "struct reparent error");
1818 }
1819 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1820 {
1821 $$ = make_node(scanner, NODE_STRUCT);
1822 $$->u._struct.has_body = 1;
1823 $$->u._struct.name = $1->s;
3122e6f0 1824 bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
b7e35bad
MD
1825 if ($3 && set_parent_node($3, $$))
1826 reparent_error(scanner, "struct reparent error");
1827 }
8b9d5b5e
MD
1828 ;
1829
1830struct_declaration_begin:
1831 LBRAC
fce8006d 1832 { push_scope(scanner); }
8b9d5b5e
MD
1833 ;
1834
1835struct_declaration_end:
1836 RBRAC
fce8006d 1837 { pop_scope(scanner); }
8b9d5b5e
MD
1838 ;
1839
1840variant_type_specifier:
1841 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1842 {
1843 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1844 $$->u.variant.has_body = 1;
5039b4cc 1845 if ($2 && set_parent_node($2, $$))
6dc474b8
MD
1846 reparent_error(scanner, "variant reparent error");
1847 }
8b9d5b5e 1848 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1849 {
1850 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1851 $$->u.variant.has_body = 1;
6dc474b8 1852 $$->u.variant.choice = $2->s;
5039b4cc 1853 if ($5 && set_parent_node($5, $$))
6dc474b8
MD
1854 reparent_error(scanner, "variant reparent error");
1855 }
8b9d5b5e 1856 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1857 {
1858 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1859 $$->u.variant.has_body = 1;
6dc474b8 1860 $$->u.variant.choice = $2->s;
5039b4cc 1861 if ($5 && set_parent_node($5, $$))
6dc474b8
MD
1862 reparent_error(scanner, "variant reparent error");
1863 }
8b9d5b5e 1864 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1865 {
1866 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1867 $$->u.variant.has_body = 1;
6dc474b8 1868 $$->u.variant.name = $1->s;
5039b4cc 1869 if ($3 && set_parent_node($3, $$))
6dc474b8
MD
1870 reparent_error(scanner, "variant reparent error");
1871 }
8b9d5b5e 1872 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1873 {
1874 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1875 $$->u.variant.has_body = 1;
6dc474b8
MD
1876 $$->u.variant.name = $1->s;
1877 $$->u.variant.choice = $3->s;
5039b4cc 1878 if ($6 && set_parent_node($6, $$))
6dc474b8
MD
1879 reparent_error(scanner, "variant reparent error");
1880 }
8b9d5b5e 1881 | IDENTIFIER LT IDENTIFIER GT
6dc474b8
MD
1882 {
1883 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1884 $$->u.variant.has_body = 0;
6dc474b8
MD
1885 $$->u.variant.name = $1->s;
1886 $$->u.variant.choice = $3->s;
1887 }
8b9d5b5e 1888 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1889 {
1890 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1891 $$->u.variant.has_body = 1;
6dc474b8
MD
1892 $$->u.variant.name = $1->s;
1893 $$->u.variant.choice = $3->s;
5039b4cc 1894 if ($6 && set_parent_node($6, $$))
6dc474b8
MD
1895 reparent_error(scanner, "variant reparent error");
1896 }
8b9d5b5e 1897 | IDENTIFIER LT ID_TYPE GT
6dc474b8
MD
1898 {
1899 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1900 $$->u.variant.has_body = 0;
6dc474b8
MD
1901 $$->u.variant.name = $1->s;
1902 $$->u.variant.choice = $3->s;
1903 }
8b9d5b5e 1904 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1905 {
1906 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1907 $$->u.variant.has_body = 1;
6dc474b8 1908 $$->u.variant.name = $1->s;
5039b4cc 1909 if ($3 && set_parent_node($3, $$))
6dc474b8
MD
1910 reparent_error(scanner, "variant reparent error");
1911 }
8b9d5b5e 1912 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1913 {
1914 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1915 $$->u.variant.has_body = 1;
6dc474b8
MD
1916 $$->u.variant.name = $1->s;
1917 $$->u.variant.choice = $3->s;
5039b4cc 1918 if ($6 && set_parent_node($6, $$))
6dc474b8
MD
1919 reparent_error(scanner, "variant reparent error");
1920 }
8b9d5b5e 1921 | ID_TYPE LT IDENTIFIER GT
6dc474b8
MD
1922 {
1923 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1924 $$->u.variant.has_body = 0;
6dc474b8
MD
1925 $$->u.variant.name = $1->s;
1926 $$->u.variant.choice = $3->s;
1927 }
8b9d5b5e 1928 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
6dc474b8
MD
1929 {
1930 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1931 $$->u.variant.has_body = 1;
6dc474b8
MD
1932 $$->u.variant.name = $1->s;
1933 $$->u.variant.choice = $3->s;
5039b4cc 1934 if ($6 && set_parent_node($6, $$))
6dc474b8
MD
1935 reparent_error(scanner, "variant reparent error");
1936 }
8b9d5b5e 1937 | ID_TYPE LT ID_TYPE GT
6dc474b8
MD
1938 {
1939 $$ = make_node(scanner, NODE_VARIANT);
1ee8e81d 1940 $$->u.variant.has_body = 0;
6dc474b8
MD
1941 $$->u.variant.name = $1->s;
1942 $$->u.variant.choice = $3->s;
1943 }
8b9d5b5e
MD
1944 ;
1945
1946variant_declaration_begin:
1947 LBRAC
fce8006d 1948 { push_scope(scanner); }
8b9d5b5e
MD
1949 ;
1950
1951variant_declaration_end:
1952 RBRAC
fce8006d 1953 { pop_scope(scanner); }
8b9d5b5e
MD
1954 ;
1955
8b9d5b5e
MD
1956enum_type_specifier:
1957 LBRAC enumerator_list RBRAC
6dc474b8
MD
1958 {
1959 $$ = make_node(scanner, NODE_ENUM);
add40b62 1960 $$->u._enum.has_body = 1;
3122e6f0 1961 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 1962 }
0fbb34a5 1963 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
6dc474b8
MD
1964 {
1965 $$ = make_node(scanner, NODE_ENUM);
add40b62 1966 $$->u._enum.has_body = 1;
3e11b713 1967 ($$)->u._enum.container_type = $2;
3122e6f0 1968 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 1969 }
8b9d5b5e 1970 | IDENTIFIER LBRAC enumerator_list RBRAC
6dc474b8
MD
1971 {
1972 $$ = make_node(scanner, NODE_ENUM);
add40b62 1973 $$->u._enum.has_body = 1;
6dc474b8 1974 $$->u._enum.enum_id = $1->s;
3122e6f0 1975 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 1976 }
0fbb34a5 1977 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
6dc474b8
MD
1978 {
1979 $$ = make_node(scanner, NODE_ENUM);
add40b62 1980 $$->u._enum.has_body = 1;
6dc474b8 1981 $$->u._enum.enum_id = $1->s;
3e11b713 1982 ($$)->u._enum.container_type = $3;
3122e6f0 1983 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 1984 }
8b9d5b5e 1985 | ID_TYPE LBRAC enumerator_list RBRAC
6dc474b8
MD
1986 {
1987 $$ = make_node(scanner, NODE_ENUM);
add40b62 1988 $$->u._enum.has_body = 1;
6dc474b8 1989 $$->u._enum.enum_id = $1->s;
3122e6f0 1990 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 1991 }
0fbb34a5 1992 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
6dc474b8
MD
1993 {
1994 $$ = make_node(scanner, NODE_ENUM);
add40b62 1995 $$->u._enum.has_body = 1;
6dc474b8 1996 $$->u._enum.enum_id = $1->s;
3e11b713 1997 ($$)->u._enum.container_type = $3;
3122e6f0 1998 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 1999 }
8b9d5b5e 2000 | LBRAC enumerator_list COMMA RBRAC
6dc474b8
MD
2001 {
2002 $$ = make_node(scanner, NODE_ENUM);
add40b62 2003 $$->u._enum.has_body = 1;
3122e6f0 2004 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2005 }
0fbb34a5 2006 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
6dc474b8
MD
2007 {
2008 $$ = make_node(scanner, NODE_ENUM);
add40b62 2009 $$->u._enum.has_body = 1;
3e11b713 2010 ($$)->u._enum.container_type = $2;
3122e6f0 2011 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2012 }
8b9d5b5e 2013 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
6dc474b8
MD
2014 {
2015 $$ = make_node(scanner, NODE_ENUM);
add40b62 2016 $$->u._enum.has_body = 1;
6dc474b8 2017 $$->u._enum.enum_id = $1->s;
3122e6f0 2018 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2019 }
0fbb34a5 2020 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
6dc474b8
MD
2021 {
2022 $$ = make_node(scanner, NODE_ENUM);
add40b62 2023 $$->u._enum.has_body = 1;
6dc474b8 2024 $$->u._enum.enum_id = $1->s;
3e11b713 2025 ($$)->u._enum.container_type = $3;
3122e6f0 2026 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2027 }
8b9d5b5e 2028 | IDENTIFIER
6dc474b8
MD
2029 {
2030 $$ = make_node(scanner, NODE_ENUM);
add40b62 2031 $$->u._enum.has_body = 0;
6dc474b8
MD
2032 $$->u._enum.enum_id = $1->s;
2033 }
8b9d5b5e 2034 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
6dc474b8
MD
2035 {
2036 $$ = make_node(scanner, NODE_ENUM);
add40b62 2037 $$->u._enum.has_body = 1;
6dc474b8 2038 $$->u._enum.enum_id = $1->s;
3122e6f0 2039 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2040 }
0fbb34a5 2041 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
6dc474b8
MD
2042 {
2043 $$ = make_node(scanner, NODE_ENUM);
add40b62 2044 $$->u._enum.has_body = 1;
6dc474b8 2045 $$->u._enum.enum_id = $1->s;
3e11b713 2046 ($$)->u._enum.container_type = $3;
3122e6f0 2047 _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
6dc474b8 2048 }
8b9d5b5e 2049 | ID_TYPE
6dc474b8
MD
2050 {
2051 $$ = make_node(scanner, NODE_ENUM);
add40b62 2052 $$->u._enum.has_body = 0;
6dc474b8
MD
2053 $$->u._enum.enum_id = $1->s;
2054 }
8b9d5b5e
MD
2055 ;
2056
2057struct_or_variant_declaration_list:
2058 /* empty */
6dc474b8 2059 { $$ = NULL; }
8b9d5b5e 2060 | struct_or_variant_declaration_list struct_or_variant_declaration
6dc474b8
MD
2061 {
2062 if ($1) {
2063 $$ = $1;
3122e6f0 2064 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
6dc474b8
MD
2065 } else {
2066 $$ = $2;
3122e6f0 2067 bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
6dc474b8
MD
2068 }
2069 }
8b9d5b5e
MD
2070 ;
2071
2072struct_or_variant_declaration:
1ee8e81d 2073 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
6dc474b8 2074 {
3e11b713
MD
2075 struct ctf_node *list;
2076
2077 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
3122e6f0 2078 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
6dc474b8 2079 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
3e11b713 2080 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
3122e6f0 2081 _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
6dc474b8 2082 }
1ee8e81d 2083 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
6dc474b8 2084 {
3e11b713
MD
2085 struct ctf_node *list;
2086
6dc474b8 2087 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713
MD
2088 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2089 $$->u._typedef.type_specifier_list = list;
3122e6f0
JD
2090 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2091 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2092 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 2093 }
1ee8e81d 2094 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
6dc474b8 2095 {
3e11b713
MD
2096 struct ctf_node *list;
2097
6dc474b8 2098 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713
MD
2099 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2100 $$->u._typedef.type_specifier_list = list;
3122e6f0
JD
2101 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2102 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 2103 }
1ee8e81d 2104 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
6dc474b8 2105 {
3e11b713
MD
2106 struct ctf_node *list;
2107
2108 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
3122e6f0 2109 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
6dc474b8 2110 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713 2111 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
3122e6f0 2112 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 2113 }
a030d084 2114 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
6dc474b8 2115 {
3e11b713
MD
2116 struct ctf_node *list;
2117
6dc474b8
MD
2118 $$ = make_node(scanner, NODE_TYPEALIAS);
2119 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2120 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
3e11b713
MD
2121
2122 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2123 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
3122e6f0
JD
2124 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2125 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
3e11b713
MD
2126
2127 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2128 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
3122e6f0
JD
2129 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2130 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
6dc474b8 2131 }
8b9d5b5e
MD
2132 ;
2133
1ee8e81d 2134alias_declaration_specifiers:
8b9d5b5e 2135 CONST
6dc474b8 2136 {
3e11b713
MD
2137 struct ctf_node *node;
2138
2139 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2140 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2141 node->u.type_specifier.type = TYPESPEC_CONST;
3122e6f0 2142 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
6dc474b8 2143 }
8b9d5b5e 2144 | type_specifier
3e11b713
MD
2145 {
2146 struct ctf_node *node;
2147
2148 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2149 node = $1;
3122e6f0 2150 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
3e11b713 2151 }
1ee8e81d
MD
2152 | IDENTIFIER
2153 {
3e11b713
MD
2154 struct ctf_node *node;
2155
1ee8e81d 2156 add_type(scanner, $1);
3e11b713
MD
2157 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2158 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2159 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2160 node->u.type_specifier.id_type = yylval.gs->s;
3122e6f0 2161 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1ee8e81d
MD
2162 }
2163 | alias_declaration_specifiers CONST
6dc474b8
MD
2164 {
2165 struct ctf_node *node;
2166
2167 $$ = $1;
2168 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2169 node->u.type_specifier.type = TYPESPEC_CONST;
3122e6f0 2170 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
6dc474b8 2171 }
1ee8e81d 2172 | alias_declaration_specifiers type_specifier
6dc474b8
MD
2173 {
2174 $$ = $1;
3122e6f0 2175 bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
6dc474b8 2176 }
1ee8e81d
MD
2177 | alias_declaration_specifiers IDENTIFIER
2178 {
2179 struct ctf_node *node;
2180
2181 add_type(scanner, $2);
2182 $$ = $1;
2183 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2184 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2185 node->u.type_specifier.id_type = yylval.gs->s;
3122e6f0 2186 bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1ee8e81d 2187 }
8b9d5b5e
MD
2188 ;
2189
2190struct_or_variant_declarator_list:
2191 struct_or_variant_declarator
0009a725 2192 { $$ = $1; }
8b9d5b5e 2193 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
6dc474b8
MD
2194 {
2195 $$ = $1;
3122e6f0 2196 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
6dc474b8 2197 }
8b9d5b5e
MD
2198 ;
2199
2200struct_or_variant_declarator:
2201 declarator
6dc474b8 2202 { $$ = $1; }
8b9d5b5e 2203 | COLON unary_expression
6dc474b8 2204 { $$ = $2; }
8b9d5b5e 2205 | declarator COLON unary_expression
6dc474b8
MD
2206 {
2207 $$ = $1;
48a01768 2208 if (set_parent_node($3, $1))
6dc474b8
MD
2209 reparent_error(scanner, "struct_or_variant_declarator");
2210 }
8b9d5b5e
MD
2211 ;
2212
2213enumerator_list:
2214 enumerator
0009a725 2215 { $$ = $1; }
8b9d5b5e 2216 | enumerator_list COMMA enumerator
6dc474b8
MD
2217 {
2218 $$ = $1;
3122e6f0 2219 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
6dc474b8 2220 }
8b9d5b5e
MD
2221 ;
2222
2223enumerator:
2224 IDENTIFIER
6dc474b8
MD
2225 {
2226 $$ = make_node(scanner, NODE_ENUMERATOR);
2227 $$->u.enumerator.id = $1->s;
2228 }
8b9d5b5e 2229 | ID_TYPE
6dc474b8
MD
2230 {
2231 $$ = make_node(scanner, NODE_ENUMERATOR);
2232 $$->u.enumerator.id = $1->s;
2233 }
8b9d5b5e 2234 | keywords
6dc474b8
MD
2235 {
2236 $$ = make_node(scanner, NODE_ENUMERATOR);
2237 $$->u.enumerator.id = $1->s;
2238 }
d876a5ba 2239 | STRING_LITERAL
6dc474b8
MD
2240 {
2241 $$ = make_node(scanner, NODE_ENUMERATOR);
d876a5ba 2242 $$->u.enumerator.id = $1->s;
6dc474b8 2243 }
8b9d5b5e 2244 | IDENTIFIER EQUAL unary_expression_or_range
6dc474b8
MD
2245 {
2246 $$ = make_node(scanner, NODE_ENUMERATOR);
2247 $$->u.enumerator.id = $1->s;
3122e6f0 2248 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
6dc474b8 2249 }
8b9d5b5e 2250 | ID_TYPE EQUAL unary_expression_or_range
6dc474b8
MD
2251 {
2252 $$ = make_node(scanner, NODE_ENUMERATOR);
2253 $$->u.enumerator.id = $1->s;
3122e6f0 2254 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
6dc474b8 2255 }
8b9d5b5e 2256 | keywords EQUAL unary_expression_or_range
6dc474b8
MD
2257 {
2258 $$ = make_node(scanner, NODE_ENUMERATOR);
2259 $$->u.enumerator.id = $1->s;
3122e6f0 2260 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
6dc474b8 2261 }
d876a5ba 2262 | STRING_LITERAL EQUAL unary_expression_or_range
6dc474b8
MD
2263 {
2264 $$ = make_node(scanner, NODE_ENUMERATOR);
d876a5ba
EB
2265 $$->u.enumerator.id = $1->s;
2266 bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
6dc474b8 2267 }
8b9d5b5e
MD
2268 ;
2269
2270abstract_declarator_list:
2271 abstract_declarator
0009a725 2272 { $$ = $1; }
8b9d5b5e 2273 | abstract_declarator_list COMMA abstract_declarator
6dc474b8
MD
2274 {
2275 $$ = $1;
3122e6f0 2276 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
6dc474b8 2277 }
8b9d5b5e
MD
2278 ;
2279
2280abstract_declarator:
2281 direct_abstract_declarator
6dc474b8 2282 { $$ = $1; }
8b9d5b5e 2283 | pointer direct_abstract_declarator
6dc474b8
MD
2284 {
2285 $$ = $2;
3122e6f0 2286 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
6dc474b8 2287 }
8b9d5b5e
MD
2288 ;
2289
2290direct_abstract_declarator:
2291 /* empty */
6dc474b8
MD
2292 {
2293 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2294 $$->u.type_declarator.type = TYPEDEC_ID;
2295 /* id is NULL */
2296 }
8b9d5b5e 2297 | IDENTIFIER
6dc474b8
MD
2298 {
2299 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2300 $$->u.type_declarator.type = TYPEDEC_ID;
2301 $$->u.type_declarator.u.id = $1->s;
2302 }
8b9d5b5e 2303 | LPAREN abstract_declarator RPAREN
6dc474b8
MD
2304 {
2305 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2306 $$->u.type_declarator.type = TYPEDEC_NESTED;
2307 $$->u.type_declarator.u.nested.type_declarator = $2;
2308 }
98df1c9f 2309 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
6dc474b8
MD
2310 {
2311 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2312 $$->u.type_declarator.type = TYPEDEC_NESTED;
2313 $$->u.type_declarator.u.nested.type_declarator = $1;
3122e6f0
JD
2314 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2315 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
6dc474b8 2316 }
8b9d5b5e 2317 | direct_abstract_declarator LSBRAC RSBRAC
6dc474b8
MD
2318 {
2319 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2320 $$->u.type_declarator.type = TYPEDEC_NESTED;
2321 $$->u.type_declarator.u.nested.type_declarator = $1;
2322 $$->u.type_declarator.u.nested.abstract_array = 1;
2323 }
8b9d5b5e
MD
2324 ;
2325
e0c14875
MD
2326alias_abstract_declarator_list:
2327 alias_abstract_declarator
6dc474b8 2328 { $$ = $1; }
e0c14875
MD
2329 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2330 {
2331 $$ = $1;
3122e6f0 2332 bt_list_add_tail(&($3)->siblings, &($$)->tmp_head);
e0c14875
MD
2333 }
2334 ;
2335
2336alias_abstract_declarator:
2337 direct_alias_abstract_declarator
2338 { $$ = $1; }
2339 | pointer direct_alias_abstract_declarator
6dc474b8
MD
2340 {
2341 $$ = $2;
3122e6f0 2342 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
6dc474b8 2343 }
8b9d5b5e
MD
2344 ;
2345
e0c14875
MD
2346direct_alias_abstract_declarator:
2347 /* empty */
6dc474b8
MD
2348 {
2349 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
e0c14875
MD
2350 $$->u.type_declarator.type = TYPEDEC_ID;
2351 /* id is NULL */
6dc474b8 2352 }
e0c14875 2353 | LPAREN alias_abstract_declarator RPAREN
6dc474b8
MD
2354 {
2355 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2356 $$->u.type_declarator.type = TYPEDEC_NESTED;
2357 $$->u.type_declarator.u.nested.type_declarator = $2;
2358 }
98df1c9f 2359 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
6dc474b8
MD
2360 {
2361 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2362 $$->u.type_declarator.type = TYPEDEC_NESTED;
2363 $$->u.type_declarator.u.nested.type_declarator = $1;
3122e6f0
JD
2364 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2365 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
6dc474b8 2366 }
e0c14875
MD
2367 | direct_alias_abstract_declarator LSBRAC RSBRAC
2368 {
2369 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2370 $$->u.type_declarator.type = TYPEDEC_NESTED;
2371 $$->u.type_declarator.u.nested.type_declarator = $1;
2372 $$->u.type_declarator.u.nested.abstract_array = 1;
2373 }
8b9d5b5e
MD
2374 ;
2375
e0c14875
MD
2376declarator:
2377 direct_declarator
6dc474b8 2378 { $$ = $1; }
e0c14875 2379 | pointer direct_declarator
6dc474b8
MD
2380 {
2381 $$ = $2;
3122e6f0 2382 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
6dc474b8 2383 }
8b9d5b5e
MD
2384 ;
2385
e0c14875 2386direct_declarator:
8b9d5b5e 2387 IDENTIFIER
6dc474b8 2388 {
6dc474b8
MD
2389 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2390 $$->u.type_declarator.type = TYPEDEC_ID;
2391 $$->u.type_declarator.u.id = $1->s;
2392 }
e0c14875 2393 | LPAREN declarator RPAREN
6dc474b8
MD
2394 {
2395 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2396 $$->u.type_declarator.type = TYPEDEC_NESTED;
2397 $$->u.type_declarator.u.nested.type_declarator = $2;
2398 }
98df1c9f 2399 | direct_declarator LSBRAC unary_expression RSBRAC
6dc474b8
MD
2400 {
2401 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2402 $$->u.type_declarator.type = TYPEDEC_NESTED;
2403 $$->u.type_declarator.u.nested.type_declarator = $1;
3122e6f0
JD
2404 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2405 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
6dc474b8 2406 }
8b9d5b5e
MD
2407 ;
2408
e0c14875
MD
2409type_declarator:
2410 direct_type_declarator
6dc474b8 2411 { $$ = $1; }
e0c14875 2412 | pointer direct_type_declarator
6dc474b8
MD
2413 {
2414 $$ = $2;
3122e6f0 2415 bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
6dc474b8 2416 }
8b9d5b5e
MD
2417 ;
2418
e0c14875
MD
2419direct_type_declarator:
2420 IDENTIFIER
6dc474b8
MD
2421 {
2422 add_type(scanner, $1);
2423 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2424 $$->u.type_declarator.type = TYPEDEC_ID;
2425 $$->u.type_declarator.u.id = $1->s;
2426 }
e0c14875 2427 | LPAREN type_declarator RPAREN
6dc474b8
MD
2428 {
2429 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2430 $$->u.type_declarator.type = TYPEDEC_NESTED;
2431 $$->u.type_declarator.u.nested.type_declarator = $2;
2432 }
98df1c9f 2433 | direct_type_declarator LSBRAC unary_expression RSBRAC
6dc474b8
MD
2434 {
2435 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2436 $$->u.type_declarator.type = TYPEDEC_NESTED;
2437 $$->u.type_declarator.u.nested.type_declarator = $1;
3122e6f0
JD
2438 BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2439 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
6dc474b8 2440 }
8b9d5b5e
MD
2441 ;
2442
2443pointer:
2444 STAR
48a01768
MD
2445 {
2446 $$ = make_node(scanner, NODE_POINTER);
48a01768 2447 }
8b9d5b5e 2448 | STAR pointer
6dc474b8
MD
2449 {
2450 $$ = make_node(scanner, NODE_POINTER);
3122e6f0 2451 bt_list_splice(&($2)->tmp_head, &($$)->tmp_head);
6dc474b8 2452 }
8b9d5b5e 2453 | STAR type_qualifier_list pointer
6dc474b8
MD
2454 {
2455 $$ = make_node(scanner, NODE_POINTER);
2456 $$->u.pointer.const_qualifier = 1;
3122e6f0 2457 bt_list_splice(&($3)->tmp_head, &($$)->tmp_head);
6dc474b8 2458 }
8b9d5b5e
MD
2459 ;
2460
2461type_qualifier_list:
6dc474b8 2462 /* pointer assumes only const type qualifier */
8b9d5b5e
MD
2463 CONST
2464 | type_qualifier_list CONST
2465 ;
2466
2467/* 2.3: CTF-specific declarations */
2468
2469ctf_assignment_expression_list:
2470 ctf_assignment_expression SEMICOLON
0009a725 2471 { $$ = $1; }
8b9d5b5e 2472 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
6dc474b8
MD
2473 {
2474 $$ = $1;
3122e6f0 2475 bt_list_add_tail(&($2)->siblings, &($$)->tmp_head);
6dc474b8 2476 }
8b9d5b5e
MD
2477 ;
2478
2479ctf_assignment_expression:
2480 unary_expression EQUAL unary_expression
02b234c4 2481 {
6dc474b8
MD
2482 /*
2483 * Because we have left and right, cannot use
48a01768 2484 * set_parent_node.
6dc474b8 2485 */
02b234c4 2486 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
3122e6f0 2487 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
6dc474b8
MD
2488 if ($1->u.unary_expression.type != UNARY_STRING)
2489 reparent_error(scanner, "ctf_assignment_expression left expects string");
3122e6f0 2490 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
02b234c4 2491 }
427c09b7 2492 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
6dc474b8
MD
2493 {
2494 /*
2495 * Because we have left and right, cannot use
48a01768 2496 * set_parent_node.
6dc474b8
MD
2497 */
2498 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
3122e6f0 2499 _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
6dc474b8
MD
2500 if ($1->u.unary_expression.type != UNARY_STRING)
2501 reparent_error(scanner, "ctf_assignment_expression left expects string");
3122e6f0 2502 bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
6dc474b8 2503 }
8b9d5b5e 2504 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
6dc474b8 2505 {
3e11b713
MD
2506 struct ctf_node *list;
2507
2508 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
3122e6f0
JD
2509 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2510 _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
6dc474b8 2511 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713 2512 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
3122e6f0 2513 _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 2514 }
8b9d5b5e 2515 | TYPEDEF declaration_specifiers type_declarator_list
6dc474b8 2516 {
3e11b713
MD
2517 struct ctf_node *list;
2518
6dc474b8 2519 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713
MD
2520 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2521 $$->u._typedef.type_specifier_list = list;
3122e6f0
JD
2522 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2523 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 2524 }
8b9d5b5e 2525 | declaration_specifiers TYPEDEF type_declarator_list
6dc474b8 2526 {
3e11b713
MD
2527 struct ctf_node *list;
2528
2529 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
3122e6f0 2530 _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
6dc474b8 2531 $$ = make_node(scanner, NODE_TYPEDEF);
3e11b713 2532 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
3122e6f0 2533 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
6dc474b8 2534 }
a030d084 2535 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
6dc474b8 2536 {
3e11b713
MD
2537 struct ctf_node *list;
2538
6dc474b8
MD
2539 $$ = make_node(scanner, NODE_TYPEALIAS);
2540 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2541 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
3e11b713
MD
2542
2543 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2544 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
3122e6f0
JD
2545 _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2546 _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
3e11b713
MD
2547
2548 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2549 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
3122e6f0
JD
2550 _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2551 _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
6dc474b8 2552 }
8b9d5b5e 2553 ;
This page took 0.1664 seconds and 4 git commands to generate.