estate: rename filter_range() to estate_filter_range()
[smatch.git] / smatch_extra.h
blob6c0875b065098891e4472f6b8e7e8bed34e15de6
1 /*
2 * sparse/smatch_extra.h
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 enum data_type {
11 DATA_RANGE,
14 DECLARE_PTR_LIST(range_list, struct data_range);
15 DECLARE_PTR_LIST(range_list_stack, struct range_list);
17 struct relation {
18 int op;
19 char *name;
20 struct symbol *sym;
23 DECLARE_PTR_LIST(related_list, struct relation);
25 struct data_info {
26 struct related_list *related;
27 enum data_type type;
28 struct range_list *value_ranges;
29 unsigned int hard_max:1;
31 DECLARE_ALLOCATOR(data_info);
33 extern struct string_list *__ignored_macros;
35 /* these are implemented in smatch_ranges.c */
36 char *show_ranges(struct range_list *list);
37 void str_to_rl(struct symbol *type, char *value, struct range_list **rl);
39 struct data_range *alloc_range(sval_t min, sval_t max);
40 struct data_range *alloc_range_perm(sval_t min, sval_t max);
42 struct range_list *alloc_rl(sval_t min, sval_t max);
43 struct range_list *clone_rl(struct range_list *list);
44 struct range_list *clone_rl_permanent(struct range_list *list);
45 struct range_list *alloc_whole_rl(struct symbol *type);
47 void add_range(struct range_list **list, sval_t min, sval_t max);
48 struct range_list *remove_range(struct range_list *list, sval_t min, sval_t max);
49 void tack_on(struct range_list **list, struct data_range *drange);
51 int true_comparison_range(struct data_range *left, int comparison, struct data_range *right);
52 int true_comparison_range_LR(int comparison, struct data_range *var, struct data_range *val, int left);
53 int false_comparison_range_LR(int comparison, struct data_range *var, struct data_range *val, int left);
55 int possibly_true(struct expression *left, int comparison, struct expression *right);
56 int possibly_true_rl(struct range_list *left_ranges, int comparison, struct range_list *right_ranges);
57 int possibly_true_rl_LR(int comparison, struct range_list *a, struct range_list *b, int left);
59 int possibly_false(struct expression *left, int comparison, struct expression *right);
60 int possibly_false_rl(struct range_list *left_ranges, int comparison, struct range_list *right_ranges);
61 int possibly_false_rl_LR(int comparison, struct range_list *a, struct range_list *b, int left);
63 int ranges_equiv(struct data_range *one, struct data_range *two);
65 int rl_equiv(struct range_list *one, struct range_list *two);
66 int is_whole_rl(struct range_list *rl);
68 sval_t rl_min(struct range_list *rl);
69 sval_t rl_max(struct range_list *rl);
71 struct range_list *rl_invert(struct range_list *orig);
72 struct range_list *rl_filter(struct range_list *rl, struct range_list *filter);
73 struct range_list *rl_intersection(struct range_list *one, struct range_list *two);
74 struct range_list *rl_union(struct range_list *one, struct range_list *two);
76 void push_rl(struct range_list_stack **rl_stack, struct range_list *rl);
77 struct range_list *pop_rl(struct range_list_stack **rl_stack);
78 struct range_list *top_rl(struct range_list_stack *rl_stack);
79 void filter_top_rl(struct range_list_stack **rl_stack, sval_t sval);
81 struct range_list *cast_rl(struct symbol *type, struct range_list *rl);
82 int get_implied_rl(struct expression *expr, struct range_list **rl);
84 void free_rl(struct range_list **rlist);
85 void free_data_info_allocs(void);
87 /* smatch_estate.c */
89 struct smatch_state *alloc_estate_empty(void);
90 struct smatch_state *alloc_estate_sval(sval_t sval);
91 struct smatch_state *alloc_estate_range(sval_t min, sval_t max);
92 struct smatch_state *alloc_estate_rl(struct range_list *rl);
93 struct smatch_state *alloc_estate_whole(struct symbol *type);
94 struct smatch_state *clone_estate(struct smatch_state *state);
96 struct smatch_state *merge_estates(struct smatch_state *s1, struct smatch_state *s2);
98 int estates_equiv(struct smatch_state *one, struct smatch_state *two);
99 int estate_is_whole(struct smatch_state *state);
101 struct range_list *estate_rl(struct smatch_state *state);
102 struct related_list *estate_related(struct smatch_state *state);
104 sval_t estate_min(struct smatch_state *state);
105 sval_t estate_max(struct smatch_state *state);
106 struct symbol *estate_type(struct smatch_state *state);
108 int estate_has_hard_max(struct smatch_state *state);
109 void estate_set_hard_max(struct smatch_state *state);
110 void estate_clear_hard_max(struct smatch_state *state);
111 int estate_get_hard_max(struct smatch_state *state, sval_t *sval);
113 int estate_get_single_value(struct smatch_state *state, sval_t *sval);
114 struct smatch_state *get_implied_estate(struct expression *expr);
116 struct smatch_state *estate_filter_sval(struct smatch_state *orig, sval_t filter);
117 struct smatch_state *estate_filter_range(struct smatch_state *orig, sval_t filter_min, sval_t filter_max);
119 /* used in smatch_slist. implemented in smatch_extra.c */
120 void add_extra_mod_hook(void (*fn)(const char *name, struct symbol *sym, struct smatch_state *state));
121 int implied_not_equal(struct expression *expr, long long val);
122 struct sm_state *__extra_handle_canonical_loops(struct statement *loop, struct state_list **slist);
123 int __iterator_unchanged(struct sm_state *sm);
124 void __extra_pre_loop_hook_after(struct sm_state *sm,
125 struct statement *iterator,
126 struct expression *condition);
128 /* also implemented in smatch_extra */
129 struct sm_state *set_extra_mod(const char *name, struct symbol *sym, struct smatch_state *state);
130 struct sm_state *set_extra_expr_mod(struct expression *expr, struct smatch_state *state);
131 void set_extra_expr_nomod(struct expression *expr, struct smatch_state *state);
132 struct data_info *get_dinfo(struct smatch_state *state);
134 void function_comparison(int comparison, struct expression *expr, sval_t sval, int left);
136 /* smatch_expressions.c */
137 struct expression *zero_expr();
138 struct expression *value_expr(long long val);
139 struct expression *deref_expression(struct expression *deref, int op, struct ident *member);
140 struct expression *assign_expression(struct expression *left, struct expression *right);
141 struct expression *symbol_expression(struct symbol *sym);
143 /* implemented in smatch_constraints */
144 void set_equiv(struct expression *left, struct expression *right);
145 void set_related(struct smatch_state *estate, struct related_list *rlist);
146 struct related_list *get_shared_relations(struct related_list *one,
147 struct related_list *two);
148 struct related_list *clone_related_list(struct related_list *related);
149 void remove_from_equiv(const char *name, struct symbol *sym);
150 void remove_from_equiv_expr(struct expression *expr);
151 void set_equiv_state_expr(int id, struct expression *expr, struct smatch_state *state);