| 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 | |
| 20 | #include <stdio.h> |
| 21 | #include <unistd.h> |
| 22 | #include <string.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <assert.h> |
| 25 | #include <glib.h> |
| 26 | #include <errno.h> |
| 27 | #include <inttypes.h> |
| 28 | #include <babeltrace/list.h> |
| 29 | #include "ctf-scanner.h" |
| 30 | #include "ctf-parser.h" |
| 31 | #include "ctf-ast.h" |
| 32 | |
| 33 | /* |
| 34 | * TODO: support enum, variant and struct declarations in scopes. |
| 35 | */ |
| 36 | |
| 37 | /* Join two lists, put "add" at the end of "head". */ |
| 38 | static inline void |
| 39 | _cds_list_splice_tail (struct cds_list_head *add, struct cds_list_head *head) |
| 40 | { |
| 41 | /* Do nothing if the list which gets added is empty. */ |
| 42 | if (add != add->next) { |
| 43 | add->next->prev = head->prev; |
| 44 | add->prev->next = head; |
| 45 | head->prev->next = add->next; |
| 46 | head->prev = add->prev; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | #define printf_dbg(fmt, args...) fprintf(stderr, "%s: " fmt, __func__, ## args) |
| 51 | |
| 52 | int yyparse(struct ctf_scanner *scanner); |
| 53 | int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner); |
| 54 | int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals); |
| 55 | int yylex_destroy(yyscan_t yyscanner) ; |
| 56 | void yyset_in(FILE * in_str, yyscan_t scanner); |
| 57 | |
| 58 | int yydebug; |
| 59 | |
| 60 | struct gc_string { |
| 61 | struct cds_list_head gc; |
| 62 | size_t alloclen; |
| 63 | char s[]; |
| 64 | }; |
| 65 | |
| 66 | static const char *node_type_to_str[] = { |
| 67 | [ NODE_UNKNOWN ] = "NODE_UNKNOWN", |
| 68 | [ NODE_ROOT ] = "NODE_ROOT", |
| 69 | [ NODE_EVENT ] = "NODE_EVENT", |
| 70 | [ NODE_STREAM ] = "NODE_STREAM", |
| 71 | [ NODE_TRACE ] = "NODE_TRACE", |
| 72 | [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION", |
| 73 | [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION", |
| 74 | [ NODE_TYPEDEF ] = "NODE_TYPEDEF", |
| 75 | [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET", |
| 76 | [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS", |
| 77 | [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS", |
| 78 | [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER", |
| 79 | [ NODE_POINTER ] = "NODE_POINTER", |
| 80 | [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR", |
| 81 | [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT", |
| 82 | [ NODE_INTEGER ] = "NODE_INTEGER", |
| 83 | [ NODE_STRING ] = "NODE_STRING", |
| 84 | [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR", |
| 85 | [ NODE_ENUM ] = "NODE_ENUM", |
| 86 | [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION", |
| 87 | [ NODE_VARIANT ] = "NODE_VARIANT", |
| 88 | [ NODE_STRUCT ] = "NODE_STRUCT", |
| 89 | }; |
| 90 | |
| 91 | const char *node_type(struct ctf_node *node) |
| 92 | { |
| 93 | if (node->type < NR_NODE_TYPES) |
| 94 | return node_type_to_str[node->type]; |
| 95 | else |
| 96 | return NULL; |
| 97 | } |
| 98 | |
| 99 | static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner, |
| 100 | size_t len) |
| 101 | { |
| 102 | struct gc_string *gstr; |
| 103 | size_t alloclen; |
| 104 | |
| 105 | /* TODO: could be faster with find first bit or glib Gstring */ |
| 106 | /* sizeof long to account for malloc header (int or long ?) */ |
| 107 | for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len; |
| 108 | alloclen *= 2); |
| 109 | |
| 110 | gstr = malloc(alloclen); |
| 111 | cds_list_add(&gstr->gc, &scanner->allocated_strings); |
| 112 | gstr->alloclen = alloclen; |
| 113 | return gstr; |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | * note: never use gc_string_append on a string that has external references. |
| 118 | * gsrc will be garbage collected immediately, and gstr might be. |
| 119 | * Should only be used to append characters to a string literal or constant. |
| 120 | */ |
| 121 | struct gc_string *gc_string_append(struct ctf_scanner *scanner, |
| 122 | struct gc_string *gstr, |
| 123 | struct gc_string *gsrc) |
| 124 | { |
| 125 | size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1; |
| 126 | size_t alloclen; |
| 127 | |
| 128 | /* TODO: could be faster with find first bit or glib Gstring */ |
| 129 | /* sizeof long to account for malloc header (int or long ?) */ |
| 130 | for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen; |
| 131 | alloclen *= 2); |
| 132 | |
| 133 | if (alloclen > gstr->alloclen) { |
| 134 | struct gc_string *newgstr; |
| 135 | |
| 136 | newgstr = gc_string_alloc(scanner, newlen); |
| 137 | strcpy(newgstr->s, gstr->s); |
| 138 | strcat(newgstr->s, gsrc->s); |
| 139 | cds_list_del(&gstr->gc); |
| 140 | free(gstr); |
| 141 | gstr = newgstr; |
| 142 | } else { |
| 143 | strcat(gstr->s, gsrc->s); |
| 144 | } |
| 145 | cds_list_del(&gsrc->gc); |
| 146 | free(gsrc); |
| 147 | return gstr; |
| 148 | } |
| 149 | |
| 150 | void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src) |
| 151 | { |
| 152 | lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1); |
| 153 | strcpy(lvalp->gs->s, src); |
| 154 | } |
| 155 | |
| 156 | static void init_scope(struct ctf_scanner_scope *scope, |
| 157 | struct ctf_scanner_scope *parent) |
| 158 | { |
| 159 | scope->parent = parent; |
| 160 | scope->types = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 161 | NULL, NULL); |
| 162 | } |
| 163 | |
| 164 | static void finalize_scope(struct ctf_scanner_scope *scope) |
| 165 | { |
| 166 | g_hash_table_destroy(scope->types); |
| 167 | } |
| 168 | |
| 169 | static void push_scope(struct ctf_scanner *scanner) |
| 170 | { |
| 171 | struct ctf_scanner_scope *ns; |
| 172 | |
| 173 | printf_dbg("push scope\n"); |
| 174 | ns = malloc(sizeof(struct ctf_scanner_scope)); |
| 175 | init_scope(ns, scanner->cs); |
| 176 | scanner->cs = ns; |
| 177 | } |
| 178 | |
| 179 | static void pop_scope(struct ctf_scanner *scanner) |
| 180 | { |
| 181 | struct ctf_scanner_scope *os; |
| 182 | |
| 183 | printf_dbg("pop scope\n"); |
| 184 | os = scanner->cs; |
| 185 | scanner->cs = os->parent; |
| 186 | finalize_scope(os); |
| 187 | free(os); |
| 188 | } |
| 189 | |
| 190 | static int lookup_type(struct ctf_scanner_scope *s, const char *id) |
| 191 | { |
| 192 | int ret; |
| 193 | |
| 194 | ret = (int) (long) g_hash_table_lookup(s->types, id); |
| 195 | printf_dbg("lookup %p %s %d\n", s, id, ret); |
| 196 | return ret; |
| 197 | } |
| 198 | |
| 199 | int is_type(struct ctf_scanner *scanner, const char *id) |
| 200 | { |
| 201 | struct ctf_scanner_scope *it; |
| 202 | int ret = 0; |
| 203 | |
| 204 | for (it = scanner->cs; it != NULL; it = it->parent) { |
| 205 | if (lookup_type(it, id)) { |
| 206 | ret = 1; |
| 207 | break; |
| 208 | } |
| 209 | } |
| 210 | printf_dbg("is type %s %d\n", id, ret); |
| 211 | return ret; |
| 212 | } |
| 213 | |
| 214 | static void add_type(struct ctf_scanner *scanner, struct gc_string *id) |
| 215 | { |
| 216 | printf_dbg("add type %s\n", id->s); |
| 217 | if (lookup_type(scanner->cs, id->s)) |
| 218 | return; |
| 219 | g_hash_table_insert(scanner->cs->types, id->s, id->s); |
| 220 | } |
| 221 | |
| 222 | static struct ctf_node *make_node(struct ctf_scanner *scanner, |
| 223 | enum node_type type) |
| 224 | { |
| 225 | struct ctf_ast *ast = ctf_scanner_get_ast(scanner); |
| 226 | struct ctf_node *node; |
| 227 | |
| 228 | node = malloc(sizeof(*node)); |
| 229 | if (!node) |
| 230 | return NULL; |
| 231 | memset(node, 0, sizeof(*node)); |
| 232 | node->type = type; |
| 233 | CDS_INIT_LIST_HEAD(&node->tmp_head); |
| 234 | cds_list_add(&node->gc, &ast->allocated_nodes); |
| 235 | cds_list_add(&node->siblings, &node->tmp_head); |
| 236 | |
| 237 | switch (type) { |
| 238 | case NODE_ROOT: |
| 239 | fprintf(stderr, "[error] %s: trying to create root node\n", __func__); |
| 240 | break; |
| 241 | |
| 242 | case NODE_EVENT: |
| 243 | CDS_INIT_LIST_HEAD(&node->u.event.declaration_list); |
| 244 | break; |
| 245 | case NODE_STREAM: |
| 246 | CDS_INIT_LIST_HEAD(&node->u.stream.declaration_list); |
| 247 | break; |
| 248 | case NODE_TRACE: |
| 249 | CDS_INIT_LIST_HEAD(&node->u.trace.declaration_list); |
| 250 | break; |
| 251 | |
| 252 | case NODE_CTF_EXPRESSION: |
| 253 | CDS_INIT_LIST_HEAD(&node->u.ctf_expression.left); |
| 254 | CDS_INIT_LIST_HEAD(&node->u.ctf_expression.right); |
| 255 | break; |
| 256 | case NODE_UNARY_EXPRESSION: |
| 257 | break; |
| 258 | |
| 259 | case NODE_TYPEDEF: |
| 260 | CDS_INIT_LIST_HEAD(&node->u._typedef.declaration_specifier); |
| 261 | CDS_INIT_LIST_HEAD(&node->u._typedef.type_declarators); |
| 262 | break; |
| 263 | case NODE_TYPEALIAS_TARGET: |
| 264 | CDS_INIT_LIST_HEAD(&node->u.typealias_target.declaration_specifier); |
| 265 | CDS_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators); |
| 266 | break; |
| 267 | case NODE_TYPEALIAS_ALIAS: |
| 268 | CDS_INIT_LIST_HEAD(&node->u.typealias_alias.declaration_specifier); |
| 269 | CDS_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators); |
| 270 | break; |
| 271 | case NODE_TYPEALIAS: |
| 272 | break; |
| 273 | |
| 274 | case NODE_TYPE_SPECIFIER: |
| 275 | break; |
| 276 | case NODE_POINTER: |
| 277 | break; |
| 278 | case NODE_TYPE_DECLARATOR: |
| 279 | CDS_INIT_LIST_HEAD(&node->u.type_declarator.pointers); |
| 280 | break; |
| 281 | |
| 282 | case NODE_FLOATING_POINT: |
| 283 | CDS_INIT_LIST_HEAD(&node->u.floating_point.expressions); |
| 284 | break; |
| 285 | case NODE_INTEGER: |
| 286 | CDS_INIT_LIST_HEAD(&node->u.integer.expressions); |
| 287 | break; |
| 288 | case NODE_STRING: |
| 289 | CDS_INIT_LIST_HEAD(&node->u.string.expressions); |
| 290 | break; |
| 291 | case NODE_ENUMERATOR: |
| 292 | CDS_INIT_LIST_HEAD(&node->u.enumerator.values); |
| 293 | break; |
| 294 | case NODE_ENUM: |
| 295 | CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list); |
| 296 | break; |
| 297 | case NODE_STRUCT_OR_VARIANT_DECLARATION: |
| 298 | CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.declaration_specifier); |
| 299 | CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators); |
| 300 | break; |
| 301 | case NODE_VARIANT: |
| 302 | CDS_INIT_LIST_HEAD(&node->u.variant.declaration_list); |
| 303 | break; |
| 304 | case NODE_STRUCT: |
| 305 | CDS_INIT_LIST_HEAD(&node->u._struct.declaration_list); |
| 306 | break; |
| 307 | |
| 308 | case NODE_UNKNOWN: |
| 309 | default: |
| 310 | fprintf(stderr, "[error] %s: unknown node type %d\n", __func__, |
| 311 | (int) type); |
| 312 | break; |
| 313 | } |
| 314 | |
| 315 | return node; |
| 316 | } |
| 317 | |
| 318 | static int reparent_ctf_expression(struct ctf_node *node, |
| 319 | struct ctf_node *parent) |
| 320 | { |
| 321 | switch (parent->type) { |
| 322 | case NODE_EVENT: |
| 323 | _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list); |
| 324 | break; |
| 325 | case NODE_STREAM: |
| 326 | _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list); |
| 327 | break; |
| 328 | case NODE_TRACE: |
| 329 | _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list); |
| 330 | break; |
| 331 | case NODE_FLOATING_POINT: |
| 332 | _cds_list_splice_tail(&node->tmp_head, &parent->u.floating_point.expressions); |
| 333 | break; |
| 334 | case NODE_INTEGER: |
| 335 | _cds_list_splice_tail(&node->tmp_head, &parent->u.integer.expressions); |
| 336 | break; |
| 337 | case NODE_STRING: |
| 338 | _cds_list_splice_tail(&node->tmp_head, &parent->u.string.expressions); |
| 339 | break; |
| 340 | |
| 341 | case NODE_ROOT: |
| 342 | case NODE_CTF_EXPRESSION: |
| 343 | case NODE_TYPEDEF: |
| 344 | case NODE_TYPEALIAS_TARGET: |
| 345 | case NODE_TYPEALIAS_ALIAS: |
| 346 | case NODE_TYPEALIAS: |
| 347 | case NODE_TYPE_SPECIFIER: |
| 348 | case NODE_POINTER: |
| 349 | case NODE_TYPE_DECLARATOR: |
| 350 | case NODE_ENUMERATOR: |
| 351 | case NODE_ENUM: |
| 352 | case NODE_STRUCT_OR_VARIANT_DECLARATION: |
| 353 | case NODE_VARIANT: |
| 354 | case NODE_STRUCT: |
| 355 | case NODE_UNARY_EXPRESSION: |
| 356 | return -EPERM; |
| 357 | |
| 358 | case NODE_UNKNOWN: |
| 359 | default: |
| 360 | fprintf(stderr, "[error] %s: unknown node type %d\n", __func__, |
| 361 | (int) parent->type); |
| 362 | return -EINVAL; |
| 363 | } |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent) |
| 368 | { |
| 369 | switch (parent->type) { |
| 370 | case NODE_ROOT: |
| 371 | _cds_list_splice_tail(&node->tmp_head, &parent->u.root._typedef); |
| 372 | break; |
| 373 | case NODE_EVENT: |
| 374 | _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list); |
| 375 | break; |
| 376 | case NODE_STREAM: |
| 377 | _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list); |
| 378 | break; |
| 379 | case NODE_TRACE: |
| 380 | _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list); |
| 381 | break; |
| 382 | case NODE_VARIANT: |
| 383 | _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list); |
| 384 | break; |
| 385 | case NODE_STRUCT: |
| 386 | _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list); |
| 387 | break; |
| 388 | |
| 389 | case NODE_FLOATING_POINT: |
| 390 | case NODE_INTEGER: |
| 391 | case NODE_STRING: |
| 392 | case NODE_CTF_EXPRESSION: |
| 393 | case NODE_TYPEDEF: |
| 394 | case NODE_TYPEALIAS_TARGET: |
| 395 | case NODE_TYPEALIAS_ALIAS: |
| 396 | case NODE_TYPEALIAS: |
| 397 | case NODE_TYPE_SPECIFIER: |
| 398 | case NODE_POINTER: |
| 399 | case NODE_TYPE_DECLARATOR: |
| 400 | case NODE_ENUMERATOR: |
| 401 | case NODE_ENUM: |
| 402 | case NODE_STRUCT_OR_VARIANT_DECLARATION: |
| 403 | case NODE_UNARY_EXPRESSION: |
| 404 | return -EPERM; |
| 405 | |
| 406 | case NODE_UNKNOWN: |
| 407 | default: |
| 408 | fprintf(stderr, "[error] %s: unknown node type %d\n", __func__, |
| 409 | (int) parent->type); |
| 410 | return -EINVAL; |
| 411 | } |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent) |
| 416 | { |
| 417 | switch (parent->type) { |
| 418 | case NODE_ROOT: |
| 419 | _cds_list_splice_tail(&node->tmp_head, &parent->u.root.typealias); |
| 420 | break; |
| 421 | case NODE_EVENT: |
| 422 | _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list); |
| 423 | break; |
| 424 | case NODE_STREAM: |
| 425 | _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list); |
| 426 | break; |
| 427 | case NODE_TRACE: |
| 428 | _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list); |
| 429 | break; |
| 430 | case NODE_VARIANT: |
| 431 | _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list); |
| 432 | break; |
| 433 | case NODE_STRUCT: |
| 434 | _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list); |
| 435 | break; |
| 436 | |
| 437 | case NODE_FLOATING_POINT: |
| 438 | case NODE_INTEGER: |
| 439 | case NODE_STRING: |
| 440 | case NODE_CTF_EXPRESSION: |
| 441 | case NODE_TYPEDEF: |
| 442 | case NODE_TYPEALIAS_TARGET: |
| 443 | case NODE_TYPEALIAS_ALIAS: |
| 444 | case NODE_TYPEALIAS: |
| 445 | case NODE_TYPE_SPECIFIER: |
| 446 | case NODE_POINTER: |
| 447 | case NODE_TYPE_DECLARATOR: |
| 448 | case NODE_ENUMERATOR: |
| 449 | case NODE_ENUM: |
| 450 | case NODE_STRUCT_OR_VARIANT_DECLARATION: |
| 451 | case NODE_UNARY_EXPRESSION: |
| 452 | return -EPERM; |
| 453 | |
| 454 | case NODE_UNKNOWN: |
| 455 | default: |
| 456 | fprintf(stderr, "[error] %s: unknown node type %d\n", __func__, |
| 457 | (int) parent->type); |
| 458 | return -EINVAL; |
| 459 | } |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | static int reparent_type_specifier(struct ctf_node *node, |
| 464 | struct ctf_node *parent) |
| 465 | { |
| 466 | switch (parent->type) { |
| 467 | case NODE_ROOT: |
| 468 | _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_specifier); |
| 469 | break; |
| 470 | case NODE_EVENT: |
| 471 | _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list); |
| 472 | break; |
| 473 | case NODE_STREAM: |
| 474 | _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list); |
| 475 | break; |
| 476 | case NODE_TRACE: |
| 477 | _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list); |
| 478 | break; |
| 479 | case NODE_VARIANT: |
| 480 | _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list); |
| 481 | break; |
| 482 | case NODE_STRUCT: |
| 483 | _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list); |
| 484 | break; |
| 485 | case NODE_TYPEDEF: |
| 486 | _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.declaration_specifier); |
| 487 | break; |
| 488 | case NODE_TYPEALIAS_TARGET: |
| 489 | _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.declaration_specifier); |
| 490 | break; |
| 491 | case NODE_TYPEALIAS_ALIAS: |
| 492 | _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.declaration_specifier); |
| 493 | break; |
| 494 | case NODE_TYPE_DECLARATOR: |
| 495 | parent->u.type_declarator.type = TYPEDEC_NESTED; |
| 496 | parent->u.type_declarator.u.nested.length = node; |
| 497 | break; |
| 498 | case NODE_ENUM: |
| 499 | parent->u._enum.container_type = node; |
| 500 | break; |
| 501 | case NODE_STRUCT_OR_VARIANT_DECLARATION: |
| 502 | _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.declaration_specifier); |
| 503 | break; |
| 504 | case NODE_TYPEALIAS: |
| 505 | case NODE_FLOATING_POINT: |
| 506 | case NODE_INTEGER: |
| 507 | case NODE_STRING: |
| 508 | case NODE_CTF_EXPRESSION: |
| 509 | case NODE_TYPE_SPECIFIER: |
| 510 | case NODE_POINTER: |
| 511 | case NODE_ENUMERATOR: |
| 512 | case NODE_UNARY_EXPRESSION: |
| 513 | return -EPERM; |
| 514 | |
| 515 | case NODE_UNKNOWN: |
| 516 | default: |
| 517 | fprintf(stderr, "[error] %s: unknown node type %d\n", __func__, |
| 518 | (int) parent->type); |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | static int reparent_type_declarator(struct ctf_node *node, |
| 525 | struct ctf_node *parent) |
| 526 | { |
| 527 | switch (parent->type) { |
| 528 | case NODE_TYPE_DECLARATOR: |
| 529 | parent->u.type_declarator.type = TYPEDEC_NESTED; |
| 530 | parent->u.type_declarator.u.nested.type_declarator = node; |
| 531 | break; |
| 532 | case NODE_STRUCT_OR_VARIANT_DECLARATION: |
| 533 | _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.type_declarators); |
| 534 | break; |
| 535 | case NODE_TYPEDEF: |
| 536 | _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.type_declarators); |
| 537 | break; |
| 538 | case NODE_TYPEALIAS_TARGET: |
| 539 | _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.type_declarators); |
| 540 | break; |
| 541 | case NODE_TYPEALIAS_ALIAS: |
| 542 | _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.type_declarators); |
| 543 | break; |
| 544 | |
| 545 | case NODE_ROOT: |
| 546 | case NODE_EVENT: |
| 547 | case NODE_STREAM: |
| 548 | case NODE_TRACE: |
| 549 | case NODE_VARIANT: |
| 550 | case NODE_STRUCT: |
| 551 | case NODE_TYPEALIAS: |
| 552 | case NODE_ENUM: |
| 553 | case NODE_FLOATING_POINT: |
| 554 | case NODE_INTEGER: |
| 555 | case NODE_STRING: |
| 556 | case NODE_CTF_EXPRESSION: |
| 557 | case NODE_TYPE_SPECIFIER: |
| 558 | case NODE_POINTER: |
| 559 | case NODE_ENUMERATOR: |
| 560 | case NODE_UNARY_EXPRESSION: |
| 561 | return -EPERM; |
| 562 | |
| 563 | case NODE_UNKNOWN: |
| 564 | default: |
| 565 | fprintf(stderr, "[error] %s: unknown node type %d\n", __func__, |
| 566 | (int) parent->type); |
| 567 | return -EINVAL; |
| 568 | } |
| 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | /* |
| 573 | * set_parent_node |
| 574 | * |
| 575 | * Link node to parent. Returns 0 on success, -EPERM if it is not permitted to |
| 576 | * create the link declared by the input, -ENOENT if node or parent is NULL, |
| 577 | * -EINVAL if there is an internal structure problem. |
| 578 | */ |
| 579 | static int set_parent_node(struct ctf_node *node, |
| 580 | struct ctf_node *parent) |
| 581 | { |
| 582 | if (!node || !parent) |
| 583 | return -ENOENT; |
| 584 | |
| 585 | /* Note: Linking to parent will be done only by an external visitor */ |
| 586 | |
| 587 | switch (node->type) { |
| 588 | case NODE_ROOT: |
| 589 | fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__); |
| 590 | return -EINVAL; |
| 591 | |
| 592 | case NODE_EVENT: |
| 593 | if (parent->type == NODE_ROOT) { |
| 594 | _cds_list_splice_tail(&node->tmp_head, &parent->u.root.event); |
| 595 | } else |
| 596 | return -EPERM; |
| 597 | break; |
| 598 | case NODE_STREAM: |
| 599 | if (parent->type == NODE_ROOT) { |
| 600 | _cds_list_splice_tail(&node->tmp_head, &parent->u.root.stream); |
| 601 | } else |
| 602 | return -EPERM; |
| 603 | break; |
| 604 | case NODE_TRACE: |
| 605 | if (parent->type == NODE_ROOT) { |
| 606 | _cds_list_splice_tail(&node->tmp_head, &parent->u.root.trace); |
| 607 | } else |
| 608 | return -EPERM; |
| 609 | break; |
| 610 | |
| 611 | case NODE_CTF_EXPRESSION: |
| 612 | return reparent_ctf_expression(node, parent); |
| 613 | case NODE_UNARY_EXPRESSION: |
| 614 | if (parent->type == NODE_TYPE_DECLARATOR) |
| 615 | parent->u.type_declarator.bitfield_len = node; |
| 616 | else |
| 617 | return -EPERM; |
| 618 | break; |
| 619 | |
| 620 | case NODE_TYPEDEF: |
| 621 | return reparent_typedef(node, parent); |
| 622 | case NODE_TYPEALIAS_TARGET: |
| 623 | if (parent->type == NODE_TYPEALIAS) |
| 624 | parent->u.typealias.target = node; |
| 625 | else |
| 626 | return -EINVAL; |
| 627 | case NODE_TYPEALIAS_ALIAS: |
| 628 | if (parent->type == NODE_TYPEALIAS) |
| 629 | parent->u.typealias.alias = node; |
| 630 | else |
| 631 | return -EINVAL; |
| 632 | case NODE_TYPEALIAS: |
| 633 | return reparent_typealias(node, parent); |
| 634 | |
| 635 | case NODE_POINTER: |
| 636 | if (parent->type == NODE_TYPE_DECLARATOR) { |
| 637 | _cds_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.pointers); |
| 638 | } else |
| 639 | return -EPERM; |
| 640 | break; |
| 641 | case NODE_TYPE_DECLARATOR: |
| 642 | return reparent_type_declarator(node, parent); |
| 643 | |
| 644 | case NODE_TYPE_SPECIFIER: |
| 645 | case NODE_FLOATING_POINT: |
| 646 | case NODE_INTEGER: |
| 647 | case NODE_STRING: |
| 648 | case NODE_ENUM: |
| 649 | case NODE_VARIANT: |
| 650 | case NODE_STRUCT: |
| 651 | return reparent_type_specifier(node, parent); |
| 652 | |
| 653 | case NODE_ENUMERATOR: |
| 654 | if (parent->type == NODE_ENUM) { |
| 655 | _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list); |
| 656 | } else |
| 657 | return -EPERM; |
| 658 | break; |
| 659 | case NODE_STRUCT_OR_VARIANT_DECLARATION: |
| 660 | switch (parent->type) { |
| 661 | case NODE_STRUCT: |
| 662 | _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list); |
| 663 | break; |
| 664 | case NODE_VARIANT: |
| 665 | _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list); |
| 666 | break; |
| 667 | default: |
| 668 | return -EINVAL; |
| 669 | } |
| 670 | break; |
| 671 | |
| 672 | case NODE_UNKNOWN: |
| 673 | default: |
| 674 | fprintf(stderr, "[error] %s: unknown node type %d\n", __func__, |
| 675 | (int) parent->type); |
| 676 | return -EINVAL; |
| 677 | } |
| 678 | return 0; |
| 679 | } |
| 680 | |
| 681 | void yyerror(struct ctf_scanner *scanner, const char *str) |
| 682 | { |
| 683 | fprintf(stderr, "error %s\n", str); |
| 684 | } |
| 685 | |
| 686 | int yywrap(void) |
| 687 | { |
| 688 | return 1; |
| 689 | } |
| 690 | |
| 691 | #define reparent_error(scanner, str) \ |
| 692 | do { \ |
| 693 | yyerror(scanner, YY_("reparent_error: " str "\n")); \ |
| 694 | YYERROR; \ |
| 695 | } while (0) |
| 696 | |
| 697 | static void free_strings(struct cds_list_head *list) |
| 698 | { |
| 699 | struct gc_string *gstr, *tmp; |
| 700 | |
| 701 | cds_list_for_each_entry_safe(gstr, tmp, list, gc) |
| 702 | free(gstr); |
| 703 | } |
| 704 | |
| 705 | static struct ctf_ast *ctf_ast_alloc(void) |
| 706 | { |
| 707 | struct ctf_ast *ast; |
| 708 | |
| 709 | ast = malloc(sizeof(*ast)); |
| 710 | if (!ast) |
| 711 | return NULL; |
| 712 | memset(ast, 0, sizeof(*ast)); |
| 713 | CDS_INIT_LIST_HEAD(&ast->allocated_nodes); |
| 714 | ast->root.type = NODE_ROOT; |
| 715 | CDS_INIT_LIST_HEAD(&ast->root.tmp_head); |
| 716 | CDS_INIT_LIST_HEAD(&ast->root.u.root._typedef); |
| 717 | CDS_INIT_LIST_HEAD(&ast->root.u.root.typealias); |
| 718 | CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_specifier); |
| 719 | CDS_INIT_LIST_HEAD(&ast->root.u.root.trace); |
| 720 | CDS_INIT_LIST_HEAD(&ast->root.u.root.stream); |
| 721 | CDS_INIT_LIST_HEAD(&ast->root.u.root.event); |
| 722 | return ast; |
| 723 | } |
| 724 | |
| 725 | static void ctf_ast_free(struct ctf_ast *ast) |
| 726 | { |
| 727 | struct ctf_node *node, *tmp; |
| 728 | |
| 729 | cds_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc) |
| 730 | free(node); |
| 731 | } |
| 732 | |
| 733 | int ctf_scanner_append_ast(struct ctf_scanner *scanner) |
| 734 | { |
| 735 | return yyparse(scanner); |
| 736 | } |
| 737 | |
| 738 | struct ctf_scanner *ctf_scanner_alloc(FILE *input) |
| 739 | { |
| 740 | struct ctf_scanner *scanner; |
| 741 | int ret; |
| 742 | |
| 743 | scanner = malloc(sizeof(*scanner)); |
| 744 | if (!scanner) |
| 745 | return NULL; |
| 746 | memset(scanner, 0, sizeof(*scanner)); |
| 747 | |
| 748 | ret = yylex_init_extra(scanner, &scanner->scanner); |
| 749 | if (ret) { |
| 750 | fprintf(stderr, "yylex_init error\n"); |
| 751 | goto cleanup_scanner; |
| 752 | } |
| 753 | yyset_in(input, scanner); |
| 754 | |
| 755 | scanner->ast = ctf_ast_alloc(); |
| 756 | if (!scanner->ast) |
| 757 | goto cleanup_lexer; |
| 758 | init_scope(&scanner->root_scope, NULL); |
| 759 | scanner->cs = &scanner->root_scope; |
| 760 | CDS_INIT_LIST_HEAD(&scanner->allocated_strings); |
| 761 | |
| 762 | return scanner; |
| 763 | |
| 764 | cleanup_lexer: |
| 765 | ret = yylex_destroy(scanner->scanner); |
| 766 | if (!ret) |
| 767 | fprintf(stderr, "yylex_destroy error\n"); |
| 768 | cleanup_scanner: |
| 769 | free(scanner); |
| 770 | return NULL; |
| 771 | } |
| 772 | |
| 773 | void ctf_scanner_free(struct ctf_scanner *scanner) |
| 774 | { |
| 775 | int ret; |
| 776 | |
| 777 | finalize_scope(&scanner->root_scope); |
| 778 | free_strings(&scanner->allocated_strings); |
| 779 | ctf_ast_free(scanner->ast); |
| 780 | ret = yylex_destroy(scanner->scanner); |
| 781 | if (ret) |
| 782 | fprintf(stderr, "yylex_destroy error\n"); |
| 783 | free(scanner); |
| 784 | } |
| 785 | |
| 786 | %} |
| 787 | |
| 788 | %define api.pure |
| 789 | /* %locations */ |
| 790 | %parse-param {struct ctf_scanner *scanner} |
| 791 | %lex-param {struct ctf_scanner *scanner} |
| 792 | %start file |
| 793 | %token CHARACTER_CONSTANT_START SQUOTE STRING_LITERAL_START DQUOTE ESCSEQ CHAR_STRING_TOKEN LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT |
| 794 | %token <gs> IDENTIFIER ID_TYPE |
| 795 | %token ERROR |
| 796 | %union |
| 797 | { |
| 798 | long long ll; |
| 799 | char c; |
| 800 | struct gc_string *gs; |
| 801 | struct ctf_node *n; |
| 802 | } |
| 803 | |
| 804 | %type <gs> keywords |
| 805 | %type <gs> s_char s_char_sequence c_char c_char_sequence |
| 806 | |
| 807 | %type <n> postfix_expression unary_expression unary_expression_or_range |
| 808 | |
| 809 | %type <n> declaration |
| 810 | %type <n> event_declaration |
| 811 | %type <n> stream_declaration |
| 812 | %type <n> trace_declaration |
| 813 | %type <n> declaration_specifiers |
| 814 | %type <n> alias_declaration_specifiers |
| 815 | |
| 816 | %type <n> type_declarator_list |
| 817 | %type <n> type_specifier |
| 818 | %type <n> struct_type_specifier |
| 819 | %type <n> variant_type_specifier |
| 820 | %type <n> type_specifier_or_integer_constant |
| 821 | %type <n> enum_type_specifier |
| 822 | %type <n> struct_or_variant_declaration_list |
| 823 | %type <n> struct_or_variant_declaration |
| 824 | %type <n> struct_or_variant_declarator_list |
| 825 | %type <n> struct_or_variant_declarator |
| 826 | %type <n> enumerator_list |
| 827 | %type <n> enumerator |
| 828 | %type <n> abstract_declarator_list |
| 829 | %type <n> abstract_declarator |
| 830 | %type <n> direct_abstract_declarator |
| 831 | %type <n> alias_abstract_declarator_list |
| 832 | %type <n> alias_abstract_declarator |
| 833 | %type <n> direct_alias_abstract_declarator |
| 834 | %type <n> declarator |
| 835 | %type <n> direct_declarator |
| 836 | %type <n> type_declarator |
| 837 | %type <n> direct_type_declarator |
| 838 | %type <n> pointer |
| 839 | %type <n> ctf_assignment_expression_list |
| 840 | %type <n> ctf_assignment_expression |
| 841 | |
| 842 | %% |
| 843 | |
| 844 | file: |
| 845 | declaration |
| 846 | { |
| 847 | if (set_parent_node($1, &ctf_scanner_get_ast(scanner)->root)) |
| 848 | reparent_error(scanner, "error reparenting to root"); |
| 849 | } |
| 850 | | file declaration |
| 851 | { |
| 852 | if (set_parent_node($2, &ctf_scanner_get_ast(scanner)->root)) |
| 853 | reparent_error(scanner, "error reparenting to root"); |
| 854 | } |
| 855 | ; |
| 856 | |
| 857 | keywords: |
| 858 | VOID |
| 859 | { $$ = yylval.gs; } |
| 860 | | CHAR |
| 861 | { $$ = yylval.gs; } |
| 862 | | SHORT |
| 863 | { $$ = yylval.gs; } |
| 864 | | INT |
| 865 | { $$ = yylval.gs; } |
| 866 | | LONG |
| 867 | { $$ = yylval.gs; } |
| 868 | | FLOAT |
| 869 | { $$ = yylval.gs; } |
| 870 | | DOUBLE |
| 871 | { $$ = yylval.gs; } |
| 872 | | SIGNED |
| 873 | { $$ = yylval.gs; } |
| 874 | | UNSIGNED |
| 875 | { $$ = yylval.gs; } |
| 876 | | _BOOL |
| 877 | { $$ = yylval.gs; } |
| 878 | | _COMPLEX |
| 879 | { $$ = yylval.gs; } |
| 880 | | _IMAGINARY |
| 881 | { $$ = yylval.gs; } |
| 882 | | FLOATING_POINT |
| 883 | { $$ = yylval.gs; } |
| 884 | | INTEGER |
| 885 | { $$ = yylval.gs; } |
| 886 | | STRING |
| 887 | { $$ = yylval.gs; } |
| 888 | | ENUM |
| 889 | { $$ = yylval.gs; } |
| 890 | | VARIANT |
| 891 | { $$ = yylval.gs; } |
| 892 | | STRUCT |
| 893 | { $$ = yylval.gs; } |
| 894 | | CONST |
| 895 | { $$ = yylval.gs; } |
| 896 | | TYPEDEF |
| 897 | { $$ = yylval.gs; } |
| 898 | | EVENT |
| 899 | { $$ = yylval.gs; } |
| 900 | | STREAM |
| 901 | { $$ = yylval.gs; } |
| 902 | | TRACE |
| 903 | { $$ = yylval.gs; } |
| 904 | ; |
| 905 | |
| 906 | /* 1.5 Constants */ |
| 907 | |
| 908 | c_char_sequence: |
| 909 | c_char |
| 910 | { $$ = $1; } |
| 911 | | c_char_sequence c_char |
| 912 | { $$ = gc_string_append(scanner, $1, $2); } |
| 913 | ; |
| 914 | |
| 915 | c_char: |
| 916 | CHAR_STRING_TOKEN |
| 917 | { $$ = yylval.gs; } |
| 918 | | ESCSEQ |
| 919 | { |
| 920 | reparent_error(scanner, "escape sequences not supported yet"); |
| 921 | } |
| 922 | ; |
| 923 | |
| 924 | /* 1.6 String literals */ |
| 925 | |
| 926 | s_char_sequence: |
| 927 | s_char |
| 928 | { $$ = $1; } |
| 929 | | s_char_sequence s_char |
| 930 | { $$ = gc_string_append(scanner, $1, $2); } |
| 931 | ; |
| 932 | |
| 933 | s_char: |
| 934 | CHAR_STRING_TOKEN |
| 935 | { $$ = yylval.gs; } |
| 936 | | ESCSEQ |
| 937 | { |
| 938 | reparent_error(scanner, "escape sequences not supported yet"); |
| 939 | } |
| 940 | ; |
| 941 | |
| 942 | /* 2: Phrase structure grammar */ |
| 943 | |
| 944 | postfix_expression: |
| 945 | IDENTIFIER |
| 946 | { |
| 947 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 948 | $$->u.unary_expression.type = UNARY_STRING; |
| 949 | $$->u.unary_expression.u.string = yylval.gs->s; |
| 950 | } |
| 951 | | ID_TYPE |
| 952 | { |
| 953 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 954 | $$->u.unary_expression.type = UNARY_STRING; |
| 955 | $$->u.unary_expression.u.string = yylval.gs->s; |
| 956 | } |
| 957 | | keywords |
| 958 | { |
| 959 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 960 | $$->u.unary_expression.type = UNARY_STRING; |
| 961 | $$->u.unary_expression.u.string = yylval.gs->s; |
| 962 | } |
| 963 | |
| 964 | | DECIMAL_CONSTANT |
| 965 | { |
| 966 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 967 | $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT; |
| 968 | sscanf(yylval.gs->s, "%" PRIu64, |
| 969 | &$$->u.unary_expression.u.unsigned_constant); |
| 970 | } |
| 971 | | OCTAL_CONSTANT |
| 972 | { |
| 973 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 974 | $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT; |
| 975 | sscanf(yylval.gs->s, "0%" PRIo64, |
| 976 | &$$->u.unary_expression.u.unsigned_constant); |
| 977 | } |
| 978 | | HEXADECIMAL_CONSTANT |
| 979 | { |
| 980 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 981 | $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT; |
| 982 | sscanf(yylval.gs->s, "0x%" PRIx64, |
| 983 | &$$->u.unary_expression.u.unsigned_constant); |
| 984 | } |
| 985 | | STRING_LITERAL_START DQUOTE |
| 986 | { |
| 987 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 988 | $$->u.unary_expression.type = UNARY_STRING; |
| 989 | $$->u.unary_expression.u.string = ""; |
| 990 | } |
| 991 | | STRING_LITERAL_START s_char_sequence DQUOTE |
| 992 | { |
| 993 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 994 | $$->u.unary_expression.type = UNARY_STRING; |
| 995 | $$->u.unary_expression.u.string = $2->s; |
| 996 | } |
| 997 | | CHARACTER_CONSTANT_START c_char_sequence SQUOTE |
| 998 | { |
| 999 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1000 | $$->u.unary_expression.type = UNARY_STRING; |
| 1001 | $$->u.unary_expression.u.string = $2->s; |
| 1002 | } |
| 1003 | | LPAREN unary_expression RPAREN |
| 1004 | { |
| 1005 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1006 | $$->u.unary_expression.type = UNARY_NESTED; |
| 1007 | $$->u.unary_expression.u.nested_exp = $2; |
| 1008 | } |
| 1009 | | postfix_expression LSBRAC unary_expression RSBRAC |
| 1010 | { |
| 1011 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1012 | $$->u.unary_expression.type = UNARY_SBRAC; |
| 1013 | $$->u.unary_expression.u.sbrac_exp = $3; |
| 1014 | cds_list_splice(&($1)->tmp_head, &($$)->tmp_head); |
| 1015 | cds_list_add_tail(&($$)->siblings, &($$)->tmp_head); |
| 1016 | } |
| 1017 | | postfix_expression DOT IDENTIFIER |
| 1018 | { |
| 1019 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1020 | $$->u.unary_expression.type = UNARY_STRING; |
| 1021 | $$->u.unary_expression.u.string = yylval.gs->s; |
| 1022 | $$->u.unary_expression.link = UNARY_DOTLINK; |
| 1023 | cds_list_splice(&($1)->tmp_head, &($$)->tmp_head); |
| 1024 | cds_list_add_tail(&($$)->siblings, &($$)->tmp_head); |
| 1025 | } |
| 1026 | | postfix_expression DOT ID_TYPE |
| 1027 | { |
| 1028 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1029 | $$->u.unary_expression.type = UNARY_STRING; |
| 1030 | $$->u.unary_expression.u.string = yylval.gs->s; |
| 1031 | $$->u.unary_expression.link = UNARY_DOTLINK; |
| 1032 | cds_list_splice(&($1)->tmp_head, &($$)->tmp_head); |
| 1033 | cds_list_add_tail(&($$)->siblings, &($$)->tmp_head); |
| 1034 | } |
| 1035 | | postfix_expression RARROW IDENTIFIER |
| 1036 | { |
| 1037 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1038 | $$->u.unary_expression.type = UNARY_STRING; |
| 1039 | $$->u.unary_expression.u.string = yylval.gs->s; |
| 1040 | $$->u.unary_expression.link = UNARY_ARROWLINK; |
| 1041 | cds_list_splice(&($1)->tmp_head, &($$)->tmp_head); |
| 1042 | cds_list_add_tail(&($$)->siblings, &($$)->tmp_head); |
| 1043 | } |
| 1044 | | postfix_expression RARROW ID_TYPE |
| 1045 | { |
| 1046 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1047 | $$->u.unary_expression.type = UNARY_STRING; |
| 1048 | $$->u.unary_expression.u.string = yylval.gs->s; |
| 1049 | $$->u.unary_expression.link = UNARY_ARROWLINK; |
| 1050 | cds_list_splice(&($1)->tmp_head, &($$)->tmp_head); |
| 1051 | cds_list_add_tail(&($$)->siblings, &($$)->tmp_head); |
| 1052 | } |
| 1053 | ; |
| 1054 | |
| 1055 | unary_expression: |
| 1056 | postfix_expression |
| 1057 | { $$ = $1; } |
| 1058 | | PLUS postfix_expression |
| 1059 | { $$ = $2; } |
| 1060 | | MINUS postfix_expression |
| 1061 | { |
| 1062 | $$ = $2; |
| 1063 | if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT |
| 1064 | && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) |
| 1065 | reparent_error(scanner, "expecting numeric constant"); |
| 1066 | |
| 1067 | if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) { |
| 1068 | $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT; |
| 1069 | $$->u.unary_expression.u.signed_constant = |
| 1070 | -($$->u.unary_expression.u.unsigned_constant); |
| 1071 | } else { |
| 1072 | $$->u.unary_expression.u.signed_constant = |
| 1073 | -($$->u.unary_expression.u.signed_constant); |
| 1074 | } |
| 1075 | } |
| 1076 | ; |
| 1077 | |
| 1078 | unary_expression_or_range: |
| 1079 | unary_expression DOTDOTDOT unary_expression |
| 1080 | { |
| 1081 | $$ = $1; |
| 1082 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->tmp_head); |
| 1083 | $3->u.unary_expression.link = UNARY_DOTDOTDOT; |
| 1084 | } |
| 1085 | | unary_expression |
| 1086 | { $$ = $1; } |
| 1087 | ; |
| 1088 | |
| 1089 | /* 2.2: Declarations */ |
| 1090 | |
| 1091 | declaration: |
| 1092 | declaration_specifiers SEMICOLON |
| 1093 | { $$ = $1; } |
| 1094 | | event_declaration |
| 1095 | { $$ = $1; } |
| 1096 | | stream_declaration |
| 1097 | { $$ = $1; } |
| 1098 | | trace_declaration |
| 1099 | { $$ = $1; } |
| 1100 | | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON |
| 1101 | { |
| 1102 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 1103 | _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier); |
| 1104 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.declaration_specifier); |
| 1105 | _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators); |
| 1106 | } |
| 1107 | | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON |
| 1108 | { |
| 1109 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 1110 | _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._typedef.declaration_specifier); |
| 1111 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); |
| 1112 | } |
| 1113 | | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON |
| 1114 | { |
| 1115 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 1116 | _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier); |
| 1117 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); |
| 1118 | } |
| 1119 | | TYPEALIAS declaration_specifiers abstract_declarator_list COLON alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON |
| 1120 | { |
| 1121 | $$ = make_node(scanner, NODE_TYPEALIAS); |
| 1122 | $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET); |
| 1123 | $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS); |
| 1124 | _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier); |
| 1125 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators); |
| 1126 | _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier); |
| 1127 | _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators); |
| 1128 | } |
| 1129 | ; |
| 1130 | |
| 1131 | event_declaration: |
| 1132 | event_declaration_begin event_declaration_end |
| 1133 | { |
| 1134 | $$ = make_node(scanner, NODE_EVENT); |
| 1135 | } |
| 1136 | | event_declaration_begin ctf_assignment_expression_list event_declaration_end |
| 1137 | { |
| 1138 | $$ = make_node(scanner, NODE_EVENT); |
| 1139 | if (set_parent_node($2, $$)) |
| 1140 | reparent_error(scanner, "event_declaration"); |
| 1141 | } |
| 1142 | ; |
| 1143 | |
| 1144 | event_declaration_begin: |
| 1145 | EVENT LBRAC |
| 1146 | { push_scope(scanner); } |
| 1147 | ; |
| 1148 | |
| 1149 | event_declaration_end: |
| 1150 | RBRAC SEMICOLON |
| 1151 | { pop_scope(scanner); } |
| 1152 | ; |
| 1153 | |
| 1154 | |
| 1155 | stream_declaration: |
| 1156 | stream_declaration_begin stream_declaration_end |
| 1157 | { |
| 1158 | $$ = make_node(scanner, NODE_STREAM); |
| 1159 | } |
| 1160 | | stream_declaration_begin ctf_assignment_expression_list stream_declaration_end |
| 1161 | { |
| 1162 | $$ = make_node(scanner, NODE_STREAM); |
| 1163 | if (set_parent_node($2, $$)) |
| 1164 | reparent_error(scanner, "stream_declaration"); |
| 1165 | } |
| 1166 | ; |
| 1167 | |
| 1168 | stream_declaration_begin: |
| 1169 | STREAM LBRAC |
| 1170 | { push_scope(scanner); } |
| 1171 | ; |
| 1172 | |
| 1173 | stream_declaration_end: |
| 1174 | RBRAC SEMICOLON |
| 1175 | { pop_scope(scanner); } |
| 1176 | ; |
| 1177 | |
| 1178 | |
| 1179 | trace_declaration: |
| 1180 | trace_declaration_begin trace_declaration_end |
| 1181 | { |
| 1182 | $$ = make_node(scanner, NODE_TRACE); |
| 1183 | } |
| 1184 | | trace_declaration_begin ctf_assignment_expression_list trace_declaration_end |
| 1185 | { |
| 1186 | $$ = make_node(scanner, NODE_TRACE); |
| 1187 | if (set_parent_node($2, $$)) |
| 1188 | reparent_error(scanner, "trace_declaration"); |
| 1189 | } |
| 1190 | ; |
| 1191 | |
| 1192 | trace_declaration_begin: |
| 1193 | TRACE LBRAC |
| 1194 | { push_scope(scanner); } |
| 1195 | ; |
| 1196 | |
| 1197 | trace_declaration_end: |
| 1198 | RBRAC SEMICOLON |
| 1199 | { pop_scope(scanner); } |
| 1200 | ; |
| 1201 | |
| 1202 | declaration_specifiers: |
| 1203 | CONST |
| 1204 | { |
| 1205 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1206 | $$->u.type_specifier.type = TYPESPEC_CONST; |
| 1207 | } |
| 1208 | | type_specifier |
| 1209 | { $$ = $1; } |
| 1210 | | declaration_specifiers CONST |
| 1211 | { |
| 1212 | struct ctf_node *node; |
| 1213 | |
| 1214 | $$ = $1; |
| 1215 | node = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1216 | node->u.type_specifier.type = TYPESPEC_CONST; |
| 1217 | cds_list_add_tail(&node->siblings, &($$)->tmp_head); |
| 1218 | } |
| 1219 | | declaration_specifiers type_specifier |
| 1220 | { |
| 1221 | $$ = $1; |
| 1222 | cds_list_add_tail(&($2)->siblings, &($$)->tmp_head); |
| 1223 | } |
| 1224 | ; |
| 1225 | |
| 1226 | type_declarator_list: |
| 1227 | type_declarator |
| 1228 | { $$ = $1; } |
| 1229 | | type_declarator_list COMMA type_declarator |
| 1230 | { |
| 1231 | $$ = $1; |
| 1232 | cds_list_add_tail(&($3)->siblings, &($$)->tmp_head); |
| 1233 | } |
| 1234 | ; |
| 1235 | |
| 1236 | type_specifier: |
| 1237 | VOID |
| 1238 | { |
| 1239 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1240 | $$->u.type_specifier.type = TYPESPEC_VOID; |
| 1241 | } |
| 1242 | | CHAR |
| 1243 | { |
| 1244 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1245 | $$->u.type_specifier.type = TYPESPEC_CHAR; |
| 1246 | } |
| 1247 | | SHORT |
| 1248 | { |
| 1249 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1250 | $$->u.type_specifier.type = TYPESPEC_SHORT; |
| 1251 | } |
| 1252 | | INT |
| 1253 | { |
| 1254 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1255 | $$->u.type_specifier.type = TYPESPEC_INT; |
| 1256 | } |
| 1257 | | LONG |
| 1258 | { |
| 1259 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1260 | $$->u.type_specifier.type = TYPESPEC_LONG; |
| 1261 | } |
| 1262 | | FLOAT |
| 1263 | { |
| 1264 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1265 | $$->u.type_specifier.type = TYPESPEC_FLOAT; |
| 1266 | } |
| 1267 | | DOUBLE |
| 1268 | { |
| 1269 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1270 | $$->u.type_specifier.type = TYPESPEC_DOUBLE; |
| 1271 | } |
| 1272 | | SIGNED |
| 1273 | { |
| 1274 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1275 | $$->u.type_specifier.type = TYPESPEC_SIGNED; |
| 1276 | } |
| 1277 | | UNSIGNED |
| 1278 | { |
| 1279 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1280 | $$->u.type_specifier.type = TYPESPEC_UNSIGNED; |
| 1281 | } |
| 1282 | | _BOOL |
| 1283 | { |
| 1284 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1285 | $$->u.type_specifier.type = TYPESPEC_BOOL; |
| 1286 | } |
| 1287 | | _COMPLEX |
| 1288 | { |
| 1289 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1290 | $$->u.type_specifier.type = TYPESPEC_COMPLEX; |
| 1291 | } |
| 1292 | | _IMAGINARY |
| 1293 | { |
| 1294 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1295 | $$->u.type_specifier.type = TYPESPEC_IMAGINARY; |
| 1296 | } |
| 1297 | | ID_TYPE |
| 1298 | { |
| 1299 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1300 | $$->u.type_specifier.type = TYPESPEC_ID_TYPE; |
| 1301 | $$->u.type_specifier.id_type = yylval.gs->s; |
| 1302 | } |
| 1303 | | FLOATING_POINT LBRAC RBRAC |
| 1304 | { |
| 1305 | $$ = make_node(scanner, NODE_FLOATING_POINT); |
| 1306 | } |
| 1307 | | FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC |
| 1308 | { |
| 1309 | $$ = make_node(scanner, NODE_FLOATING_POINT); |
| 1310 | if (set_parent_node($3, $$)) |
| 1311 | reparent_error(scanner, "floating point reparent error"); |
| 1312 | } |
| 1313 | | INTEGER LBRAC RBRAC |
| 1314 | { |
| 1315 | $$ = make_node(scanner, NODE_INTEGER); |
| 1316 | } |
| 1317 | | INTEGER LBRAC ctf_assignment_expression_list RBRAC |
| 1318 | { |
| 1319 | $$ = make_node(scanner, NODE_INTEGER); |
| 1320 | if (set_parent_node($3, $$)) |
| 1321 | reparent_error(scanner, "integer reparent error"); |
| 1322 | } |
| 1323 | | STRING LBRAC RBRAC |
| 1324 | { |
| 1325 | $$ = make_node(scanner, NODE_STRING); |
| 1326 | } |
| 1327 | | STRING LBRAC ctf_assignment_expression_list RBRAC |
| 1328 | { |
| 1329 | $$ = make_node(scanner, NODE_STRING); |
| 1330 | if (set_parent_node($3, $$)) |
| 1331 | reparent_error(scanner, "string reparent error"); |
| 1332 | } |
| 1333 | | ENUM enum_type_specifier |
| 1334 | { $$ = $2; } |
| 1335 | | VARIANT variant_type_specifier |
| 1336 | { $$ = $2; } |
| 1337 | | STRUCT struct_type_specifier |
| 1338 | { $$ = $2; } |
| 1339 | ; |
| 1340 | |
| 1341 | struct_type_specifier: |
| 1342 | struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end |
| 1343 | { |
| 1344 | $$ = make_node(scanner, NODE_STRUCT); |
| 1345 | $$->u._struct.has_body = 1; |
| 1346 | if (set_parent_node($2, $$)) |
| 1347 | reparent_error(scanner, "struct reparent error"); |
| 1348 | } |
| 1349 | | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end |
| 1350 | { |
| 1351 | $$ = make_node(scanner, NODE_STRUCT); |
| 1352 | $$->u._struct.has_body = 1; |
| 1353 | $$->u._struct.name = $1->s; |
| 1354 | if (set_parent_node($3, $$)) |
| 1355 | reparent_error(scanner, "struct reparent error"); |
| 1356 | } |
| 1357 | | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end |
| 1358 | { |
| 1359 | $$ = make_node(scanner, NODE_STRUCT); |
| 1360 | $$->u._struct.has_body = 1; |
| 1361 | $$->u._struct.name = $1->s; |
| 1362 | if (set_parent_node($3, $$)) |
| 1363 | reparent_error(scanner, "struct reparent error"); |
| 1364 | } |
| 1365 | | IDENTIFIER |
| 1366 | { |
| 1367 | $$ = make_node(scanner, NODE_STRUCT); |
| 1368 | $$->u._struct.has_body = 0; |
| 1369 | $$->u._struct.name = $1->s; |
| 1370 | } |
| 1371 | | ID_TYPE |
| 1372 | { |
| 1373 | $$ = make_node(scanner, NODE_STRUCT); |
| 1374 | $$->u._struct.has_body = 0; |
| 1375 | $$->u._struct.name = $1->s; |
| 1376 | } |
| 1377 | ; |
| 1378 | |
| 1379 | struct_declaration_begin: |
| 1380 | LBRAC |
| 1381 | { push_scope(scanner); } |
| 1382 | ; |
| 1383 | |
| 1384 | struct_declaration_end: |
| 1385 | RBRAC |
| 1386 | { pop_scope(scanner); } |
| 1387 | ; |
| 1388 | |
| 1389 | variant_type_specifier: |
| 1390 | variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1391 | { |
| 1392 | $$ = make_node(scanner, NODE_VARIANT); |
| 1393 | $$->u.variant.has_body = 1; |
| 1394 | if (set_parent_node($2, $$)) |
| 1395 | reparent_error(scanner, "variant reparent error"); |
| 1396 | } |
| 1397 | | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1398 | { |
| 1399 | $$ = make_node(scanner, NODE_VARIANT); |
| 1400 | $$->u.variant.has_body = 1; |
| 1401 | $$->u.variant.choice = $2->s; |
| 1402 | if (set_parent_node($5, $$)) |
| 1403 | reparent_error(scanner, "variant reparent error"); |
| 1404 | } |
| 1405 | | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1406 | { |
| 1407 | $$ = make_node(scanner, NODE_VARIANT); |
| 1408 | $$->u.variant.has_body = 1; |
| 1409 | $$->u.variant.choice = $2->s; |
| 1410 | if (set_parent_node($5, $$)) |
| 1411 | reparent_error(scanner, "variant reparent error"); |
| 1412 | } |
| 1413 | | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1414 | { |
| 1415 | $$ = make_node(scanner, NODE_VARIANT); |
| 1416 | $$->u.variant.has_body = 1; |
| 1417 | $$->u.variant.name = $1->s; |
| 1418 | if (set_parent_node($3, $$)) |
| 1419 | reparent_error(scanner, "variant reparent error"); |
| 1420 | } |
| 1421 | | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1422 | { |
| 1423 | $$ = make_node(scanner, NODE_VARIANT); |
| 1424 | $$->u.variant.has_body = 1; |
| 1425 | $$->u.variant.name = $1->s; |
| 1426 | $$->u.variant.choice = $3->s; |
| 1427 | if (set_parent_node($6, $$)) |
| 1428 | reparent_error(scanner, "variant reparent error"); |
| 1429 | } |
| 1430 | | IDENTIFIER LT IDENTIFIER GT |
| 1431 | { |
| 1432 | $$ = make_node(scanner, NODE_VARIANT); |
| 1433 | $$->u.variant.has_body = 0; |
| 1434 | $$->u.variant.name = $1->s; |
| 1435 | $$->u.variant.choice = $3->s; |
| 1436 | } |
| 1437 | | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1438 | { |
| 1439 | $$ = make_node(scanner, NODE_VARIANT); |
| 1440 | $$->u.variant.has_body = 1; |
| 1441 | $$->u.variant.name = $1->s; |
| 1442 | $$->u.variant.choice = $3->s; |
| 1443 | if (set_parent_node($6, $$)) |
| 1444 | reparent_error(scanner, "variant reparent error"); |
| 1445 | } |
| 1446 | | IDENTIFIER LT ID_TYPE GT |
| 1447 | { |
| 1448 | $$ = make_node(scanner, NODE_VARIANT); |
| 1449 | $$->u.variant.has_body = 0; |
| 1450 | $$->u.variant.name = $1->s; |
| 1451 | $$->u.variant.choice = $3->s; |
| 1452 | } |
| 1453 | | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1454 | { |
| 1455 | $$ = make_node(scanner, NODE_VARIANT); |
| 1456 | $$->u.variant.has_body = 1; |
| 1457 | $$->u.variant.name = $1->s; |
| 1458 | if (set_parent_node($3, $$)) |
| 1459 | reparent_error(scanner, "variant reparent error"); |
| 1460 | } |
| 1461 | | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1462 | { |
| 1463 | $$ = make_node(scanner, NODE_VARIANT); |
| 1464 | $$->u.variant.has_body = 1; |
| 1465 | $$->u.variant.name = $1->s; |
| 1466 | $$->u.variant.choice = $3->s; |
| 1467 | if (set_parent_node($6, $$)) |
| 1468 | reparent_error(scanner, "variant reparent error"); |
| 1469 | } |
| 1470 | | ID_TYPE LT IDENTIFIER GT |
| 1471 | { |
| 1472 | $$ = make_node(scanner, NODE_VARIANT); |
| 1473 | $$->u.variant.has_body = 0; |
| 1474 | $$->u.variant.name = $1->s; |
| 1475 | $$->u.variant.choice = $3->s; |
| 1476 | } |
| 1477 | | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end |
| 1478 | { |
| 1479 | $$ = make_node(scanner, NODE_VARIANT); |
| 1480 | $$->u.variant.has_body = 1; |
| 1481 | $$->u.variant.name = $1->s; |
| 1482 | $$->u.variant.choice = $3->s; |
| 1483 | if (set_parent_node($6, $$)) |
| 1484 | reparent_error(scanner, "variant reparent error"); |
| 1485 | } |
| 1486 | | ID_TYPE LT ID_TYPE GT |
| 1487 | { |
| 1488 | $$ = make_node(scanner, NODE_VARIANT); |
| 1489 | $$->u.variant.has_body = 0; |
| 1490 | $$->u.variant.name = $1->s; |
| 1491 | $$->u.variant.choice = $3->s; |
| 1492 | } |
| 1493 | ; |
| 1494 | |
| 1495 | variant_declaration_begin: |
| 1496 | LBRAC |
| 1497 | { push_scope(scanner); } |
| 1498 | ; |
| 1499 | |
| 1500 | variant_declaration_end: |
| 1501 | RBRAC |
| 1502 | { pop_scope(scanner); } |
| 1503 | ; |
| 1504 | |
| 1505 | type_specifier_or_integer_constant: |
| 1506 | declaration_specifiers |
| 1507 | { $$ = $1; } |
| 1508 | | DECIMAL_CONSTANT |
| 1509 | { |
| 1510 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1511 | $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT; |
| 1512 | sscanf(yylval.gs->s, "%" PRIu64, |
| 1513 | &$$->u.unary_expression.u.unsigned_constant); |
| 1514 | } |
| 1515 | | OCTAL_CONSTANT |
| 1516 | { |
| 1517 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1518 | $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT; |
| 1519 | sscanf(yylval.gs->s, "0%" PRIo64, |
| 1520 | &$$->u.unary_expression.u.unsigned_constant); |
| 1521 | } |
| 1522 | | HEXADECIMAL_CONSTANT |
| 1523 | { |
| 1524 | $$ = make_node(scanner, NODE_UNARY_EXPRESSION); |
| 1525 | $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT; |
| 1526 | sscanf(yylval.gs->s, "0x%" PRIx64, |
| 1527 | &$$->u.unary_expression.u.unsigned_constant); |
| 1528 | } |
| 1529 | ; |
| 1530 | |
| 1531 | enum_type_specifier: |
| 1532 | LBRAC enumerator_list RBRAC |
| 1533 | { |
| 1534 | $$ = make_node(scanner, NODE_ENUM); |
| 1535 | $$->u._enum.has_body = 1; |
| 1536 | _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1537 | } |
| 1538 | | LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC |
| 1539 | { |
| 1540 | $$ = make_node(scanner, NODE_ENUM); |
| 1541 | $$->u._enum.has_body = 1; |
| 1542 | $$->u._enum.container_type = $2; |
| 1543 | _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1544 | } |
| 1545 | | IDENTIFIER LBRAC enumerator_list RBRAC |
| 1546 | { |
| 1547 | $$ = make_node(scanner, NODE_ENUM); |
| 1548 | $$->u._enum.has_body = 1; |
| 1549 | $$->u._enum.enum_id = $1->s; |
| 1550 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1551 | } |
| 1552 | | IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC |
| 1553 | { |
| 1554 | $$ = make_node(scanner, NODE_ENUM); |
| 1555 | $$->u._enum.has_body = 1; |
| 1556 | $$->u._enum.enum_id = $1->s; |
| 1557 | $$->u._enum.container_type = $3; |
| 1558 | _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1559 | } |
| 1560 | | ID_TYPE LBRAC enumerator_list RBRAC |
| 1561 | { |
| 1562 | $$ = make_node(scanner, NODE_ENUM); |
| 1563 | $$->u._enum.has_body = 1; |
| 1564 | $$->u._enum.enum_id = $1->s; |
| 1565 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1566 | } |
| 1567 | | ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC |
| 1568 | { |
| 1569 | $$ = make_node(scanner, NODE_ENUM); |
| 1570 | $$->u._enum.has_body = 1; |
| 1571 | $$->u._enum.enum_id = $1->s; |
| 1572 | $$->u._enum.container_type = $3; |
| 1573 | _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1574 | } |
| 1575 | | LBRAC enumerator_list COMMA RBRAC |
| 1576 | { |
| 1577 | $$ = make_node(scanner, NODE_ENUM); |
| 1578 | $$->u._enum.has_body = 1; |
| 1579 | _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1580 | } |
| 1581 | | LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC |
| 1582 | { |
| 1583 | $$ = make_node(scanner, NODE_ENUM); |
| 1584 | $$->u._enum.has_body = 1; |
| 1585 | $$->u._enum.container_type = $2; |
| 1586 | _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1587 | } |
| 1588 | | IDENTIFIER LBRAC enumerator_list COMMA RBRAC |
| 1589 | { |
| 1590 | $$ = make_node(scanner, NODE_ENUM); |
| 1591 | $$->u._enum.has_body = 1; |
| 1592 | $$->u._enum.enum_id = $1->s; |
| 1593 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1594 | } |
| 1595 | | IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC |
| 1596 | { |
| 1597 | $$ = make_node(scanner, NODE_ENUM); |
| 1598 | $$->u._enum.has_body = 1; |
| 1599 | $$->u._enum.enum_id = $1->s; |
| 1600 | $$->u._enum.container_type = $3; |
| 1601 | _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1602 | } |
| 1603 | | IDENTIFIER |
| 1604 | { |
| 1605 | $$ = make_node(scanner, NODE_ENUM); |
| 1606 | $$->u._enum.has_body = 0; |
| 1607 | $$->u._enum.enum_id = $1->s; |
| 1608 | } |
| 1609 | | IDENTIFIER LT type_specifier_or_integer_constant GT |
| 1610 | { |
| 1611 | $$ = make_node(scanner, NODE_ENUM); |
| 1612 | $$->u._enum.has_body = 0; |
| 1613 | $$->u._enum.enum_id = $1->s; |
| 1614 | $$->u._enum.container_type = $3; |
| 1615 | } |
| 1616 | | ID_TYPE LBRAC enumerator_list COMMA RBRAC |
| 1617 | { |
| 1618 | $$ = make_node(scanner, NODE_ENUM); |
| 1619 | $$->u._enum.has_body = 1; |
| 1620 | $$->u._enum.enum_id = $1->s; |
| 1621 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1622 | } |
| 1623 | | ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC |
| 1624 | { |
| 1625 | $$ = make_node(scanner, NODE_ENUM); |
| 1626 | $$->u._enum.has_body = 1; |
| 1627 | $$->u._enum.enum_id = $1->s; |
| 1628 | $$->u._enum.container_type = $3; |
| 1629 | _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list); |
| 1630 | } |
| 1631 | | ID_TYPE |
| 1632 | { |
| 1633 | $$ = make_node(scanner, NODE_ENUM); |
| 1634 | $$->u._enum.has_body = 0; |
| 1635 | $$->u._enum.enum_id = $1->s; |
| 1636 | } |
| 1637 | | ID_TYPE LT type_specifier_or_integer_constant GT |
| 1638 | { |
| 1639 | $$ = make_node(scanner, NODE_ENUM); |
| 1640 | $$->u._enum.has_body = 0; |
| 1641 | $$->u._enum.enum_id = $1->s; |
| 1642 | $$->u._enum.container_type = $3; |
| 1643 | } |
| 1644 | ; |
| 1645 | |
| 1646 | struct_or_variant_declaration_list: |
| 1647 | /* empty */ |
| 1648 | { $$ = NULL; } |
| 1649 | | struct_or_variant_declaration_list struct_or_variant_declaration |
| 1650 | { |
| 1651 | if ($1) { |
| 1652 | $$ = $1; |
| 1653 | cds_list_add_tail(&($2)->siblings, &($$)->tmp_head); |
| 1654 | } else { |
| 1655 | $$ = $2; |
| 1656 | cds_list_add_tail(&($$)->siblings, &($$)->tmp_head); |
| 1657 | } |
| 1658 | } |
| 1659 | ; |
| 1660 | |
| 1661 | struct_or_variant_declaration: |
| 1662 | declaration_specifiers struct_or_variant_declarator_list SEMICOLON |
| 1663 | { |
| 1664 | $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION); |
| 1665 | _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.struct_or_variant_declaration.declaration_specifier); |
| 1666 | _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators); |
| 1667 | } |
| 1668 | | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON |
| 1669 | { |
| 1670 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 1671 | _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier); |
| 1672 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.declaration_specifier); |
| 1673 | _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators); |
| 1674 | } |
| 1675 | | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON |
| 1676 | { |
| 1677 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 1678 | _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._typedef.declaration_specifier); |
| 1679 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); |
| 1680 | } |
| 1681 | | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON |
| 1682 | { |
| 1683 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 1684 | _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier); |
| 1685 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); |
| 1686 | } |
| 1687 | | TYPEALIAS declaration_specifiers abstract_declarator_list COLON alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON |
| 1688 | { |
| 1689 | $$ = make_node(scanner, NODE_TYPEALIAS); |
| 1690 | $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET); |
| 1691 | $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS); |
| 1692 | _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier); |
| 1693 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators); |
| 1694 | _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier); |
| 1695 | _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators); |
| 1696 | } |
| 1697 | ; |
| 1698 | |
| 1699 | alias_declaration_specifiers: |
| 1700 | CONST |
| 1701 | { |
| 1702 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1703 | $$->u.type_specifier.type = TYPESPEC_CONST; |
| 1704 | } |
| 1705 | | type_specifier |
| 1706 | { $$ = $1; } |
| 1707 | | IDENTIFIER |
| 1708 | { |
| 1709 | add_type(scanner, $1); |
| 1710 | $$ = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1711 | ($$)->u.type_specifier.type = TYPESPEC_ID_TYPE; |
| 1712 | ($$)->u.type_specifier.id_type = yylval.gs->s; |
| 1713 | } |
| 1714 | | alias_declaration_specifiers CONST |
| 1715 | { |
| 1716 | struct ctf_node *node; |
| 1717 | |
| 1718 | $$ = $1; |
| 1719 | node = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1720 | node->u.type_specifier.type = TYPESPEC_CONST; |
| 1721 | cds_list_add_tail(&node->siblings, &($$)->tmp_head); |
| 1722 | } |
| 1723 | | alias_declaration_specifiers type_specifier |
| 1724 | { |
| 1725 | $$ = $1; |
| 1726 | cds_list_add_tail(&($2)->siblings, &($$)->tmp_head); |
| 1727 | } |
| 1728 | | alias_declaration_specifiers IDENTIFIER |
| 1729 | { |
| 1730 | struct ctf_node *node; |
| 1731 | |
| 1732 | add_type(scanner, $2); |
| 1733 | $$ = $1; |
| 1734 | node = make_node(scanner, NODE_TYPE_SPECIFIER); |
| 1735 | node->u.type_specifier.type = TYPESPEC_ID_TYPE; |
| 1736 | node->u.type_specifier.id_type = yylval.gs->s; |
| 1737 | cds_list_add_tail(&node->siblings, &($$)->tmp_head); |
| 1738 | } |
| 1739 | ; |
| 1740 | |
| 1741 | struct_or_variant_declarator_list: |
| 1742 | struct_or_variant_declarator |
| 1743 | { $$ = $1; } |
| 1744 | | struct_or_variant_declarator_list COMMA struct_or_variant_declarator |
| 1745 | { |
| 1746 | $$ = $1; |
| 1747 | cds_list_add_tail(&($3)->siblings, &($$)->tmp_head); |
| 1748 | } |
| 1749 | ; |
| 1750 | |
| 1751 | struct_or_variant_declarator: |
| 1752 | declarator |
| 1753 | { $$ = $1; } |
| 1754 | | COLON unary_expression |
| 1755 | { $$ = $2; } |
| 1756 | | declarator COLON unary_expression |
| 1757 | { |
| 1758 | $$ = $1; |
| 1759 | if (set_parent_node($3, $1)) |
| 1760 | reparent_error(scanner, "struct_or_variant_declarator"); |
| 1761 | } |
| 1762 | ; |
| 1763 | |
| 1764 | enumerator_list: |
| 1765 | enumerator |
| 1766 | { $$ = $1; } |
| 1767 | | enumerator_list COMMA enumerator |
| 1768 | { |
| 1769 | $$ = $1; |
| 1770 | cds_list_add_tail(&($3)->siblings, &($$)->tmp_head); |
| 1771 | } |
| 1772 | ; |
| 1773 | |
| 1774 | enumerator: |
| 1775 | IDENTIFIER |
| 1776 | { |
| 1777 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 1778 | $$->u.enumerator.id = $1->s; |
| 1779 | } |
| 1780 | | ID_TYPE |
| 1781 | { |
| 1782 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 1783 | $$->u.enumerator.id = $1->s; |
| 1784 | } |
| 1785 | | keywords |
| 1786 | { |
| 1787 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 1788 | $$->u.enumerator.id = $1->s; |
| 1789 | } |
| 1790 | | STRING_LITERAL_START DQUOTE |
| 1791 | { |
| 1792 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 1793 | $$->u.enumerator.id = ""; |
| 1794 | } |
| 1795 | | STRING_LITERAL_START s_char_sequence DQUOTE |
| 1796 | { |
| 1797 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 1798 | $$->u.enumerator.id = $2->s; |
| 1799 | } |
| 1800 | | IDENTIFIER EQUAL unary_expression_or_range |
| 1801 | { |
| 1802 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 1803 | $$->u.enumerator.id = $1->s; |
| 1804 | cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values); |
| 1805 | } |
| 1806 | | ID_TYPE EQUAL unary_expression_or_range |
| 1807 | { |
| 1808 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 1809 | $$->u.enumerator.id = $1->s; |
| 1810 | cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values); |
| 1811 | } |
| 1812 | | keywords EQUAL unary_expression_or_range |
| 1813 | { |
| 1814 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 1815 | $$->u.enumerator.id = $1->s; |
| 1816 | cds_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values); |
| 1817 | } |
| 1818 | | STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range |
| 1819 | { |
| 1820 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 1821 | $$->u.enumerator.id = ""; |
| 1822 | cds_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values); |
| 1823 | } |
| 1824 | | STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range |
| 1825 | { |
| 1826 | $$ = make_node(scanner, NODE_ENUMERATOR); |
| 1827 | $$->u.enumerator.id = $2->s; |
| 1828 | cds_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values); |
| 1829 | } |
| 1830 | ; |
| 1831 | |
| 1832 | abstract_declarator_list: |
| 1833 | abstract_declarator |
| 1834 | { $$ = $1; } |
| 1835 | | abstract_declarator_list COMMA abstract_declarator |
| 1836 | { |
| 1837 | $$ = $1; |
| 1838 | cds_list_add_tail(&($3)->siblings, &($$)->tmp_head); |
| 1839 | } |
| 1840 | ; |
| 1841 | |
| 1842 | abstract_declarator: |
| 1843 | direct_abstract_declarator |
| 1844 | { $$ = $1; } |
| 1845 | | pointer direct_abstract_declarator |
| 1846 | { |
| 1847 | $$ = $2; |
| 1848 | cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers); |
| 1849 | } |
| 1850 | ; |
| 1851 | |
| 1852 | direct_abstract_declarator: |
| 1853 | /* empty */ |
| 1854 | { |
| 1855 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1856 | $$->u.type_declarator.type = TYPEDEC_ID; |
| 1857 | /* id is NULL */ |
| 1858 | } |
| 1859 | | IDENTIFIER |
| 1860 | { |
| 1861 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1862 | $$->u.type_declarator.type = TYPEDEC_ID; |
| 1863 | $$->u.type_declarator.u.id = $1->s; |
| 1864 | } |
| 1865 | | LPAREN abstract_declarator RPAREN |
| 1866 | { |
| 1867 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1868 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 1869 | $$->u.type_declarator.u.nested.type_declarator = $2; |
| 1870 | } |
| 1871 | | direct_abstract_declarator LSBRAC type_specifier_or_integer_constant RSBRAC |
| 1872 | { |
| 1873 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1874 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 1875 | $$->u.type_declarator.u.nested.type_declarator = $1; |
| 1876 | $$->u.type_declarator.u.nested.length = $3; |
| 1877 | } |
| 1878 | | direct_abstract_declarator LSBRAC RSBRAC |
| 1879 | { |
| 1880 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1881 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 1882 | $$->u.type_declarator.u.nested.type_declarator = $1; |
| 1883 | $$->u.type_declarator.u.nested.abstract_array = 1; |
| 1884 | } |
| 1885 | ; |
| 1886 | |
| 1887 | alias_abstract_declarator_list: |
| 1888 | alias_abstract_declarator |
| 1889 | { $$ = $1; } |
| 1890 | | alias_abstract_declarator_list COMMA alias_abstract_declarator |
| 1891 | { |
| 1892 | $$ = $1; |
| 1893 | cds_list_add_tail(&($3)->siblings, &($$)->tmp_head); |
| 1894 | } |
| 1895 | ; |
| 1896 | |
| 1897 | alias_abstract_declarator: |
| 1898 | direct_alias_abstract_declarator |
| 1899 | { $$ = $1; } |
| 1900 | | pointer direct_alias_abstract_declarator |
| 1901 | { |
| 1902 | $$ = $2; |
| 1903 | cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers); |
| 1904 | } |
| 1905 | ; |
| 1906 | |
| 1907 | direct_alias_abstract_declarator: |
| 1908 | /* empty */ |
| 1909 | { |
| 1910 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1911 | $$->u.type_declarator.type = TYPEDEC_ID; |
| 1912 | /* id is NULL */ |
| 1913 | } |
| 1914 | | LPAREN alias_abstract_declarator RPAREN |
| 1915 | { |
| 1916 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1917 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 1918 | $$->u.type_declarator.u.nested.type_declarator = $2; |
| 1919 | } |
| 1920 | | direct_alias_abstract_declarator LSBRAC type_specifier_or_integer_constant RSBRAC |
| 1921 | { |
| 1922 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1923 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 1924 | $$->u.type_declarator.u.nested.type_declarator = $1; |
| 1925 | $$->u.type_declarator.u.nested.length = $3; |
| 1926 | } |
| 1927 | | direct_alias_abstract_declarator LSBRAC RSBRAC |
| 1928 | { |
| 1929 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1930 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 1931 | $$->u.type_declarator.u.nested.type_declarator = $1; |
| 1932 | $$->u.type_declarator.u.nested.abstract_array = 1; |
| 1933 | } |
| 1934 | ; |
| 1935 | |
| 1936 | declarator: |
| 1937 | direct_declarator |
| 1938 | { $$ = $1; } |
| 1939 | | pointer direct_declarator |
| 1940 | { |
| 1941 | $$ = $2; |
| 1942 | cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers); |
| 1943 | } |
| 1944 | ; |
| 1945 | |
| 1946 | direct_declarator: |
| 1947 | IDENTIFIER |
| 1948 | { |
| 1949 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1950 | $$->u.type_declarator.type = TYPEDEC_ID; |
| 1951 | $$->u.type_declarator.u.id = $1->s; |
| 1952 | } |
| 1953 | | LPAREN declarator RPAREN |
| 1954 | { |
| 1955 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1956 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 1957 | $$->u.type_declarator.u.nested.type_declarator = $2; |
| 1958 | } |
| 1959 | | direct_declarator LSBRAC type_specifier_or_integer_constant RSBRAC |
| 1960 | { |
| 1961 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1962 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 1963 | $$->u.type_declarator.u.nested.type_declarator = $1; |
| 1964 | $$->u.type_declarator.u.nested.length = $3; |
| 1965 | } |
| 1966 | ; |
| 1967 | |
| 1968 | type_declarator: |
| 1969 | direct_type_declarator |
| 1970 | { $$ = $1; } |
| 1971 | | pointer direct_type_declarator |
| 1972 | { |
| 1973 | $$ = $2; |
| 1974 | cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers); |
| 1975 | } |
| 1976 | ; |
| 1977 | |
| 1978 | direct_type_declarator: |
| 1979 | IDENTIFIER |
| 1980 | { |
| 1981 | add_type(scanner, $1); |
| 1982 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1983 | $$->u.type_declarator.type = TYPEDEC_ID; |
| 1984 | $$->u.type_declarator.u.id = $1->s; |
| 1985 | } |
| 1986 | | LPAREN type_declarator RPAREN |
| 1987 | { |
| 1988 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1989 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 1990 | $$->u.type_declarator.u.nested.type_declarator = $2; |
| 1991 | } |
| 1992 | | direct_type_declarator LSBRAC type_specifier_or_integer_constant RSBRAC |
| 1993 | { |
| 1994 | $$ = make_node(scanner, NODE_TYPE_DECLARATOR); |
| 1995 | $$->u.type_declarator.type = TYPEDEC_NESTED; |
| 1996 | $$->u.type_declarator.u.nested.type_declarator = $1; |
| 1997 | $$->u.type_declarator.u.nested.length = $3; |
| 1998 | } |
| 1999 | ; |
| 2000 | |
| 2001 | pointer: |
| 2002 | STAR |
| 2003 | { |
| 2004 | $$ = make_node(scanner, NODE_POINTER); |
| 2005 | } |
| 2006 | | STAR pointer |
| 2007 | { |
| 2008 | $$ = make_node(scanner, NODE_POINTER); |
| 2009 | cds_list_splice(&($2)->tmp_head, &($$)->tmp_head); |
| 2010 | } |
| 2011 | | STAR type_qualifier_list pointer |
| 2012 | { |
| 2013 | $$ = make_node(scanner, NODE_POINTER); |
| 2014 | $$->u.pointer.const_qualifier = 1; |
| 2015 | cds_list_splice(&($3)->tmp_head, &($$)->tmp_head); |
| 2016 | } |
| 2017 | ; |
| 2018 | |
| 2019 | type_qualifier_list: |
| 2020 | /* pointer assumes only const type qualifier */ |
| 2021 | CONST |
| 2022 | | type_qualifier_list CONST |
| 2023 | ; |
| 2024 | |
| 2025 | /* 2.3: CTF-specific declarations */ |
| 2026 | |
| 2027 | ctf_assignment_expression_list: |
| 2028 | ctf_assignment_expression SEMICOLON |
| 2029 | { $$ = $1; } |
| 2030 | | ctf_assignment_expression_list ctf_assignment_expression SEMICOLON |
| 2031 | { |
| 2032 | $$ = $1; |
| 2033 | cds_list_add_tail(&($2)->siblings, &($$)->tmp_head); |
| 2034 | } |
| 2035 | ; |
| 2036 | |
| 2037 | ctf_assignment_expression: |
| 2038 | unary_expression EQUAL unary_expression |
| 2039 | { |
| 2040 | /* |
| 2041 | * Because we have left and right, cannot use |
| 2042 | * set_parent_node. |
| 2043 | */ |
| 2044 | $$ = make_node(scanner, NODE_CTF_EXPRESSION); |
| 2045 | _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left); |
| 2046 | if ($1->u.unary_expression.type != UNARY_STRING) |
| 2047 | reparent_error(scanner, "ctf_assignment_expression left expects string"); |
| 2048 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right); |
| 2049 | } |
| 2050 | | unary_expression TYPEASSIGN type_specifier |
| 2051 | { |
| 2052 | /* |
| 2053 | * Because we have left and right, cannot use |
| 2054 | * set_parent_node. |
| 2055 | */ |
| 2056 | $$ = make_node(scanner, NODE_CTF_EXPRESSION); |
| 2057 | _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left); |
| 2058 | if ($1->u.unary_expression.type != UNARY_STRING) |
| 2059 | reparent_error(scanner, "ctf_assignment_expression left expects string"); |
| 2060 | cds_list_add(&($3)->siblings, &($3)->tmp_head); |
| 2061 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right); |
| 2062 | } |
| 2063 | | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list |
| 2064 | { |
| 2065 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 2066 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.declaration_specifier); |
| 2067 | _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier); |
| 2068 | _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators); |
| 2069 | } |
| 2070 | | TYPEDEF declaration_specifiers type_declarator_list |
| 2071 | { |
| 2072 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 2073 | _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._typedef.declaration_specifier); |
| 2074 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); |
| 2075 | } |
| 2076 | | declaration_specifiers TYPEDEF type_declarator_list |
| 2077 | { |
| 2078 | $$ = make_node(scanner, NODE_TYPEDEF); |
| 2079 | _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier); |
| 2080 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); |
| 2081 | } |
| 2082 | | TYPEALIAS declaration_specifiers abstract_declarator_list COLON alias_declaration_specifiers alias_abstract_declarator_list |
| 2083 | { |
| 2084 | $$ = make_node(scanner, NODE_TYPEALIAS); |
| 2085 | $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET); |
| 2086 | $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS); |
| 2087 | _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier); |
| 2088 | _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators); |
| 2089 | _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier); |
| 2090 | _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators); |
| 2091 | } |
| 2092 | ; |