Remove unneeded check.
[smatch.git] / smatch.h
blob51b827a1d2ee0dde5ce6cbb77867ea68e3452551
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
23 struct state_history {
24 unsigned int loc;
26 DECLARE_PTR_LIST(history_list, struct state_history);
28 struct smatch_state {
29 char *name;
30 unsigned int owner;
31 struct symbol *sym;
32 int state;
33 struct history_list *line_history;
34 struct history_list *path_history;
37 enum hook_type {
38 EXPR_HOOK,
39 STMT_HOOK,
40 SYM_HOOK,
41 DECLARATION_HOOK,
42 ASSIGNMENT_HOOK,
43 ASSIGNMENT_AFTER_HOOK,
44 CONDITION_HOOK,
45 WHOLE_CONDITION_HOOK,
46 FUNCTION_CALL_HOOK,
47 FUNCTION_CALL_AFTER_HOOK,
48 OP_HOOK,
49 DEREF_HOOK,
50 BASE_HOOK,
51 FUNC_DEF_HOOK,
52 END_FUNC_HOOK,
53 RETURN_HOOK,
55 void add_hook(void *func, enum hook_type type);
56 typedef int (merge_func_t)(const char *name, struct symbol *sym, int s1,
57 int s2);
58 void add_merge_hook(int client_id, merge_func_t *func);
60 #define smatch_msg(msg...) \
61 do { \
62 printf("%s %d %s(%d) ", get_filename(), get_lineno(), \
63 get_function(), get_func_pos()); \
64 printf(msg); \
65 printf("\n"); \
66 } while (0)
68 #define SM_DEBUG(msg...) do { if (debug_states) printf(msg); } while (0)
70 #define NOTFOUND INT_MIN
71 #define UNDEFINED INT_MIN + 1
73 int get_state(const char *name, int owner, struct symbol *sym);
74 void add_state(const char *name, int owner, struct symbol *sym, int state);
75 void set_state(const char *name, int owner, struct symbol *sym, int state);
76 void delete_state(const char *name, int owner, struct symbol *sym);
77 void set_true_false_states(const char *name, int owner, struct symbol *sym,
78 int true_state, int false_state);
79 int state_defined(const char *name, int owner, struct symbol *sym);
81 struct state_list *get_all_states();
82 void nullify_path();
83 void clear_all_states();
85 char *get_filename();
86 char *get_function();
87 int get_lineno();
88 int get_func_pos();
90 /* smatch_helper.c */
91 char *alloc_string(char *str);
92 void free_string(char *str);
93 struct expression *get_argument_from_call_expr(struct expression_list *args,
94 int num);
95 char * get_variable_from_expr(struct expression * expr,
96 struct symbol **sym_ptr);
97 char * get_variable_from_expr_simple(struct expression * expr,
98 struct symbol **sym_ptr);
99 int sym_name_is(const char *name, struct expression *expr);
100 int get_value(struct expression *expr, int *discard);
101 int is_zero(struct expression *expr);
103 /* ----------------------------------------------------------------
104 The stuff below is all used internally and shouldn't
105 be called from other programs
106 -----------------------------------------------------------------*/
108 /* smatch_flow.c */
110 void smatch (int argc, char **argv);
111 void __split_expr(struct expression *expr);
113 /* smatch_conditions */
114 void __split_whole_condition(struct expression *expr);
116 /* smatch_extras.c */
117 int known_condition_true(struct expression *expr);
119 /* smatch_states.c */
121 extern int debug_states;
123 void __use_false_only_stack();
124 void __pop_false_only_stack();
125 void __use_true_states();
126 void __use_false_states();
127 void __pop_false_states();
128 void __merge_false_states();
129 void __merge_true_states();
130 void __pop_true_states();
132 void __negate_cond_stacks();
133 void __use_cond_true_states();
134 void __use_cond_false_states();
135 void __push_cond_stacks();
136 void __and_cond_states();
137 void __or_cond_states();
138 void __save_pre_cond_states();
139 void __pop_pre_cond_states();
140 void __use_cond_states();
142 void __push_continues();
143 void __pop_continues();
144 void __process_continues();
145 void __merge_continues();
147 void __push_breaks();
148 void __pop_breaks();
149 void __process_breaks();
150 void __merge_breaks();
151 void __use_breaks();
153 void __save_switch_states();
154 void __pop_switches();
155 void __merge_switches();
156 void __push_default();
157 void __set_default();
158 int __pop_default();
160 void __push_conditions();
161 void __pop_conditions();
162 void __overwrite_true_states();
164 void __save_gotos(const char *name);
165 void __merge_gotos(const char *name);
167 void __print_cur_slist();
169 /* smatch_hooks.c */
170 void __pass_to_client(void *data, enum hook_type type);
171 void __pass_declarations_to_client(struct symbol_list *sym_list);
172 int __has_merge_function(int client_id);
173 int __client_merge_function(int owner, const char *name, struct symbol *sym,
174 int s1, int s2);
176 #endif /* !SMATCH_H_ */