4 * Copyright (C) 2006 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
19 #include "expression.h"
22 #define MAXSMSTATES 1000000 /* Limits RAM use. Give up on big functions */
27 #define STATE(_x) static struct smatch_state _x = { .name = #_x }
28 extern struct smatch_state undefined
;
29 extern struct smatch_state merged
;
30 extern struct smatch_state true_state
;
31 extern struct smatch_state false_state
;
37 struct smatch_state
*state
;
39 struct state_list_stack
*my_pools
;
40 struct state_list_stack
*all_pools
;
41 struct state_list
*possible
;
61 void add_hook(void *func
, enum hook_type type
);
62 typedef struct smatch_state
*(merge_func_t
)(const char *name
,
64 struct smatch_state
*s1
,
65 struct smatch_state
*s2
);
66 typedef struct smatch_state
*(unmatched_func_t
)(struct sm_state
*state
);
67 void add_merge_hook(int client_id
, merge_func_t
*func
);
68 void add_unmatched_state_hook(int client_id
, unmatched_func_t
*func
);
69 typedef void (func_hook
)(const char *fn
, struct expression
*expr
, void *data
);
70 void add_function_hook(const char *lock_for
, func_hook
*call_back
, void *data
);
72 void add_conditional_hook(const char *look_for
, func_hook
*call_back
, void *data
);
73 void set_cond_states(const char *name
, int owner
, struct symbol
*sym
,
74 struct smatch_state
*true_state
,
75 struct smatch_state
*false_state
);
77 #define smatch_msg(msg...) \
79 printf("%s +%d %s(%d) ", get_filename(), get_lineno(), \
80 get_function(), get_func_pos()); \
85 #define SM_DEBUG(msg...) do { if (debug_states) printf(msg); } while (0)
86 #define DIMPLIED(msg...) do { if (debug_implied_states) printf(msg); } while (0)
88 #define UNDEFINED INT_MIN
90 struct smatch_state
*get_state(const char *name
, int owner
, struct symbol
*sym
);
91 struct state_list
*get_possible_states(const char *name
, int owner
,
93 void set_state(const char *name
, int owner
, struct symbol
*sym
,
94 struct smatch_state
*state
);
95 void delete_state(const char *name
, int owner
, struct symbol
*sym
);
96 void set_true_false_states(const char *name
, int owner
, struct symbol
*sym
,
97 struct smatch_state
*true_state
,
98 struct smatch_state
*false_state
);
100 struct state_list
*get_all_states(int id
);
102 char *get_filename();
103 char *get_function();
107 /* smatch_helper.c */
108 char *alloc_string(const char *str
);
109 void free_string(char *str
);
110 struct expression
*get_argument_from_call_expr(struct expression_list
*args
,
112 char *get_variable_from_expr_complex(struct expression
*expr
,
113 struct symbol
**sym_ptr
);
114 char *get_variable_from_expr(struct expression
*expr
,
115 struct symbol
**sym_ptr
);
116 int sym_name_is(const char *name
, struct expression
*expr
);
117 int get_value(struct expression
*expr
);
118 int is_zero(struct expression
*expr
);
119 const char *show_state(struct smatch_state
*state
);
120 struct statement
*get_block_thing(struct expression
*expr
);
121 struct expression
*strip_expr(struct expression
*expr
);
123 /* smatch_ignore.c */
129 DECLARE_PTR_LIST(tracker_list
, struct tracker
);
131 void add_ignore(const char *name
, int owner
, struct symbol
*sym
);
132 int is_ignored(const char *name
, int owner
, struct symbol
*sym
);
135 void add_tracker(struct tracker_list
**list
, const char *name
, int owner
,
137 void del_tracker(struct tracker_list
**list
, const char *name
, int owner
,
139 int in_tracker_list(struct tracker_list
*list
, const char *name
, int owner
,
141 void free_tracker_list(struct tracker_list
**list
);
142 void free_trackers_and_list(struct tracker_list
**list
);
144 /* smatch_conditions */
147 /* ----------------------------------------------------------------
148 The stuff below is all used internally and shouldn't
149 be called from other programs
150 -----------------------------------------------------------------*/
154 void smatch (int argc
, char **argv
);
155 void __split_expr(struct expression
*expr
);
156 void __split_statements(struct statement
*stmt
);
157 extern int option_assume_loops
;
158 extern int option_known_conditions
;
160 /* smatch_conditions */
161 void __split_whole_condition(struct expression
*expr
);
163 /* smatch_implied.c */
164 extern int debug_implied_states
;
165 extern int option_no_implied
;
167 /* smatch_extras.c */
168 #define SMATCH_EXTRA 1 /* this is my_id from smatch extra set in smatch.c */
169 int true_comparison(int left
, int comparison
, int right
);
170 int known_condition_true(struct expression
*expr
);
171 int known_condition_false(struct expression
*expr
);
173 /* smatch_states.c */
174 extern int debug_states
;
176 struct state_list
*__get_cur_slist();
177 void __set_true_false_sm(struct sm_state
*true_state
,
178 struct sm_state
*false_state
);
180 void __match_nullify_path_hook(const char *fn
, struct expression
*expr
,
182 void __unnullify_path();
183 int __path_is_null();
184 void clear_all_states();
186 struct sm_state
*get_sm_state(const char *name
, int owner
,
188 void __use_false_only_stack();
189 void __pop_false_only_stack();
190 void __push_true_states();
191 void __use_false_states();
192 void __pop_false_states();
193 void __merge_false_states();
194 void __merge_true_states();
196 void __negate_cond_stacks();
197 void __save_false_states_for_later();
198 void __use_previously_stored_false_states();
199 void __use_cond_true_states();
200 void __use_cond_false_states();
201 void __push_cond_stacks();
202 void __and_cond_states();
203 void __or_cond_states();
204 void __save_pre_cond_states();
205 void __pop_pre_cond_states();
206 void __use_cond_states();
208 void __warn_on_silly_pre_loops();
210 void __push_continues();
211 void __pop_continues();
212 void __process_continues();
213 void __merge_continues();
215 void __push_breaks();
216 void __process_breaks();
217 void __merge_breaks();
220 void __save_switch_states();
221 void __pop_switches();
222 void __merge_switches();
223 void __push_default();
224 void __set_default();
227 void __push_conditions();
228 void __pop_conditions();
230 void __save_gotos(const char *name
);
231 void __merge_gotos(const char *name
);
233 void __print_cur_slist();
236 void __pass_to_client(void *data
, enum hook_type type
);
237 void __pass_to_client_no_data(enum hook_type type
);
238 void __pass_declarations_to_client(struct symbol_list
*sym_list
);
239 int __has_merge_function(int client_id
);
240 struct smatch_state
*__client_merge_function(int owner
, const char *name
,
242 struct smatch_state
*s1
,
243 struct smatch_state
*s2
);
244 struct smatch_state
*__client_unmatched_state_function(struct sm_state
*sm
);
246 /* smatch_function_hooks.c */
248 func_hook
*call_back
;
251 DECLARE_ALLOCATOR(fcall_back
);
252 DECLARE_PTR_LIST(call_back_list
, struct fcall_back
);
254 #endif /* !SMATCH_H_ */