2 * Copyright (C) 2011 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
19 #include "smatch_slist.h"
23 struct return_states_callback
{
24 void (*callback
)(struct state_list
*slist
);
26 ALLOCATOR(return_states_callback
, "return states callbacks");
27 DECLARE_PTR_LIST(callback_list
, struct return_states_callback
);
28 static struct callback_list
*callback_list
;
30 static struct state_list
*all_return_states
;
31 static struct state_list_stack
*saved_stack
;
33 void all_return_states_hook(void (*callback
)(struct state_list
*slist
))
35 struct return_states_callback
*rs_cb
= __alloc_return_states_callback(0);
37 rs_cb
->callback
= callback
;
38 add_ptr_list(&callback_list
, rs_cb
);
41 static void call_hooks()
43 struct return_states_callback
*rs_cb
;
45 FOR_EACH_PTR(callback_list
, rs_cb
) {
46 rs_cb
->callback(all_return_states
);
47 } END_FOR_EACH_PTR(rs_cb
);
50 static void match_return(struct expression
*ret_value
)
52 merge_slist(&all_return_states
, __get_cur_slist());
55 static void match_end_func(struct symbol
*sym
)
57 merge_slist(&all_return_states
, __get_cur_slist());
59 free_slist(&all_return_states
);
62 static void match_save_states(struct expression
*expr
)
64 push_slist(&saved_stack
, all_return_states
);
65 all_return_states
= NULL
;
68 static void match_restore_states(struct expression
*expr
)
70 all_return_states
= pop_slist(&saved_stack
);
73 void register_returns(int id
)
77 add_hook(&match_return
, RETURN_HOOK
);
78 add_hook(&match_end_func
, END_FUNC_HOOK
);
79 add_hook(&match_save_states
, INLINE_FN_START
);
80 add_hook(&match_restore_states
, INLINE_FN_END
);