From 404be88c0498a60b658b3852c9a737548fc0606b Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sun, 21 Dec 2008 21:00:06 +0300 Subject: [PATCH] Stuff left over from October. Implied pools work. Also move the __print_slist() function to smatch_slist. --- smatch_slist.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- smatch_slist.h | 2 ++ smatch_states.c | 12 +----------- 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/smatch_slist.c b/smatch_slist.c index d3007550..2c03add1 100644 --- a/smatch_slist.c +++ b/smatch_slist.c @@ -18,6 +18,17 @@ ALLOCATOR(named_slist, "named slist"); #undef CHECKORDER +void __print_slist(struct state_list *slist) +{ + struct sm_state *state; + + printf("dumping slist at %d\n", get_lineno()); + FOR_EACH_PTR(slist, state) { + printf("'%s'=%s\n", state->name, show_state(state->state)); + } END_FOR_EACH_PTR(state); + printf("---\n"); +} + void add_history(struct sm_state *state) { struct state_history *tmp; @@ -46,7 +57,11 @@ struct sm_state *alloc_state(const char *name, int owner, struct sm_state *clone_state(struct sm_state *s) { - return alloc_state(s->name, s->owner, s->sym, s->state); + struct sm_state *tmp; + + tmp = alloc_state(s->name, s->owner, s->sym, s->state); + tmp->pools = clone_stack(s->pools); + return tmp; } /* NULL states go at the end to simplify merge_slist */ @@ -122,6 +137,17 @@ struct state_list *clone_slist(struct state_list *from_slist) return to_slist; } +struct state_list_stack *clone_stack(struct state_list_stack *from_stack) +{ + struct state_list *slist; + struct state_list_stack *to_stack = NULL; + + FOR_EACH_PTR(from_stack, slist) { + push_slist(&to_stack, slist); + } END_FOR_EACH_PTR(slist); + return to_stack; +} + // FIXME... shouldn't we free some of these state pointers? struct smatch_state *merge_states(const char *name, int owner, struct symbol *sym, @@ -176,6 +202,28 @@ struct sm_state *get_sm_state_slist(struct state_list *slist, const char *name, return NULL; } +static void overwrite_sm_state(struct state_list **slist, + struct sm_state *state) +{ + struct sm_state *tmp; + struct sm_state *new = clone_state(state); + + FOR_EACH_PTR(*slist, tmp) { + if (cmp_sm_states(tmp, new) < 0) + continue; + else if (cmp_sm_states(tmp, new) == 0) { + tmp->state = new->state; + tmp->pools = new->pools; + __free_sm_state(new); + return; + } else { + INSERT_CURRENT(new, tmp); + return; + } + } END_FOR_EACH_PTR(tmp); + add_ptr_list(slist, new); +} + void set_state_slist(struct state_list **slist, const char *name, int owner, struct symbol *sym, struct smatch_state *state) { @@ -188,6 +236,7 @@ void set_state_slist(struct state_list **slist, const char *name, int owner, else if (cmp_sm_states(tmp, new) == 0) { __free_sm_state(new); tmp->state = state; + tmp->pools = NULL; return; } else { INSERT_CURRENT(new, tmp); @@ -475,7 +524,7 @@ void overwrite_slist(struct state_list *from, struct state_list **to) struct sm_state *tmp; FOR_EACH_PTR(from, tmp) { - set_state_slist(to, tmp->name, tmp->owner, tmp->sym, tmp->state); + overwrite_sm_state(to, tmp); } END_FOR_EACH_PTR(tmp); } diff --git a/smatch_slist.h b/smatch_slist.h index d4d8ec0d..0c868393 100644 --- a/smatch_slist.h +++ b/smatch_slist.h @@ -24,6 +24,7 @@ DECLARE_PTR_LIST(slist_stack, struct named_slist); extern struct state_list_stack *implied_pools; +void __print_slist(struct state_list *slist); void add_history(struct sm_state *state); struct sm_state *alloc_state(const char *name, int owner, struct symbol *sym, @@ -31,6 +32,7 @@ struct sm_state *alloc_state(const char *name, int owner, struct sm_state *clone_state(struct sm_state *s); struct state_list *clone_slist(struct state_list *from_slist); +struct state_list_stack *clone_stack(struct state_list_stack *from_stack); struct smatch_state *merge_states(const char *name, int owner, struct symbol *sym, diff --git a/smatch_states.c b/smatch_states.c index 4bbe0a91..a6cfbf07 100644 --- a/smatch_states.c +++ b/smatch_states.c @@ -54,17 +54,6 @@ struct state_list_stack *implied_pools; int debug_states; -void __print_slist(struct state_list *slist) -{ - struct sm_state *state; - - printf("dumping slist at %d\n", get_lineno()); - FOR_EACH_PTR(slist, state) { - printf("'%s'=%s\n", state->name, show_state(state->state)); - } END_FOR_EACH_PTR(state); - printf("---\n"); -} - void __print_cur_slist() { __print_slist(cur_slist); @@ -301,6 +290,7 @@ void __use_cond_states() del_slist(&cur_slist); cur_slist = pre; + false_states = pop_slist(&cond_false_stack); push_slist(&false_only_stack, clone_slist(false_states)); overwrite_slist(false_states, &pre_clone); -- 2.11.4.GIT