2 * Copyright (C) 2015 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 static struct stree
*used_stree
;
24 static struct stree_stack
*saved_stack
;
28 static void get_state_hook(int owner
, const char *name
, struct symbol
*sym
)
37 arg
= get_param_num_from_sym(sym
);
39 set_state_stree(&used_stree
, my_id
, name
, sym
, &used
);
42 static void set_param_used(struct expression
*call
, struct expression
*arg
, char *key
, char *unused
)
48 name
= get_variable_from_key(arg
, key
, &sym
);
52 arg_nr
= get_param_num_from_sym(sym
);
54 set_state(my_id
, name
, sym
, &used
);
59 static void process_states(void)
65 FOR_EACH_SM(used_stree
, tmp
) {
66 arg
= get_param_num_from_sym(tmp
->sym
);
69 name
= get_param_name(tmp
);
73 sql_insert_return_implies(PARAM_USED
, arg
, name
, "");
74 } END_FOR_EACH_SM(tmp
);
76 free_stree(&used_stree
);
79 static void match_function_def(struct symbol
*sym
)
81 free_stree(&used_stree
);
84 static void match_save_states(struct expression
*expr
)
86 push_stree(&saved_stack
, used_stree
);
90 static void match_restore_states(struct expression
*expr
)
92 free_stree(&used_stree
);
93 used_stree
= pop_stree(&saved_stack
);
96 void register_param_used(int id
)
100 add_hook(&match_function_def
, FUNC_DEF_HOOK
);
102 add_get_state_hook(&get_state_hook
);
104 add_hook(&match_save_states
, INLINE_FN_START
);
105 add_hook(&match_restore_states
, INLINE_FN_END
);
107 select_return_implies_hook(PARAM_USED
, &set_param_used
);
108 all_return_states_hook(&process_states
);