Handle while and for loops slightly better.
[smatch.git] / smatch.h
blob91337c64e7b1e113416b45592eca69fff6bb2776
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 "lib.h"
16 #include "allocate.h"
17 #include "parse.h"
18 #include "expression.h"
20 #define KERNEL
22 struct state_history {
23 unsigned int loc;
25 DECLARE_PTR_LIST(history_list, struct state_history);
27 struct smatch_state {
28 char *name;
29 unsigned int owner;
30 struct symbol *sym;
31 int state;
32 struct history_list *line_history;
33 struct history_list *path_history;
36 enum hook_type {
37 EXPR_HOOK,
38 STMT_HOOK,
39 SYM_HOOK,
40 DECLARATION_HOOK,
41 ASSIGNMENT_HOOK,
42 ASSIGNMENT_AFTER_HOOK,
43 CONDITION_HOOK,
44 WHOLE_CONDITION_HOOK,
45 FUNCTION_CALL_HOOK,
46 FUNCTION_CALL_AFTER_HOOK,
47 DEREF_HOOK,
48 BASE_HOOK,
49 FUNC_DEF_HOOK,
50 END_FUNC_HOOK,
51 RETURN_HOOK,
53 void add_hook(void *func, enum hook_type type);
54 typedef int (merge_func_t)(const char *name, struct symbol *sym, int s1,
55 int s2);
56 void add_merge_hook(int client_id, merge_func_t *func);
58 #define smatch_msg(msg...) \
59 do { \
60 printf("%s %d %s(%d) ", get_filename(), get_lineno(), \
61 get_function(), get_func_pos()); \
62 printf(msg); \
63 printf("\n"); \
64 } while (0)
66 #define SM_DEBUG(msg...) do { if (debug_states) printf(msg); } while (0)
68 #define NOTFOUND -2
69 #define UNDEFINED -1
71 int get_state(const char *name, int owner, struct symbol *sym);
72 void add_state(const char *name, int owner, struct symbol *sym, int state);
73 void set_state(const char *name, int owner, struct symbol *sym, int 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 int true_state, int false_state);
77 int state_defined(const char *name, int owner, struct symbol *sym);
79 struct state_list *get_all_states();
80 void nullify_path();
81 void clear_all_states();
83 char *get_filename();
84 char *get_function();
85 int get_lineno();
86 int get_func_pos();
88 /* smatch_helper.c */
89 char *alloc_string(char *str);
90 void free_string(char *str);
91 struct expression *get_argument_from_call_expr(struct expression_list *args,
92 int num);
93 char * get_variable_from_expr(struct expression * expr,
94 struct symbol **sym_ptr);
95 char * get_variable_from_expr_simple(struct expression * expr,
96 struct symbol **sym_ptr);
97 int sym_name_is(const char *name, 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 extern int __ands;
111 extern int __ors;
112 int __negate();
113 void __split_whole_condition(struct expression *expr);
115 /* smatch_states.c */
117 extern int debug_states;
119 void __first_and_clump();
120 void __merge_and_clump();
121 void __use_and_clumps();
122 void __split_true_false_paths();
123 void __split_false_states_mini();
124 void __use_false_states_mini();
125 void __pop_false_states_mini();
126 void __prep_false_only_stack();
127 void __use_false_only_stack();
128 void __use_true_states();
129 void __use_false_states();
130 void __pop_false_states();
131 void __merge_false_states();
132 void __merge_true_states();
133 void __pop_true_states();
135 void __push_continues();
136 void __pop_continues();
137 void __process_continues();
138 void __merge_continues();
140 void __push_breaks();
141 void __pop_breaks();
142 void __process_breaks();
143 void __merge_breaks();
145 void __save_switch_states();
146 void __pop_switches();
147 void __merge_switches();
148 void __push_default();
149 void __set_default();
150 int __pop_default();
152 void __push_conditions();
153 void __pop_conditions();
154 void __overwrite_true_states();
156 void __save_gotos(const char *name);
157 void __merge_gotos(const char *name);
159 void __print_cur_slist();
161 /* smatch_hooks.c */
162 void __pass_to_client(void *data, enum hook_type type);
163 void __pass_declarations_to_client(struct symbol_list *sym_list);
164 int __has_merge_function(int client_id);
165 int __client_merge_function(int owner, const char *name, struct symbol *sym,
166 int s1, int s2);
168 #endif /* !SMATCH_H_ */