Instead of special-casing SYM_NORMAL, do not map any name to it. Also explicitly set the single-letter name of the symbol type, which will be needed by a further patch. The only user-visible change is one debug printf.
Unified · Split
| @@ -53,8 +53,15 @@ static int nsyms; · 52 unmodified lines | ||
| 53 | 53 | static struct symbol *expansion_trail; |
| 54 | 54 | static struct symbol *visited_symbols; |
| 55 | 55 | |
| 56 | −static const char *const symbol_type_name[] = { | |
| 57 | − "normal", "typedef", "enum", "struct", "union" | |
| 56 | +static const struct { | |
| 57 | + int n; | |
| 58 | + const char *name; | |
| 59 | +} symbol_types[] = { | |
| 60 | + [SYM_NORMAL] = { 0, NULL}, | |
| 61 | + [SYM_TYPEDEF] = {'t', "typedef"}, | |
| 62 | + [SYM_ENUM] = {'e', "enum"}, | |
| 63 | + [SYM_STRUCT] = {'s', "struct"}, | |
| 64 | + [SYM_UNION] = {'u', "union"}, | |
| 58 | 65 | }; |
| 59 | 66 | |
| 60 | 67 | static int equal_list(struct string_list *a, struct string_list *b); |
| @@ -247,8 +254,12 @@ static struct symbol *__add_symbol(const char *name, enum symbol_type type, · 186 unmodified lines | ||
| 247 | 254 | sym->is_override = 0; |
| 248 | 255 | |
| 249 | 256 | if (flag_debug) { |
| 250 | − fprintf(debugfile, "Defn for %s %s == <", | |
| 251 | − symbol_type_name[type], name); | |
| 257 | + if (symbol_types[type].name) | |
| 258 | + fprintf(debugfile, "Defn for %s %s == <", | |
| 259 | + symbol_types[type].name, name); | |
| 260 | + else | |
| 261 | + fprintf(debugfile, "Defn for type%d %s == <", | |
| 262 | + type, name); | |
| 252 | 263 | if (is_extern) |
| 253 | 264 | fputs("extern ", debugfile); |
| 254 | 265 | print_list(debugfile, defn); |
| @@ -346,8 +357,8 @@ static struct string_list *read_node(FILE *f) · 91 unmodified lines | ||
| 346 | 357 | if (node.string[1] == '#') { |
| 347 | 358 | int n; |
| 348 | 359 | |
| 349 | − for (n = 0; n < ARRAY_SIZE(symbol_type_name); n++) { | |
| 350 | − if (node.string[0] == symbol_type_name[n][0]) { | |
| 360 | + for (n = 0; n < ARRAY_SIZE(symbol_types); n++) { | |
| 361 | + if (node.string[0] == symbol_types[n].n) { | |
| 351 | 362 | node.tag = n; |
| 352 | 363 | node.string += 2; |
| 353 | 364 | return copy_node(&node); |
| @@ -397,8 +408,8 @@ static void read_reference(FILE *f) · 43 unmodified lines | ||
| 397 | 408 | |
| 398 | 409 | static void print_node(FILE * f, struct string_list *list) |
| 399 | 410 | { |
| 400 | − if (list->tag != SYM_NORMAL) { | |
| 401 | − putc(symbol_type_name[list->tag][0], f); | |
| 411 | + if (symbol_types[list->tag].n) { | |
| 412 | + putc(symbol_types[list->tag].n, f); | |
| 402 | 413 | putc('#', f); |
| 403 | 414 | } |
| 404 | 415 | fputs(list->string, f); |
| @@ -491,11 +502,11 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc) · 86 unmodified lines | ||
| 491 | 502 | struct string_list *n, *t = NULL; |
| 492 | 503 | |
| 493 | 504 | error_with_pos("expand undefined %s %s", |
| 494 | − symbol_type_name[cur->tag], | |
| 505 | + symbol_types[cur->tag].name, | |
| 495 | 506 | cur->string); |
| 496 | 507 | |
| 497 | 508 | n = xmalloc(sizeof(*n)); |
| 498 | − n->string = xstrdup(symbol_type_name[cur->tag]); | |
| 509 | + n->string = xstrdup(symbol_types[cur->tag].name); | |
| 499 | 510 | n->tag = SYM_NORMAL; |
| 500 | 511 | n->next = t; |
| 501 | 512 | t = n; |
| @@ -530,11 +541,11 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc) · 28 unmodified lines | ||
| 530 | 541 | if (subsym->expansion_trail) { |
| 531 | 542 | if (flag_dump_defs) { |
| 532 | 543 | fprintf(debugfile, "%s %s ", |
| 533 | − symbol_type_name[cur->tag], | |
| 544 | + symbol_types[cur->tag].name, | |
| 534 | 545 | cur->string); |
| 535 | 546 | } |
| 536 | 547 | |
| 537 | − crc = partial_crc32(symbol_type_name[cur->tag], | |
| 548 | + crc = partial_crc32(symbol_types[cur->tag].name, | |
| 538 | 549 | crc); |
| 539 | 550 | crc = partial_crc32_one(' ', crc); |
| 540 | 551 | crc = partial_crc32(cur->string, crc); |
| @@ -624,8 +635,8 @@ static void print_location(void) · 83 unmodified lines | ||
| 624 | 635 | |
| 625 | 636 | static void print_type_name(enum symbol_type type, const char *name) |
| 626 | 637 | { |
| 627 | − if (type != SYM_NORMAL) | |
| 628 | − fprintf(stderr, "%s %s", symbol_type_name[type], name); | |
| 638 | + if (symbol_types[type].name) | |
| 639 | + fprintf(stderr, "%s %s", symbol_types[type].name, name); | |
| 629 | 640 | else |
| 630 | 641 | fprintf(stderr, "%s", name); |
| 631 | 642 | } |
| @@ -771,8 +782,8 @@ int main(int argc, char **argv) · 139 unmodified lines | ||
| 771 | 782 | |
| 772 | 783 | if (sym->is_override) |
| 773 | 784 | fputs("override ", dumpfile); |
| 774 | − if (sym->type != SYM_NORMAL) { | |
| 775 | − putc(symbol_type_name[sym->type][0], dumpfile); | |
| 785 | + if (symbol_types[sym->type].n) { | |
| 786 | + putc(symbol_types[sym->type].n, dumpfile); | |
| 776 | 787 | putc('#', dumpfile); |
| 777 | 788 | } |
| 778 | 789 | fputs(sym->name, dumpfile); |