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