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