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
;
38 struct state_list_stack
*my_pools
;
39 struct state_list_stack
*all_pools
;
40 struct state_list
*possible
;
49 ASSIGNMENT_AFTER_HOOK
,
53 FUNCTION_CALL_AFTER_HOOK
,
62 void add_hook(void *func
, enum hook_type type
);
63 typedef struct smatch_state
*(merge_func_t
)(const char *name
,
65 struct smatch_state
*s1
,
66 struct smatch_state
*s2
);
67 void add_merge_hook(int client_id
, merge_func_t
*func
);
69 #define smatch_msg(msg...) \
71 printf("%s +%d %s(%d) ", get_filename(), get_lineno(), \
72 get_function(), get_func_pos()); \
77 #define SM_DEBUG(msg...) do { if (debug_states) printf(msg); } while (0)
78 #define DIMPLIED(msg...) do { if (debug_implied_states) printf(msg); } while (0)
80 #define UNDEFINED INT_MIN
82 struct smatch_state
*get_state(const char *name
, int owner
, struct symbol
*sym
);
83 struct state_list
*get_possible_states(const char *name
, int owner
,
85 void set_state(const char *name
, int owner
, struct symbol
*sym
,
86 struct smatch_state
*state
);
87 void delete_state(const char *name
, int owner
, struct symbol
*sym
);
88 void set_true_false_states(const char *name
, int owner
, struct symbol
*sym
,
89 struct smatch_state
*true_state
,
90 struct smatch_state
*false_state
);
92 struct state_list
*get_all_states(int id
);
100 char *alloc_string(const char *str
);
101 void free_string(char *str
);
102 struct expression
*get_argument_from_call_expr(struct expression_list
*args
,
104 char *get_variable_from_expr_complex(struct expression
*expr
,
105 struct symbol
**sym_ptr
);
106 char *get_variable_from_expr(struct expression
*expr
,
107 struct symbol
**sym_ptr
);
108 int sym_name_is(const char *name
, struct expression
*expr
);
109 int get_value(struct expression
*expr
);
110 int is_zero(struct expression
*expr
);
111 const char *show_state(struct smatch_state
*state
);
112 struct statement
*get_block_thing(struct expression
*expr
);
113 struct expression
*strip_expr(struct expression
*expr
);
115 /* smatch_ignore.c */
121 DECLARE_PTR_LIST(tracker_list
, struct tracker
);
123 void add_ignore(const char *name
, int owner
, struct symbol
*sym
);
124 int is_ignored(const char *name
, int owner
, struct symbol
*sym
);
127 void add_tracker(struct tracker_list
**list
, const char *name
, int owner
,
129 int in_tracker_list(struct tracker_list
*list
, const char *name
, int owner
,
131 void free_tracker_list(struct tracker_list
**list
);
132 void free_trackers_and_list(struct tracker_list
**list
);
134 /* smatch_conditions */
137 /* ----------------------------------------------------------------
138 The stuff below is all used internally and shouldn't
139 be called from other programs
140 -----------------------------------------------------------------*/
144 void smatch (int argc
, char **argv
);
145 void __split_expr(struct expression
*expr
);
146 void __split_statements(struct statement
*stmt
);
148 /* smatch_conditions */
149 void __split_whole_condition(struct expression
*expr
);
151 /* smatch_implied.c */
152 extern int debug_implied_states
;
153 void __implied_states_hook(struct expression
*expr
);
155 /* smatch_extras.c */
156 #define SMATCH_EXTRA 1 /* this is my_id from smatch extra set in smatch.c */
157 int known_condition_true(struct expression
*expr
);
158 int known_condition_false(struct expression
*expr
);
160 /* smatch_states.c */
161 extern int debug_states
;
163 struct state_list
*__get_cur_slist();
164 void __set_true_false_sm(struct sm_state
*true_state
,
165 struct sm_state
*false_state
);
167 void __unnullify_path();
168 int __path_is_null();
169 void clear_all_states();
171 struct sm_state
*get_sm_state(const char *name
, int owner
,
173 void __use_false_only_stack();
174 void __pop_false_only_stack();
175 void __push_true_states();
176 void __use_false_states();
177 void __pop_false_states();
178 void __merge_false_states();
179 void __merge_true_states();
181 void __negate_cond_stacks();
182 void __save_false_states_for_later();
183 void __use_previously_stored_false_states();
184 void __use_cond_true_states();
185 void __use_cond_false_states();
186 void __push_cond_stacks();
187 void __and_cond_states();
188 void __or_cond_states();
189 void __save_pre_cond_states();
190 void __pop_pre_cond_states();
191 void __use_cond_states();
193 void __push_continues();
194 void __pop_continues();
195 void __process_continues();
196 void __merge_continues();
198 void __push_breaks();
199 void __process_breaks();
200 void __merge_breaks();
203 void __save_switch_states();
204 void __pop_switches();
205 void __merge_switches();
206 void __push_default();
207 void __set_default();
210 void __push_conditions();
211 void __pop_conditions();
213 void __save_gotos(const char *name
);
214 void __merge_gotos(const char *name
);
216 void __print_cur_slist();
219 void __pass_to_client(void *data
, enum hook_type type
);
220 void __pass_to_client_no_data(enum hook_type type
);
221 void __pass_declarations_to_client(struct symbol_list
*sym_list
);
222 int __has_merge_function(int client_id
);
223 struct smatch_state
*__client_merge_function(int owner
, const char *name
, struct symbol
*sym
,
224 struct smatch_state
*s1
, struct smatch_state
*s2
);
226 #endif /* !SMATCH_H_ */