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