rename del_slist_stack() to free_stack_and_slists()
[smatch.git] / smatch.h
blobb119aa8b566c056b6a81bcb2780ce23da38466d8
1 /*
2 * sparse/smatch.h
4 * Copyright (C) 2006 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #ifndef SMATCH_H_
11 # define SMATCH_H_
13 #include <stdio.h>
14 #include <string.h>
15 #include <limits.h>
16 #include "lib.h"
17 #include "allocate.h"
18 #include "parse.h"
19 #include "expression.h"
21 #define KERNEL
22 struct smatch_state {
23 const char *name;
24 void *data;
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;
32 struct sm_state {
33 char *name;
34 unsigned int owner;
35 struct symbol *sym;
36 struct smatch_state *state;
37 struct history_list *line_history;
38 struct state_list_stack *my_pools;
39 struct state_list_stack *all_pools;
40 struct state_list *possible;
43 enum hook_type {
44 EXPR_HOOK,
45 STMT_HOOK,
46 SYM_HOOK,
47 DECLARATION_HOOK,
48 ASSIGNMENT_HOOK,
49 ASSIGNMENT_AFTER_HOOK,
50 CONDITION_HOOK,
51 WHOLE_CONDITION_HOOK,
52 FUNCTION_CALL_HOOK,
53 FUNCTION_CALL_AFTER_HOOK,
54 OP_HOOK,
55 DEREF_HOOK,
56 BASE_HOOK,
57 FUNC_DEF_HOOK,
58 END_FUNC_HOOK,
59 RETURN_HOOK,
60 END_FILE_HOOK,
62 void add_hook(void *func, enum hook_type type);
63 typedef struct smatch_state *(merge_func_t)(const char *name,
64 struct symbol *sym,
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...) \
70 do { \
71 printf("%s +%d %s(%d) ", get_filename(), get_lineno(), \
72 get_function(), get_func_pos()); \
73 printf(msg); \
74 printf("\n"); \
75 } while (0)
77 #define SM_DEBUG(msg...) do { if (debug_states) printf(msg); } while (0)
79 #define UNDEFINED INT_MIN
81 struct smatch_state *get_state(const char *name, int owner, struct symbol *sym);
82 struct state_list *get_possible_states(const char *name, int owner,
83 struct symbol *sym);
84 void set_state(const char *name, int owner, struct symbol *sym,
85 struct smatch_state *state);
86 void delete_state(const char *name, int owner, struct symbol *sym);
87 void set_true_false_states(const char *name, int owner, struct symbol *sym,
88 struct smatch_state *true_state,
89 struct smatch_state *false_state);
91 struct state_list *get_all_states(int id);
92 char *get_filename();
93 char *get_function();
94 int get_lineno();
95 int get_func_pos();
97 /* smatch_helper.c */
98 char *alloc_string(char *str);
99 void free_string(char *str);
100 struct expression *get_argument_from_call_expr(struct expression_list *args,
101 int num);
102 char *get_variable_from_expr_complex(struct expression *expr,
103 struct symbol **sym_ptr);
104 char *get_variable_from_expr(struct expression *expr,
105 struct symbol **sym_ptr);
106 int sym_name_is(const char *name, struct expression *expr);
107 int get_value(struct expression *expr);
108 int is_zero(struct expression *expr);
109 const char *show_state(struct smatch_state *state);
110 struct statement *get_block_thing(struct expression *expr);
111 struct expression *strip_expr(struct expression *expr);
113 /* smatch_ignore.c */
114 struct tracker {
115 const char *name;
116 int owner;
117 struct symbol *sym;
119 DECLARE_PTR_LIST(tracker_list, struct tracker);
121 void add_ignore(const char *name, int owner, struct symbol *sym);
122 int is_ignored(const char *name, int owner, struct symbol *sym);
124 /* smatch_tracker */
125 void add_tracker(struct tracker_list **list, const char *name, int owner,
126 struct symbol *sym);
127 int in_tracker_list(struct tracker_list *list, const char *name, int owner,
128 struct symbol *sym);
131 /* smatch_conditions */
132 int in_condition();
134 /* ----------------------------------------------------------------
135 The stuff below is all used internally and shouldn't
136 be called from other programs
137 -----------------------------------------------------------------*/
139 /* smatch_flow.c */
141 void smatch (int argc, char **argv);
142 void __split_expr(struct expression *expr);
143 void __split_statements(struct statement *stmt);
145 /* smatch_conditions */
146 void __split_whole_condition(struct expression *expr);
148 /* smatch_implied.c */
149 void __implied_states_hook(struct expression *expr);
151 /* smatch_extras.c */
152 #define SMATCH_EXTRA 1 /* this is my_id from smatch extra set in smatch.c */
153 int known_condition_true(struct expression *expr);
154 int known_condition_false(struct expression *expr);
156 /* smatch_states.c */
157 extern int debug_states;
159 struct state_list *__get_cur_slist();
160 void __set_true_false_sm(struct sm_state *true_state,
161 struct sm_state *false_state);
162 void nullify_path();
163 void __unnullify_path();
164 int __path_is_null();
165 void clear_all_states();
167 struct sm_state *get_sm_state(const char *name, int owner,
168 struct symbol *sym);
169 void __use_false_only_stack();
170 void __pop_false_only_stack();
171 void __push_true_states();
172 void __use_false_states();
173 void __pop_false_states();
174 void __merge_false_states();
175 void __merge_true_states();
177 void __negate_cond_stacks();
178 void __save_false_states_for_later();
179 void __use_previously_stored_false_states();
180 void __use_cond_true_states();
181 void __use_cond_false_states();
182 void __push_cond_stacks();
183 void __and_cond_states();
184 void __or_cond_states();
185 void __save_pre_cond_states();
186 void __pop_pre_cond_states();
187 void __use_cond_states();
189 void __push_continues();
190 void __pop_continues();
191 void __process_continues();
192 void __merge_continues();
194 void __push_breaks();
195 void __process_breaks();
196 void __merge_breaks();
197 void __use_breaks();
199 void __save_switch_states();
200 void __pop_switches();
201 void __merge_switches();
202 void __push_default();
203 void __set_default();
204 int __pop_default();
206 void __push_conditions();
207 void __pop_conditions();
209 void __save_gotos(const char *name);
210 void __merge_gotos(const char *name);
212 void __print_cur_slist();
214 /* smatch_hooks.c */
215 void __pass_to_client(void *data, enum hook_type type);
216 void __pass_to_client_no_data(enum hook_type type);
217 void __pass_declarations_to_client(struct symbol_list *sym_list);
218 int __has_merge_function(int client_id);
219 struct smatch_state *__client_merge_function(int owner, const char *name, struct symbol *sym,
220 struct smatch_state *s1, struct smatch_state *s2);
222 #endif /* !SMATCH_H_ */