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