2 * smatch/smatch_dinfo.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 * smatch_dinfo.c has helper functions for handling data_info structs
22 #include "smatch_slist.h"
23 #include "smatch_extra.h"
25 struct data_range whole_range
= {
30 static struct data_info
*alloc_dinfo(void)
32 struct data_info
*ret
;
34 ret
= __alloc_data_info(0);
36 ret
->type
= DATA_RANGE
;
37 ret
->value_ranges
= NULL
;
41 static struct data_info
*alloc_dinfo_range(long long min
, long long max
)
43 struct data_info
*ret
;
46 add_range(&ret
->value_ranges
, min
, max
);
50 static struct data_info
*alloc_dinfo_range_list(struct range_list
*rl
)
52 struct data_info
*ret
;
55 ret
->value_ranges
= rl
;
59 static struct data_info
*clone_dinfo(struct data_info
*dinfo
)
61 struct data_info
*ret
;
64 ret
->related
= clone_related_list(dinfo
->related
);
65 ret
->value_ranges
= clone_range_list(dinfo
->value_ranges
);
69 struct smatch_state
*clone_extra_state(struct smatch_state
*state
)
71 struct smatch_state
*ret
;
73 ret
= __alloc_smatch_state(0);
74 ret
->name
= state
->name
;
75 ret
->data
= clone_dinfo(get_dinfo(state
));
79 struct smatch_state
*alloc_extra_state_empty(void)
81 struct smatch_state
*state
;
82 struct data_info
*dinfo
;
84 dinfo
= alloc_dinfo();
85 state
= __alloc_smatch_state(0);
91 static struct smatch_state
*alloc_extra_state_no_name(int val
)
93 struct smatch_state
*state
;
95 state
= __alloc_smatch_state(0);
96 state
->data
= (void *)alloc_dinfo_range(val
, val
);
100 /* We do this because ->value_ranges is a list */
101 struct smatch_state
*extra_undefined(void)
103 struct data_info
*dinfo
;
104 static struct smatch_state
*ret
;
105 static struct symbol
*prev_func
;
107 if (prev_func
== cur_func_sym
)
109 prev_func
= cur_func_sym
;
111 dinfo
= alloc_dinfo_range(whole_range
.min
, whole_range
.max
);
112 ret
= __alloc_smatch_state(0);
113 ret
->name
= "unknown";
118 struct smatch_state
*alloc_extra_state(long long val
)
120 struct smatch_state
*state
;
122 state
= alloc_extra_state_no_name(val
);
123 state
->name
= show_ranges(get_dinfo(state
)->value_ranges
);
127 struct smatch_state
*alloc_extra_state_range(long long min
, long long max
)
129 struct smatch_state
*state
;
131 if (min
== whole_range
.min
&& max
== whole_range
.max
)
132 return extra_undefined();
133 state
= __alloc_smatch_state(0);
134 state
->data
= (void *)alloc_dinfo_range(min
, max
);
135 state
->name
= show_ranges(get_dinfo(state
)->value_ranges
);
139 struct smatch_state
*alloc_extra_state_range_list(struct range_list
*rl
)
141 struct smatch_state
*state
;
143 if (is_whole_range_rl(rl
))
144 return extra_undefined();
146 state
= __alloc_smatch_state(0);
147 state
->data
= (void *)alloc_dinfo_range_list(rl
);
148 state
->name
= show_ranges(get_dinfo(state
)->value_ranges
);