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