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