Add script to find NULL dereferences between functions.
[smatch.git] / smatch.h
blob4bfb62f64fd8a3ea6ca419b3f3db8e7449dca16e
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 true_state;
29 extern struct smatch_state false_state;
31 enum hook_type {
32 EXPR_HOOK,
33 STMT_HOOK,
34 SYM_HOOK,
35 DECLARATION_HOOK,
36 ASSIGNMENT_HOOK,
37 ASSIGNMENT_AFTER_HOOK,
38 CONDITION_HOOK,
39 WHOLE_CONDITION_HOOK,
40 FUNCTION_CALL_HOOK,
41 FUNCTION_CALL_AFTER_HOOK,
42 OP_HOOK,
43 DEREF_HOOK,
44 BASE_HOOK,
45 FUNC_DEF_HOOK,
46 END_FUNC_HOOK,
47 RETURN_HOOK,
48 END_FILE_HOOK,
50 void add_hook(void *func, enum hook_type type);
51 typedef struct smatch_state *(merge_func_t)(const char *name,
52 struct symbol *sym,
53 struct smatch_state *s1,
54 struct smatch_state *s2);
55 void add_merge_hook(int client_id, merge_func_t *func);
57 #define smatch_msg(msg...) \
58 do { \
59 printf("%s +%d %s(%d) ", get_filename(), get_lineno(), \
60 get_function(), get_func_pos()); \
61 printf(msg); \
62 printf("\n"); \
63 } while (0)
65 #define SM_DEBUG(msg...) do { if (debug_states) printf(msg); } while (0)
67 #define UNDEFINED INT_MIN
69 struct smatch_state *get_state(const char *name, int owner, struct symbol *sym);
70 struct state_list *get_possible_states(const char *name, int owner,
71 struct symbol *sym);
72 void set_state(const char *name, int owner, struct symbol *sym,
73 struct smatch_state *state);
74 void delete_state(const char *name, int owner, struct symbol *sym);
75 void set_true_false_states(const char *name, int owner, struct symbol *sym,
76 struct smatch_state *true_state,
77 struct smatch_state *false_state);
79 struct state_list *get_all_states(int id);
80 char *get_filename();
81 char *get_function();
82 int get_lineno();
83 int get_func_pos();
85 /* smatch_helper.c */
86 char *alloc_string(char *str);
87 void free_string(char *str);
88 struct expression *get_argument_from_call_expr(struct expression_list *args,
89 int num);
90 char *get_variable_from_expr_complex(struct expression *expr,
91 struct symbol **sym_ptr);
92 char *get_variable_from_expr(struct expression *expr,
93 struct symbol **sym_ptr);
94 int sym_name_is(const char *name, struct expression *expr);
95 int get_value(struct expression *expr);
96 int is_zero(struct expression *expr);
97 const char *show_state(struct smatch_state *state);
98 struct expression *strip_expr(struct expression *expr);
100 /* smatch_ignore.c */
101 void add_ignore(const char *name, int owner, struct symbol *sym);
102 int is_ignored(const char *name, int owner, struct symbol *sym);
104 /* smatch_conditions */
105 int in_condition();
107 /* ----------------------------------------------------------------
108 The stuff below is all used internally and shouldn't
109 be called from other programs
110 -----------------------------------------------------------------*/
112 /* smatch_flow.c */
114 void smatch (int argc, char **argv);
115 void __split_expr(struct expression *expr);
117 /* smatch_conditions */
118 void __split_whole_condition(struct expression *expr);
120 /* smatch_implied.c */
121 void __implied_states_hook(struct expression *expr);
123 /* smatch_extras.c */
124 #define SMATCH_EXTRA 1 /* this is my_id from smatch extra set in smatch.c */
125 int known_condition_true(struct expression *expr);
127 /* smatch_states.c */
128 extern int debug_states;
130 void nullify_path();
131 void __unnullify_path();
132 int __path_is_null();
133 void clear_all_states();
135 struct sm_state *__get_sm_state(const char *name, int owner,
136 struct symbol *sym);
137 void __overwrite_cur_slist(struct state_list *slist);
138 void __use_false_only_stack();
139 void __pop_false_only_stack();
140 void __push_true_states();
141 void __use_false_states();
142 void __pop_false_states();
143 void __merge_false_states();
144 void __merge_true_states();
146 void __negate_cond_stacks();
147 void __use_cond_true_states();
148 void __use_cond_false_states();
149 void __push_cond_stacks();
150 void __and_cond_states();
151 void __or_cond_states();
152 void __save_pre_cond_states();
153 void __pop_pre_cond_states();
154 void __use_cond_states();
156 void __push_continues();
157 void __pop_continues();
158 void __process_continues();
159 void __merge_continues();
161 void __push_breaks();
162 void __process_breaks();
163 void __merge_breaks();
164 void __use_breaks();
166 void __save_switch_states();
167 void __pop_switches();
168 void __merge_switches();
169 void __push_default();
170 void __set_default();
171 int __pop_default();
173 void __push_conditions();
174 void __pop_conditions();
175 void __overwrite_true_states();
177 void __save_gotos(const char *name);
178 void __merge_gotos(const char *name);
180 void __print_cur_slist();
182 /* smatch_hooks.c */
183 void __pass_to_client(void *data, enum hook_type type);
184 void __pass_to_client_no_data(enum hook_type type);
185 void __pass_declarations_to_client(struct symbol_list *sym_list);
186 int __has_merge_function(int client_id);
187 struct smatch_state *__client_merge_function(int owner, const char *name, struct symbol *sym,
188 struct smatch_state *s1, struct smatch_state *s2);
190 #endif /* !SMATCH_H_ */