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
*silenced_funcs
;
33 static struct hashtable
*no_inline_funcs
;
35 static unsigned long skipped
;
37 void set_function_skipped(void)
42 int is_skipped_function(void)
47 static void match_function_def(struct symbol
*sym
)
51 func
= get_function();
54 if (search_func(skipped_funcs
, func
))
55 set_function_skipped();
59 * A silenced function will still be processed and potentially appear in info
60 * output, but not regular checks.
62 int is_silenced_function(void)
66 if (is_skipped_function())
69 func
= get_function();
72 if (search_func(silenced_funcs
, func
))
77 int is_no_inline_function(const char *function
)
79 if (search_func(no_inline_funcs
, (char *)function
))
84 static void register_no_return_funcs(void)
90 snprintf(name
, 256, "%s.no_return_funcs", option_project_str
);
92 token
= get_tokens_file(name
);
95 if (token_type(token
) != TOKEN_STREAMBEGIN
)
98 while (token_type(token
) != TOKEN_STREAMEND
) {
99 if (token_type(token
) != TOKEN_IDENT
)
101 func
= show_ident(token
->ident
);
102 add_function_hook(func
, &__match_nullify_path_hook
, NULL
);
108 static void register_ignored_macros(void)
114 if (option_project
== PROJ_NONE
)
115 strcpy(name
, "ignored_macros");
117 snprintf(name
, 256, "%s.ignored_macros", option_project_str
);
119 token
= get_tokens_file(name
);
122 if (token_type(token
) != TOKEN_STREAMBEGIN
)
125 while (token_type(token
) != TOKEN_STREAMEND
) {
126 if (token_type(token
) != TOKEN_IDENT
)
128 macro
= alloc_string(show_ident(token
->ident
));
129 add_ptr_list(&__ignored_macros
, macro
);
135 static void register_skipped_functions(void)
141 skipped_funcs
= create_function_hashtable(500);
143 if (option_project
== PROJ_NONE
)
146 snprintf(name
, 256, "%s.skipped_functions", option_project_str
);
148 token
= get_tokens_file(name
);
151 if (token_type(token
) != TOKEN_STREAMBEGIN
)
154 while (token_type(token
) != TOKEN_STREAMEND
) {
155 if (token_type(token
) != TOKEN_IDENT
)
157 func
= alloc_string(show_ident(token
->ident
));
158 insert_func(skipped_funcs
, func
, INT_PTR(1));
164 static void register_silenced_functions(void)
170 silenced_funcs
= create_function_hashtable(500);
172 if (option_project
== PROJ_NONE
)
175 snprintf(name
, 256, "%s.silenced_functions", option_project_str
);
177 token
= get_tokens_file(name
);
180 if (token_type(token
) != TOKEN_STREAMBEGIN
)
183 while (token_type(token
) != TOKEN_STREAMEND
) {
184 if (token_type(token
) != TOKEN_IDENT
)
186 func
= alloc_string(show_ident(token
->ident
));
187 insert_func(silenced_funcs
, func
, INT_PTR(1));
193 static void register_no_inline_functions(void)
199 no_inline_funcs
= create_function_hashtable(500);
201 if (option_project
== PROJ_NONE
)
204 snprintf(name
, 256, "%s.no_inline_functions", option_project_str
);
206 token
= get_tokens_file(name
);
209 if (token_type(token
) != TOKEN_STREAMBEGIN
)
212 while (token_type(token
) != TOKEN_STREAMEND
) {
213 if (token_type(token
) != TOKEN_IDENT
)
215 func
= alloc_string(show_ident(token
->ident
));
216 insert_func(no_inline_funcs
, func
, INT_PTR(1));
222 void register_project(int id
)
224 add_hook(&match_function_def
, FUNC_DEF_HOOK
);
225 add_function_data(&skipped
);
226 register_no_return_funcs();
227 register_ignored_macros();
228 register_skipped_functions();
229 register_silenced_functions();
230 register_no_inline_functions();