smatch.h: move stree_stack declaration from smatch_slist.h to smatch.h
[smatch.git] / smatch_project.c
blob53937bca4e02cf9cd28149076044bf069a41f601
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 if (option_project == PROJ_NONE)
60 strcpy(name, "no_return_funcs");
61 else
62 snprintf(name, 256, "%s.no_return_funcs", option_project_str);
64 token = get_tokens_file(name);
65 if (!token)
66 return;
67 if (token_type(token) != TOKEN_STREAMBEGIN)
68 return;
69 token = token->next;
70 while (token_type(token) != TOKEN_STREAMEND) {
71 if (token_type(token) != TOKEN_IDENT)
72 return;
73 func = show_ident(token->ident);
74 add_function_hook(func, &__match_nullify_path_hook, NULL);
75 token = token->next;
77 clear_token_alloc();
80 static void register_ignored_macros(void)
82 struct token *token;
83 char *macro;
84 char name[256];
86 if (option_project == PROJ_NONE)
87 strcpy(name, "ignored_macros");
88 else
89 snprintf(name, 256, "%s.ignored_macros", option_project_str);
91 token = get_tokens_file(name);
92 if (!token)
93 return;
94 if (token_type(token) != TOKEN_STREAMBEGIN)
95 return;
96 token = token->next;
97 while (token_type(token) != TOKEN_STREAMEND) {
98 if (token_type(token) != TOKEN_IDENT)
99 return;
100 macro = alloc_string(show_ident(token->ident));
101 add_ptr_list(&__ignored_macros, macro);
102 token = token->next;
104 clear_token_alloc();
107 static void register_silenced_functions(void)
109 struct token *token;
110 char *func;
111 char name[256];
113 silenced_funcs = create_function_hashtable(500);
115 if (option_project == PROJ_NONE)
116 return;
118 snprintf(name, 256, "%s.silenced_functions", option_project_str);
120 token = get_tokens_file(name);
121 if (!token)
122 return;
123 if (token_type(token) != TOKEN_STREAMBEGIN)
124 return;
125 token = token->next;
126 while (token_type(token) != TOKEN_STREAMEND) {
127 if (token_type(token) != TOKEN_IDENT)
128 return;
129 func = alloc_string(show_ident(token->ident));
130 insert_func(silenced_funcs, func, INT_PTR(1));
131 token = token->next;
133 clear_token_alloc();
136 static void register_no_inline_functions(void)
138 struct token *token;
139 char *func;
140 char name[256];
142 no_inline_funcs = create_function_hashtable(500);
144 if (option_project == PROJ_NONE)
145 return;
147 snprintf(name, 256, "%s.no_inline_functions", option_project_str);
149 token = get_tokens_file(name);
150 if (!token)
151 return;
152 if (token_type(token) != TOKEN_STREAMBEGIN)
153 return;
154 token = token->next;
155 while (token_type(token) != TOKEN_STREAMEND) {
156 if (token_type(token) != TOKEN_IDENT)
157 return;
158 func = alloc_string(show_ident(token->ident));
159 insert_func(no_inline_funcs, func, INT_PTR(1));
160 token = token->next;
162 clear_token_alloc();
165 void register_project(int id)
167 register_no_return_funcs();
168 register_ignored_macros();
169 register_silenced_functions();
170 register_no_inline_functions();