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
;
25 int is_silenced_function(void)
29 func
= get_function();
32 if (search_func(silenced_funcs
, func
))
37 static void register_no_return_funcs(void)
43 if (option_project
== PROJ_NONE
)
44 strcpy(name
, "no_return_funcs");
46 snprintf(name
, 256, "%s.no_return_funcs", option_project_str
);
48 token
= get_tokens_file(name
);
51 if (token_type(token
) != TOKEN_STREAMBEGIN
)
54 while (token_type(token
) != TOKEN_STREAMEND
) {
55 if (token_type(token
) != TOKEN_IDENT
)
57 func
= show_ident(token
->ident
);
58 add_function_hook(func
, &__match_nullify_path_hook
, NULL
);
64 static void register_ignored_macros(void)
70 if (option_project
== PROJ_NONE
)
71 strcpy(name
, "ignored_macros");
73 snprintf(name
, 256, "%s.ignored_macros", option_project_str
);
75 token
= get_tokens_file(name
);
78 if (token_type(token
) != TOKEN_STREAMBEGIN
)
81 while (token_type(token
) != TOKEN_STREAMEND
) {
82 if (token_type(token
) != TOKEN_IDENT
)
84 macro
= alloc_string(show_ident(token
->ident
));
85 add_ptr_list(&__ignored_macros
, macro
);
91 static void register_silenced_functions(void)
97 silenced_funcs
= create_function_hashtable(500);
99 if (option_project
== PROJ_NONE
)
102 snprintf(name
, 256, "%s.silenced_functions", option_project_str
);
104 token
= get_tokens_file(name
);
107 if (token_type(token
) != TOKEN_STREAMBEGIN
)
110 while (token_type(token
) != TOKEN_STREAMEND
) {
111 if (token_type(token
) != TOKEN_IDENT
)
113 func
= alloc_string(show_ident(token
->ident
));
114 insert_func(silenced_funcs
, func
, INT_PTR(1));
119 void register_project(int id
)
121 register_no_return_funcs();
122 register_ignored_macros();
123 register_silenced_functions();