*new* stored_conditions: make a list of known true/false conditions
[smatch.git] / smatch_returns.c
blob2ac267a2214ad07d1c4ef326e84b7bad03d03dfe
1 /*
2 * smatch/smatch_returns.c
4 * Copyright (C) 2011 Oracle.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
11 #include "smatch_slist.h"
13 static int my_id;
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;
23 static struct state_list_stack *saved_stack;
25 void all_return_states_hook(void (*callback)(struct state_list *slist))
27 struct return_states_callback *rs_cb = __alloc_return_states_callback(0);
29 rs_cb->callback = callback;
30 add_ptr_list(&callback_list, rs_cb);
33 static void call_hooks()
35 struct return_states_callback *rs_cb;
37 FOR_EACH_PTR(callback_list, rs_cb) {
38 rs_cb->callback(all_return_states);
39 } END_FOR_EACH_PTR(rs_cb);
42 static void match_return(struct expression *ret_value)
44 merge_slist(&all_return_states, __get_cur_slist());
47 static void match_end_func(struct symbol *sym)
49 merge_slist(&all_return_states, __get_cur_slist());
50 call_hooks();
51 free_slist(&all_return_states);
54 static void match_save_states(struct expression *expr)
56 push_slist(&saved_stack, all_return_states);
57 all_return_states = NULL;
60 static void match_restore_states(struct expression *expr)
62 all_return_states = pop_slist(&saved_stack);
65 void register_returns(int id)
67 my_id = id;
69 add_hook(&match_return, RETURN_HOOK);
70 add_hook(&match_end_func, END_FUNC_HOOK);
71 add_hook(&match_save_states, INLINE_FN_START);
72 add_hook(&match_restore_states, INLINE_FN_END);