function_ptrs: store arrays better
[smatch.git] / smatch_project.c
blob0511e3ca1e4997207c2a282645391422871cf63b
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;
24 static struct hashtable *no_inline_funcs;
26 int is_silenced_function(void)
28 char *func;
30 func = get_function();
31 if (!func)
32 return 0;
33 if (search_func(silenced_funcs, func))
34 return 1;
35 return 0;
38 int is_no_inline_function(const char *function)
40 if (search_func(no_inline_funcs, (char *)function))
41 return 1;
42 return 0;
45 static void register_no_return_funcs(void)
47 struct token *token;
48 const char *func;
49 char name[256];
51 if (option_project == PROJ_NONE)
52 strcpy(name, "no_return_funcs");
53 else
54 snprintf(name, 256, "%s.no_return_funcs", option_project_str);
56 token = get_tokens_file(name);
57 if (!token)
58 return;
59 if (token_type(token) != TOKEN_STREAMBEGIN)
60 return;
61 token = token->next;
62 while (token_type(token) != TOKEN_STREAMEND) {
63 if (token_type(token) != TOKEN_IDENT)
64 return;
65 func = show_ident(token->ident);
66 add_function_hook(func, &__match_nullify_path_hook, NULL);
67 token = token->next;
69 clear_token_alloc();
72 static void register_ignored_macros(void)
74 struct token *token;
75 char *macro;
76 char name[256];
78 if (option_project == PROJ_NONE)
79 strcpy(name, "ignored_macros");
80 else
81 snprintf(name, 256, "%s.ignored_macros", option_project_str);
83 token = get_tokens_file(name);
84 if (!token)
85 return;
86 if (token_type(token) != TOKEN_STREAMBEGIN)
87 return;
88 token = token->next;
89 while (token_type(token) != TOKEN_STREAMEND) {
90 if (token_type(token) != TOKEN_IDENT)
91 return;
92 macro = alloc_string(show_ident(token->ident));
93 add_ptr_list(&__ignored_macros, macro);
94 token = token->next;
96 clear_token_alloc();
99 static void register_silenced_functions(void)
101 struct token *token;
102 char *func;
103 char name[256];
105 silenced_funcs = create_function_hashtable(500);
107 if (option_project == PROJ_NONE)
108 return;
110 snprintf(name, 256, "%s.silenced_functions", option_project_str);
112 token = get_tokens_file(name);
113 if (!token)
114 return;
115 if (token_type(token) != TOKEN_STREAMBEGIN)
116 return;
117 token = token->next;
118 while (token_type(token) != TOKEN_STREAMEND) {
119 if (token_type(token) != TOKEN_IDENT)
120 return;
121 func = alloc_string(show_ident(token->ident));
122 insert_func(silenced_funcs, func, INT_PTR(1));
123 token = token->next;
125 clear_token_alloc();
128 static void register_no_inline_functions(void)
130 struct token *token;
131 char *func;
132 char name[256];
134 no_inline_funcs = create_function_hashtable(500);
136 if (option_project == PROJ_NONE)
137 return;
139 snprintf(name, 256, "%s.no_inline_functions", option_project_str);
141 token = get_tokens_file(name);
142 if (!token)
143 return;
144 if (token_type(token) != TOKEN_STREAMBEGIN)
145 return;
146 token = token->next;
147 while (token_type(token) != TOKEN_STREAMEND) {
148 if (token_type(token) != TOKEN_IDENT)
149 return;
150 func = alloc_string(show_ident(token->ident));
151 insert_func(no_inline_funcs, func, INT_PTR(1));
152 token = token->next;
154 clear_token_alloc();
157 void register_project(int id)
159 register_no_return_funcs();
160 register_ignored_macros();
161 register_silenced_functions();
162 register_no_inline_functions();