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