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