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