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