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