History

genksyms: Simplify printing of symbol types

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.

Michal Marek committed 15 years ago

Commit 7ec8eda1 parent 95f1d631 file · +27 −16Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/genksyms/genksyms.c+27−16
@@ -53,8 +53,15 @@ static int nsyms; · 52 unmodified lines
53static struct symbol *expansion_trail;53static struct symbol *expansion_trail;
54static struct symbol *visited_symbols;54static struct symbol *visited_symbols;
55 55
56static const char *const symbol_type_name[] = {56static const struct {
57 "normal", "typedef", "enum", "struct", "union"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
60static int equal_list(struct string_list *a, struct string_list *b);67static 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 sym->is_override = 0;254 sym->is_override = 0;
248 255
249 if (flag_debug) {256 if (flag_debug) {
250 fprintf(debugfile, "Defn for %s %s == <",257 if (symbol_types[type].name)
251 symbol_type_name[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 if (is_extern)263 if (is_extern)
253 fputs("extern ", debugfile);264 fputs("extern ", debugfile);
254 print_list(debugfile, defn);265 print_list(debugfile, defn);
@@ -346,8 +357,8 @@ static struct string_list *read_node(FILE *f) · 91 unmodified lines
346 if (node.string[1] == '#') {357 if (node.string[1] == '#') {
347 int n;358 int n;
348 359
349 for (n = 0; n < ARRAY_SIZE(symbol_type_name); n++) {360 for (n = 0; n < ARRAY_SIZE(symbol_types); n++) {
350 if (node.string[0] == symbol_type_name[n][0]) {361 if (node.string[0] == symbol_types[n].n) {
351 node.tag = n;362 node.tag = n;
352 node.string += 2;363 node.string += 2;
353 return copy_node(&node);364 return copy_node(&node);
@@ -397,8 +408,8 @@ static void read_reference(FILE *f) · 43 unmodified lines
397 408
398static void print_node(FILE * f, struct string_list *list)409static void print_node(FILE * f, struct string_list *list)
399{410{
400 if (list->tag != SYM_NORMAL) {411 if (symbol_types[list->tag].n) {
401 putc(symbol_type_name[list->tag][0], f);412 putc(symbol_types[list->tag].n, f);
402 putc('#', f);413 putc('#', f);
403 }414 }
404 fputs(list->string, f);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 struct string_list *n, *t = NULL;502 struct string_list *n, *t = NULL;
492 503
493 error_with_pos("expand undefined %s %s",504 error_with_pos("expand undefined %s %s",
494 symbol_type_name[cur->tag],505 symbol_types[cur->tag].name,
495 cur->string);506 cur->string);
496 507
497 n = xmalloc(sizeof(*n));508 n = xmalloc(sizeof(*n));
498 n->string = xstrdup(symbol_type_name[cur->tag]);509 n->string = xstrdup(symbol_types[cur->tag].name);
499 n->tag = SYM_NORMAL;510 n->tag = SYM_NORMAL;
500 n->next = t;511 n->next = t;
501 t = n;512 t = n;
@@ -530,11 +541,11 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc) · 28 unmodified lines
530 if (subsym->expansion_trail) {541 if (subsym->expansion_trail) {
531 if (flag_dump_defs) {542 if (flag_dump_defs) {
532 fprintf(debugfile, "%s %s ",543 fprintf(debugfile, "%s %s ",
533 symbol_type_name[cur->tag],544 symbol_types[cur->tag].name,
534 cur->string);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 crc);549 crc);
539 crc = partial_crc32_one(' ', crc);550 crc = partial_crc32_one(' ', crc);
540 crc = partial_crc32(cur->string, crc);551 crc = partial_crc32(cur->string, crc);
@@ -624,8 +635,8 @@ static void print_location(void) · 83 unmodified lines
624 635
625static void print_type_name(enum symbol_type type, const char *name)636static void print_type_name(enum symbol_type type, const char *name)
626{637{
627 if (type != SYM_NORMAL)638 if (symbol_types[type].name)
628 fprintf(stderr, "%s %s", symbol_type_name[type], name);639 fprintf(stderr, "%s %s", symbol_types[type].name, name);
629 else640 else
630 fprintf(stderr, "%s", name);641 fprintf(stderr, "%s", name);
631}642}
@@ -771,8 +782,8 @@ int main(int argc, char **argv) · 139 unmodified lines
771 782
772 if (sym->is_override)783 if (sym->is_override)
773 fputs("override ", dumpfile);784 fputs("override ", dumpfile);
774 if (sym->type != SYM_NORMAL) {785 if (symbol_types[sym->type].n) {
775 putc(symbol_type_name[sym->type][0], dumpfile);786 putc(symbol_types[sym->type].n, dumpfile);
776 putc('#', dumpfile);787 putc('#', dumpfile);
777 }788 }
778 fputs(sym->name, dumpfile);789 fputs(sym->name, dumpfile);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t