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 struct statement_list
*stmt_list
;
22 static int end_of_function(struct statement
*stmt
)
24 struct symbol
*fn
= get_base_type(cur_func_sym
);
26 /* err on the conservative side of things */
29 if (stmt
== fn
->stmt
|| stmt
== fn
->inline_stmt
)
35 * We're wasting a lot of time worrying about out of scope variables.
36 * When we come to the end of a scope then just delete them all the out of
39 static void match_end_of_block(struct statement
*stmt
)
41 struct statement
*tmp
;
44 if (stmt
->type
!= STMT_COMPOUND
)
47 if (end_of_function(stmt
))
50 FOR_EACH_PTR(stmt
->stmts
, tmp
) {
51 if (tmp
->type
!= STMT_DECLARATION
)
54 FOR_EACH_PTR(tmp
->declaration
, sym
) {
57 __delete_all_states_sym(sym
);
58 } END_FOR_EACH_PTR(sym
);
59 } END_FOR_EACH_PTR(tmp
);
62 static int is_outer_stmt(struct statement
*stmt
)
64 struct symbol
*fn
= get_base_type(cur_func_sym
);
69 * There are times when ->parent is not set but it's set for
70 * the outer statement so ignoring NULLs works as a work-around.
74 if (stmt
->parent
== fn
->stmt
||
75 stmt
->parent
== fn
->inline_stmt
)
80 static void match_stmt(struct statement
*stmt
)
82 struct statement
*tmp
;
87 add_ptr_list(&stmt_list
, stmt
);
89 if (!is_outer_stmt(stmt
))
92 FOR_EACH_PTR(stmt_list
, tmp
) {
93 match_end_of_block(tmp
);
94 } END_FOR_EACH_PTR(tmp
);
95 free_ptr_list(&stmt_list
);
98 static void match_end_func(struct symbol
*sym
)
102 free_ptr_list(&stmt_list
);
105 void register_scope(int id
)
107 add_hook(&match_stmt
, STMT_HOOK_AFTER
);
108 add_hook(&match_end_func
, AFTER_FUNC_HOOK
);