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