| 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> |
| 37 | #include <babeltrace/list.h> |
| 38 | #include <babeltrace/babeltrace-internal.h> |
| 39 | #include "ctf-scanner.h" |
| 40 | #include "ctf-parser.h" |
| 41 | #include "ctf-ast.h" |
| 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 | |
| 333 | ret = (int) (long) g_hash_table_lookup(s->types, id); |
| 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 | } |
| 943 | |
| 944 | BT_HIDDEN |
| 945 | int yywrap(void) |
| 946 | { |
| 947 | return 1; |
| 948 | } |
| 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) |
| 976 | { |
| 977 | return yyparse(scanner, scanner->scanner); |
| 978 | } |
| 979 | |
| 980 | struct ctf_scanner *ctf_scanner_alloc(FILE *input) |
| 981 | { |
| 982 | struct ctf_scanner *scanner; |
| 983 | int ret; |
| 984 | |
| 985 | yydebug = babeltrace_debug; |
| 986 | |
| 987 | scanner = malloc(sizeof(*scanner)); |
| 988 | if (!scanner) |
| 989 | return NULL; |
| 990 | memset(scanner, 0, sizeof(*scanner)); |
| 991 | |
| 992 | ret = yylex_init_extra(scanner, &scanner->scanner); |
| 993 | if (ret) { |
| 994 | printf_fatal("yylex_init error"); |
| 995 | goto cleanup_scanner; |
| 996 | } |
| 997 | /* Start processing new stream */ |
| 998 | yyrestart(input, scanner->scanner); |
| 999 | |
| 1000 | scanner->objstack = objstack_create(); |
| 1001 | if (!scanner->objstack) |
| 1002 | goto cleanup_lexer; |
| 1003 | scanner->ast = ctf_ast_alloc(scanner); |
| 1004 | if (!scanner->ast) |
| 1005 | goto cleanup_objstack; |
| 1006 | init_scope(&scanner->root_scope, NULL); |
| 1007 | scanner->cs = &scanner->root_scope; |
| 1008 | |
| 1009 | if (yydebug) |
| 1010 | fprintf(stdout, "Scanner input is a%s.\n", |
| 1011 | isatty(fileno(input)) ? "n interactive tty" : |
| 1012 | " noninteractive file"); |
| 1013 | |
| 1014 | return scanner; |
| 1015 | |
| 1016 | cleanup_objstack: |
| 1017 | objstack_destroy(scanner->objstack); |
| 1018 | cleanup_lexer: |
| 1019 | ret = yylex_destroy(scanner->scanner); |
| 1020 | if (!ret) |
| 1021 | printf_fatal("yylex_destroy error"); |
| 1022 | cleanup_scanner: |
| 1023 | free(scanner); |
| 1024 | return NULL; |
| 1025 | } |
| 1026 | |
| 1027 | void ctf_scanner_free(struct ctf_scanner *scanner) |
| 1028 | { |
| 1029 | int ret; |
| 1030 | |
| 1031 | finalize_scope(&scanner->root_scope); |
| 1032 | objstack_destroy(scanner->objstack); |
| 1033 | ret = yylex_destroy(scanner->scanner); |
| 1034 | if (ret) |
| 1035 | printf_error("yylex_destroy error"); |
| 1036 | free(scanner); |
| 1037 | } |
| 1038 | |
| 1039 | %} |
| 1040 | |
| 1041 | %define api.pure |
| 1042 | /* %locations */ |
| 1043 | %error-verbose |
| 1044 | %parse-param {struct ctf_scanner *scanner} |
| 1045 | %parse-param {yyscan_t yyscanner} |
| 1046 | %lex-param {yyscan_t yyscanner} |
| 1047 | /* |
| 1048 | * Expect two shift-reduce conflicts. Caused by enum name-opt : type {} |
| 1049 | * vs struct { int :value; } (unnamed bit-field). The default is to |
| 1050 | * shift, so whenever we encounter an enumeration, we are doing the |
| 1051 | * proper thing (shift). It is illegal to declare an enumeration |
| 1052 | * "bit-field", so it is OK if this situation ends up in a parsing |
| 1053 | * error. |
| 1054 | */ |
| 1055 | %expect 2 |
| 1056 | %start file |
| 1057 | %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 |
| 1058 | %token <s> IDENTIFIER ID_TYPE |
| 1059 | %token ERROR |
| 1060 | %union |
| 1061 | { |
| 1062 | long long ll; |
| 1063 | unsigned long long ull; |
| 1064 | char c; |
| 1065 | char *s; |
| 1066 | struct ctf_node *n; |
| 1067 | } |
| 1068 | |
| 1069 | %type <s> STRING_LITERAL CHARACTER_LITERAL |
| 1070 | |
| 1071 | %type <s> keywords |
| 1072 | |
| 1073 | %type <ull> INTEGER_LITERAL |
| 1074 | %type <n> postfix_expression unary_expression unary_expression_or_range |
| 1075 | |
| 1076 | %type <n> declaration |
| 1077 | %type <n> event_declaration |
| 1078 | %type <n> stream_declaration |
| 1079 | %type <n> env_declaration |
| 1080 | %type <n> trace_declaration |
| 1081 | %type <n> clock_declaration |
| 1082 | %type <n> callsite_declaration |
| 1083 | %type <n> integer_declaration_specifiers |
| 1084 | %type <n> declaration_specifiers |
| 1085 | %type <n> alias_declaration_specifiers |
| 1086 | |
| 1087 | %type <n> type_declarator_list |
| 1088 | %type <n> integer_type_specifier |
| 1089 | %type <n> type_specifier |
| 1090 | %type <n> struct_type_specifier |
| 1091 | %type <n> variant_type_specifier |
| 1092 | %type <n> enum_type_specifier |
| 1093 | %type <n> struct_or_variant_declaration_list |
| 1094 | %type <n> struct_or_variant_declaration |
| 1095 | %type <n> struct_or_variant_declarator_list |
| 1096 | %type <n> struct_or_variant_declarator |
| 1097 | %type <n> enumerator_list |
| 1098 | %type <n> enumerator |
| 1099 | %type <n> abstract_declarator_list |
| 1100 | %type <n> abstract_declarator |
| 1101 | %type <n> direct_abstract_declarator |
| 1102 | %type <n> alias_abstract_declarator_list |
| 1103 | %type <n> alias_abstract_declarator |
| 1104 | %type <n> direct_alias_abstract_declarator |
| 1105 | %type <n> declarator |
| 1106 | %type <n> direct_declarator |
| 1107 | %type <n> type_declarator |
| 1108 | %type <n> direct_type_declarator |
| 1109 | %type <n> pointer |
| 1110 | %type <n> ctf_assignment_expression_list |
| 1111 | %type <n> ctf_assignment_expression |
| 1112 | |
| 1113 | %% |
| 1114 | |
| 1115 | file: |
| 1116 | declaration |
| 1117 | { |
| 1118 | if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root)) |
| 1119 | reparent_error(scanner, "error reparenting to root"); |
| 1120 | } |
| 1121 | | file declaration |
| 1122 | { |
| 1123 | if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root)) |
| 1124 | reparent_error(scanner, "error reparenting to root"); |
| 1125 | } |
| 1126 | ; |
| 1127 | |
| 1128 | keywords: |
| 1129 | VOID |
| 1130 | { $$ = yylval.s; } |
| 1131 | | CHAR |
| 1132 | { $$ = yylval.s; } |
| 1133 | | SHORT |
| 1134 | { $$ = yylval.s; } |
| 1135 | | INT |
| 1136 | { $$ = yylval.s; } |
| 1137 | | LONG |
| 1138 | { $$ = yylval.s; } |
| 1139 | | FLOAT |
| 1140 | { $$ = yylval.s; } |
| 1141 | | DOUBLE |
| 1142 | { $$ = yylval.s; } |
| 1143 | | SIGNED |
| 1144 | { $$ = yylval.s; } |
| 1145 | | UNSIGNED |
| 1146 | { $$ = yylval.s; } |
| 1147 | | _BOOL |
| 1148 | { $$ = yylval.s; } |
| 1149 | | _COMPLEX |
| 1150 | { $$ = yylval.s; } |
| 1151 | | _IMAGINARY |
| 1152 | { $$ = yylval.s; } |
| 1153 | | FLOATING_POINT |
| 1154 | { $$ = yylval.s; } |
| 1155 | | INTEGER |
| 1156 | { $$ = yylval.s; } |
| 1157 | | STRING |
| 1158 | { $$ = yylval.s; } |
| 1159 | | ENUM |
| 1160 | { $$ = yylval.s; } |
| 1161 | | VARIANT |
| 1162 | { $$ = yylval.s; } |
| 1163 | | STRUCT |
| 1164 | { $$ = yylval.s; } |
| 1165 | | CONST |
| 1166 | { $$ = yylval.s; } |
| 1167 | | TYPEDEF |
| 1168 | { $$ = yylval.s; } |
| 1169 | | EVENT |
| 1170 | { $$ = yylval.s; } |
| 1171 | | STREAM |
| 1172 | { $$ = yylval.s; } |
| 1173 | | ENV |
| 1174 | { $$ = yylval.s; } |
| 1175 | | TRACE |
| 1176 | { $$ = yylval.s; } |
| 1177 | | CLOCK |
| 1178 | { $$ = yylval.s; } |
| 1179 | | CALLSITE |
| 1180 | { $$ = yylval.s; } |
| 1181 | | TOK_ALIGN |
| 1182 | { $$ = yylval.s; } |
| 1183 | ; |
| 1184 | |
| 1185 | |
| 1186 | /* 2: Phrase structure grammar */ |
| 1187 | |
| 1188 | postfix_expression: |
| 1189 | IDENTIFIER |
| 1190 | { |
| 1191 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1192 | $$->u.unary_expression.type = UNARY_STRING; |
| 1193 | $$->u.unary_expression.u.string = yylval.s; |
| 1194 | } |
| 1195 | | ID_TYPE |
| 1196 | { |
| 1197 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1198 | $$->u.unary_expression.type = UNARY_STRING; |
| 1199 | $$->u.unary_expression.u.string = yylval.s; |
| 1200 | } |
| 1201 | | keywords |
| 1202 | { |
| 1203 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1204 | $$->u.unary_expression.type = UNARY_STRING; |
| 1205 | $$->u.unary_expression.u.string = yylval.s; |
| 1206 | } |
| 1207 | | INTEGER_LITERAL |
| 1208 | { |
| 1209 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1210 | $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT; |
| 1211 | $$->u.unary_expression.u.unsigned_constant = $1; |
| 1212 | } |
| 1213 | | STRING_LITERAL |
| 1214 | { |
| 1215 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1216 | $$->u.unary_expression.type = UNARY_STRING; |
| 1217 | $$->u.unary_expression.u.string = $1; |
| 1218 | } |
| 1219 | | CHARACTER_LITERAL |
| 1220 | { |
| 1221 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1222 | $$->u.unary_expression.type = UNARY_STRING; |
| 1223 | $$->u.unary_expression.u.string = $1; |
| 1224 | } |
| 1225 | | LPAREN unary_expression RPAREN |
| 1226 | { |
| 1227 | $$ = $2; |
| 1228 | } |
| 1229 | | postfix_expression LSBRAC unary_expression RSBRAC |
| 1230 | { |
| 1231 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1232 | $$->u.unary_expression.type = UNARY_SBRAC; |
| 1233 | $$->u.unary_expression.u.sbrac_exp = $3; |
| 1234 | bt_list_splice(&($1)->tmp_head, &($$)->tmp_head); |
| 1235 | bt_list_add_tail(&($$)->siblings, &($$)->tmp_head); |
| 1236 | } |
| 1237 | | postfix_expression DOT IDENTIFIER |
| 1238 | { |
| 1239 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1240 | $$->u.unary_expression.type = UNARY_STRING; |
| 1241 | $$->u.unary_expression.u.string = yylval.s; |
| 1242 | $$->u.unary_expression.link = UNARY_DOTLINK; |
| 1243 | bt_list_splice(&($1)->tmp_head, &($$)->tmp_head); |
| 1244 | bt_list_add_tail(&($$)->siblings, &($$)->tmp_head); |
| 1245 | } |
| 1246 | | postfix_expression DOT ID_TYPE |
| 1247 | { |
| 1248 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1249 | $$->u.unary_expression.type = UNARY_STRING; |
| 1250 | $$->u.unary_expression.u.string = yylval.s; |
| 1251 | $$->u.unary_expression.link = UNARY_DOTLINK; |
| 1252 | bt_list_splice(&($1)->tmp_head, &($$)->tmp_head); |
| 1253 | bt_list_add_tail(&($$)->siblings, &($$)->tmp_head); |
| 1254 | } |
| 1255 | | postfix_expression RARROW IDENTIFIER |
| 1256 | { |
| 1257 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1258 | $$->u.unary_expression.type = UNARY_STRING; |
| 1259 | $$->u.unary_expression.u.string = yylval.s; |
| 1260 | $$->u.unary_expression.link = UNARY_ARROWLINK; |
| 1261 | bt_list_splice(&($1)->tmp_head, &($$)->tmp_head); |
| 1262 | bt_list_add_tail(&($$)->siblings, &($$)->tmp_head); |
| 1263 | } |
| 1264 | | postfix_expression RARROW ID_TYPE |
| 1265 | { |
| 1266 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1267 | $$->u.unary_expression.type = UNARY_STRING; |
| 1268 | $$->u.unary_expression.u.string = yylval.s; |
| 1269 | $$->u.unary_expression.link = UNARY_ARROWLINK; |
| 1270 | bt_list_splice(&($1)->tmp_head, &($$)->tmp_head); |
| 1271 | bt_list_add_tail(&($$)->siblings, &($$)->tmp_head); |
| 1272 | } |
| 1273 | ; |
| 1274 | |
| 1275 | unary_expression: |
| 1276 | postfix_expression |
| 1277 | { $$ = $1; } |
| 1278 | | PLUS postfix_expression |
| 1279 | { |
| 1280 | $$ = $2; |
| 1281 | if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT |
| 1282 | && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) { |
| 1283 | reparent_error(scanner, "expecting numeric constant"); |
| 1284 | } |
| 1285 | } |
| 1286 | | MINUS postfix_expression |
| 1287 | { |
| 1288 | $$ = $2; |
| 1289 | if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) { |
| 1290 | $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT; |
| 1291 | $$->u.unary_expression.u.signed_constant = |
| 1292 | -($$->u.unary_expression.u.unsigned_constant); |
| 1293 | } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) { |
| 1294 | $$->u.unary_expression.u.signed_constant = |
| 1295 | -($$->u.unary_expression.u.signed_constant); |
| 1296 | } else { |
| 1297 | reparent_error(scanner, "expecting numeric constant"); |
| 1298 | } |
| 1299 | } |
| 1300 | ; |
| 1301 | |
| 1302 | unary_expression_or_range: |
| 1303 | unary_expression DOTDOTDOT unary_expression |
| 1304 | { |
| 1305 | $$ = $1; |
| 1306 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head); |
| 1307 | $3->u.unary_expression.link = UNARY_DOTDOTDOT; |
| 1308 | } |
| 1309 | | unary_expression |
| 1310 | { $$ = $1; } |
| 1311 | ; |
| 1312 | |
| 1313 | /* 2.2: Declarations */ |
| 1314 | |
| 1315 | declaration: |
| 1316 | declaration_specifiers SEMICOLON |
| 1317 | { $$ = $1; } |
| 1318 | | event_declaration |
| 1319 | { $$ = $1; } |
| 1320 | | stream_declaration |
| 1321 | { $$ = $1; } |
| 1322 | | env_declaration |
| 1323 | { $$ = $1; } |
| 1324 | | trace_declaration |
| 1325 | { $$ = $1; } |
| 1326 | | clock_declaration |
| 1327 | { $$ = $1; } |
| 1328 | | callsite_declaration |
| 1329 | { $$ = $1; } |
| 1330 | | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON |
| 1331 | { |
| 1332 | struct ctf_node *list; |
| 1333 | |
| 1334 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 1335 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 1336 | $$->u._typedef.type_specifier_list = list; |
| 1337 | _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 1338 | _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 1339 | _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators); |
| 1340 | } |
| 1341 | | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON |
| 1342 | { |
| 1343 | struct ctf_node *list; |
| 1344 | |
| 1345 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 1346 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 1347 | $$->u._typedef.type_specifier_list = list; |
| 1348 | _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 1349 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); |
| 1350 | } |
| 1351 | | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON |
| 1352 | { |
| 1353 | struct ctf_node *list; |
| 1354 | |
| 1355 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 1356 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 1357 | $$->u._typedef.type_specifier_list = list; |
| 1358 | _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 1359 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); |
| 1360 | } |
| 1361 | | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON |
| 1362 | { |
| 1363 | struct ctf_node *list; |
| 1364 | |
| 1365 | $$ = make_node(scanner, NODE_TYPEALIAS); |
| 1366 | $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET); |
| 1367 | $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS); |
| 1368 | |
| 1369 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 1370 | $$->u.typealias.target->u.typealias_target.type_specifier_list = list; |
| 1371 | _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 1372 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators); |
| 1373 | |
| 1374 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 1375 | $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list; |
| 1376 | _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 1377 | _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators); |
| 1378 | } |
| 1379 | ; |
| 1380 | |
| 1381 | event_declaration: |
| 1382 | event_declaration_begin event_declaration_end |
| 1383 | { |
| 1384 | $$ = make_node(scanner, NODE_EVENT); |
| 1385 | } |
| 1386 | | event_declaration_begin ctf_assignment_expression_list event_declaration_end |
| 1387 | { |
| 1388 | $$ = make_node(scanner, NODE_EVENT); |
| 1389 | if (set_parent_node($2, $$)) |
| 1390 | reparent_error(scanner, "event_declaration"); |
| 1391 | } |
| 1392 | ; |
| 1393 | |
| 1394 | event_declaration_begin: |
| 1395 | EVENT LBRAC |
| 1396 | { push_scope(scanner); } |
| 1397 | ; |
| 1398 | |
| 1399 | event_declaration_end: |
| 1400 | RBRAC SEMICOLON |
| 1401 | { pop_scope(scanner); } |
| 1402 | ; |
| 1403 | |
| 1404 | |
| 1405 | stream_declaration: |
| 1406 | stream_declaration_begin stream_declaration_end |
| 1407 | { |
| 1408 | $$ = make_node(scanner, NODE_STREAM); |
| 1409 | } |
| 1410 | | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end |
| 1411 | { |
| 1412 | $$ = make_node(scanner, NODE_STREAM); |
| 1413 | if (set_parent_node($2, $$)) |
| 1414 | reparent_error(scanner, "stream_declaration"); |
| 1415 | } |
| 1416 | ; |
| 1417 | |
| 1418 | stream_declaration_begin: |
| 1419 | STREAM LBRAC |
| 1420 | { push_scope(scanner); } |
| 1421 | ; |
| 1422 | |
| 1423 | stream_declaration_end: |
| 1424 | RBRAC SEMICOLON |
| 1425 | { pop_scope(scanner); } |
| 1426 | ; |
| 1427 | |
| 1428 | env_declaration: |
| 1429 | env_declaration_begin env_declaration_end |
| 1430 | { |
| 1431 | $$ = make_node(scanner, NODE_ENV); |
| 1432 | } |
| 1433 | | env_declaration_begin ctf_assignment_expression_list env_declaration_end |
| 1434 | { |
| 1435 | $$ = make_node(scanner, NODE_ENV); |
| 1436 | if (set_parent_node($2, $$)) |
| 1437 | reparent_error(scanner, "env declaration"); |
| 1438 | } |
| 1439 | ; |
| 1440 | |
| 1441 | env_declaration_begin: |
| 1442 | ENV LBRAC |
| 1443 | { push_scope(scanner); } |
| 1444 | ; |
| 1445 | |
| 1446 | env_declaration_end: |
| 1447 | RBRAC SEMICOLON |
| 1448 | { pop_scope(scanner); } |
| 1449 | ; |
| 1450 | |
| 1451 | trace_declaration: |
| 1452 | trace_declaration_begin trace_declaration_end |
| 1453 | { |
| 1454 | $$ = make_node(scanner, NODE_TRACE); |
| 1455 | } |
| 1456 | | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end |
| 1457 | { |
| 1458 | $$ = make_node(scanner, NODE_TRACE); |
| 1459 | if (set_parent_node($2, $$)) |
| 1460 | reparent_error(scanner, "trace_declaration"); |
| 1461 | } |
| 1462 | ; |
| 1463 | |
| 1464 | trace_declaration_begin: |
| 1465 | TRACE LBRAC |
| 1466 | { push_scope(scanner); } |
| 1467 | ; |
| 1468 | |
| 1469 | trace_declaration_end: |
| 1470 | RBRAC SEMICOLON |
| 1471 | { pop_scope(scanner); } |
| 1472 | ; |
| 1473 | |
| 1474 | clock_declaration: |
| 1475 | CLOCK clock_declaration_begin clock_declaration_end |
| 1476 | { |
| 1477 | $$ = make_node(scanner, NODE_CLOCK); |
| 1478 | } |
| 1479 | | CLOCK clock_declaration_begin ctf_assignment_expression_list clock_declaration_end |
| 1480 | { |
| 1481 | $$ = make_node(scanner, NODE_CLOCK); |
| 1482 | if (set_parent_node($3, $$)) |
| 1483 | reparent_error(scanner, "trace_declaration"); |
| 1484 | } |
| 1485 | ; |
| 1486 | |
| 1487 | clock_declaration_begin: |
| 1488 | LBRAC |
| 1489 | { push_scope(scanner); } |
| 1490 | ; |
| 1491 | |
| 1492 | clock_declaration_end: |
| 1493 | RBRAC SEMICOLON |
| 1494 | { pop_scope(scanner); } |
| 1495 | ; |
| 1496 | |
| 1497 | callsite_declaration: |
| 1498 | CALLSITE callsite_declaration_begin callsite_declaration_end |
| 1499 | { |
| 1500 | $$ = make_node(scanner, NODE_CALLSITE); |
| 1501 | } |
| 1502 | | CALLSITE callsite_declaration_begin ctf_assignment_expression_list callsite_declaration_end |
| 1503 | { |
| 1504 | $$ = make_node(scanner, NODE_CALLSITE); |
| 1505 | if (set_parent_node($3, $$)) |
| 1506 | reparent_error(scanner, "trace_declaration"); |
| 1507 | } |
| 1508 | ; |
| 1509 | |
| 1510 | callsite_declaration_begin: |
| 1511 | LBRAC |
| 1512 | { push_scope(scanner); } |
| 1513 | ; |
| 1514 | |
| 1515 | callsite_declaration_end: |
| 1516 | RBRAC SEMICOLON |
| 1517 | { pop_scope(scanner); } |
| 1518 | ; |
| 1519 | |
| 1520 | integer_declaration_specifiers: |
| 1521 | CONST |
| 1522 | { |
| 1523 | struct ctf_node *node; |
| 1524 | |
| 1525 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 1526 | node = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1527 | node->u.type_specifier.type = TYPESPEC_CONST; |
| 1528 | bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head); |
| 1529 | } |
| 1530 | | integer_type_specifier |
| 1531 | { |
| 1532 | struct ctf_node *node; |
| 1533 | |
| 1534 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 1535 | node = $1; |
| 1536 | bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head); |
| 1537 | } |
| 1538 | | integer_declaration_specifiers CONST |
| 1539 | { |
| 1540 | struct ctf_node *node; |
| 1541 | |
| 1542 | $$ = $1; |
| 1543 | node = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1544 | node->u.type_specifier.type = TYPESPEC_CONST; |
| 1545 | bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head); |
| 1546 | } |
| 1547 | | integer_declaration_specifiers integer_type_specifier |
| 1548 | { |
| 1549 | $$ = $1; |
| 1550 | bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head); |
| 1551 | } |
| 1552 | ; |
| 1553 | |
| 1554 | declaration_specifiers: |
| 1555 | CONST |
| 1556 | { |
| 1557 | struct ctf_node *node; |
| 1558 | |
| 1559 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 1560 | node = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1561 | node->u.type_specifier.type = TYPESPEC_CONST; |
| 1562 | bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head); |
| 1563 | } |
| 1564 | | type_specifier |
| 1565 | { |
| 1566 | struct ctf_node *node; |
| 1567 | |
| 1568 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 1569 | node = $1; |
| 1570 | bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head); |
| 1571 | } |
| 1572 | | declaration_specifiers CONST |
| 1573 | { |
| 1574 | struct ctf_node *node; |
| 1575 | |
| 1576 | $$ = $1; |
| 1577 | node = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1578 | node->u.type_specifier.type = TYPESPEC_CONST; |
| 1579 | bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head); |
| 1580 | } |
| 1581 | | declaration_specifiers type_specifier |
| 1582 | { |
| 1583 | $$ = $1; |
| 1584 | bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head); |
| 1585 | } |
| 1586 | ; |
| 1587 | |
| 1588 | type_declarator_list: |
| 1589 | type_declarator |
| 1590 | { $$ = $1; } |
| 1591 | | type_declarator_list COMMA type_declarator |
| 1592 | { |
| 1593 | $$ = $1; |
| 1594 | bt_list_add_tail(&($3)->siblings, &($$)->tmp_head); |
| 1595 | } |
| 1596 | ; |
| 1597 | |
| 1598 | integer_type_specifier: |
| 1599 | CHAR |
| 1600 | { |
| 1601 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1602 | $$->u.type_specifier.type = TYPESPEC_CHAR; |
| 1603 | } |
| 1604 | | SHORT |
| 1605 | { |
| 1606 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1607 | $$->u.type_specifier.type = TYPESPEC_SHORT; |
| 1608 | } |
| 1609 | | INT |
| 1610 | { |
| 1611 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1612 | $$->u.type_specifier.type = TYPESPEC_INT; |
| 1613 | } |
| 1614 | | LONG |
| 1615 | { |
| 1616 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1617 | $$->u.type_specifier.type = TYPESPEC_LONG; |
| 1618 | } |
| 1619 | | SIGNED |
| 1620 | { |
| 1621 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1622 | $$->u.type_specifier.type = TYPESPEC_SIGNED; |
| 1623 | } |
| 1624 | | UNSIGNED |
| 1625 | { |
| 1626 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1627 | $$->u.type_specifier.type = TYPESPEC_UNSIGNED; |
| 1628 | } |
| 1629 | | _BOOL |
| 1630 | { |
| 1631 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1632 | $$->u.type_specifier.type = TYPESPEC_BOOL; |
| 1633 | } |
| 1634 | | ID_TYPE |
| 1635 | { |
| 1636 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1637 | $$->u.type_specifier.type = TYPESPEC_ID_TYPE; |
| 1638 | $$->u.type_specifier.id_type = yylval.s; |
| 1639 | } |
| 1640 | | INTEGER LBRAC RBRAC |
| 1641 | { |
| 1642 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1643 | $$->u.type_specifier.type = TYPESPEC_INTEGER; |
| 1644 | $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER); |
| 1645 | } |
| 1646 | | INTEGER LBRAC ctf_assignment_expression_list RBRAC |
| 1647 | { |
| 1648 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1649 | $$->u.type_specifier.type = TYPESPEC_INTEGER; |
| 1650 | $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER); |
| 1651 | if (set_parent_node($3, $$->u.type_specifier.node)) |
| 1652 | reparent_error(scanner, "integer reparent error"); |
| 1653 | } |
| 1654 | ; |
| 1655 | |
| 1656 | type_specifier: |
| 1657 | VOID |
| 1658 | { |
| 1659 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1660 | $$->u.type_specifier.type = TYPESPEC_VOID; |
| 1661 | } |
| 1662 | | CHAR |
| 1663 | { |
| 1664 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1665 | $$->u.type_specifier.type = TYPESPEC_CHAR; |
| 1666 | } |
| 1667 | | SHORT |
| 1668 | { |
| 1669 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1670 | $$->u.type_specifier.type = TYPESPEC_SHORT; |
| 1671 | } |
| 1672 | | INT |
| 1673 | { |
| 1674 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1675 | $$->u.type_specifier.type = TYPESPEC_INT; |
| 1676 | } |
| 1677 | | LONG |
| 1678 | { |
| 1679 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1680 | $$->u.type_specifier.type = TYPESPEC_LONG; |
| 1681 | } |
| 1682 | | FLOAT |
| 1683 | { |
| 1684 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1685 | $$->u.type_specifier.type = TYPESPEC_FLOAT; |
| 1686 | } |
| 1687 | | DOUBLE |
| 1688 | { |
| 1689 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1690 | $$->u.type_specifier.type = TYPESPEC_DOUBLE; |
| 1691 | } |
| 1692 | | SIGNED |
| 1693 | { |
| 1694 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1695 | $$->u.type_specifier.type = TYPESPEC_SIGNED; |
| 1696 | } |
| 1697 | | UNSIGNED |
| 1698 | { |
| 1699 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1700 | $$->u.type_specifier.type = TYPESPEC_UNSIGNED; |
| 1701 | } |
| 1702 | | _BOOL |
| 1703 | { |
| 1704 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1705 | $$->u.type_specifier.type = TYPESPEC_BOOL; |
| 1706 | } |
| 1707 | | _COMPLEX |
| 1708 | { |
| 1709 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1710 | $$->u.type_specifier.type = TYPESPEC_COMPLEX; |
| 1711 | } |
| 1712 | | _IMAGINARY |
| 1713 | { |
| 1714 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1715 | $$->u.type_specifier.type = TYPESPEC_IMAGINARY; |
| 1716 | } |
| 1717 | | ID_TYPE |
| 1718 | { |
| 1719 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1720 | $$->u.type_specifier.type = TYPESPEC_ID_TYPE; |
| 1721 | $$->u.type_specifier.id_type = yylval.s; |
| 1722 | } |
| 1723 | | FLOATING_POINT LBRAC RBRAC |
| 1724 | { |
| 1725 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1726 | $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT; |
| 1727 | $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT); |
| 1728 | } |
| 1729 | | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC |
| 1730 | { |
| 1731 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1732 | $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT; |
| 1733 | $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT); |
| 1734 | if (set_parent_node($3, $$->u.type_specifier.node)) |
| 1735 | reparent_error(scanner, "floating point reparent error"); |
| 1736 | } |
| 1737 | | INTEGER LBRAC RBRAC |
| 1738 | { |
| 1739 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1740 | $$->u.type_specifier.type = TYPESPEC_INTEGER; |
| 1741 | $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER); |
| 1742 | } |
| 1743 | | INTEGER LBRAC ctf_assignment_expression_list RBRAC |
| 1744 | { |
| 1745 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1746 | $$->u.type_specifier.type = TYPESPEC_INTEGER; |
| 1747 | $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER); |
| 1748 | if (set_parent_node($3, $$->u.type_specifier.node)) |
| 1749 | reparent_error(scanner, "integer reparent error"); |
| 1750 | } |
| 1751 | | STRING |
| 1752 | { |
| 1753 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1754 | $$->u.type_specifier.type = TYPESPEC_STRING; |
| 1755 | $$->u.type_specifier.node = make_node(scanner, NODE_STRING); |
| 1756 | } |
| 1757 | | STRING LBRAC RBRAC |
| 1758 | { |
| 1759 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1760 | $$->u.type_specifier.type = TYPESPEC_STRING; |
| 1761 | $$->u.type_specifier.node = make_node(scanner, NODE_STRING); |
| 1762 | } |
| 1763 | | STRING LBRAC ctf_assignment_expression_list RBRAC |
| 1764 | { |
| 1765 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1766 | $$->u.type_specifier.type = TYPESPEC_STRING; |
| 1767 | $$->u.type_specifier.node = make_node(scanner, NODE_STRING); |
| 1768 | if (set_parent_node($3, $$->u.type_specifier.node)) |
| 1769 | reparent_error(scanner, "string reparent error"); |
| 1770 | } |
| 1771 | | ENUM enum_type_specifier |
| 1772 | { |
| 1773 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1774 | $$->u.type_specifier.type = TYPESPEC_ENUM; |
| 1775 | $$->u.type_specifier.node = $2; |
| 1776 | } |
| 1777 | | VARIANT variant_type_specifier |
| 1778 | { |
| 1779 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1780 | $$->u.type_specifier.type = TYPESPEC_VARIANT; |
| 1781 | $$->u.type_specifier.node = $2; |
| 1782 | } |
| 1783 | | STRUCT struct_type_specifier |
| 1784 | { |
| 1785 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1786 | $$->u.type_specifier.type = TYPESPEC_STRUCT; |
| 1787 | $$->u.type_specifier.node = $2; |
| 1788 | } |
| 1789 | ; |
| 1790 | |
| 1791 | struct_type_specifier: |
| 1792 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end |
| 1793 | { |
| 1794 | $$ = make_node(scanner, NODE_STRUCT); |
| 1795 | $$->u._struct.has_body = 1; |
| 1796 | if ($2 && set_parent_node($2, $$)) |
| 1797 | reparent_error(scanner, "struct reparent error"); |
| 1798 | } |
| 1799 | | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end |
| 1800 | { |
| 1801 | $$ = make_node(scanner, NODE_STRUCT); |
| 1802 | $$->u._struct.has_body = 1; |
| 1803 | $$->u._struct.name = $1; |
| 1804 | if ($3 && set_parent_node($3, $$)) |
| 1805 | reparent_error(scanner, "struct reparent error"); |
| 1806 | } |
| 1807 | | ID_TYPE 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 | | IDENTIFIER |
| 1816 | { |
| 1817 | $$ = make_node(scanner, NODE_STRUCT); |
| 1818 | $$->u._struct.has_body = 0; |
| 1819 | $$->u._struct.name = $1; |
| 1820 | } |
| 1821 | | ID_TYPE |
| 1822 | { |
| 1823 | $$ = make_node(scanner, NODE_STRUCT); |
| 1824 | $$->u._struct.has_body = 0; |
| 1825 | $$->u._struct.name = $1; |
| 1826 | } |
| 1827 | | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN |
| 1828 | { |
| 1829 | $$ = make_node(scanner, NODE_STRUCT); |
| 1830 | $$->u._struct.has_body = 1; |
| 1831 | bt_list_add_tail(&($6)->siblings, &$$->u._struct.min_align); |
| 1832 | if ($2 && set_parent_node($2, $$)) |
| 1833 | reparent_error(scanner, "struct reparent error"); |
| 1834 | } |
| 1835 | | IDENTIFIER 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 | $$->u._struct.name = $1; |
| 1840 | bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align); |
| 1841 | if ($3 && set_parent_node($3, $$)) |
| 1842 | reparent_error(scanner, "struct reparent error"); |
| 1843 | } |
| 1844 | | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN |
| 1845 | { |
| 1846 | $$ = make_node(scanner, NODE_STRUCT); |
| 1847 | $$->u._struct.has_body = 1; |
| 1848 | $$->u._struct.name = $1; |
| 1849 | bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align); |
| 1850 | if ($3 && set_parent_node($3, $$)) |
| 1851 | reparent_error(scanner, "struct reparent error"); |
| 1852 | } |
| 1853 | ; |
| 1854 | |
| 1855 | struct_declaration_begin: |
| 1856 | LBRAC |
| 1857 | { push_scope(scanner); } |
| 1858 | ; |
| 1859 | |
| 1860 | struct_declaration_end: |
| 1861 | RBRAC |
| 1862 | { pop_scope(scanner); } |
| 1863 | ; |
| 1864 | |
| 1865 | variant_type_specifier: |
| 1866 | variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1867 | { |
| 1868 | $$ = make_node(scanner, NODE_VARIANT); |
| 1869 | $$->u.variant.has_body = 1; |
| 1870 | if ($2 && set_parent_node($2, $$)) |
| 1871 | reparent_error(scanner, "variant reparent error"); |
| 1872 | } |
| 1873 | | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1874 | { |
| 1875 | $$ = make_node(scanner, NODE_VARIANT); |
| 1876 | $$->u.variant.has_body = 1; |
| 1877 | $$->u.variant.choice = $2; |
| 1878 | if ($5 && set_parent_node($5, $$)) |
| 1879 | reparent_error(scanner, "variant reparent error"); |
| 1880 | } |
| 1881 | | LT ID_TYPE 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 | | IDENTIFIER 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.name = $1; |
| 1894 | if ($3 && set_parent_node($3, $$)) |
| 1895 | reparent_error(scanner, "variant reparent error"); |
| 1896 | } |
| 1897 | | IDENTIFIER LT IDENTIFIER GT 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 | $$->u.variant.choice = $3; |
| 1903 | if ($6 && set_parent_node($6, $$)) |
| 1904 | reparent_error(scanner, "variant reparent error"); |
| 1905 | } |
| 1906 | | IDENTIFIER LT IDENTIFIER GT |
| 1907 | { |
| 1908 | $$ = make_node(scanner, NODE_VARIANT); |
| 1909 | $$->u.variant.has_body = 0; |
| 1910 | $$->u.variant.name = $1; |
| 1911 | $$->u.variant.choice = $3; |
| 1912 | } |
| 1913 | | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1914 | { |
| 1915 | $$ = make_node(scanner, NODE_VARIANT); |
| 1916 | $$->u.variant.has_body = 1; |
| 1917 | $$->u.variant.name = $1; |
| 1918 | $$->u.variant.choice = $3; |
| 1919 | if ($6 && set_parent_node($6, $$)) |
| 1920 | reparent_error(scanner, "variant reparent error"); |
| 1921 | } |
| 1922 | | IDENTIFIER LT ID_TYPE GT |
| 1923 | { |
| 1924 | $$ = make_node(scanner, NODE_VARIANT); |
| 1925 | $$->u.variant.has_body = 0; |
| 1926 | $$->u.variant.name = $1; |
| 1927 | $$->u.variant.choice = $3; |
| 1928 | } |
| 1929 | | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1930 | { |
| 1931 | $$ = make_node(scanner, NODE_VARIANT); |
| 1932 | $$->u.variant.has_body = 1; |
| 1933 | $$->u.variant.name = $1; |
| 1934 | if ($3 && set_parent_node($3, $$)) |
| 1935 | reparent_error(scanner, "variant reparent error"); |
| 1936 | } |
| 1937 | | ID_TYPE LT IDENTIFIER GT 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 | $$->u.variant.choice = $3; |
| 1943 | if ($6 && set_parent_node($6, $$)) |
| 1944 | reparent_error(scanner, "variant reparent error"); |
| 1945 | } |
| 1946 | | ID_TYPE LT IDENTIFIER GT |
| 1947 | { |
| 1948 | $$ = make_node(scanner, NODE_VARIANT); |
| 1949 | $$->u.variant.has_body = 0; |
| 1950 | $$->u.variant.name = $1; |
| 1951 | $$->u.variant.choice = $3; |
| 1952 | } |
| 1953 | | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1954 | { |
| 1955 | $$ = make_node(scanner, NODE_VARIANT); |
| 1956 | $$->u.variant.has_body = 1; |
| 1957 | $$->u.variant.name = $1; |
| 1958 | $$->u.variant.choice = $3; |
| 1959 | if ($6 && set_parent_node($6, $$)) |
| 1960 | reparent_error(scanner, "variant reparent error"); |
| 1961 | } |
| 1962 | | ID_TYPE LT ID_TYPE GT |
| 1963 | { |
| 1964 | $$ = make_node(scanner, NODE_VARIANT); |
| 1965 | $$->u.variant.has_body = 0; |
| 1966 | $$->u.variant.name = $1; |
| 1967 | $$->u.variant.choice = $3; |
| 1968 | } |
| 1969 | ; |
| 1970 | |
| 1971 | variant_declaration_begin: |
| 1972 | LBRAC |
| 1973 | { push_scope(scanner); } |
| 1974 | ; |
| 1975 | |
| 1976 | variant_declaration_end: |
| 1977 | RBRAC |
| 1978 | { pop_scope(scanner); } |
| 1979 | ; |
| 1980 | |
| 1981 | enum_type_specifier: |
| 1982 | LBRAC enumerator_list RBRAC |
| 1983 | { |
| 1984 | $$ = make_node(scanner, NODE_ENUM); |
| 1985 | $$->u._enum.has_body = 1; |
| 1986 | _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1987 | } |
| 1988 | | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC |
| 1989 | { |
| 1990 | $$ = make_node(scanner, NODE_ENUM); |
| 1991 | $$->u._enum.has_body = 1; |
| 1992 | ($$)->u._enum.container_type = $2; |
| 1993 | _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1994 | } |
| 1995 | | IDENTIFIER LBRAC enumerator_list RBRAC |
| 1996 | { |
| 1997 | $$ = make_node(scanner, NODE_ENUM); |
| 1998 | $$->u._enum.has_body = 1; |
| 1999 | $$->u._enum.enum_id = $1; |
| 2000 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list); |
| 2001 | } |
| 2002 | | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC |
| 2003 | { |
| 2004 | $$ = make_node(scanner, NODE_ENUM); |
| 2005 | $$->u._enum.has_body = 1; |
| 2006 | $$->u._enum.enum_id = $1; |
| 2007 | ($$)->u._enum.container_type = $3; |
| 2008 | _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); |
| 2009 | } |
| 2010 | | ID_TYPE LBRAC enumerator_list RBRAC |
| 2011 | { |
| 2012 | $$ = make_node(scanner, NODE_ENUM); |
| 2013 | $$->u._enum.has_body = 1; |
| 2014 | $$->u._enum.enum_id = $1; |
| 2015 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list); |
| 2016 | } |
| 2017 | | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC |
| 2018 | { |
| 2019 | $$ = make_node(scanner, NODE_ENUM); |
| 2020 | $$->u._enum.has_body = 1; |
| 2021 | $$->u._enum.enum_id = $1; |
| 2022 | ($$)->u._enum.container_type = $3; |
| 2023 | _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); |
| 2024 | } |
| 2025 | | LBRAC enumerator_list COMMA RBRAC |
| 2026 | { |
| 2027 | $$ = make_node(scanner, NODE_ENUM); |
| 2028 | $$->u._enum.has_body = 1; |
| 2029 | _bt_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list); |
| 2030 | } |
| 2031 | | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC |
| 2032 | { |
| 2033 | $$ = make_node(scanner, NODE_ENUM); |
| 2034 | $$->u._enum.has_body = 1; |
| 2035 | ($$)->u._enum.container_type = $2; |
| 2036 | _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list); |
| 2037 | } |
| 2038 | | IDENTIFIER LBRAC enumerator_list COMMA RBRAC |
| 2039 | { |
| 2040 | $$ = make_node(scanner, NODE_ENUM); |
| 2041 | $$->u._enum.has_body = 1; |
| 2042 | $$->u._enum.enum_id = $1; |
| 2043 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list); |
| 2044 | } |
| 2045 | | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC |
| 2046 | { |
| 2047 | $$ = make_node(scanner, NODE_ENUM); |
| 2048 | $$->u._enum.has_body = 1; |
| 2049 | $$->u._enum.enum_id = $1; |
| 2050 | ($$)->u._enum.container_type = $3; |
| 2051 | _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); |
| 2052 | } |
| 2053 | | IDENTIFIER |
| 2054 | { |
| 2055 | $$ = make_node(scanner, NODE_ENUM); |
| 2056 | $$->u._enum.has_body = 0; |
| 2057 | $$->u._enum.enum_id = $1; |
| 2058 | } |
| 2059 | | ID_TYPE LBRAC enumerator_list COMMA RBRAC |
| 2060 | { |
| 2061 | $$ = make_node(scanner, NODE_ENUM); |
| 2062 | $$->u._enum.has_body = 1; |
| 2063 | $$->u._enum.enum_id = $1; |
| 2064 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list); |
| 2065 | } |
| 2066 | | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC |
| 2067 | { |
| 2068 | $$ = make_node(scanner, NODE_ENUM); |
| 2069 | $$->u._enum.has_body = 1; |
| 2070 | $$->u._enum.enum_id = $1; |
| 2071 | ($$)->u._enum.container_type = $3; |
| 2072 | _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); |
| 2073 | } |
| 2074 | | ID_TYPE |
| 2075 | { |
| 2076 | $$ = make_node(scanner, NODE_ENUM); |
| 2077 | $$->u._enum.has_body = 0; |
| 2078 | $$->u._enum.enum_id = $1; |
| 2079 | } |
| 2080 | ; |
| 2081 | |
| 2082 | struct_or_variant_declaration_list: |
| 2083 | /* empty */ |
| 2084 | { $$ = NULL; } |
| 2085 | | struct_or_variant_declaration_list struct_or_variant_declaration |
| 2086 | { |
| 2087 | if ($1) { |
| 2088 | $$ = $1; |
| 2089 | bt_list_add_tail(&($2)->siblings, &($$)->tmp_head); |
| 2090 | } else { |
| 2091 | $$ = $2; |
| 2092 | bt_list_add_tail(&($$)->siblings, &($$)->tmp_head); |
| 2093 | } |
| 2094 | } |
| 2095 | ; |
| 2096 | |
| 2097 | struct_or_variant_declaration: |
| 2098 | declaration_specifiers struct_or_variant_declarator_list SEMICOLON |
| 2099 | { |
| 2100 | struct ctf_node *list; |
| 2101 | |
| 2102 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2103 | _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 2104 | $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION); |
| 2105 | ($$)->u.struct_or_variant_declaration.type_specifier_list = list; |
| 2106 | _bt_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators); |
| 2107 | } |
| 2108 | | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON |
| 2109 | { |
| 2110 | struct ctf_node *list; |
| 2111 | |
| 2112 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 2113 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2114 | $$->u._typedef.type_specifier_list = list; |
| 2115 | _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 2116 | _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 2117 | _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators); |
| 2118 | } |
| 2119 | | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON |
| 2120 | { |
| 2121 | struct ctf_node *list; |
| 2122 | |
| 2123 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 2124 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2125 | $$->u._typedef.type_specifier_list = list; |
| 2126 | _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 2127 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); |
| 2128 | } |
| 2129 | | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON |
| 2130 | { |
| 2131 | struct ctf_node *list; |
| 2132 | |
| 2133 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2134 | _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 2135 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 2136 | ($$)->u.struct_or_variant_declaration.type_specifier_list = list; |
| 2137 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); |
| 2138 | } |
| 2139 | | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON |
| 2140 | { |
| 2141 | struct ctf_node *list; |
| 2142 | |
| 2143 | $$ = make_node(scanner, NODE_TYPEALIAS); |
| 2144 | $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET); |
| 2145 | $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS); |
| 2146 | |
| 2147 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2148 | $$->u.typealias.target->u.typealias_target.type_specifier_list = list; |
| 2149 | _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 2150 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators); |
| 2151 | |
| 2152 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2153 | $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list; |
| 2154 | _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 2155 | _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators); |
| 2156 | } |
| 2157 | ; |
| 2158 | |
| 2159 | alias_declaration_specifiers: |
| 2160 | CONST |
| 2161 | { |
| 2162 | struct ctf_node *node; |
| 2163 | |
| 2164 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2165 | node = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 2166 | node->u.type_specifier.type = TYPESPEC_CONST; |
| 2167 | bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head); |
| 2168 | } |
| 2169 | | type_specifier |
| 2170 | { |
| 2171 | struct ctf_node *node; |
| 2172 | |
| 2173 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2174 | node = $1; |
| 2175 | bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head); |
| 2176 | } |
| 2177 | | IDENTIFIER |
| 2178 | { |
| 2179 | struct ctf_node *node; |
| 2180 | |
| 2181 | add_type(scanner, $1); |
| 2182 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2183 | node = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 2184 | node->u.type_specifier.type = TYPESPEC_ID_TYPE; |
| 2185 | node->u.type_specifier.id_type = yylval.s; |
| 2186 | bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head); |
| 2187 | } |
| 2188 | | alias_declaration_specifiers CONST |
| 2189 | { |
| 2190 | struct ctf_node *node; |
| 2191 | |
| 2192 | $$ = $1; |
| 2193 | node = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 2194 | node->u.type_specifier.type = TYPESPEC_CONST; |
| 2195 | bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head); |
| 2196 | } |
| 2197 | | alias_declaration_specifiers type_specifier |
| 2198 | { |
| 2199 | $$ = $1; |
| 2200 | bt_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head); |
| 2201 | } |
| 2202 | | alias_declaration_specifiers IDENTIFIER |
| 2203 | { |
| 2204 | struct ctf_node *node; |
| 2205 | |
| 2206 | add_type(scanner, $2); |
| 2207 | $$ = $1; |
| 2208 | node = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 2209 | node->u.type_specifier.type = TYPESPEC_ID_TYPE; |
| 2210 | node->u.type_specifier.id_type = yylval.s; |
| 2211 | bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head); |
| 2212 | } |
| 2213 | ; |
| 2214 | |
| 2215 | struct_or_variant_declarator_list: |
| 2216 | struct_or_variant_declarator |
| 2217 | { $$ = $1; } |
| 2218 | | struct_or_variant_declarator_list COMMA struct_or_variant_declarator |
| 2219 | { |
| 2220 | $$ = $1; |
| 2221 | bt_list_add_tail(&($3)->siblings, &($$)->tmp_head); |
| 2222 | } |
| 2223 | ; |
| 2224 | |
| 2225 | struct_or_variant_declarator: |
| 2226 | declarator |
| 2227 | { $$ = $1; } |
| 2228 | | COLON unary_expression |
| 2229 | { $$ = $2; } |
| 2230 | | declarator COLON unary_expression |
| 2231 | { |
| 2232 | $$ = $1; |
| 2233 | if (set_parent_node($3, $1)) |
| 2234 | reparent_error(scanner, "struct_or_variant_declarator"); |
| 2235 | } |
| 2236 | ; |
| 2237 | |
| 2238 | enumerator_list: |
| 2239 | enumerator |
| 2240 | { $$ = $1; } |
| 2241 | | enumerator_list COMMA enumerator |
| 2242 | { |
| 2243 | $$ = $1; |
| 2244 | bt_list_add_tail(&($3)->siblings, &($$)->tmp_head); |
| 2245 | } |
| 2246 | ; |
| 2247 | |
| 2248 | enumerator: |
| 2249 | IDENTIFIER |
| 2250 | { |
| 2251 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 2252 | $$->u.enumerator.id = $1; |
| 2253 | } |
| 2254 | | ID_TYPE |
| 2255 | { |
| 2256 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 2257 | $$->u.enumerator.id = $1; |
| 2258 | } |
| 2259 | | keywords |
| 2260 | { |
| 2261 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 2262 | $$->u.enumerator.id = $1; |
| 2263 | } |
| 2264 | | STRING_LITERAL |
| 2265 | { |
| 2266 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 2267 | $$->u.enumerator.id = $1; |
| 2268 | } |
| 2269 | | IDENTIFIER EQUAL unary_expression_or_range |
| 2270 | { |
| 2271 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 2272 | $$->u.enumerator.id = $1; |
| 2273 | bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values); |
| 2274 | } |
| 2275 | | ID_TYPE EQUAL unary_expression_or_range |
| 2276 | { |
| 2277 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 2278 | $$->u.enumerator.id = $1; |
| 2279 | bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values); |
| 2280 | } |
| 2281 | | keywords EQUAL unary_expression_or_range |
| 2282 | { |
| 2283 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 2284 | $$->u.enumerator.id = $1; |
| 2285 | bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values); |
| 2286 | } |
| 2287 | | STRING_LITERAL EQUAL unary_expression_or_range |
| 2288 | { |
| 2289 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 2290 | $$->u.enumerator.id = $1; |
| 2291 | bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values); |
| 2292 | } |
| 2293 | ; |
| 2294 | |
| 2295 | abstract_declarator_list: |
| 2296 | abstract_declarator |
| 2297 | { $$ = $1; } |
| 2298 | | abstract_declarator_list COMMA abstract_declarator |
| 2299 | { |
| 2300 | $$ = $1; |
| 2301 | bt_list_add_tail(&($3)->siblings, &($$)->tmp_head); |
| 2302 | } |
| 2303 | ; |
| 2304 | |
| 2305 | abstract_declarator: |
| 2306 | direct_abstract_declarator |
| 2307 | { $$ = $1; } |
| 2308 | | pointer direct_abstract_declarator |
| 2309 | { |
| 2310 | $$ = $2; |
| 2311 | bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers); |
| 2312 | } |
| 2313 | ; |
| 2314 | |
| 2315 | direct_abstract_declarator: |
| 2316 | /* empty */ |
| 2317 | { |
| 2318 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 2319 | $$->u.type_declarator.type = TYPEDEC_ID; |
| 2320 | /* id is NULL */ |
| 2321 | } |
| 2322 | | IDENTIFIER |
| 2323 | { |
| 2324 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 2325 | $$->u.type_declarator.type = TYPEDEC_ID; |
| 2326 | $$->u.type_declarator.u.id = $1; |
| 2327 | } |
| 2328 | | LPAREN abstract_declarator RPAREN |
| 2329 | { |
| 2330 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 2331 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 2332 | $$->u.type_declarator.u.nested.type_declarator = $2; |
| 2333 | } |
| 2334 | | direct_abstract_declarator LSBRAC unary_expression RSBRAC |
| 2335 | { |
| 2336 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 2337 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 2338 | $$->u.type_declarator.u.nested.type_declarator = $1; |
| 2339 | BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length); |
| 2340 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length); |
| 2341 | } |
| 2342 | | direct_abstract_declarator LSBRAC 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 | $$->u.type_declarator.u.nested.abstract_array = 1; |
| 2348 | } |
| 2349 | ; |
| 2350 | |
| 2351 | alias_abstract_declarator_list: |
| 2352 | alias_abstract_declarator |
| 2353 | { $$ = $1; } |
| 2354 | | alias_abstract_declarator_list COMMA alias_abstract_declarator |
| 2355 | { |
| 2356 | $$ = $1; |
| 2357 | bt_list_add_tail(&($3)->siblings, &($$)->tmp_head); |
| 2358 | } |
| 2359 | ; |
| 2360 | |
| 2361 | alias_abstract_declarator: |
| 2362 | direct_alias_abstract_declarator |
| 2363 | { $$ = $1; } |
| 2364 | | pointer direct_alias_abstract_declarator |
| 2365 | { |
| 2366 | $$ = $2; |
| 2367 | bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers); |
| 2368 | } |
| 2369 | ; |
| 2370 | |
| 2371 | direct_alias_abstract_declarator: |
| 2372 | /* empty */ |
| 2373 | { |
| 2374 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 2375 | $$->u.type_declarator.type = TYPEDEC_ID; |
| 2376 | /* id is NULL */ |
| 2377 | } |
| 2378 | | LPAREN alias_abstract_declarator RPAREN |
| 2379 | { |
| 2380 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 2381 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 2382 | $$->u.type_declarator.u.nested.type_declarator = $2; |
| 2383 | } |
| 2384 | | direct_alias_abstract_declarator LSBRAC unary_expression RSBRAC |
| 2385 | { |
| 2386 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 2387 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 2388 | $$->u.type_declarator.u.nested.type_declarator = $1; |
| 2389 | BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length); |
| 2390 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length); |
| 2391 | } |
| 2392 | | direct_alias_abstract_declarator LSBRAC 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 | $$->u.type_declarator.u.nested.abstract_array = 1; |
| 2398 | } |
| 2399 | ; |
| 2400 | |
| 2401 | declarator: |
| 2402 | direct_declarator |
| 2403 | { $$ = $1; } |
| 2404 | | pointer direct_declarator |
| 2405 | { |
| 2406 | $$ = $2; |
| 2407 | bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers); |
| 2408 | } |
| 2409 | ; |
| 2410 | |
| 2411 | direct_declarator: |
| 2412 | IDENTIFIER |
| 2413 | { |
| 2414 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 2415 | $$->u.type_declarator.type = TYPEDEC_ID; |
| 2416 | $$->u.type_declarator.u.id = $1; |
| 2417 | } |
| 2418 | | LPAREN declarator RPAREN |
| 2419 | { |
| 2420 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 2421 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 2422 | $$->u.type_declarator.u.nested.type_declarator = $2; |
| 2423 | } |
| 2424 | | direct_declarator LSBRAC unary_expression RSBRAC |
| 2425 | { |
| 2426 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 2427 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 2428 | $$->u.type_declarator.u.nested.type_declarator = $1; |
| 2429 | BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length); |
| 2430 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length); |
| 2431 | } |
| 2432 | ; |
| 2433 | |
| 2434 | type_declarator: |
| 2435 | direct_type_declarator |
| 2436 | { $$ = $1; } |
| 2437 | | pointer direct_type_declarator |
| 2438 | { |
| 2439 | $$ = $2; |
| 2440 | bt_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers); |
| 2441 | } |
| 2442 | ; |
| 2443 | |
| 2444 | direct_type_declarator: |
| 2445 | IDENTIFIER |
| 2446 | { |
| 2447 | add_type(scanner, $1); |
| 2448 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 2449 | $$->u.type_declarator.type = TYPEDEC_ID; |
| 2450 | $$->u.type_declarator.u.id = $1; |
| 2451 | } |
| 2452 | | LPAREN type_declarator RPAREN |
| 2453 | { |
| 2454 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 2455 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 2456 | $$->u.type_declarator.u.nested.type_declarator = $2; |
| 2457 | } |
| 2458 | | direct_type_declarator LSBRAC unary_expression RSBRAC |
| 2459 | { |
| 2460 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 2461 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 2462 | $$->u.type_declarator.u.nested.type_declarator = $1; |
| 2463 | BT_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length); |
| 2464 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length); |
| 2465 | } |
| 2466 | ; |
| 2467 | |
| 2468 | pointer: |
| 2469 | STAR |
| 2470 | { |
| 2471 | $$ = make_node(scanner, NODE_POINTER); |
| 2472 | } |
| 2473 | | STAR pointer |
| 2474 | { |
| 2475 | $$ = make_node(scanner, NODE_POINTER); |
| 2476 | bt_list_splice(&($2)->tmp_head, &($$)->tmp_head); |
| 2477 | } |
| 2478 | | STAR type_qualifier_list pointer |
| 2479 | { |
| 2480 | $$ = make_node(scanner, NODE_POINTER); |
| 2481 | $$->u.pointer.const_qualifier = 1; |
| 2482 | bt_list_splice(&($3)->tmp_head, &($$)->tmp_head); |
| 2483 | } |
| 2484 | ; |
| 2485 | |
| 2486 | type_qualifier_list: |
| 2487 | /* pointer assumes only const type qualifier */ |
| 2488 | CONST |
| 2489 | | type_qualifier_list CONST |
| 2490 | ; |
| 2491 | |
| 2492 | /* 2.3: CTF-specific declarations */ |
| 2493 | |
| 2494 | ctf_assignment_expression_list: |
| 2495 | ctf_assignment_expression SEMICOLON |
| 2496 | { $$ = $1; } |
| 2497 | | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON |
| 2498 | { |
| 2499 | $$ = $1; |
| 2500 | bt_list_add_tail(&($2)->siblings, &($$)->tmp_head); |
| 2501 | } |
| 2502 | ; |
| 2503 | |
| 2504 | ctf_assignment_expression: |
| 2505 | unary_expression EQUAL unary_expression |
| 2506 | { |
| 2507 | /* |
| 2508 | * Because we have left and right, cannot use |
| 2509 | * set_parent_node. |
| 2510 | */ |
| 2511 | $$ = make_node(scanner, NODE_CTF_EXPRESSION); |
| 2512 | _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left); |
| 2513 | if ($1->u.unary_expression.type != UNARY_STRING) |
| 2514 | reparent_error(scanner, "ctf_assignment_expression left expects string"); |
| 2515 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right); |
| 2516 | } |
| 2517 | | unary_expression TYPEASSIGN declaration_specifiers /* Only allow struct */ |
| 2518 | { |
| 2519 | /* |
| 2520 | * Because we have left and right, cannot use |
| 2521 | * set_parent_node. |
| 2522 | */ |
| 2523 | $$ = make_node(scanner, NODE_CTF_EXPRESSION); |
| 2524 | _bt_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left); |
| 2525 | if ($1->u.unary_expression.type != UNARY_STRING) |
| 2526 | reparent_error(scanner, "ctf_assignment_expression left expects string"); |
| 2527 | bt_list_add_tail(&($3)->siblings, &($$)->u.ctf_expression.right); |
| 2528 | } |
| 2529 | | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list |
| 2530 | { |
| 2531 | struct ctf_node *list; |
| 2532 | |
| 2533 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2534 | _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 2535 | _bt_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 2536 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 2537 | ($$)->u.struct_or_variant_declaration.type_specifier_list = list; |
| 2538 | _bt_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators); |
| 2539 | } |
| 2540 | | TYPEDEF declaration_specifiers type_declarator_list |
| 2541 | { |
| 2542 | struct ctf_node *list; |
| 2543 | |
| 2544 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 2545 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2546 | $$->u._typedef.type_specifier_list = list; |
| 2547 | _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 2548 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); |
| 2549 | } |
| 2550 | | declaration_specifiers TYPEDEF type_declarator_list |
| 2551 | { |
| 2552 | struct ctf_node *list; |
| 2553 | |
| 2554 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2555 | _bt_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 2556 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 2557 | ($$)->u.struct_or_variant_declaration.type_specifier_list = list; |
| 2558 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); |
| 2559 | } |
| 2560 | | TYPEALIAS declaration_specifiers abstract_declarator_list TYPEASSIGN alias_declaration_specifiers alias_abstract_declarator_list |
| 2561 | { |
| 2562 | struct ctf_node *list; |
| 2563 | |
| 2564 | $$ = make_node(scanner, NODE_TYPEALIAS); |
| 2565 | $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET); |
| 2566 | $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS); |
| 2567 | |
| 2568 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2569 | $$->u.typealias.target->u.typealias_target.type_specifier_list = list; |
| 2570 | _bt_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 2571 | _bt_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators); |
| 2572 | |
| 2573 | list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); |
| 2574 | $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list; |
| 2575 | _bt_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head); |
| 2576 | _bt_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators); |
| 2577 | } |
| 2578 | ; |