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