Print this page
new smatch
*** 29,40 ****
#include "parse.h"
#include "cwchash/hashtable.h"
static struct hashtable *macro_table;
! static DEFINE_HASHTABLE_INSERT(do_insert_macro, struct position, char);
! static DEFINE_HASHTABLE_SEARCH(do_search_macro, struct position, char);
static inline unsigned int position_hash(void *_pos)
{
struct position *pos = _pos;
--- 29,40 ----
#include "parse.h"
#include "cwchash/hashtable.h"
static struct hashtable *macro_table;
! static DEFINE_HASHTABLE_INSERT(do_insert_macro, struct position, struct string_list);
! static DEFINE_HASHTABLE_SEARCH(do_search_macro, struct position, struct string_list);
static inline unsigned int position_hash(void *_pos)
{
struct position *pos = _pos;
*** 48,67 ****
return pos1->line == pos2->line && pos1->pos == pos2->pos &&
pos1->stream == pos2->stream;
}
void store_macro_pos(struct token *token)
{
if (!macro_table)
macro_table = create_hashtable(5000, position_hash, equalkeys);
! if (get_macro_name(token->pos))
! return;
! do_insert_macro(macro_table, &token->pos, token->ident->name);
}
char *get_macro_name(struct position pos)
{
return do_search_macro(macro_table, &pos);
}
--- 48,96 ----
return pos1->line == pos2->line && pos1->pos == pos2->pos &&
pos1->stream == pos2->stream;
}
+ static void insert_macro_string(struct string_list **str_list, char *new)
+ {
+ add_ptr_list(str_list, new);
+ }
+
void store_macro_pos(struct token *token)
{
+ struct string_list *list;
+
if (!macro_table)
macro_table = create_hashtable(5000, position_hash, equalkeys);
! list = do_search_macro(macro_table, &token->pos);
! insert_macro_string(&list, token->ident->name);
! do_insert_macro(macro_table, &token->pos, list);
}
char *get_macro_name(struct position pos)
{
+ struct string_list *list;
+
+ if (!macro_table)
+ return NULL;
+ list = do_search_macro(macro_table, &pos);
+ return first_ptr_list((struct ptr_list *)list);
+ }
+
+ char *get_inner_macro(struct position pos)
+ {
+ struct string_list *list;
+
+ if (!macro_table)
+ return NULL;
+ list = do_search_macro(macro_table, &pos);
+ return last_ptr_list((struct ptr_list *)list);
+ }
+
+ struct string_list *get_all_macros(struct position pos)
+ {
+ if (!macro_table)
+ return NULL;
return do_search_macro(macro_table, &pos);
}