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