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