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