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