data_source: rename a variable "tmp" => "arg"
[smatch.git] / smatch_param_used.c
blobe94f011b83542599eac81c59713b197985666fd9
1 /*
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
18 #include "smatch.h"
19 #include "smatch_slist.h"
21 static int my_id;
23 struct stree *used_stree;
24 STATE(used);
27 * I am a loser. This should be a proper hook, but I am too lazy. I'll add
28 * that stuff if we have a second user.
30 void __get_state_hook(int owner, const char *name, struct symbol *sym)
32 int arg;
34 if (!option_info)
35 return;
36 if (__in_fake_assign)
37 return;
39 arg = get_param_num_from_sym(sym);
40 if (arg < 0)
41 return;
43 set_state_stree(&used_stree, my_id, name, sym, &used);
46 static void set_param_used(struct expression *arg, char *key, char *unused)
48 struct symbol *sym;
49 char *name;
50 int arg_nr;
52 name = get_variable_from_key(arg, key, &sym);
53 if (!name || !sym)
54 goto free;
56 arg_nr = get_param_num_from_sym(sym);
57 if (arg_nr < 0)
58 goto free;
60 set_state(my_id, name, sym, &used);
61 free:
62 free_string(name);
65 static void process_states(struct stree *stree)
67 struct sm_state *tmp;
68 int arg;
69 const char *name;
71 FOR_EACH_SM(used_stree, tmp) {
72 arg = get_param_num_from_sym(tmp->sym);
73 name = get_param_name(tmp);
74 if (!name)
75 continue;
76 sql_insert_call_implies(PARAM_USED, arg, name, "1");
77 } END_FOR_EACH_SM(tmp);
79 free_stree(&used_stree);
82 void register_param_used(int id)
84 my_id = id;
86 if (!option_info)
87 return;
89 select_call_implies_hook(PARAM_USED, &set_param_used);
90 all_return_states_hook(&process_states);