Skip to content

Commit 01762c4

Browse files
committed
genksyms: simplify usage of find_symbol()
Allow searching for symbols of an exact type. The lexer does this and a subsequent patch will add one more usage. Signed-off-by: Michal Marek <[email protected]> Acked-by: Sam Ravnborg <[email protected]>
1 parent 68eb856 commit 01762c4

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

scripts/genksyms/genksyms.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static enum symbol_type map_to_ns(enum symbol_type t)
156156
return t;
157157
}
158158

159-
struct symbol *find_symbol(const char *name, enum symbol_type ns)
159+
struct symbol *find_symbol(const char *name, enum symbol_type ns, int exact)
160160
{
161161
unsigned long h = crc32(name) % HASH_BUCKETS;
162162
struct symbol *sym;
@@ -167,6 +167,8 @@ struct symbol *find_symbol(const char *name, enum symbol_type ns)
167167
sym->is_declared)
168168
break;
169169

170+
if (exact && sym && sym->type != ns)
171+
return NULL;
170172
return sym;
171173
}
172174

@@ -511,7 +513,7 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc)
511513
break;
512514

513515
case SYM_TYPEDEF:
514-
subsym = find_symbol(cur->string, cur->tag);
516+
subsym = find_symbol(cur->string, cur->tag, 0);
515517
/* FIXME: Bad reference files can segfault here. */
516518
if (subsym->expansion_trail) {
517519
if (flag_dump_defs)
@@ -528,7 +530,7 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc)
528530
case SYM_STRUCT:
529531
case SYM_UNION:
530532
case SYM_ENUM:
531-
subsym = find_symbol(cur->string, cur->tag);
533+
subsym = find_symbol(cur->string, cur->tag, 0);
532534
if (!subsym) {
533535
struct string_list *n;
534536

@@ -582,7 +584,7 @@ void export_symbol(const char *name)
582584
{
583585
struct symbol *sym;
584586

585-
sym = find_symbol(name, SYM_NORMAL);
587+
sym = find_symbol(name, SYM_NORMAL, 0);
586588
if (!sym)
587589
error_with_pos("export undefined symbol %s", name);
588590
else {

scripts/genksyms/genksyms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ typedef struct string_list **yystype;
5858
extern int cur_line;
5959
extern char *cur_filename;
6060

61-
struct symbol *find_symbol(const char *name, enum symbol_type ns);
61+
struct symbol *find_symbol(const char *name, enum symbol_type ns, int exact);
6262
struct symbol *add_symbol(const char *name, enum symbol_type type,
6363
struct string_list *defn, int is_extern);
6464
void export_symbol(const char *);

scripts/genksyms/lex.c_shipped

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,8 +2347,7 @@ repeat:
23472347
}
23482348
if (!suppress_type_lookup)
23492349
{
2350-
struct symbol *sym = find_symbol(yytext, SYM_TYPEDEF);
2351-
if (sym && sym->type == SYM_TYPEDEF)
2350+
if (find_symbol(yytext, SYM_TYPEDEF, 1))
23522351
token = TYPE;
23532352
}
23542353
}

scripts/genksyms/lex.l

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ repeat:
193193
}
194194
if (!suppress_type_lookup)
195195
{
196-
struct symbol *sym = find_symbol(yytext, SYM_TYPEDEF);
197-
if (sym && sym->type == SYM_TYPEDEF)
196+
if (find_symbol(yytext, SYM_TYPEDEF, 1))
198197
token = TYPE;
199198
}
200199
}

0 commit comments

Comments
 (0)