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