genksyms: simplify usage of find_symbol()
authorMichal Marek <mmarek@suse.cz>
Tue, 15 Feb 2011 14:11:36 +0000 (15:11 +0100)
committerMichal Marek <mmarek@suse.cz>
Thu, 17 Mar 2011 14:13:55 +0000 (15:13 +0100)
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>
scripts/genksyms/genksyms.c
scripts/genksyms/genksyms.h
scripts/genksyms/lex.c_shipped
scripts/genksyms/lex.l

index d17b7a2b941f7c5b4213d75018f72652f315940e..4a350816a9e8eb737e2c7170dc7f3c20ca7bb6af 100644 (file)
@@ -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;
@@ -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;
 }
 
@@ -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)
@@ -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;
 
@@ -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 {
index 25c4d40cefc134f2609593ed60546daba55e1aab..9fdafb667e76e4f4910bd2afe8bacd5f8ba2a1c7 100644 (file)
@@ -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 *);
index d0a0423361fd956d0a9cbdbee05a523164a11ecd..f231c0810c60203e407106c25a83acfac8a20063 100644 (file)
@@ -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;
              }
          }
index 4687b1d147dea9f890fee5ac786e61c8338c64ca..c125d06fbd365504055f9d2797542c3683a10b2f 100644 (file)
@@ -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;
              }
          }