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