Merge branch 'devel'
[smatch.git] / smatch.h
blobcfcf0d74af38af02e2c022f981d79dfd9030ae95
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 __prep_false_only_stack();
120 void __use_false_only_stack();
121 void __use_true_states();
122 void __use_false_states();
123 void __pop_false_states();
124 void __merge_false_states();
125 void __merge_true_states();
126 void __pop_true_states();
128 void __negate_cond_stacks();
129 void __use_cond_true_states();
130 void __use_cond_false_states();
131 void __push_cond_stacks();
132 void __and_cond_states();
133 void __or_cond_states();
134 void __save_pre_cond_states();
135 void __pop_pre_cond_states();
136 void __use_cond_states();
138 void __push_continues();
139 void __pop_continues();
140 void __process_continues();
141 void __merge_continues();
143 void __push_breaks();
144 void __pop_breaks();
145 void __process_breaks();
146 void __merge_breaks();
148 void __save_switch_states();
149 void __pop_switches();
150 void __merge_switches();
151 void __push_default();
152 void __set_default();
153 int __pop_default();
155 void __push_conditions();
156 void __pop_conditions();
157 void __overwrite_true_states();
159 void __save_gotos(const char *name);
160 void __merge_gotos(const char *name);
162 void __print_cur_slist();
164 /* smatch_hooks.c */
165 void __pass_to_client(void *data, enum hook_type type);
166 void __pass_declarations_to_client(struct symbol_list *sym_list);
167 int __has_merge_function(int client_id);
168 int __client_merge_function(int owner, const char *name, struct symbol *sym,
169 int s1, int s2);
171 #endif /* !SMATCH_H_ */