diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2022-05-21 11:21:01 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2022-05-21 11:21:33 +0200 |
commit | b22b01e5c1c6da0a6eeb6b3bb5d538f493f696b6 (patch) | |
tree | a939975060225ae16326fb10debf2665de53d33a | |
parent | 7d990b119a6249af9a1ef4f3df9957d8975b56b2 (diff) | |
parent | 62dafeef8ba83d210d0ce861476d4071f66fc34a (diff) | |
download | sparse-b22b01e5c1c6da0a6eeb6b3bb5d538f493f696b6.tar.gz |
Merge branch 'semid'
* semind: Index more symbols
For indexing purposes, macros definitions and typedefs are added to the
semind database. Functions that are not used in the code are also indexed.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | dissect.c | 61 | ||||
-rw-r--r-- | options.c | 5 | ||||
-rw-r--r-- | options.h | 2 | ||||
-rw-r--r-- | semind.c | 1 | ||||
-rw-r--r-- | test-dissect.c | 5 |
5 files changed, 72 insertions, 2 deletions
@@ -610,6 +610,16 @@ static struct symbol *do_initializer(struct symbol *type, struct expression *exp return type; } +static inline bool is_macro(struct symbol *sym) +{ + return (sym->namespace == NS_MACRO || sym->namespace == NS_UNDEF); +} + +static inline bool is_typedef(struct symbol *sym) +{ + return (sym->namespace == NS_TYPEDEF); +} + static inline struct symbol *do_symbol(struct symbol *sym) { struct symbol *type = base_type(sym); @@ -652,9 +662,58 @@ static void do_sym_list(struct symbol_list *list) DO_LIST(list, sym, do_symbol(sym)); } +static inline bool valid_namespace(enum namespace ns) +{ + return (ns == NS_TYPEDEF || ns == NS_MACRO || ns == NS_UNDEF || ns == NS_STRUCT || ns == NS_SYMBOL); +} + +static void do_file(char *file) +{ + struct symbol_list *res = sparse_keep_tokens(file); + + if (!dissect_show_all_symbols) { + do_sym_list(res); + goto end; + } + + DO_LIST(file_scope->symbols, sym, + if (input_streams[sym->pos.stream].fd != -1 && valid_namespace(sym->namespace)) { + if (is_typedef(sym)) { + sym->kind = 't'; + reporter->r_symdef(sym); + continue; + } + + if (is_macro(sym)) { + sym->kind = 'd'; + reporter->r_symdef(sym); + continue; + } + + if (sym->type == SYM_STRUCT || sym->type == SYM_UNION) { + sym->ctype.base_type = sym; + examine_sym_node(sym, NULL); + continue; + } + + do_symbol(sym); + } + ); + + DO_LIST(global_scope->symbols, sym, + if (input_streams[sym->pos.stream].fd != -1 && valid_namespace(sym->namespace)) { + do_symbol(sym); + } + ); + +end: + /* Drop the tokens for this file after parsing */ + clear_token_alloc(); +} + void dissect(struct reporter *rep, struct string_list *filelist) { reporter = rep; - DO_LIST(filelist, file, do_sym_list(__sparse(file))); + DO_LIST(filelist, file, do_file(file)); } @@ -70,6 +70,8 @@ int dbg_postorder = 0; int dump_macro_defs = 0; int dump_macros_only = 0; +int dissect_show_all_symbols = 0; + unsigned long fdump_ir; int fhosted = 1; unsigned int fmax_errors = 100; @@ -958,6 +960,9 @@ static char **handle_param(char *arg, char **next) if (!value) die("missing argument for --param option"); + if (!strcmp(value, "dissect-show-all-symbols")) + dissect_show_all_symbols = 1; + return next; } @@ -70,6 +70,8 @@ extern int dbg_postorder; extern int dump_macro_defs; extern int dump_macros_only; +extern int dissect_show_all_symbols; + extern unsigned long fdump_ir; extern int fhosted; extern unsigned int fmax_errors; @@ -329,6 +329,7 @@ done: optind--; sparse_initialize(argc - optind, argv + optind, &semind_filelist); + dissect_show_all_symbols = 1; } static void parse_cmdline_rm(int argc, char **argv) diff --git a/test-dissect.c b/test-dissect.c index 58b3e633..65b205f8 100644 --- a/test-dissect.c +++ b/test-dissect.c @@ -57,11 +57,14 @@ static void r_symbol(unsigned mode, struct position *pos, struct symbol *sym) show_typename(sym->ctype.base_type)); switch (sym->kind) { + case 'd': + break; case 's': if (sym->type == SYM_STRUCT || sym->type == SYM_UNION) break; goto err; - + case 't': + break; case 'f': if (sym->type != SYM_BAD && sym->ctype.base_type->type != SYM_FN) goto err; |