debug: add __smatch_state_count()
[smatch.git] / smatch_project.c
blobb2fa3ce6e58bfa29e8179b9fb04fa4de3703c478
1 /*
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.
25 #include "smatch.h"
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 *silenced_funcs;
32 static struct hashtable *no_inline_funcs;
34 int is_silenced_function(void)
36 char *func;
38 func = get_function();
39 if (!func)
40 return 0;
41 if (search_func(silenced_funcs, func))
42 return 1;
43 return 0;
46 int is_no_inline_function(const char *function)
48 if (search_func(no_inline_funcs, (char *)function))
49 return 1;
50 return 0;
53 static void register_no_return_funcs(void)
55 struct token *token;
56 const char *func;
57 char name[256];
59 snprintf(name, 256, "%s.no_return_funcs", option_project_str);
61 token = get_tokens_file(name);
62 if (!token)
63 return;
64 if (token_type(token) != TOKEN_STREAMBEGIN)
65 return;
66 token = token->next;
67 while (token_type(token) != TOKEN_STREAMEND) {
68 if (token_type(token) != TOKEN_IDENT)
69 return;
70 func = show_ident(token->ident);
71 add_function_hook(func, &__match_nullify_path_hook, NULL);
72 token = token->next;
74 clear_token_alloc();
77 static void register_ignored_macros(void)
79 struct token *token;
80 char *macro;
81 char name[256];
83 if (option_project == PROJ_NONE)
84 strcpy(name, "ignored_macros");
85 else
86 snprintf(name, 256, "%s.ignored_macros", option_project_str);
88 token = get_tokens_file(name);
89 if (!token)
90 return;
91 if (token_type(token) != TOKEN_STREAMBEGIN)
92 return;
93 token = token->next;
94 while (token_type(token) != TOKEN_STREAMEND) {
95 if (token_type(token) != TOKEN_IDENT)
96 return;
97 macro = alloc_string(show_ident(token->ident));
98 add_ptr_list(&__ignored_macros, macro);
99 token = token->next;
101 clear_token_alloc();
104 static void register_silenced_functions(void)
106 struct token *token;
107 char *func;
108 char name[256];
110 silenced_funcs = create_function_hashtable(500);
112 if (option_project == PROJ_NONE)
113 return;
115 snprintf(name, 256, "%s.silenced_functions", option_project_str);
117 token = get_tokens_file(name);
118 if (!token)
119 return;
120 if (token_type(token) != TOKEN_STREAMBEGIN)
121 return;
122 token = token->next;
123 while (token_type(token) != TOKEN_STREAMEND) {
124 if (token_type(token) != TOKEN_IDENT)
125 return;
126 func = alloc_string(show_ident(token->ident));
127 insert_func(silenced_funcs, func, INT_PTR(1));
128 token = token->next;
130 clear_token_alloc();
133 static void register_no_inline_functions(void)
135 struct token *token;
136 char *func;
137 char name[256];
139 no_inline_funcs = create_function_hashtable(500);
141 if (option_project == PROJ_NONE)
142 return;
144 snprintf(name, 256, "%s.no_inline_functions", option_project_str);
146 token = get_tokens_file(name);
147 if (!token)
148 return;
149 if (token_type(token) != TOKEN_STREAMBEGIN)
150 return;
151 token = token->next;
152 while (token_type(token) != TOKEN_STREAMEND) {
153 if (token_type(token) != TOKEN_IDENT)
154 return;
155 func = alloc_string(show_ident(token->ident));
156 insert_func(no_inline_funcs, func, INT_PTR(1));
157 token = token->next;
159 clear_token_alloc();
162 void register_project(int id)
164 register_no_return_funcs();
165 register_ignored_macros();
166 register_silenced_functions();
167 register_no_inline_functions();