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