From 6f5c308c6a1d3b3f35243e1944101560ff18e47e Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 11 Jun 2012 13:29:49 +0300 Subject: [PATCH] function_hash: make it easier to handle a file with a list of strings One thing that we often do is store a list of strings and then check if a macro name is in the list of strings. This sets up some helper macros so we don't have to manually register the file from the smatch_data/ directory every time. Signed-off-by: Dan Carpenter --- smatch_function_hashtable.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/smatch_function_hashtable.h b/smatch_function_hashtable.h index 80410cbf..0ccfc0ba 100644 --- a/smatch_function_hashtable.h +++ b/smatch_function_hashtable.h @@ -68,3 +68,33 @@ static inline void destroy_function_hashtable(struct hashtable *table) static DEFINE_HASHTABLE_SEARCH(search_##_name, char, _list_type); \ static DEFINE_HASHTABLE_REMOVE(remove_##_name, char, _list_type); \ static DEFINE_FUNCTION_ADD_HOOK(_name, _item_type, _list_type); + +#define DEFINE_STRING_HASHTABLE_STATIC(_name) \ + static DEFINE_HASHTABLE_INSERT(insert_##_name, char, int); \ + static DEFINE_HASHTABLE_SEARCH(search_##_name, char, int); \ + static struct hashtable *_name + +static inline void load_hashtable_helper(const char *file, int (*insert_func)(struct hashtable *, char *, int *), struct hashtable *table) +{ + char filename[256]; + struct token *token; + char *name; + + snprintf(filename, sizeof(filename), "%s.%s", option_project_str, file); + token = get_tokens_file(filename); + if (!token) + return; + if (token_type(token) != TOKEN_STREAMBEGIN) + return; + token = token->next; + while (token_type(token) != TOKEN_STREAMEND) { + if (token_type(token) != TOKEN_IDENT) + return; + name = alloc_string(show_ident(token->ident)); + insert_func(table, name, (void *)1); + token = token->next; + } + clear_token_alloc(); +} + +#define load_strings(file, _table) load_hashtable_helper(file, insert_##_table, _table) -- 2.11.4.GIT