2 * Copyright (C) 2012 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 * This is for functions like:
30 * If we return 1 that means the value of *x has been set to 0. If we return
31 * 0 then we have left *x alone.
37 #include "smatch_slist.h"
38 #include "smatch_extra.h"
42 static struct smatch_state
*unmatched_state(struct sm_state
*sm
)
44 return alloc_estate_empty();
47 static void extra_mod_hook(const char *name
, struct symbol
*sym
, struct smatch_state
*state
)
49 if (get_param_num_from_sym(sym
) < 0)
51 set_state(my_id
, name
, sym
, state
);
55 * This relies on the fact that these states are stored so that
56 * foo->bar is before foo->bar->baz.
58 static int parent_set(struct string_list
*list
, const char *name
)
64 FOR_EACH_PTR(list
, tmp
) {
66 ret
= strncmp(tmp
, name
, len
);
73 } END_FOR_EACH_PTR(tmp
);
78 static void print_return_value_param(int return_id
, char *return_ranges
, struct expression
*expr
)
82 struct smatch_state
*extra
;
84 struct range_list
*rl
;
85 const char *param_name
;
86 struct string_list
*set_list
= NULL
;
89 stree
= __get_cur_stree();
91 FOR_EACH_MY_SM(my_id
, stree
, sm
) {
92 if (!estate_rl(sm
->state
))
94 extra
= get_state(SMATCH_EXTRA
, sm
->name
, sm
->sym
);
95 if (!estate_rl(extra
))
97 rl
= rl_intersection(estate_rl(sm
->state
), estate_rl(extra
));
101 param
= get_param_num_from_sym(sm
->sym
);
104 param_name
= get_param_name(sm
);
107 if (strcmp(param_name
, "$$") == 0)
110 math_str
= get_value_in_terms_of_parameter_math_var_sym(sm
->name
, sm
->sym
);
112 insert_string(&set_list
, (char *)sm
->name
);
113 sql_insert_return_states(return_id
, return_ranges
, ADDED_VALUE
,
114 param
, param_name
, math_str
);
118 /* no useful information here. */
119 if (is_whole_rl(rl
) && parent_set(set_list
, sm
->name
))
121 insert_string(&set_list
, (char *)sm
->name
);
123 sql_insert_return_states(return_id
, return_ranges
, ADDED_VALUE
,
124 param
, param_name
, show_rl(rl
));
125 } END_FOR_EACH_SM(sm
);
127 free_ptr_list((struct ptr_list
**)&set_list
);
130 int param_was_set(struct expression
*expr
)
132 if (get_state_expr(my_id
, expr
))
137 void register_param_set(int id
)
141 add_extra_mod_hook(&extra_mod_hook
);
142 add_unmatched_state_hook(my_id
, &unmatched_state
);
143 add_merge_hook(my_id
, &merge_estates
);
144 add_split_return_callback(&print_return_value_param
);