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