2 * sparse/smatch_param_set.c
4 * Copyright (C) 2012 Oracle.
6 * Licensed under the Open Software License version 1.1
11 * This is for functions like:
22 * If we return 1 that means the value of *x has been set to 0. If we return
23 * 0 then we have left *x alone.
29 #include "smatch_slist.h"
30 #include "smatch_extra.h"
34 static struct smatch_state
*unmatched_state(struct sm_state
*sm
)
36 return alloc_estate_empty();
39 static void extra_mod_hook(const char *name
, struct symbol
*sym
, struct smatch_state
*state
)
41 set_state(my_id
, name
, sym
, state
);
44 static void print_one_return_value_param(int return_id
, char *return_ranges
,
45 int param
, struct sm_state
*sm
, char *implied_rl
)
47 const char *param_name
;
49 param_name
= get_param_name(sm
);
52 if (strcmp(param_name
, "$$") == 0)
55 sql_insert_return_states(return_id
, return_ranges
, ADDED_VALUE
, param
,
56 param_name
, implied_rl
);
59 static void print_return_value_param(int return_id
, char *return_ranges
, struct expression
*expr
)
61 struct state_list
*my_slist
;
63 struct smatch_state
*extra
;
65 struct range_list
*rl
;
67 my_slist
= get_all_states(my_id
);
69 FOR_EACH_PTR(my_slist
, sm
) {
70 if (!estate_rl(sm
->state
))
72 extra
= get_state(SMATCH_EXTRA
, sm
->name
, sm
->sym
);
73 if (!estate_rl(extra
))
75 rl
= rl_intersection(estate_rl(sm
->state
), estate_rl(extra
));
79 param
= get_param_num_from_sym(sm
->sym
);
84 print_one_return_value_param(return_id
, return_ranges
, param
, sm
, show_rl(rl
));
85 } END_FOR_EACH_PTR(sm
);
88 void register_param_set(int id
)
92 add_extra_mod_hook(&extra_mod_hook
);
93 add_unmatched_state_hook(my_id
, &unmatched_state
);
94 add_merge_hook(my_id
, &merge_estates
);
95 add_split_return_callback(&print_return_value_param
);