Skip to content

Commit

Permalink
genksyms: simplify usage of find_symbol()
Browse files Browse the repository at this point in the history
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 <mmarek@suse.cz>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
  • Loading branch information
Michal Marek committed Mar 17, 2011
1 parent 68eb856 commit 01762c4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
10 changes: 6 additions & 4 deletions scripts/genksyms/genksyms.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static enum symbol_type map_to_ns(enum symbol_type t)
return t;
}

struct symbol *find_symbol(const char *name, enum symbol_type ns)
struct symbol *find_symbol(const char *name, enum symbol_type ns, int exact)
{
unsigned long h = crc32(name) % HASH_BUCKETS;
struct symbol *sym;
Expand All @@ -167,6 +167,8 @@ struct symbol *find_symbol(const char *name, enum symbol_type ns)
sym->is_declared)
break;

if (exact && sym && sym->type != ns)
return NULL;
return sym;
}

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

case SYM_TYPEDEF:
subsym = find_symbol(cur->string, cur->tag);
subsym = find_symbol(cur->string, cur->tag, 0);
/* FIXME: Bad reference files can segfault here. */
if (subsym->expansion_trail) {
if (flag_dump_defs)
Expand All @@ -528,7 +530,7 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc)
case SYM_STRUCT:
case SYM_UNION:
case SYM_ENUM:
subsym = find_symbol(cur->string, cur->tag);
subsym = find_symbol(cur->string, cur->tag, 0);
if (!subsym) {
struct string_list *n;

Expand Down Expand Up @@ -582,7 +584,7 @@ void export_symbol(const char *name)
{
struct symbol *sym;

sym = find_symbol(name, SYM_NORMAL);
sym = find_symbol(name, SYM_NORMAL, 0);
if (!sym)
error_with_pos("export undefined symbol %s", name);
else {
Expand Down
2 changes: 1 addition & 1 deletion scripts/genksyms/genksyms.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ typedef struct string_list **yystype;
extern int cur_line;
extern char *cur_filename;

struct symbol *find_symbol(const char *name, enum symbol_type ns);
struct symbol *find_symbol(const char *name, enum symbol_type ns, int exact);
struct symbol *add_symbol(const char *name, enum symbol_type type,
struct string_list *defn, int is_extern);
void export_symbol(const char *);
Expand Down
3 changes: 1 addition & 2 deletions scripts/genksyms/lex.c_shipped
Original file line number Diff line number Diff line change
Expand Up @@ -2347,8 +2347,7 @@ repeat:
}
if (!suppress_type_lookup)
{
struct symbol *sym = find_symbol(yytext, SYM_TYPEDEF);
if (sym && sym->type == SYM_TYPEDEF)
if (find_symbol(yytext, SYM_TYPEDEF, 1))
token = TYPE;
}
}
Expand Down
3 changes: 1 addition & 2 deletions scripts/genksyms/lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ repeat:
}
if (!suppress_type_lookup)
{
struct symbol *sym = find_symbol(yytext, SYM_TYPEDEF);
if (sym && sym->type == SYM_TYPEDEF)
if (find_symbol(yytext, SYM_TYPEDEF, 1))
token = TYPE;
}
}
Expand Down

0 comments on commit 01762c4

Please sign in to comment.