Change the merge rules for custom merge scripts so that the first state
[smatch.git] / smatch.h
blob6453501a935e195f9dc5075aa1d0c8d518a52a0c
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 struct state_history {
21 unsigned int loc;
23 DECLARE_PTR_LIST(history_list, struct state_history);
25 struct smatch_state {
26 char *name;
27 unsigned int owner;
28 struct symbol *sym;
29 int state;
30 struct history_list *line_history;
31 struct history_list *path_history;
34 enum hook_type {
35 EXPR_HOOK,
36 STMT_HOOK,
37 SYM_HOOK,
38 DECLARATION_HOOK,
39 ASSIGNMENT_HOOK,
40 ASSIGNMENT_AFTER_HOOK,
41 CONDITION_HOOK,
42 WHOLE_CONDITION_HOOK,
43 FUNCTION_CALL_HOOK,
44 FUNCTION_CALL_AFTER_HOOK,
45 DEREF_HOOK,
46 BASE_HOOK,
47 FUNC_DEF_HOOK,
48 END_FUNC_HOOK,
49 RETURN_HOOK,
51 void add_hook(void *func, enum hook_type type);
52 typedef int (merge_func_t)(const char *name, struct symbol *sym, int s1,
53 int s2);
54 void add_merge_hook(int client_id, merge_func_t *func);
56 #define smatch_msg(msg...) \
57 do { \
58 printf("%s %d %s(%d) ", get_filename(), get_lineno(), \
59 get_function(), get_func_pos()); \
60 printf(msg); \
61 printf("\n"); \
62 } while (0)
64 #define SM_DEBUG(msg...) do { if (debug_states) printf(msg); } while (0)
66 #define NOTFOUND -2
67 #define UNDEFINED -1
69 int get_state(const char *name, int owner, struct symbol *sym);
70 void add_state(const char *name, int owner, struct symbol *sym, int state);
71 void set_state(const char *name, int owner, struct symbol *sym, int state);
72 void delete_state(const char *name, int owner, struct symbol *sym);
73 void set_true_false_states(const char *name, int owner, struct symbol *sym,
74 int true_state, int false_state);
75 int state_defined(const char *name, int owner, struct symbol *sym);
77 struct state_list *get_all_states();
78 void nullify_path();
79 void clear_all_states();
81 char *get_filename();
82 char *get_function();
83 int get_lineno();
84 int get_func_pos();
86 /* smatch_helper.c */
87 char *alloc_string(char *str);
88 void free_string(char *str);
89 struct expression *get_argument_from_call_expr(struct expression_list *args,
90 int num);
91 char * get_variable_from_expr(struct expression * expr,
92 struct symbol **sym_ptr);
93 char * get_variable_from_expr_simple(struct expression * expr,
94 struct symbol **sym_ptr);
96 /* ----------------------------------------------------------------
97 The stuff below is all used internally and shouldn't
98 be called from other programs
99 -----------------------------------------------------------------*/
101 /* smatch_flow.c */
103 extern int __negate;
104 extern int __ands;
105 extern int __ors;
106 void smatch (int argc, char **argv);
107 void split_conditions(struct expression *expr);
108 unsigned int get_path_id();
110 /* smatch_states.c */
112 extern int debug_states;
114 void __first_and_clump();
115 void __merge_and_clump();
116 void __use_and_clumps();
117 void __split_true_false_paths();
118 void __split_false_states_mini();
119 void __use_false_states_mini();
120 void __pop_false_states_mini();
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 __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();
138 void __save_switch_states();
139 void __pop_switches();
140 void __merge_switches();
141 void __push_default();
142 void __set_default();
143 int __pop_default();
145 void __push_conditions();
146 void __pop_conditions();
147 void __overwrite_true_states();
149 void __save_gotos(const char *name);
150 void __merge_gotos(const char *name);
152 /* smatch_hooks.c */
153 void __pass_to_client(void *data, enum hook_type type);
154 void __pass_declarations_to_client(struct symbol_list *sym_list);
155 int __has_merge_function(int client_id);
156 int __client_merge_function(int owner, const char *name, struct symbol *sym,
157 int s1, int s2);
159 #endif /* !SMATCH_H_ */