2 * Copyright (C) 2009 Dan Carpenter.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
18 DECLARE_PTR_LIST(range_list
, struct data_range
);
19 DECLARE_PTR_LIST(range_list_stack
, struct range_list
);
26 DECLARE_PTR_LIST(related_list
, struct relation
);
29 struct related_list
*related
;
30 struct range_list
*value_ranges
;
32 unsigned int hard_max
:1;
34 DECLARE_ALLOCATOR(data_info
);
36 extern struct string_list
*__ignored_macros
;
38 /* these are implemented in smatch_ranges.c */
39 char *show_rl(struct range_list
*list
);
40 int str_to_comparison_arg(const char *c
, struct expression
*call
, int *comparison
, struct expression
**arg
);
41 void str_to_rl(struct symbol
*type
, char *value
, struct range_list
**rl
);
42 void call_results_to_rl(struct expression
*call
, struct symbol
*type
, char *value
, struct range_list
**rl
);
44 struct data_range
*alloc_range(sval_t min
, sval_t max
);
45 struct data_range
*alloc_range_perm(sval_t min
, sval_t max
);
47 struct range_list
*alloc_rl(sval_t min
, sval_t max
);
48 struct range_list
*clone_rl(struct range_list
*list
);
49 struct range_list
*clone_rl_permanent(struct range_list
*list
);
50 struct range_list
*alloc_whole_rl(struct symbol
*type
);
52 void add_range(struct range_list
**list
, sval_t min
, sval_t max
);
53 struct range_list
*remove_range(struct range_list
*list
, sval_t min
, sval_t max
);
54 void tack_on(struct range_list
**list
, struct data_range
*drange
);
56 int true_comparison_range(struct data_range
*left
, int comparison
, struct data_range
*right
);
57 int true_comparison_range_LR(int comparison
, struct data_range
*var
, struct data_range
*val
, int left
);
58 int false_comparison_range_LR(int comparison
, struct data_range
*var
, struct data_range
*val
, int left
);
60 int possibly_true(struct expression
*left
, int comparison
, struct expression
*right
);
61 int possibly_true_rl(struct range_list
*left_ranges
, int comparison
, struct range_list
*right_ranges
);
62 int possibly_true_rl_LR(int comparison
, struct range_list
*a
, struct range_list
*b
, int left
);
64 int possibly_false(struct expression
*left
, int comparison
, struct expression
*right
);
65 int possibly_false_rl(struct range_list
*left_ranges
, int comparison
, struct range_list
*right_ranges
);
66 int possibly_false_rl_LR(int comparison
, struct range_list
*a
, struct range_list
*b
, int left
);
68 int rl_has_sval(struct range_list
*rl
, sval_t sval
);
69 int ranges_equiv(struct data_range
*one
, struct data_range
*two
);
71 int rl_equiv(struct range_list
*one
, struct range_list
*two
);
72 int is_whole_rl(struct range_list
*rl
);
74 sval_t
rl_min(struct range_list
*rl
);
75 sval_t
rl_max(struct range_list
*rl
);
76 int rl_to_sval(struct range_list
*rl
, sval_t
*sval
);
77 struct symbol
*rl_type(struct range_list
*rl
);
79 struct range_list
*rl_invert(struct range_list
*orig
);
80 struct range_list
*rl_filter(struct range_list
*rl
, struct range_list
*filter
);
81 struct range_list
*rl_intersection(struct range_list
*one
, struct range_list
*two
);
82 struct range_list
*rl_union(struct range_list
*one
, struct range_list
*two
);
84 void push_rl(struct range_list_stack
**rl_stack
, struct range_list
*rl
);
85 struct range_list
*pop_rl(struct range_list_stack
**rl_stack
);
86 struct range_list
*top_rl(struct range_list_stack
*rl_stack
);
87 void filter_top_rl(struct range_list_stack
**rl_stack
, sval_t sval
);
89 struct range_list
*rl_truncate_cast(struct symbol
*type
, struct range_list
*rl
);
90 struct range_list
*cast_rl(struct symbol
*type
, struct range_list
*rl
);
91 int get_implied_rl(struct expression
*expr
, struct range_list
**rl
);
92 int get_absolute_rl(struct expression
*expr
, struct range_list
**rl
);
93 int get_implied_rl_var_sym(const char *var
, struct symbol
*sym
, struct range_list
**rl
);
95 void free_rl(struct range_list
**rlist
);
96 void free_data_info_allocs(void);
100 struct smatch_state
*alloc_estate_empty(void);
101 struct smatch_state
*alloc_estate_sval(sval_t sval
);
102 struct smatch_state
*alloc_estate_range(sval_t min
, sval_t max
);
103 struct smatch_state
*alloc_estate_rl(struct range_list
*rl
);
104 struct smatch_state
*alloc_estate_whole(struct symbol
*type
);
105 struct smatch_state
*clone_estate(struct smatch_state
*state
);
107 struct smatch_state
*merge_estates(struct smatch_state
*s1
, struct smatch_state
*s2
);
109 int estates_equiv(struct smatch_state
*one
, struct smatch_state
*two
);
110 int estate_is_whole(struct smatch_state
*state
);
112 struct range_list
*estate_rl(struct smatch_state
*state
);
113 struct related_list
*estate_related(struct smatch_state
*state
);
115 sval_t
estate_min(struct smatch_state
*state
);
116 sval_t
estate_max(struct smatch_state
*state
);
117 struct symbol
*estate_type(struct smatch_state
*state
);
119 int estate_has_fuzzy_max(struct smatch_state
*state
);
120 sval_t
estate_get_fuzzy_max(struct smatch_state
*state
);
121 void estate_set_fuzzy_max(struct smatch_state
*state
, sval_t max
);
122 void estate_copy_fuzzy_max(struct smatch_state
*new, struct smatch_state
*old
);
123 void estate_clear_fuzzy_max(struct smatch_state
*state
);
124 int estate_has_hard_max(struct smatch_state
*state
);
125 void estate_set_hard_max(struct smatch_state
*state
);
126 void estate_clear_hard_max(struct smatch_state
*state
);
127 int estate_get_hard_max(struct smatch_state
*state
, sval_t
*sval
);
129 int estate_get_single_value(struct smatch_state
*state
, sval_t
*sval
);
130 struct smatch_state
*get_implied_estate(struct expression
*expr
);
132 struct smatch_state
*estate_filter_sval(struct smatch_state
*orig
, sval_t filter
);
133 struct smatch_state
*estate_filter_range(struct smatch_state
*orig
, sval_t filter_min
, sval_t filter_max
);
136 void call_extra_mod_hooks(const char *name
, struct symbol
*sym
, struct smatch_state
*state
);
137 struct sm_state
*set_extra_mod(const char *name
, struct symbol
*sym
, struct smatch_state
*state
);
138 struct sm_state
*set_extra_expr_mod(struct expression
*expr
, struct smatch_state
*state
);
139 void set_extra_nomod(const char *name
, struct symbol
*sym
, struct smatch_state
*state
);
140 void set_extra_expr_nomod(struct expression
*expr
, struct smatch_state
*state
);
142 struct data_info
*get_dinfo(struct smatch_state
*state
);
144 void add_extra_mod_hook(void (*fn
)(const char *name
, struct symbol
*sym
, struct smatch_state
*state
));
145 int implied_not_equal(struct expression
*expr
, long long val
);
147 struct sm_state
*__extra_handle_canonical_loops(struct statement
*loop
, struct state_list
**slist
);
148 int __iterator_unchanged(struct sm_state
*sm
);
149 void __extra_pre_loop_hook_after(struct sm_state
*sm
,
150 struct statement
*iterator
,
151 struct expression
*condition
);
154 void set_equiv(struct expression
*left
, struct expression
*right
);
155 void set_related(struct smatch_state
*estate
, struct related_list
*rlist
);
156 struct related_list
*get_shared_relations(struct related_list
*one
,
157 struct related_list
*two
);
158 struct related_list
*clone_related_list(struct related_list
*related
);
159 void remove_from_equiv(const char *name
, struct symbol
*sym
);
160 void remove_from_equiv_expr(struct expression
*expr
);
161 void set_equiv_state_expr(int id
, struct expression
*expr
, struct smatch_state
*state
);
163 /* smatch_function_hooks.c */
164 void function_comparison(int comparison
, struct expression
*expr
, sval_t sval
, int left
);
166 /* smatch_expressions.c */
167 struct expression
*zero_expr();
168 struct expression
*value_expr(long long val
);
169 struct expression
*member_expression(struct expression
*deref
, int op
, struct ident
*member
);
170 struct expression
*deref_expression(struct expression
*expr
);
171 struct expression
*assign_expression(struct expression
*left
, struct expression
*right
);
172 struct expression
*binop_expression(struct expression
*left
, int op
, struct expression
*right
);
173 struct expression
*array_element_expression(struct expression
*array
, struct expression
*offset
);
174 struct expression
*symbol_expression(struct symbol
*sym
);
175 struct expression
*unknown_value_expression(struct expression
*expr
);
176 int is_fake_call(struct expression
*expr
);
178 /* smatch_param_limit.c */
179 struct smatch_state
*get_orig_estate(const char *name
, struct symbol
*sym
);