2 * sparse/smatch_param_set.c
4 * Copyright (C) 2012 Oracle.
6 * Licensed under the Open Software License version 1.1
12 #include "smatch_slist.h"
13 #include "smatch_extra.h"
17 static struct smatch_state
*unmatched_state(struct sm_state
*sm
)
19 return alloc_estate_empty();
22 static void extra_mod_hook(const char *name
, struct symbol
*sym
, struct smatch_state
*state
)
24 set_state(my_id
, name
, sym
, state
);
27 static const char *get_param_name(struct sm_state
*sm
)
33 param_name
= sm
->sym
->ident
->name
;
34 name_len
= strlen(param_name
);
36 if (sm
->name
[name_len
] == '-' && /* check for '-' from "->" */
37 strncmp(sm
->name
, param_name
, name_len
) == 0) {
38 snprintf(buf
, sizeof(buf
), "$$%s", sm
->name
+ name_len
);
40 } else if (sm
->name
[0] == '*' && strcmp(sm
->name
+ 1, param_name
) == 0) {
46 static void print_one_return_value_param(int return_id
, char *return_ranges
,
47 int param
, struct sm_state
*sm
, char *implied_rl
,
48 struct state_list
*slist
)
50 const char *param_name
;
52 param_name
= get_param_name(sm
);
56 sm_msg("info: return_param_add %d %d '%s' '%s' '%s' %s",
57 return_id
, param
, return_ranges
,
58 param_name
, implied_rl
, global_static());
61 static void print_return_value_param(int return_id
, char *return_ranges
, struct expression
*expr
, struct state_list
*slist
)
63 struct state_list
*my_slist
;
65 struct smatch_state
*extra
;
67 struct range_list
*rl
;
69 my_slist
= get_all_states_slist(my_id
, slist
);
71 FOR_EACH_PTR(my_slist
, sm
) {
72 if (!estate_ranges(sm
->state
))
74 extra
= get_state_slist(slist
, SMATCH_EXTRA
, sm
->name
, sm
->sym
);
75 if (!estate_ranges(extra
))
77 rl
= rl_intersection(estate_ranges(sm
->state
), estate_ranges(extra
));
81 param
= get_param_num_from_sym(sm
->sym
);
86 print_one_return_value_param(return_id
, return_ranges
, param
, sm
, show_ranges(rl
), slist
);
87 } END_FOR_EACH_PTR(sm
);
90 void register_param_set(int id
)
97 add_extra_mod_hook(&extra_mod_hook
);
98 add_unmatched_state_hook(my_id
, &unmatched_state
);
99 add_merge_hook(my_id
, &merge_estates
);
100 add_returned_state_callback(&print_return_value_param
);