4 * Copyright (C) 2006 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
19 #include "expression.h"
26 #define STATE(_x) static struct smatch_state _x = { .name = #_x }
27 extern struct smatch_state undefined
;
28 extern struct smatch_state merged
;
29 extern struct smatch_state true_state
;
30 extern struct smatch_state false_state
;
36 struct smatch_state
*state
;
37 struct history_list
*line_history
;
38 struct state_list_stack
*pools
;
39 struct state_list
*possible
;
48 ASSIGNMENT_AFTER_HOOK
,
52 FUNCTION_CALL_AFTER_HOOK
,
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 void add_merge_hook(int client_id
, merge_func_t
*func
);
68 #define smatch_msg(msg...) \
70 printf("%s +%d %s(%d) ", get_filename(), get_lineno(), \
71 get_function(), get_func_pos()); \
76 #define SM_DEBUG(msg...) do { if (debug_states) printf(msg); } while (0)
78 #define UNDEFINED INT_MIN
80 struct smatch_state
*get_state(const char *name
, int owner
, struct symbol
*sym
);
81 struct state_list
*get_possible_states(const char *name
, int owner
,
83 void set_state(const char *name
, int owner
, struct symbol
*sym
,
84 struct smatch_state
*state
);
85 void delete_state(const char *name
, int owner
, struct symbol
*sym
);
86 void set_true_false_states(const char *name
, int owner
, struct symbol
*sym
,
87 struct smatch_state
*true_state
,
88 struct smatch_state
*false_state
);
90 struct state_list
*get_all_states(int id
);
97 char *alloc_string(char *str
);
98 void free_string(char *str
);
99 struct expression
*get_argument_from_call_expr(struct expression_list
*args
,
101 char *get_variable_from_expr_complex(struct expression
*expr
,
102 struct symbol
**sym_ptr
);
103 char *get_variable_from_expr(struct expression
*expr
,
104 struct symbol
**sym_ptr
);
105 int sym_name_is(const char *name
, struct expression
*expr
);
106 int get_value(struct expression
*expr
);
107 int is_zero(struct expression
*expr
);
108 const char *show_state(struct smatch_state
*state
);
109 struct statement
*get_block_thing(struct expression
*expr
);
110 struct expression
*strip_expr(struct expression
*expr
);
112 /* smatch_ignore.c */
118 DECLARE_PTR_LIST(tracker_list
, struct tracker
);
120 void add_ignore(const char *name
, int owner
, struct symbol
*sym
);
121 int is_ignored(const char *name
, int owner
, struct symbol
*sym
);
124 void add_tracker(struct tracker_list
**list
, const char *name
, int owner
,
126 int in_tracker_list(struct tracker_list
*list
, const char *name
, int owner
,
130 /* smatch_conditions */
133 /* ----------------------------------------------------------------
134 The stuff below is all used internally and shouldn't
135 be called from other programs
136 -----------------------------------------------------------------*/
140 void smatch (int argc
, char **argv
);
141 void __split_expr(struct expression
*expr
);
142 void __split_statements(struct statement
*stmt
);
144 /* smatch_conditions */
145 void __split_whole_condition(struct expression
*expr
);
147 /* smatch_implied.c */
148 void __implied_states_hook(struct expression
*expr
);
150 /* smatch_extras.c */
151 #define SMATCH_EXTRA 1 /* this is my_id from smatch extra set in smatch.c */
152 int known_condition_true(struct expression
*expr
);
153 int known_condition_false(struct expression
*expr
);
155 /* smatch_states.c */
156 extern int debug_states
;
158 struct state_list
*__get_cur_slist();
159 void __set_true_false_sm(struct sm_state
*true_state
,
160 struct sm_state
*false_state
);
162 void __unnullify_path();
163 int __path_is_null();
164 void clear_all_states();
166 struct sm_state
*get_sm_state(const char *name
, int owner
,
168 void __use_false_only_stack();
169 void __pop_false_only_stack();
170 void __push_true_states();
171 void __use_false_states();
172 void __pop_false_states();
173 void __merge_false_states();
174 void __merge_true_states();
176 void __negate_cond_stacks();
177 void __save_false_states_for_later();
178 void __use_previously_stored_false_states();
179 void __use_cond_true_states();
180 void __use_cond_false_states();
181 void __push_cond_stacks();
182 void __and_cond_states();
183 void __or_cond_states();
184 void __save_pre_cond_states();
185 void __pop_pre_cond_states();
186 void __use_cond_states();
188 void __push_continues();
189 void __pop_continues();
190 void __process_continues();
191 void __merge_continues();
193 void __push_breaks();
194 void __process_breaks();
195 void __merge_breaks();
198 void __save_switch_states();
199 void __pop_switches();
200 void __merge_switches();
201 void __push_default();
202 void __set_default();
205 void __push_conditions();
206 void __pop_conditions();
208 void __save_gotos(const char *name
);
209 void __merge_gotos(const char *name
);
211 void __print_cur_slist();
214 void __pass_to_client(void *data
, enum hook_type type
);
215 void __pass_to_client_no_data(enum hook_type type
);
216 void __pass_declarations_to_client(struct symbol_list
*sym_list
);
217 int __has_merge_function(int client_id
);
218 struct smatch_state
*__client_merge_function(int owner
, const char *name
, struct symbol
*sym
,
219 struct smatch_state
*s1
, struct smatch_state
*s2
);
221 #endif /* !SMATCH_H_ */