implied: remove unused add_pool() function
[smatch.git] / smatch_scope.c
blobed9dafb160d75f0a33e9e5992fd05d6317f33fd5
1 /*
2 * Copyright (C) 2016 Oracle.
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
18 #include "smatch.h"
20 static int end_of_function(struct statement *stmt)
22 struct symbol *fn = get_base_type(cur_func_sym);
24 /* err on the conservative side of things */
25 if (!fn)
26 return 1;
27 if (stmt == fn->stmt || stmt == fn->inline_stmt)
28 return 1;
29 return 0;
33 * We're wasting a lot of time worrying about out of scope variables.
34 * When we come to the end of a scope then just delete them all the out of
35 * scope states.
37 static void match_end_of_block(struct statement *stmt)
39 struct statement *tmp;
40 struct symbol *sym;
42 if (stmt->type != STMT_COMPOUND)
43 return;
45 if (end_of_function(stmt))
46 return;
48 FOR_EACH_PTR(stmt->stmts, tmp) {
49 if (tmp->type != STMT_DECLARATION)
50 return;
52 FOR_EACH_PTR(tmp->declaration, sym) {
53 if (!sym->ident)
54 continue;
55 __delete_all_states_sym(sym);
56 } END_FOR_EACH_PTR(sym);
57 } END_FOR_EACH_PTR(tmp);
60 void register_scope(int id)
62 add_hook(&match_end_of_block, STMT_HOOK_AFTER);