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