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