2 * sparse/smatch_project.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 * This file is only for very generic stuff, that is reusable
12 * between projects. If you need something special create a
13 * check_your_project.c.
18 #include "smatch_extra.h"
19 #include "smatch_function_hashtable.h"
21 static DEFINE_HASHTABLE_INSERT(insert_func
, char, int);
22 static DEFINE_HASHTABLE_SEARCH(search_func
, char, int);
23 static struct hashtable
*silenced_funcs
;
24 static struct hashtable
*no_inline_funcs
;
26 int is_silenced_function(void)
30 func
= get_function();
33 if (search_func(silenced_funcs
, func
))
38 int is_no_inline_function(const char *function
)
40 if (search_func(no_inline_funcs
, (char *)function
))
45 static void register_no_return_funcs(void)
51 if (option_project
== PROJ_NONE
)
52 strcpy(name
, "no_return_funcs");
54 snprintf(name
, 256, "%s.no_return_funcs", option_project_str
);
56 token
= get_tokens_file(name
);
59 if (token_type(token
) != TOKEN_STREAMBEGIN
)
62 while (token_type(token
) != TOKEN_STREAMEND
) {
63 if (token_type(token
) != TOKEN_IDENT
)
65 func
= show_ident(token
->ident
);
66 add_function_hook(func
, &__match_nullify_path_hook
, NULL
);
72 static void register_ignored_macros(void)
78 if (option_project
== PROJ_NONE
)
79 strcpy(name
, "ignored_macros");
81 snprintf(name
, 256, "%s.ignored_macros", option_project_str
);
83 token
= get_tokens_file(name
);
86 if (token_type(token
) != TOKEN_STREAMBEGIN
)
89 while (token_type(token
) != TOKEN_STREAMEND
) {
90 if (token_type(token
) != TOKEN_IDENT
)
92 macro
= alloc_string(show_ident(token
->ident
));
93 add_ptr_list(&__ignored_macros
, macro
);
99 static void register_silenced_functions(void)
105 silenced_funcs
= create_function_hashtable(500);
107 if (option_project
== PROJ_NONE
)
110 snprintf(name
, 256, "%s.silenced_functions", option_project_str
);
112 token
= get_tokens_file(name
);
115 if (token_type(token
) != TOKEN_STREAMBEGIN
)
118 while (token_type(token
) != TOKEN_STREAMEND
) {
119 if (token_type(token
) != TOKEN_IDENT
)
121 func
= alloc_string(show_ident(token
->ident
));
122 insert_func(silenced_funcs
, func
, INT_PTR(1));
128 static void register_no_inline_functions(void)
134 no_inline_funcs
= create_function_hashtable(500);
136 if (option_project
== PROJ_NONE
)
139 snprintf(name
, 256, "%s.no_inline_functions", option_project_str
);
141 token
= get_tokens_file(name
);
144 if (token_type(token
) != TOKEN_STREAMBEGIN
)
147 while (token_type(token
) != TOKEN_STREAMEND
) {
148 if (token_type(token
) != TOKEN_IDENT
)
150 func
= alloc_string(show_ident(token
->ident
));
151 insert_func(no_inline_funcs
, func
, INT_PTR(1));
157 void register_project(int id
)
159 register_no_return_funcs();
160 register_ignored_macros();
161 register_silenced_functions();
162 register_no_inline_functions();