2 * smatch/smatch_returns.c
4 * Copyright (C) 2011 Oracle.
6 * Licensed under the Open Software License version 1.1
11 #include "smatch_slist.h"
15 struct return_states_callback
{
16 void (*callback
)(struct state_list
*slist
);
18 ALLOCATOR(return_states_callback
, "return states callbacks");
19 DECLARE_PTR_LIST(callback_list
, struct return_states_callback
);
20 static struct callback_list
*callback_list
;
22 static struct state_list
*all_return_states
;
24 void all_return_states_hook(void (*callback
)(struct state_list
*slist
))
26 struct return_states_callback
*rs_cb
= __alloc_return_states_callback(0);
28 rs_cb
->callback
= callback
;
29 add_ptr_list(&callback_list
, rs_cb
);
32 static void call_hooks()
34 struct return_states_callback
*rs_cb
;
36 FOR_EACH_PTR(callback_list
, rs_cb
) {
37 rs_cb
->callback(all_return_states
);
38 } END_FOR_EACH_PTR(rs_cb
);
41 static void match_return(struct expression
*ret_value
)
43 merge_slist(&all_return_states
, __get_cur_slist());
46 static void match_end_func(struct symbol
*sym
)
48 merge_slist(&all_return_states
, __get_cur_slist());
50 free_slist(&all_return_states
);
53 void register_returns(int id
)
57 add_hook(&match_return
, RETURN_HOOK
);
58 add_hook(&match_end_func
, END_FUNC_HOOK
);