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