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