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