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