Handle assignmeents inside conditions better.
[smatch.git] / smatch.h
blobce6e349dfb7bd19ca75e81168a463e8df911351b
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,
49 void add_hook(void *func, enum hook_type type);
50 typedef struct smatch_state *(merge_func_t)(const char *name, struct symbol *sym, struct smatch_state *s1,
51 struct smatch_state *s2);
52 void add_merge_hook(int client_id, merge_func_t *func);
54 #define smatch_msg(msg...) \
55 do { \
56 printf("%s %d %s(%d) ", get_filename(), get_lineno(), \
57 get_function(), get_func_pos()); \
58 printf(msg); \
59 printf("\n"); \
60 } while (0)
62 #define SM_DEBUG(msg...) do { if (debug_states) printf(msg); } while (0)
64 #define UNDEFINED INT_MIN
66 struct smatch_state *get_state(const char *name, int owner, struct symbol *sym);
67 void add_state(const char *name, int owner, struct symbol *sym, struct smatch_state *state);
68 void set_state(const char *name, int owner, struct symbol *sym, struct smatch_state *state);
69 void delete_state(const char *name, int owner, struct symbol *sym);
70 void set_true_false_states(const char *name, int owner, struct symbol *sym,
71 struct smatch_state *true_state, struct smatch_state *false_state);
72 int state_defined(const char *name, int owner, struct symbol *sym);
74 struct state_list *get_all_states();
75 void nullify_path();
76 void __unnullify_path();
77 void clear_all_states();
79 char *get_filename();
80 char *get_function();
81 int get_lineno();
82 int get_func_pos();
84 /* smatch_helper.c */
85 char *alloc_string(char *str);
86 void free_string(char *str);
87 struct expression *get_argument_from_call_expr(struct expression_list *args,
88 int num);
89 char * get_variable_from_expr(struct expression * expr,
90 struct symbol **sym_ptr);
91 char * get_variable_from_expr_simple(struct expression * expr,
92 struct symbol **sym_ptr);
93 int sym_name_is(const char *name, struct expression *expr);
94 int get_value(struct expression *expr, int *discard);
95 int is_zero(struct expression *expr);
96 const char *show_state(struct smatch_state *state);
97 struct expression *strip_expr(struct expression *expr);
99 /* ----------------------------------------------------------------
100 The stuff below is all used internally and shouldn't
101 be called from other programs
102 -----------------------------------------------------------------*/
104 /* smatch_flow.c */
106 void smatch (int argc, char **argv);
107 void __split_expr(struct expression *expr);
109 /* smatch_conditions */
110 void __split_whole_condition(struct expression *expr);
112 /* smatch_extras.c */
113 int known_condition_true(struct expression *expr);
115 /* smatch_ignore.c */
116 void add_ignore(const char *name, int owner, struct symbol *sym);
117 int is_ignored(const char *name, int owner, struct symbol *sym);
119 /* smatch_states.c */
121 extern int debug_states;
123 void __use_false_only_stack();
124 void __pop_false_only_stack();
125 void __push_true_states();
126 void __use_false_states();
127 void __pop_false_states();
128 void __merge_false_states();
129 void __merge_true_states();
131 void __negate_cond_stacks();
132 void __use_cond_true_states();
133 void __use_cond_false_states();
134 void __push_cond_stacks();
135 void __and_cond_states();
136 void __or_cond_states();
137 void __save_pre_cond_states();
138 void __pop_pre_cond_states();
139 void __use_cond_states();
141 void __push_continues();
142 void __pop_continues();
143 void __process_continues();
144 void __merge_continues();
146 void __push_breaks();
147 void __process_breaks();
148 void __merge_breaks();
149 void __use_breaks();
151 void __save_switch_states();
152 void __pop_switches();
153 void __merge_switches();
154 void __push_default();
155 void __set_default();
156 int __pop_default();
158 void __push_conditions();
159 void __pop_conditions();
160 void __overwrite_true_states();
162 void __save_gotos(const char *name);
163 void __merge_gotos(const char *name);
165 void __print_cur_slist();
167 /* smatch_hooks.c */
168 void __pass_to_client(void *data, enum hook_type type);
169 void __pass_declarations_to_client(struct symbol_list *sym_list);
170 int __has_merge_function(int client_id);
171 struct smatch_state *__client_merge_function(int owner, const char *name, struct symbol *sym,
172 struct smatch_state *s1, struct smatch_state *s2);
174 #endif /* !SMATCH_H_ */