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
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 */
27 if (stmt
== fn
->stmt
|| stmt
== fn
->inline_stmt
)
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
37 static void match_end_of_block(struct statement
*stmt
)
39 struct statement
*tmp
;
42 if (stmt
->type
!= STMT_COMPOUND
)
45 if (end_of_function(stmt
))
48 FOR_EACH_PTR(stmt
->stmts
, tmp
) {
49 if (tmp
->type
!= STMT_DECLARATION
)
52 FOR_EACH_PTR(tmp
->declaration
, sym
) {
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
);