2 * Copyright (C) 2010 Dan Carpenter.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 * This file is only for very generic stuff, that is reusable
20 * between projects. If you need something special create a
21 * check_your_project.c.
26 #include "smatch_extra.h"
27 #include "smatch_function_hashtable.h"
29 static DEFINE_HASHTABLE_INSERT(insert_func
, char, int);
30 static DEFINE_HASHTABLE_SEARCH(search_func
, char, int);
31 static struct hashtable
*skipped_funcs
;
32 static struct hashtable
*skipped_macros
;
33 static struct hashtable
*silenced_funcs
;
34 static struct hashtable
*no_inline_funcs
;
36 static unsigned long skipped
;
38 void set_function_skipped(void)
43 int is_skipped_function(void)
48 static void match_function_def(struct symbol
*sym
)
53 func
= get_function();
56 if (skipped_funcs
&& search_func(skipped_funcs
, func
)) {
57 set_function_skipped();
60 macro
= get_macro_name(cur_func_sym
->pos
);
61 if (macro
&& skipped_macros
&& search_func(skipped_macros
, macro
)) {
62 set_function_skipped();
68 * A silenced function will still be processed and potentially appear in info
69 * output, but not regular checks.
71 int is_silenced_function(void)
75 if (is_skipped_function())
78 func
= get_function();
81 if (search_func(silenced_funcs
, func
))
86 int is_no_inline_function(const char *function
)
88 if (search_func(no_inline_funcs
, (char *)function
))
93 static void register_no_return_funcs(void)
99 snprintf(name
, 256, "%s.no_return_funcs", option_project_str
);
101 token
= get_tokens_file(name
);
104 if (token_type(token
) != TOKEN_STREAMBEGIN
)
107 while (token_type(token
) != TOKEN_STREAMEND
) {
108 if (token_type(token
) != TOKEN_IDENT
)
110 func
= show_ident(token
->ident
);
111 add_function_hook(func
, &__match_nullify_path_hook
, NULL
);
117 static void register_ignored_macros(void)
123 if (option_project
== PROJ_NONE
)
124 strcpy(name
, "ignored_macros");
126 snprintf(name
, 256, "%s.ignored_macros", option_project_str
);
128 token
= get_tokens_file(name
);
131 if (token_type(token
) != TOKEN_STREAMBEGIN
)
134 while (token_type(token
) != TOKEN_STREAMEND
) {
135 if (token_type(token
) != TOKEN_IDENT
)
137 macro
= alloc_string(show_ident(token
->ident
));
138 add_ptr_list(&__ignored_macros
, macro
);
144 static struct hashtable
*register_skipped(const char *filename
)
146 struct hashtable
*table
;
151 if (option_project
== PROJ_NONE
)
154 snprintf(name
, 256, "%s.%s", option_project_str
, filename
);
156 token
= get_tokens_file(name
);
159 if (token_type(token
) != TOKEN_STREAMBEGIN
)
162 table
= create_function_hashtable(500);
165 while (token_type(token
) != TOKEN_STREAMEND
) {
166 if (token_type(token
) != TOKEN_IDENT
)
168 func
= alloc_string(show_ident(token
->ident
));
169 insert_func(table
, func
, INT_PTR(1));
177 static void register_silenced_functions(void)
183 silenced_funcs
= create_function_hashtable(500);
185 if (option_project
== PROJ_NONE
)
188 snprintf(name
, 256, "%s.silenced_functions", option_project_str
);
190 token
= get_tokens_file(name
);
193 if (token_type(token
) != TOKEN_STREAMBEGIN
)
196 while (token_type(token
) != TOKEN_STREAMEND
) {
197 if (token_type(token
) != TOKEN_IDENT
)
199 func
= alloc_string(show_ident(token
->ident
));
200 insert_func(silenced_funcs
, func
, INT_PTR(1));
206 static void register_no_inline_functions(void)
212 no_inline_funcs
= create_function_hashtable(500);
214 if (option_project
== PROJ_NONE
)
217 snprintf(name
, 256, "%s.no_inline_functions", option_project_str
);
219 token
= get_tokens_file(name
);
222 if (token_type(token
) != TOKEN_STREAMBEGIN
)
225 while (token_type(token
) != TOKEN_STREAMEND
) {
226 if (token_type(token
) != TOKEN_IDENT
)
228 func
= alloc_string(show_ident(token
->ident
));
229 insert_func(no_inline_funcs
, func
, INT_PTR(1));
235 void register_project(int id
)
237 add_hook(&match_function_def
, FUNC_DEF_HOOK
);
238 add_function_data(&skipped
);
239 register_no_return_funcs();
240 register_ignored_macros();
241 skipped_funcs
= register_skipped("skipped_functions");
242 skipped_macros
= register_skipped("skipped_macros");
243 register_silenced_functions();
244 register_no_inline_functions();