757af5d53f74ddd81ecfe634f8f6fdedb249fddb
[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 | ENV
1020 { $$ = yylval.gs; }
1021 | TRACE
1022 { $$ = yylval.gs; }
1023 | CLOCK
1024 { $$ = yylval.gs; }
1025 | TOK_ALIGN
1026 { $$ = yylval.gs; }
1027 ;
1028
1029 /* 1.5 Constants */
1030
1031 c_char_sequence:
1032 c_char
1033 { $$ = $1; }
1034 | c_char_sequence c_char
1035 { $$ = gc_string_append(scanner, $1, $2); }
1036 ;
1037
1038 c_char:
1039 CHAR_STRING_TOKEN
1040 { $$ = yylval.gs; }
1041 | ESCSEQ
1042 {
1043 reparent_error(scanner, "escape sequences not supported yet");
1044 }
1045 ;
1046
1047 /* 1.6 String literals */
1048
1049 s_char_sequence:
1050 s_char
1051 { $$ = $1; }
1052 | s_char_sequence s_char
1053 { $$ = gc_string_append(scanner, $1, $2); }
1054 ;
1055
1056 s_char:
1057 CHAR_STRING_TOKEN
1058 { $$ = yylval.gs; }
1059 | ESCSEQ
1060 {
1061 reparent_error(scanner, "escape sequences not supported yet");
1062 }
1063 ;
1064
1065 /* 2: Phrase structure grammar */
1066
1067 postfix_expression:
1068 IDENTIFIER
1069 {
1070 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1071 $$->u.unary_expression.type = UNARY_STRING;
1072 $$->u.unary_expression.u.string = yylval.gs->s;
1073 }
1074 | ID_TYPE
1075 {
1076 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1077 $$->u.unary_expression.type = UNARY_STRING;
1078 $$->u.unary_expression.u.string = yylval.gs->s;
1079 }
1080 | keywords
1081 {
1082 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1083 $$->u.unary_expression.type = UNARY_STRING;
1084 $$->u.unary_expression.u.string = yylval.gs->s;
1085 }
1086 | DECIMAL_CONSTANT
1087 {
1088 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1089 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1090 sscanf(yylval.gs->s, "%" PRIu64,
1091 &$$->u.unary_expression.u.unsigned_constant);
1092 }
1093 | OCTAL_CONSTANT
1094 {
1095 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1096 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1097 sscanf(yylval.gs->s, "0%" PRIo64,
1098 &$$->u.unary_expression.u.unsigned_constant);
1099 }
1100 | HEXADECIMAL_CONSTANT
1101 {
1102 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1103 $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
1104 sscanf(yylval.gs->s, "0x%" PRIx64,
1105 &$$->u.unary_expression.u.unsigned_constant);
1106 }
1107 | STRING_LITERAL_START DQUOTE
1108 {
1109 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1110 $$->u.unary_expression.type = UNARY_STRING;
1111 $$->u.unary_expression.u.string = "";
1112 }
1113 | STRING_LITERAL_START s_char_sequence DQUOTE
1114 {
1115 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1116 $$->u.unary_expression.type = UNARY_STRING;
1117 $$->u.unary_expression.u.string = $2->s;
1118 }
1119 | CHARACTER_CONSTANT_START c_char_sequence SQUOTE
1120 {
1121 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1122 $$->u.unary_expression.type = UNARY_STRING;
1123 $$->u.unary_expression.u.string = $2->s;
1124 }
1125 | LPAREN unary_expression RPAREN
1126 {
1127 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1128 $$->u.unary_expression.type = UNARY_NESTED;
1129 $$->u.unary_expression.u.nested_exp = $2;
1130 }
1131 | postfix_expression LSBRAC unary_expression RSBRAC
1132 {
1133 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1134 $$->u.unary_expression.type = UNARY_SBRAC;
1135 $$->u.unary_expression.u.sbrac_exp = $3;
1136 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1137 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1138 }
1139 | postfix_expression DOT IDENTIFIER
1140 {
1141 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1142 $$->u.unary_expression.type = UNARY_STRING;
1143 $$->u.unary_expression.u.string = yylval.gs->s;
1144 $$->u.unary_expression.link = UNARY_DOTLINK;
1145 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1146 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1147 }
1148 | postfix_expression DOT ID_TYPE
1149 {
1150 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1151 $$->u.unary_expression.type = UNARY_STRING;
1152 $$->u.unary_expression.u.string = yylval.gs->s;
1153 $$->u.unary_expression.link = UNARY_DOTLINK;
1154 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1155 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1156 }
1157 | postfix_expression RARROW IDENTIFIER
1158 {
1159 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1160 $$->u.unary_expression.type = UNARY_STRING;
1161 $$->u.unary_expression.u.string = yylval.gs->s;
1162 $$->u.unary_expression.link = UNARY_ARROWLINK;
1163 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1164 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1165 }
1166 | postfix_expression RARROW ID_TYPE
1167 {
1168 $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
1169 $$->u.unary_expression.type = UNARY_STRING;
1170 $$->u.unary_expression.u.string = yylval.gs->s;
1171 $$->u.unary_expression.link = UNARY_ARROWLINK;
1172 cds_list_splice(&($1)->tmp_head, &($$)->tmp_head);
1173 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1174 }
1175 ;
1176
1177 unary_expression:
1178 postfix_expression
1179 { $$ = $1; }
1180 | PLUS postfix_expression
1181 { $$ = $2; }
1182 | MINUS postfix_expression
1183 {
1184 $$ = $2;
1185 if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
1186 && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
1187 reparent_error(scanner, "expecting numeric constant");
1188
1189 if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
1190 $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
1191 $$->u.unary_expression.u.signed_constant =
1192 -($$->u.unary_expression.u.unsigned_constant);
1193 } else {
1194 $$->u.unary_expression.u.signed_constant =
1195 -($$->u.unary_expression.u.signed_constant);
1196 }
1197 }
1198 ;
1199
1200 unary_expression_or_range:
1201 unary_expression DOTDOTDOT unary_expression
1202 {
1203 $$ = $1;
1204 _cds_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head);
1205 $3->u.unary_expression.link = UNARY_DOTDOTDOT;
1206 }
1207 | unary_expression
1208 { $$ = $1; }
1209 ;
1210
1211 /* 2.2: Declarations */
1212
1213 declaration:
1214 declaration_specifiers SEMICOLON
1215 { $$ = $1; }
1216 | event_declaration
1217 { $$ = $1; }
1218 | stream_declaration
1219 { $$ = $1; }
1220 | env_declaration
1221 { $$ = $1; }
1222 | trace_declaration
1223 { $$ = $1; }
1224 | clock_declaration
1225 { $$ = $1; }
1226 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1227 {
1228 struct ctf_node *list;
1229
1230 $$ = make_node(scanner, NODE_TYPEDEF);
1231 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1232 $$->u._typedef.type_specifier_list = list;
1233 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1234 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1235 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1236 }
1237 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1238 {
1239 struct ctf_node *list;
1240
1241 $$ = make_node(scanner, NODE_TYPEDEF);
1242 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1243 $$->u._typedef.type_specifier_list = list;
1244 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1245 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1246 }
1247 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
1248 {
1249 struct ctf_node *list;
1250
1251 $$ = make_node(scanner, NODE_TYPEDEF);
1252 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1253 $$->u._typedef.type_specifier_list = list;
1254 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1255 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
1256 }
1257 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
1258 {
1259 struct ctf_node *list;
1260
1261 $$ = make_node(scanner, NODE_TYPEALIAS);
1262 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
1263 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
1264
1265 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1266 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
1267 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1268 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
1269
1270 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1271 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
1272 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1273 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
1274 }
1275 ;
1276
1277 event_declaration:
1278 event_declaration_begin event_declaration_end
1279 {
1280 $$ = make_node(scanner, NODE_EVENT);
1281 }
1282 | event_declaration_begin ctf_assignment_expression_list event_declaration_end
1283 {
1284 $$ = make_node(scanner, NODE_EVENT);
1285 if (set_parent_node($2, $$))
1286 reparent_error(scanner, "event_declaration");
1287 }
1288 ;
1289
1290 event_declaration_begin:
1291 EVENT LBRAC
1292 { push_scope(scanner); }
1293 ;
1294
1295 event_declaration_end:
1296 RBRAC SEMICOLON
1297 { pop_scope(scanner); }
1298 ;
1299
1300
1301 stream_declaration:
1302 stream_declaration_begin stream_declaration_end
1303 {
1304 $$ = make_node(scanner, NODE_STREAM);
1305 }
1306 | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
1307 {
1308 $$ = make_node(scanner, NODE_STREAM);
1309 if (set_parent_node($2, $$))
1310 reparent_error(scanner, "stream_declaration");
1311 }
1312 ;
1313
1314 stream_declaration_begin:
1315 STREAM LBRAC
1316 { push_scope(scanner); }
1317 ;
1318
1319 stream_declaration_end:
1320 RBRAC SEMICOLON
1321 { pop_scope(scanner); }
1322 ;
1323
1324 env_declaration:
1325 env_declaration_begin env_declaration_end
1326 {
1327 $$ = make_node(scanner, NODE_ENV);
1328 }
1329 | env_declaration_begin ctf_assignment_expression_list env_declaration_end
1330 {
1331 $$ = make_node(scanner, NODE_ENV);
1332 if (set_parent_node($2, $$))
1333 reparent_error(scanner, "env declaration");
1334 }
1335 ;
1336
1337 env_declaration_begin:
1338 ENV LBRAC
1339 { push_scope(scanner); }
1340 ;
1341
1342 env_declaration_end:
1343 RBRAC SEMICOLON
1344 { pop_scope(scanner); }
1345 ;
1346
1347 trace_declaration:
1348 trace_declaration_begin trace_declaration_end
1349 {
1350 $$ = make_node(scanner, NODE_TRACE);
1351 }
1352 | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
1353 {
1354 $$ = make_node(scanner, NODE_TRACE);
1355 if (set_parent_node($2, $$))
1356 reparent_error(scanner, "trace_declaration");
1357 }
1358 ;
1359
1360 trace_declaration_begin:
1361 TRACE LBRAC
1362 { push_scope(scanner); }
1363 ;
1364
1365 trace_declaration_end:
1366 RBRAC SEMICOLON
1367 { pop_scope(scanner); }
1368 ;
1369
1370 clock_declaration:
1371 CLOCK clock_declaration_begin clock_declaration_end
1372 {
1373 $$ = make_node(scanner, NODE_CLOCK);
1374 }
1375 | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end
1376 {
1377 $$ = make_node(scanner, NODE_CLOCK);
1378 if (set_parent_node($3, $$))
1379 reparent_error(scanner, "trace_declaration");
1380 }
1381 ;
1382
1383 clock_declaration_begin:
1384 LBRAC
1385 { push_scope(scanner); }
1386 ;
1387
1388 clock_declaration_end:
1389 RBRAC SEMICOLON
1390 { pop_scope(scanner); }
1391 ;
1392
1393 integer_declaration_specifiers:
1394 CONST
1395 {
1396 struct ctf_node *node;
1397
1398 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1399 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1400 node->u.type_specifier.type = TYPESPEC_CONST;
1401 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1402 }
1403 | integer_type_specifier
1404 {
1405 struct ctf_node *node;
1406
1407 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1408 node = $1;
1409 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1410 }
1411 | integer_declaration_specifiers CONST
1412 {
1413 struct ctf_node *node;
1414
1415 $$ = $1;
1416 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1417 node->u.type_specifier.type = TYPESPEC_CONST;
1418 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1419 }
1420 | integer_declaration_specifiers integer_type_specifier
1421 {
1422 $$ = $1;
1423 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1424 }
1425 ;
1426
1427 declaration_specifiers:
1428 CONST
1429 {
1430 struct ctf_node *node;
1431
1432 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1433 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1434 node->u.type_specifier.type = TYPESPEC_CONST;
1435 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1436 }
1437 | type_specifier
1438 {
1439 struct ctf_node *node;
1440
1441 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1442 node = $1;
1443 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1444 }
1445 | declaration_specifiers CONST
1446 {
1447 struct ctf_node *node;
1448
1449 $$ = $1;
1450 node = make_node(scanner, NODE_TYPE_SPECIFIER);
1451 node->u.type_specifier.type = TYPESPEC_CONST;
1452 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
1453 }
1454 | declaration_specifiers type_specifier
1455 {
1456 $$ = $1;
1457 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
1458 }
1459 ;
1460
1461 type_declarator_list:
1462 type_declarator
1463 { $$ = $1; }
1464 | type_declarator_list COMMA type_declarator
1465 {
1466 $$ = $1;
1467 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
1468 }
1469 ;
1470
1471 integer_type_specifier:
1472 CHAR
1473 {
1474 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1475 $$->u.type_specifier.type = TYPESPEC_CHAR;
1476 }
1477 | SHORT
1478 {
1479 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1480 $$->u.type_specifier.type = TYPESPEC_SHORT;
1481 }
1482 | INT
1483 {
1484 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1485 $$->u.type_specifier.type = TYPESPEC_INT;
1486 }
1487 | LONG
1488 {
1489 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1490 $$->u.type_specifier.type = TYPESPEC_LONG;
1491 }
1492 | SIGNED
1493 {
1494 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1495 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1496 }
1497 | UNSIGNED
1498 {
1499 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1500 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1501 }
1502 | _BOOL
1503 {
1504 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1505 $$->u.type_specifier.type = TYPESPEC_BOOL;
1506 }
1507 | ID_TYPE
1508 {
1509 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1510 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1511 $$->u.type_specifier.id_type = yylval.gs->s;
1512 }
1513 | INTEGER LBRAC RBRAC
1514 {
1515 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1516 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1517 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1518 }
1519 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1520 {
1521 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1522 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1523 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1524 if (set_parent_node($3, $$->u.type_specifier.node))
1525 reparent_error(scanner, "integer reparent error");
1526 }
1527 ;
1528
1529 type_specifier:
1530 VOID
1531 {
1532 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1533 $$->u.type_specifier.type = TYPESPEC_VOID;
1534 }
1535 | CHAR
1536 {
1537 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1538 $$->u.type_specifier.type = TYPESPEC_CHAR;
1539 }
1540 | SHORT
1541 {
1542 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1543 $$->u.type_specifier.type = TYPESPEC_SHORT;
1544 }
1545 | INT
1546 {
1547 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1548 $$->u.type_specifier.type = TYPESPEC_INT;
1549 }
1550 | LONG
1551 {
1552 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1553 $$->u.type_specifier.type = TYPESPEC_LONG;
1554 }
1555 | FLOAT
1556 {
1557 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1558 $$->u.type_specifier.type = TYPESPEC_FLOAT;
1559 }
1560 | DOUBLE
1561 {
1562 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1563 $$->u.type_specifier.type = TYPESPEC_DOUBLE;
1564 }
1565 | SIGNED
1566 {
1567 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1568 $$->u.type_specifier.type = TYPESPEC_SIGNED;
1569 }
1570 | UNSIGNED
1571 {
1572 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1573 $$->u.type_specifier.type = TYPESPEC_UNSIGNED;
1574 }
1575 | _BOOL
1576 {
1577 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1578 $$->u.type_specifier.type = TYPESPEC_BOOL;
1579 }
1580 | _COMPLEX
1581 {
1582 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1583 $$->u.type_specifier.type = TYPESPEC_COMPLEX;
1584 }
1585 | _IMAGINARY
1586 {
1587 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1588 $$->u.type_specifier.type = TYPESPEC_IMAGINARY;
1589 }
1590 | ID_TYPE
1591 {
1592 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1593 $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
1594 $$->u.type_specifier.id_type = yylval.gs->s;
1595 }
1596 | FLOATING_POINT LBRAC RBRAC
1597 {
1598 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1599 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1600 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1601 }
1602 | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
1603 {
1604 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1605 $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
1606 $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
1607 if (set_parent_node($3, $$->u.type_specifier.node))
1608 reparent_error(scanner, "floating point reparent error");
1609 }
1610 | INTEGER LBRAC RBRAC
1611 {
1612 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1613 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1614 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1615 }
1616 | INTEGER LBRAC ctf_assignment_expression_list RBRAC
1617 {
1618 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1619 $$->u.type_specifier.type = TYPESPEC_INTEGER;
1620 $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
1621 if (set_parent_node($3, $$->u.type_specifier.node))
1622 reparent_error(scanner, "integer reparent error");
1623 }
1624 | STRING
1625 {
1626 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1627 $$->u.type_specifier.type = TYPESPEC_STRING;
1628 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1629 }
1630 | STRING LBRAC RBRAC
1631 {
1632 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1633 $$->u.type_specifier.type = TYPESPEC_STRING;
1634 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1635 }
1636 | STRING LBRAC ctf_assignment_expression_list RBRAC
1637 {
1638 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1639 $$->u.type_specifier.type = TYPESPEC_STRING;
1640 $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
1641 if (set_parent_node($3, $$->u.type_specifier.node))
1642 reparent_error(scanner, "string reparent error");
1643 }
1644 | ENUM enum_type_specifier
1645 {
1646 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1647 $$->u.type_specifier.type = TYPESPEC_ENUM;
1648 $$->u.type_specifier.node = $2;
1649 }
1650 | VARIANT variant_type_specifier
1651 {
1652 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1653 $$->u.type_specifier.type = TYPESPEC_VARIANT;
1654 $$->u.type_specifier.node = $2;
1655 }
1656 | STRUCT struct_type_specifier
1657 {
1658 $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
1659 $$->u.type_specifier.type = TYPESPEC_STRUCT;
1660 $$->u.type_specifier.node = $2;
1661 }
1662 ;
1663
1664 struct_type_specifier:
1665 struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1666 {
1667 $$ = make_node(scanner, NODE_STRUCT);
1668 $$->u._struct.has_body = 1;
1669 if ($2 && set_parent_node($2, $$))
1670 reparent_error(scanner, "struct reparent error");
1671 }
1672 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1673 {
1674 $$ = make_node(scanner, NODE_STRUCT);
1675 $$->u._struct.has_body = 1;
1676 $$->u._struct.name = $1->s;
1677 if ($3 && set_parent_node($3, $$))
1678 reparent_error(scanner, "struct reparent error");
1679 }
1680 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end
1681 {
1682 $$ = make_node(scanner, NODE_STRUCT);
1683 $$->u._struct.has_body = 1;
1684 $$->u._struct.name = $1->s;
1685 if ($3 && set_parent_node($3, $$))
1686 reparent_error(scanner, "struct reparent error");
1687 }
1688 | IDENTIFIER
1689 {
1690 $$ = make_node(scanner, NODE_STRUCT);
1691 $$->u._struct.has_body = 0;
1692 $$->u._struct.name = $1->s;
1693 }
1694 | ID_TYPE
1695 {
1696 $$ = make_node(scanner, NODE_STRUCT);
1697 $$->u._struct.has_body = 0;
1698 $$->u._struct.name = $1->s;
1699 }
1700 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1701 {
1702 $$ = make_node(scanner, NODE_STRUCT);
1703 $$->u._struct.has_body = 1;
1704 cds_list_add_tail(&($6)->siblings, &$$->u._struct.min_align);
1705 if ($2 && set_parent_node($2, $$))
1706 reparent_error(scanner, "struct reparent error");
1707 }
1708 | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1709 {
1710 $$ = make_node(scanner, NODE_STRUCT);
1711 $$->u._struct.has_body = 1;
1712 $$->u._struct.name = $1->s;
1713 cds_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1714 if ($3 && set_parent_node($3, $$))
1715 reparent_error(scanner, "struct reparent error");
1716 }
1717 | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
1718 {
1719 $$ = make_node(scanner, NODE_STRUCT);
1720 $$->u._struct.has_body = 1;
1721 $$->u._struct.name = $1->s;
1722 cds_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
1723 if ($3 && set_parent_node($3, $$))
1724 reparent_error(scanner, "struct reparent error");
1725 }
1726 ;
1727
1728 struct_declaration_begin:
1729 LBRAC
1730 { push_scope(scanner); }
1731 ;
1732
1733 struct_declaration_end:
1734 RBRAC
1735 { pop_scope(scanner); }
1736 ;
1737
1738 variant_type_specifier:
1739 variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1740 {
1741 $$ = make_node(scanner, NODE_VARIANT);
1742 $$->u.variant.has_body = 1;
1743 if ($2 && set_parent_node($2, $$))
1744 reparent_error(scanner, "variant reparent error");
1745 }
1746 | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1747 {
1748 $$ = make_node(scanner, NODE_VARIANT);
1749 $$->u.variant.has_body = 1;
1750 $$->u.variant.choice = $2->s;
1751 if ($5 && set_parent_node($5, $$))
1752 reparent_error(scanner, "variant reparent error");
1753 }
1754 | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1755 {
1756 $$ = make_node(scanner, NODE_VARIANT);
1757 $$->u.variant.has_body = 1;
1758 $$->u.variant.choice = $2->s;
1759 if ($5 && set_parent_node($5, $$))
1760 reparent_error(scanner, "variant reparent error");
1761 }
1762 | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1763 {
1764 $$ = make_node(scanner, NODE_VARIANT);
1765 $$->u.variant.has_body = 1;
1766 $$->u.variant.name = $1->s;
1767 if ($3 && set_parent_node($3, $$))
1768 reparent_error(scanner, "variant reparent error");
1769 }
1770 | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1771 {
1772 $$ = make_node(scanner, NODE_VARIANT);
1773 $$->u.variant.has_body = 1;
1774 $$->u.variant.name = $1->s;
1775 $$->u.variant.choice = $3->s;
1776 if ($6 && set_parent_node($6, $$))
1777 reparent_error(scanner, "variant reparent error");
1778 }
1779 | IDENTIFIER LT IDENTIFIER GT
1780 {
1781 $$ = make_node(scanner, NODE_VARIANT);
1782 $$->u.variant.has_body = 0;
1783 $$->u.variant.name = $1->s;
1784 $$->u.variant.choice = $3->s;
1785 }
1786 | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1787 {
1788 $$ = make_node(scanner, NODE_VARIANT);
1789 $$->u.variant.has_body = 1;
1790 $$->u.variant.name = $1->s;
1791 $$->u.variant.choice = $3->s;
1792 if ($6 && set_parent_node($6, $$))
1793 reparent_error(scanner, "variant reparent error");
1794 }
1795 | IDENTIFIER LT ID_TYPE GT
1796 {
1797 $$ = make_node(scanner, NODE_VARIANT);
1798 $$->u.variant.has_body = 0;
1799 $$->u.variant.name = $1->s;
1800 $$->u.variant.choice = $3->s;
1801 }
1802 | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1803 {
1804 $$ = make_node(scanner, NODE_VARIANT);
1805 $$->u.variant.has_body = 1;
1806 $$->u.variant.name = $1->s;
1807 if ($3 && set_parent_node($3, $$))
1808 reparent_error(scanner, "variant reparent error");
1809 }
1810 | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1811 {
1812 $$ = make_node(scanner, NODE_VARIANT);
1813 $$->u.variant.has_body = 1;
1814 $$->u.variant.name = $1->s;
1815 $$->u.variant.choice = $3->s;
1816 if ($6 && set_parent_node($6, $$))
1817 reparent_error(scanner, "variant reparent error");
1818 }
1819 | ID_TYPE LT IDENTIFIER GT
1820 {
1821 $$ = make_node(scanner, NODE_VARIANT);
1822 $$->u.variant.has_body = 0;
1823 $$->u.variant.name = $1->s;
1824 $$->u.variant.choice = $3->s;
1825 }
1826 | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
1827 {
1828 $$ = make_node(scanner, NODE_VARIANT);
1829 $$->u.variant.has_body = 1;
1830 $$->u.variant.name = $1->s;
1831 $$->u.variant.choice = $3->s;
1832 if ($6 && set_parent_node($6, $$))
1833 reparent_error(scanner, "variant reparent error");
1834 }
1835 | ID_TYPE LT ID_TYPE GT
1836 {
1837 $$ = make_node(scanner, NODE_VARIANT);
1838 $$->u.variant.has_body = 0;
1839 $$->u.variant.name = $1->s;
1840 $$->u.variant.choice = $3->s;
1841 }
1842 ;
1843
1844 variant_declaration_begin:
1845 LBRAC
1846 { push_scope(scanner); }
1847 ;
1848
1849 variant_declaration_end:
1850 RBRAC
1851 { pop_scope(scanner); }
1852 ;
1853
1854 enum_type_specifier:
1855 LBRAC enumerator_list RBRAC
1856 {
1857 $$ = make_node(scanner, NODE_ENUM);
1858 $$->u._enum.has_body = 1;
1859 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1860 }
1861 | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1862 {
1863 $$ = make_node(scanner, NODE_ENUM);
1864 $$->u._enum.has_body = 1;
1865 ($$)->u._enum.container_type = $2;
1866 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1867 }
1868 | IDENTIFIER LBRAC enumerator_list RBRAC
1869 {
1870 $$ = make_node(scanner, NODE_ENUM);
1871 $$->u._enum.has_body = 1;
1872 $$->u._enum.enum_id = $1->s;
1873 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1874 }
1875 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1876 {
1877 $$ = make_node(scanner, NODE_ENUM);
1878 $$->u._enum.has_body = 1;
1879 $$->u._enum.enum_id = $1->s;
1880 ($$)->u._enum.container_type = $3;
1881 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1882 }
1883 | ID_TYPE LBRAC enumerator_list RBRAC
1884 {
1885 $$ = make_node(scanner, NODE_ENUM);
1886 $$->u._enum.has_body = 1;
1887 $$->u._enum.enum_id = $1->s;
1888 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1889 }
1890 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
1891 {
1892 $$ = make_node(scanner, NODE_ENUM);
1893 $$->u._enum.has_body = 1;
1894 $$->u._enum.enum_id = $1->s;
1895 ($$)->u._enum.container_type = $3;
1896 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1897 }
1898 | LBRAC enumerator_list COMMA RBRAC
1899 {
1900 $$ = make_node(scanner, NODE_ENUM);
1901 $$->u._enum.has_body = 1;
1902 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
1903 }
1904 | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1905 {
1906 $$ = make_node(scanner, NODE_ENUM);
1907 $$->u._enum.has_body = 1;
1908 ($$)->u._enum.container_type = $2;
1909 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list);
1910 }
1911 | IDENTIFIER LBRAC enumerator_list COMMA RBRAC
1912 {
1913 $$ = make_node(scanner, NODE_ENUM);
1914 $$->u._enum.has_body = 1;
1915 $$->u._enum.enum_id = $1->s;
1916 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1917 }
1918 | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1919 {
1920 $$ = make_node(scanner, NODE_ENUM);
1921 $$->u._enum.has_body = 1;
1922 $$->u._enum.enum_id = $1->s;
1923 ($$)->u._enum.container_type = $3;
1924 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1925 }
1926 | IDENTIFIER
1927 {
1928 $$ = make_node(scanner, NODE_ENUM);
1929 $$->u._enum.has_body = 0;
1930 $$->u._enum.enum_id = $1->s;
1931 }
1932 | ID_TYPE LBRAC enumerator_list COMMA RBRAC
1933 {
1934 $$ = make_node(scanner, NODE_ENUM);
1935 $$->u._enum.has_body = 1;
1936 $$->u._enum.enum_id = $1->s;
1937 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
1938 }
1939 | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
1940 {
1941 $$ = make_node(scanner, NODE_ENUM);
1942 $$->u._enum.has_body = 1;
1943 $$->u._enum.enum_id = $1->s;
1944 ($$)->u._enum.container_type = $3;
1945 _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
1946 }
1947 | ID_TYPE
1948 {
1949 $$ = make_node(scanner, NODE_ENUM);
1950 $$->u._enum.has_body = 0;
1951 $$->u._enum.enum_id = $1->s;
1952 }
1953 ;
1954
1955 struct_or_variant_declaration_list:
1956 /* empty */
1957 { $$ = NULL; }
1958 | struct_or_variant_declaration_list struct_or_variant_declaration
1959 {
1960 if ($1) {
1961 $$ = $1;
1962 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
1963 } else {
1964 $$ = $2;
1965 cds_list_add_tail(&($$)->siblings, &($$)->tmp_head);
1966 }
1967 }
1968 ;
1969
1970 struct_or_variant_declaration:
1971 declaration_specifiers struct_or_variant_declarator_list SEMICOLON
1972 {
1973 struct ctf_node *list;
1974
1975 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1976 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1977 $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
1978 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
1979 _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
1980 }
1981 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1982 {
1983 struct ctf_node *list;
1984
1985 $$ = make_node(scanner, NODE_TYPEDEF);
1986 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1987 $$->u._typedef.type_specifier_list = list;
1988 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1989 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
1990 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
1991 }
1992 | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
1993 {
1994 struct ctf_node *list;
1995
1996 $$ = make_node(scanner, NODE_TYPEDEF);
1997 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
1998 $$->u._typedef.type_specifier_list = list;
1999 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2000 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2001 }
2002 | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
2003 {
2004 struct ctf_node *list;
2005
2006 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2007 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2008 $$ = make_node(scanner, NODE_TYPEDEF);
2009 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2010 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2011 }
2012 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
2013 {
2014 struct ctf_node *list;
2015
2016 $$ = make_node(scanner, NODE_TYPEALIAS);
2017 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2018 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2019
2020 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2021 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2022 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2023 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2024
2025 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2026 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2027 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2028 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2029 }
2030 ;
2031
2032 alias_declaration_specifiers:
2033 CONST
2034 {
2035 struct ctf_node *node;
2036
2037 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2038 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2039 node->u.type_specifier.type = TYPESPEC_CONST;
2040 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2041 }
2042 | type_specifier
2043 {
2044 struct ctf_node *node;
2045
2046 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2047 node = $1;
2048 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2049 }
2050 | IDENTIFIER
2051 {
2052 struct ctf_node *node;
2053
2054 add_type(scanner, $1);
2055 $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2056 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2057 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2058 node->u.type_specifier.id_type = yylval.gs->s;
2059 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2060 }
2061 | alias_declaration_specifiers CONST
2062 {
2063 struct ctf_node *node;
2064
2065 $$ = $1;
2066 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2067 node->u.type_specifier.type = TYPESPEC_CONST;
2068 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2069 }
2070 | alias_declaration_specifiers type_specifier
2071 {
2072 $$ = $1;
2073 cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
2074 }
2075 | alias_declaration_specifiers IDENTIFIER
2076 {
2077 struct ctf_node *node;
2078
2079 add_type(scanner, $2);
2080 $$ = $1;
2081 node = make_node(scanner, NODE_TYPE_SPECIFIER);
2082 node->u.type_specifier.type = TYPESPEC_ID_TYPE;
2083 node->u.type_specifier.id_type = yylval.gs->s;
2084 cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
2085 }
2086 ;
2087
2088 struct_or_variant_declarator_list:
2089 struct_or_variant_declarator
2090 { $$ = $1; }
2091 | struct_or_variant_declarator_list COMMA struct_or_variant_declarator
2092 {
2093 $$ = $1;
2094 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2095 }
2096 ;
2097
2098 struct_or_variant_declarator:
2099 declarator
2100 { $$ = $1; }
2101 | COLON unary_expression
2102 { $$ = $2; }
2103 | declarator COLON unary_expression
2104 {
2105 $$ = $1;
2106 if (set_parent_node($3, $1))
2107 reparent_error(scanner, "struct_or_variant_declarator");
2108 }
2109 ;
2110
2111 enumerator_list:
2112 enumerator
2113 { $$ = $1; }
2114 | enumerator_list COMMA enumerator
2115 {
2116 $$ = $1;
2117 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2118 }
2119 ;
2120
2121 enumerator:
2122 IDENTIFIER
2123 {
2124 $$ = make_node(scanner, NODE_ENUMERATOR);
2125 $$->u.enumerator.id = $1->s;
2126 }
2127 | ID_TYPE
2128 {
2129 $$ = make_node(scanner, NODE_ENUMERATOR);
2130 $$->u.enumerator.id = $1->s;
2131 }
2132 | keywords
2133 {
2134 $$ = make_node(scanner, NODE_ENUMERATOR);
2135 $$->u.enumerator.id = $1->s;
2136 }
2137 | STRING_LITERAL_START DQUOTE
2138 {
2139 $$ = make_node(scanner, NODE_ENUMERATOR);
2140 $$->u.enumerator.id = "";
2141 }
2142 | STRING_LITERAL_START s_char_sequence DQUOTE
2143 {
2144 $$ = make_node(scanner, NODE_ENUMERATOR);
2145 $$->u.enumerator.id = $2->s;
2146 }
2147 | IDENTIFIER EQUAL unary_expression_or_range
2148 {
2149 $$ = make_node(scanner, NODE_ENUMERATOR);
2150 $$->u.enumerator.id = $1->s;
2151 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2152 }
2153 | ID_TYPE EQUAL unary_expression_or_range
2154 {
2155 $$ = make_node(scanner, NODE_ENUMERATOR);
2156 $$->u.enumerator.id = $1->s;
2157 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2158 }
2159 | keywords EQUAL unary_expression_or_range
2160 {
2161 $$ = make_node(scanner, NODE_ENUMERATOR);
2162 $$->u.enumerator.id = $1->s;
2163 cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
2164 }
2165 | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
2166 {
2167 $$ = make_node(scanner, NODE_ENUMERATOR);
2168 $$->u.enumerator.id = "";
2169 cds_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
2170 }
2171 | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
2172 {
2173 $$ = make_node(scanner, NODE_ENUMERATOR);
2174 $$->u.enumerator.id = $2->s;
2175 cds_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
2176 }
2177 ;
2178
2179 abstract_declarator_list:
2180 abstract_declarator
2181 { $$ = $1; }
2182 | abstract_declarator_list COMMA abstract_declarator
2183 {
2184 $$ = $1;
2185 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2186 }
2187 ;
2188
2189 abstract_declarator:
2190 direct_abstract_declarator
2191 { $$ = $1; }
2192 | pointer direct_abstract_declarator
2193 {
2194 $$ = $2;
2195 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2196 }
2197 ;
2198
2199 direct_abstract_declarator:
2200 /* empty */
2201 {
2202 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2203 $$->u.type_declarator.type = TYPEDEC_ID;
2204 /* id is NULL */
2205 }
2206 | IDENTIFIER
2207 {
2208 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2209 $$->u.type_declarator.type = TYPEDEC_ID;
2210 $$->u.type_declarator.u.id = $1->s;
2211 }
2212 | LPAREN abstract_declarator RPAREN
2213 {
2214 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2215 $$->u.type_declarator.type = TYPEDEC_NESTED;
2216 $$->u.type_declarator.u.nested.type_declarator = $2;
2217 }
2218 | direct_abstract_declarator LSBRAC unary_expression RSBRAC
2219 {
2220 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2221 $$->u.type_declarator.type = TYPEDEC_NESTED;
2222 $$->u.type_declarator.u.nested.type_declarator = $1;
2223 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2224 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2225 }
2226 | direct_abstract_declarator LSBRAC RSBRAC
2227 {
2228 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2229 $$->u.type_declarator.type = TYPEDEC_NESTED;
2230 $$->u.type_declarator.u.nested.type_declarator = $1;
2231 $$->u.type_declarator.u.nested.abstract_array = 1;
2232 }
2233 ;
2234
2235 alias_abstract_declarator_list:
2236 alias_abstract_declarator
2237 { $$ = $1; }
2238 | alias_abstract_declarator_list COMMA alias_abstract_declarator
2239 {
2240 $$ = $1;
2241 cds_list_add_tail(&($3)->siblings, &($$)->tmp_head);
2242 }
2243 ;
2244
2245 alias_abstract_declarator:
2246 direct_alias_abstract_declarator
2247 { $$ = $1; }
2248 | pointer direct_alias_abstract_declarator
2249 {
2250 $$ = $2;
2251 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2252 }
2253 ;
2254
2255 direct_alias_abstract_declarator:
2256 /* empty */
2257 {
2258 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2259 $$->u.type_declarator.type = TYPEDEC_ID;
2260 /* id is NULL */
2261 }
2262 | LPAREN alias_abstract_declarator RPAREN
2263 {
2264 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2265 $$->u.type_declarator.type = TYPEDEC_NESTED;
2266 $$->u.type_declarator.u.nested.type_declarator = $2;
2267 }
2268 | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC
2269 {
2270 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2271 $$->u.type_declarator.type = TYPEDEC_NESTED;
2272 $$->u.type_declarator.u.nested.type_declarator = $1;
2273 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2274 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2275 }
2276 | direct_alias_abstract_declarator LSBRAC RSBRAC
2277 {
2278 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2279 $$->u.type_declarator.type = TYPEDEC_NESTED;
2280 $$->u.type_declarator.u.nested.type_declarator = $1;
2281 $$->u.type_declarator.u.nested.abstract_array = 1;
2282 }
2283 ;
2284
2285 declarator:
2286 direct_declarator
2287 { $$ = $1; }
2288 | pointer direct_declarator
2289 {
2290 $$ = $2;
2291 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2292 }
2293 ;
2294
2295 direct_declarator:
2296 IDENTIFIER
2297 {
2298 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2299 $$->u.type_declarator.type = TYPEDEC_ID;
2300 $$->u.type_declarator.u.id = $1->s;
2301 }
2302 | LPAREN declarator RPAREN
2303 {
2304 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2305 $$->u.type_declarator.type = TYPEDEC_NESTED;
2306 $$->u.type_declarator.u.nested.type_declarator = $2;
2307 }
2308 | direct_declarator LSBRAC unary_expression RSBRAC
2309 {
2310 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2311 $$->u.type_declarator.type = TYPEDEC_NESTED;
2312 $$->u.type_declarator.u.nested.type_declarator = $1;
2313 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2314 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2315 }
2316 ;
2317
2318 type_declarator:
2319 direct_type_declarator
2320 { $$ = $1; }
2321 | pointer direct_type_declarator
2322 {
2323 $$ = $2;
2324 cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers);
2325 }
2326 ;
2327
2328 direct_type_declarator:
2329 IDENTIFIER
2330 {
2331 add_type(scanner, $1);
2332 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2333 $$->u.type_declarator.type = TYPEDEC_ID;
2334 $$->u.type_declarator.u.id = $1->s;
2335 }
2336 | LPAREN type_declarator RPAREN
2337 {
2338 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2339 $$->u.type_declarator.type = TYPEDEC_NESTED;
2340 $$->u.type_declarator.u.nested.type_declarator = $2;
2341 }
2342 | direct_type_declarator LSBRAC unary_expression RSBRAC
2343 {
2344 $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
2345 $$->u.type_declarator.type = TYPEDEC_NESTED;
2346 $$->u.type_declarator.u.nested.type_declarator = $1;
2347 CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
2348 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
2349 }
2350 ;
2351
2352 pointer:
2353 STAR
2354 {
2355 $$ = make_node(scanner, NODE_POINTER);
2356 }
2357 | STAR pointer
2358 {
2359 $$ = make_node(scanner, NODE_POINTER);
2360 cds_list_splice(&($2)->tmp_head, &($$)->tmp_head);
2361 }
2362 | STAR type_qualifier_list pointer
2363 {
2364 $$ = make_node(scanner, NODE_POINTER);
2365 $$->u.pointer.const_qualifier = 1;
2366 cds_list_splice(&($3)->tmp_head, &($$)->tmp_head);
2367 }
2368 ;
2369
2370 type_qualifier_list:
2371 /* pointer assumes only const type qualifier */
2372 CONST
2373 | type_qualifier_list CONST
2374 ;
2375
2376 /* 2.3: CTF-specific declarations */
2377
2378 ctf_assignment_expression_list:
2379 ctf_assignment_expression SEMICOLON
2380 { $$ = $1; }
2381 | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
2382 {
2383 $$ = $1;
2384 cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
2385 }
2386 ;
2387
2388 ctf_assignment_expression:
2389 unary_expression EQUAL unary_expression
2390 {
2391 /*
2392 * Because we have left and right, cannot use
2393 * set_parent_node.
2394 */
2395 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2396 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2397 if ($1->u.unary_expression.type != UNARY_STRING)
2398 reparent_error(scanner, "ctf_assignment_expression left expects string");
2399 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
2400 }
2401 | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */
2402 {
2403 /*
2404 * Because we have left and right, cannot use
2405 * set_parent_node.
2406 */
2407 $$ = make_node(scanner, NODE_CTF_EXPRESSION);
2408 _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
2409 if ($1->u.unary_expression.type != UNARY_STRING)
2410 reparent_error(scanner, "ctf_assignment_expression left expects string");
2411 cds_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right);
2412 }
2413 | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
2414 {
2415 struct ctf_node *list;
2416
2417 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2418 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2419 _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2420 $$ = make_node(scanner, NODE_TYPEDEF);
2421 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2422 _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
2423 }
2424 | TYPEDEF declaration_specifiers type_declarator_list
2425 {
2426 struct ctf_node *list;
2427
2428 $$ = make_node(scanner, NODE_TYPEDEF);
2429 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2430 $$->u._typedef.type_specifier_list = list;
2431 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2432 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2433 }
2434 | declaration_specifiers TYPEDEF type_declarator_list
2435 {
2436 struct ctf_node *list;
2437
2438 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2439 _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2440 $$ = make_node(scanner, NODE_TYPEDEF);
2441 ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
2442 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
2443 }
2444 | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list
2445 {
2446 struct ctf_node *list;
2447
2448 $$ = make_node(scanner, NODE_TYPEALIAS);
2449 $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
2450 $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
2451
2452 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2453 $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
2454 _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2455 _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
2456
2457 list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
2458 $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
2459 _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
2460 _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
2461 }
2462 ;
This page took 0.117718 seconds and 3 git commands to generate.