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