Update the line number at the very start of the function. Otherwise it was
[smatch.git] / smatch.h
blob478b854fef7489d6c0848551b6a7111d8bc57bec
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 NOTFOUND -2
65 #define UNDEFINED -1
67 int get_state(const char *name, int owner, struct symbol *sym);
68 void add_state(const char *name, int owner, struct symbol *sym, int state);
69 void set_state(const char *name, int owner, struct symbol *sym, int state);
70 void delete_state(const char *name, int owner, struct symbol *sym);
71 void set_true_false_states(const char *name, int owner, struct symbol *sym,
72 int true_state, int false_state);
73 int state_defined(const char *name, int owner, struct symbol *sym);
75 struct state_list *get_all_states();
76 void nullify_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);
94 /* ----------------------------------------------------------------
95 The stuff below is all used internally and shouldn't
96 be called from other programs
97 -----------------------------------------------------------------*/
99 /* smatch_flow.c */
101 extern int __negate;
102 extern int __ands;
103 extern int __ors;
104 void smatch (int argc, char **argv);
105 void split_conditions(struct expression *expr);
106 unsigned int get_path_id();
108 /* smatch_states.c */
110 extern int debug_states;
112 void __first_and_clump();
113 void __merge_and_clump();
114 void __use_and_clumps();
115 void __split_true_false_paths();
116 void __split_false_states_mini();
117 void __use_false_states_mini();
118 void __pop_false_states_mini();
119 void __use_true_states();
120 void __use_false_states();
121 void __pop_false_states();
122 void __merge_false_states();
123 void __merge_true_states();
124 void __pop_true_states();
126 void __push_continues();
127 void __pop_continues();
128 void __process_continues();
129 void __merge_continues();
131 void __push_breaks();
132 void __pop_breaks();
133 void __process_breaks();
134 void __merge_breaks();
136 void __save_switch_states();
137 void __pop_switches();
138 void __merge_switches();
139 void __push_default();
140 void __set_default();
141 int __pop_default();
143 void __push_conditions();
144 void __pop_conditions();
145 void __overwrite_true_states();
147 void __save_gotos(const char *name);
148 void __merge_gotos(const char *name);
150 /* smatch_hooks.c */
151 void __pass_to_client(void *data, enum hook_type type);
152 void __pass_declarations_to_client(struct symbol_list *sym_list);
153 int __has_merge_function(int client_id);
154 int __client_merge_function(int owner, const char *name, struct symbol *sym,
155 int s1, int s2);
157 #endif /* !SMATCH_H_ */