I want to reuse the name smatch_state. The current use is only needed
[smatch.git] / smatch.h
blobafa7f215fc69f1576a56e39f78bd818d16ab4dc0
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 enum hook_type {
24 EXPR_HOOK,
25 STMT_HOOK,
26 SYM_HOOK,
27 DECLARATION_HOOK,
28 ASSIGNMENT_HOOK,
29 ASSIGNMENT_AFTER_HOOK,
30 CONDITION_HOOK,
31 WHOLE_CONDITION_HOOK,
32 FUNCTION_CALL_HOOK,
33 FUNCTION_CALL_AFTER_HOOK,
34 OP_HOOK,
35 DEREF_HOOK,
36 BASE_HOOK,
37 FUNC_DEF_HOOK,
38 END_FUNC_HOOK,
39 RETURN_HOOK,
41 void add_hook(void *func, enum hook_type type);
42 typedef int (merge_func_t)(const char *name, struct symbol *sym, int s1,
43 int s2);
44 void add_merge_hook(int client_id, merge_func_t *func);
46 #define smatch_msg(msg...) \
47 do { \
48 printf("%s %d %s(%d) ", get_filename(), get_lineno(), \
49 get_function(), get_func_pos()); \
50 printf(msg); \
51 printf("\n"); \
52 } while (0)
54 #define SM_DEBUG(msg...) do { if (debug_states) printf(msg); } while (0)
56 #define NOTFOUND INT_MIN
57 #define UNDEFINED INT_MIN + 1
59 int get_state(const char *name, int owner, struct symbol *sym);
60 void add_state(const char *name, int owner, struct symbol *sym, int state);
61 void set_state(const char *name, int owner, struct symbol *sym, int state);
62 void delete_state(const char *name, int owner, struct symbol *sym);
63 void set_true_false_states(const char *name, int owner, struct symbol *sym,
64 int true_state, int false_state);
65 int state_defined(const char *name, int owner, struct symbol *sym);
67 struct state_list *get_all_states();
68 void nullify_path();
69 void __unnullify_path();
70 void clear_all_states();
72 char *get_filename();
73 char *get_function();
74 int get_lineno();
75 int get_func_pos();
77 /* smatch_helper.c */
78 char *alloc_string(char *str);
79 void free_string(char *str);
80 struct expression *get_argument_from_call_expr(struct expression_list *args,
81 int num);
82 char * get_variable_from_expr(struct expression * expr,
83 struct symbol **sym_ptr);
84 char * get_variable_from_expr_simple(struct expression * expr,
85 struct symbol **sym_ptr);
86 int sym_name_is(const char *name, struct expression *expr);
87 int get_value(struct expression *expr, int *discard);
88 int is_zero(struct expression *expr);
90 /* ----------------------------------------------------------------
91 The stuff below is all used internally and shouldn't
92 be called from other programs
93 -----------------------------------------------------------------*/
95 /* smatch_flow.c */
97 void smatch (int argc, char **argv);
98 void __split_expr(struct expression *expr);
100 /* smatch_conditions */
101 void __split_whole_condition(struct expression *expr);
103 /* smatch_extras.c */
104 int known_condition_true(struct expression *expr);
106 /* smatch_states.c */
108 extern int debug_states;
110 void __use_false_only_stack();
111 void __pop_false_only_stack();
112 void __push_true_states();
113 void __use_false_states();
114 void __pop_false_states();
115 void __merge_false_states();
116 void __merge_true_states();
118 void __negate_cond_stacks();
119 void __use_cond_true_states();
120 void __use_cond_false_states();
121 void __push_cond_stacks();
122 void __and_cond_states();
123 void __or_cond_states();
124 void __save_pre_cond_states();
125 void __pop_pre_cond_states();
126 void __use_cond_states();
128 void __push_continues();
129 void __pop_continues();
130 void __process_continues();
131 void __merge_continues();
133 void __push_breaks();
134 void __pop_breaks();
135 void __process_breaks();
136 void __merge_breaks();
137 void __use_breaks();
139 void __save_switch_states();
140 void __pop_switches();
141 void __merge_switches();
142 void __push_default();
143 void __set_default();
144 int __pop_default();
146 void __push_conditions();
147 void __pop_conditions();
148 void __overwrite_true_states();
150 void __save_gotos(const char *name);
151 void __merge_gotos(const char *name);
153 void __print_cur_slist();
155 /* smatch_hooks.c */
156 void __pass_to_client(void *data, enum hook_type type);
157 void __pass_declarations_to_client(struct symbol_list *sym_list);
158 int __has_merge_function(int client_id);
159 int __client_merge_function(int owner, const char *name, struct symbol *sym,
160 int s1, int s2);
162 #endif /* !SMATCH_H_ */