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