extra: estate: move merge_estate() from extra to estate
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 14 Dec 2012 12:01:46 +0000 (14 15:01 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Fri, 14 Dec 2012 12:01:46 +0000 (14 15:01 +0300)
I want to use this function in a later check.  It fits very nicely into
smatch_estate.c as well.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch_estate.c
smatch_extra.c
smatch_extra.h

index a58706f..c31b9dc 100644 (file)
 #include "smatch_slist.h"
 #include "smatch_extra.h"
 
+struct smatch_state *merge_estates(struct smatch_state *s1, struct smatch_state *s2)
+{
+       struct smatch_state *tmp;
+       struct range_list *value_ranges;
+       struct related_list *rlist;
+
+       if (estates_equiv(s1, s2))
+               return s1;
+
+       value_ranges = range_list_union(estate_ranges(s1), estate_ranges(s2));
+       tmp = alloc_estate_range_list(value_ranges);
+       rlist = get_shared_relations(estate_related(s1), estate_related(s2));
+       set_related(tmp, rlist);
+       if (estate_has_hard_max(s1) && estate_has_hard_max(s2))
+               estate_set_hard_max(tmp);
+
+       return tmp;
+}
+
 struct data_info *get_dinfo(struct smatch_state *state)
 {
        if (!state)
index dba2c7d..aa3f5e1 100644 (file)
@@ -144,25 +144,6 @@ struct smatch_state *add_filter(struct smatch_state *orig, sval_t sval)
        return filter_range(orig, sval, sval);
 }
 
-static struct smatch_state *merge_func(struct smatch_state *s1, struct smatch_state *s2)
-{
-       struct smatch_state *tmp;
-       struct range_list *value_ranges;
-       struct related_list *rlist;
-
-       if (estates_equiv(s1, s2))
-               return s1;
-
-       value_ranges = range_list_union(estate_ranges(s1), estate_ranges(s2));
-       tmp = alloc_estate_range_list(value_ranges);
-       rlist = get_shared_relations(estate_related(s1), estate_related(s2));
-       set_related(tmp, rlist);
-       if (estate_has_hard_max(s1) && estate_has_hard_max(s2))
-               estate_set_hard_max(tmp);
-
-       return tmp;
-}
-
 static struct sm_state *handle_canonical_while_count_down(struct statement *loop)
 {
        struct expression *iter_var;
@@ -1173,7 +1154,7 @@ void register_smatch_extra(int id)
 {
        my_id = id;
 
-       add_merge_hook(my_id, &merge_func);
+       add_merge_hook(my_id, &merge_estates);
        add_unmatched_state_hook(my_id, &unmatched_state);
        add_hook(&match_function_def, FUNC_DEF_HOOK);
        add_hook(&match_declarations, DECLARATION_HOOK);
index d742553..41ab414 100644 (file)
@@ -71,6 +71,7 @@ void __extra_pre_loop_hook_after(struct sm_state *sm,
                                struct expression *condition);
 
 /* also implemented in smatch_extra */
+struct smatch_state *merge_estates(struct smatch_state *s1, struct smatch_state *s2);
 int estates_equiv(struct smatch_state *one, struct smatch_state *two);
 struct smatch_state *clone_estate(struct smatch_state *state);
 struct sm_state *set_extra_mod(const char *name, struct symbol *sym, struct smatch_state *state);