13 *
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
16 */
17
18 #include "scope.h"
19 #include "smatch.h"
20 #include "smatch_slist.h"
21 #include "smatch_expression_stacks.h"
22
23 static int my_id;
24
25 static struct string_list *ignored_macros;
26 static struct position old_pos;
27
28 static struct smatch_state *alloc_my_state(struct expression *expr)
29 {
30 struct smatch_state *state;
31 char *name;
32
33 state = __alloc_smatch_state(0);
34 expr = strip_expr(expr);
35 name = expr_to_str(expr);
36 state->name = alloc_sname(name);
37 free_string(name);
38 state->data = expr;
39 return state;
40 }
41
42 static int defined_inside_macro(struct position macro_pos, struct expression *expr)
43 {
44 char *name;
45 struct symbol *sym;
46 int ret = 0;
47
48 name = expr_to_var_sym(expr, &sym);
49 if (!name || !sym)
50 goto free;
51 if (!sym->scope || !sym->scope->token)
52 goto free;
53 if (positions_eq(macro_pos, sym->scope->token->pos))
54 ret = 1;
55 free:
143 if (token_type(token) != TOKEN_STREAMBEGIN)
144 return;
145 token = token->next;
146 while (token_type(token) != TOKEN_STREAMEND) {
147 if (token_type(token) != TOKEN_IDENT)
148 return;
149 macro = alloc_string(show_ident(token->ident));
150 add_ptr_list(&ignored_macros, macro);
151 token = token->next;
152 }
153 clear_token_alloc();
154 }
155
156 void check_macro_side_effects(int id)
157 {
158 my_id = id;
159
160 if (!option_spammy)
161 return;
162
163 add_hook(&match_unop, OP_HOOK);
164 add_hook(&match_stmt, STMT_HOOK);
165 register_ignored_macros();
166 }
|
13 *
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
16 */
17
18 #include "scope.h"
19 #include "smatch.h"
20 #include "smatch_slist.h"
21 #include "smatch_expression_stacks.h"
22
23 static int my_id;
24
25 static struct string_list *ignored_macros;
26 static struct position old_pos;
27
28 static struct smatch_state *alloc_my_state(struct expression *expr)
29 {
30 struct smatch_state *state;
31 char *name;
32
33 expr = strip_expr(expr);
34 name = expr_to_str(expr);
35 if (!name)
36 return NULL;
37
38 state = __alloc_smatch_state(0);
39 state->name = alloc_sname(name);
40 free_string(name);
41 state->data = expr;
42 return state;
43 }
44
45 static int defined_inside_macro(struct position macro_pos, struct expression *expr)
46 {
47 char *name;
48 struct symbol *sym;
49 int ret = 0;
50
51 name = expr_to_var_sym(expr, &sym);
52 if (!name || !sym)
53 goto free;
54 if (!sym->scope || !sym->scope->token)
55 goto free;
56 if (positions_eq(macro_pos, sym->scope->token->pos))
57 ret = 1;
58 free:
146 if (token_type(token) != TOKEN_STREAMBEGIN)
147 return;
148 token = token->next;
149 while (token_type(token) != TOKEN_STREAMEND) {
150 if (token_type(token) != TOKEN_IDENT)
151 return;
152 macro = alloc_string(show_ident(token->ident));
153 add_ptr_list(&ignored_macros, macro);
154 token = token->next;
155 }
156 clear_token_alloc();
157 }
158
159 void check_macro_side_effects(int id)
160 {
161 my_id = id;
162
163 if (!option_spammy)
164 return;
165
166 set_dynamic_states(my_id);
167 add_hook(&match_unop, OP_HOOK);
168 add_hook(&match_stmt, STMT_HOOK);
169 register_ignored_macros();
170 }
|