*new* add smatch_data/kernel.silenced_functions to silence common noise
[smatch.git] / smatch_project.c
blob5b9601b2f7f508d3a0b895095f62c147c36d9259
1 /*
2 * sparse/smatch_project.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
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.
17 #include "smatch.h"
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)
27 char *func;
29 func = get_function();
30 if (!func)
31 return 0;
32 if (search_func(silenced_funcs, func))
33 return 1;
34 return 0;
37 static void register_no_return_funcs(void)
39 struct token *token;
40 const char *func;
41 char name[256];
43 if (option_project == PROJ_NONE)
44 strcpy(name, "no_return_funcs");
45 else
46 snprintf(name, 256, "%s.no_return_funcs", option_project_str);
48 token = get_tokens_file(name);
49 if (!token)
50 return;
51 if (token_type(token) != TOKEN_STREAMBEGIN)
52 return;
53 token = token->next;
54 while (token_type(token) != TOKEN_STREAMEND) {
55 if (token_type(token) != TOKEN_IDENT)
56 return;
57 func = show_ident(token->ident);
58 add_function_hook(func, &__match_nullify_path_hook, NULL);
59 token = token->next;
61 clear_token_alloc();
64 static void register_ignored_macros(void)
66 struct token *token;
67 char *macro;
68 char name[256];
70 if (option_project == PROJ_NONE)
71 strcpy(name, "ignored_macros");
72 else
73 snprintf(name, 256, "%s.ignored_macros", option_project_str);
75 token = get_tokens_file(name);
76 if (!token)
77 return;
78 if (token_type(token) != TOKEN_STREAMBEGIN)
79 return;
80 token = token->next;
81 while (token_type(token) != TOKEN_STREAMEND) {
82 if (token_type(token) != TOKEN_IDENT)
83 return;
84 macro = alloc_string(show_ident(token->ident));
85 add_ptr_list(&__ignored_macros, macro);
86 token = token->next;
88 clear_token_alloc();
91 static void register_silenced_functions(void)
93 struct token *token;
94 char *func;
95 char name[256];
97 silenced_funcs = create_function_hashtable(500);
99 if (option_project == PROJ_NONE)
100 return;
102 snprintf(name, 256, "%s.silenced_functions", option_project_str);
104 token = get_tokens_file(name);
105 if (!token)
106 return;
107 if (token_type(token) != TOKEN_STREAMBEGIN)
108 return;
109 token = token->next;
110 while (token_type(token) != TOKEN_STREAMEND) {
111 if (token_type(token) != TOKEN_IDENT)
112 return;
113 func = alloc_string(show_ident(token->ident));
114 insert_func(silenced_funcs, func, INT_PTR(1));
115 token = token->next;
117 clear_token_alloc();
119 void register_project(int id)
121 register_no_return_funcs();
122 register_ignored_macros();
123 register_silenced_functions();