6
6
7
7
\*******************************************************************/
8
8
9
- #include " boolbv.h"
10
-
11
9
#include < util/arith_tools.h>
12
10
#include < util/c_types.h>
13
11
#include < util/namespace.h>
14
12
#include < util/simplify_expr.h>
15
13
#include < util/std_expr.h>
16
14
#include < util/threeval.h>
17
15
16
+ #include " boolbv.h"
18
17
#include " boolbv_type.h"
19
18
19
+ #include < iostream>
20
+
20
21
exprt boolbvt::get (const exprt &expr) const
21
22
{
22
23
if (expr.id ()==ID_symbol ||
@@ -33,21 +34,26 @@ exprt boolbvt::get(const exprt &expr) const
33
34
// the value of clock symbols, which do not have a fixed type as the clock
34
35
// type is computed during symbolic execution) or match the type stored in
35
36
// the mapping
36
- PRECONDITION (expr.type () == typet () || expr.type () == map_entry.type );
37
-
38
- return bv_get_rec (expr, map_entry.literal_map , 0 , map_entry.type );
37
+ if (expr.type () == map_entry.type )
38
+ return bv_get_rec (expr, map_entry.literal_map , 0 );
39
+ else
40
+ {
41
+ PRECONDITION (expr.type () == typet{});
42
+ exprt skeleton = expr;
43
+ skeleton.type () = map_entry.type ;
44
+ return bv_get_rec (skeleton, map_entry.literal_map , 0 );
45
+ }
39
46
}
40
47
}
41
48
42
49
return SUB::get (expr);
43
50
}
44
51
45
- exprt boolbvt::bv_get_rec (
46
- const exprt &expr,
47
- const bvt &bv,
48
- std::size_t offset,
49
- const typet &type) const
52
+ exprt boolbvt::bv_get_rec (const exprt &expr, const bvt &bv, std::size_t offset)
53
+ const
50
54
{
55
+ const typet &type = expr.type ();
56
+
51
57
if (type.id ()==ID_bool)
52
58
{
53
59
PRECONDITION (bv.size () > offset);
@@ -91,7 +97,7 @@ exprt boolbvt::bv_get_rec(
91
97
const index_exprt index {
92
98
expr,
93
99
from_integer (new_offset / sub_width, array_type.index_type ())};
94
- op.push_back (bv_get_rec (index , bv, offset + new_offset, subtype ));
100
+ op.push_back (bv_get_rec (index , bv, offset + new_offset));
95
101
}
96
102
97
103
exprt dest=exprt (ID_array, type);
@@ -103,24 +109,12 @@ exprt boolbvt::bv_get_rec(
103
109
return array_exprt{{}, array_type};
104
110
}
105
111
}
106
- else if (type.id ()==ID_struct_tag)
107
- {
108
- exprt result =
109
- bv_get_rec (expr, bv, offset, ns.follow_tag (to_struct_tag_type (type)));
110
- result.type () = type;
111
- return result;
112
- }
113
- else if (type.id ()==ID_union_tag)
114
- {
115
- exprt result =
116
- bv_get_rec (expr, bv, offset, ns.follow_tag (to_union_tag_type (type)));
117
- result.type () = type;
118
- return result;
119
- }
120
- else if (type.id ()==ID_struct)
112
+ else if (type.id () == ID_struct || type.id () == ID_struct_tag)
121
113
{
122
- const struct_typet &struct_type=to_struct_type (type);
123
- const struct_typet::componentst &components=struct_type.components ();
114
+ const struct_typet::componentst &components =
115
+ type.id () == ID_struct
116
+ ? to_struct_type (type).components ()
117
+ : ns.follow_tag (to_struct_tag_type (type)).components ();
124
118
std::size_t new_offset=0 ;
125
119
exprt::operandst op;
126
120
op.reserve (components.size ());
@@ -130,17 +124,19 @@ exprt boolbvt::bv_get_rec(
130
124
const typet &subtype = c.type ();
131
125
132
126
const member_exprt member{expr, c.get_name (), subtype};
133
- op.push_back (bv_get_rec (member, bv, offset + new_offset, subtype ));
127
+ op.push_back (bv_get_rec (member, bv, offset + new_offset));
134
128
135
129
new_offset += boolbv_width (subtype);
136
130
}
137
131
138
132
return struct_exprt (std::move (op), type);
139
133
}
140
- else if (type.id ()== ID_union)
134
+ else if (type.id () == ID_union || type. id () == ID_union_tag )
141
135
{
142
- const union_typet &union_type=to_union_type (type);
143
- const union_typet::componentst &components=union_type.components ();
136
+ const union_typet::componentst &components =
137
+ type.id () == ID_union
138
+ ? to_union_type (type).components ()
139
+ : ns.follow_tag (to_union_tag_type (type)).components ();
144
140
145
141
if (components.empty ())
146
142
return empty_union_exprt (type);
@@ -154,8 +150,8 @@ exprt boolbvt::bv_get_rec(
154
150
expr, components[component_nr].get_name (), subtype};
155
151
return union_exprt (
156
152
components[component_nr].get_name (),
157
- bv_get_rec (member, bv, offset, subtype ),
158
- union_type );
153
+ bv_get_rec (member, bv, offset),
154
+ type );
159
155
}
160
156
else if (type.id ()==ID_vector)
161
157
{
@@ -176,8 +172,7 @@ exprt boolbvt::bv_get_rec(
176
172
{
177
173
const index_exprt index {expr,
178
174
from_integer (i, vector_type.index_type ())};
179
- value.operands ().push_back (
180
- bv_get_rec (index , bv, i * element_width, element_type));
175
+ value.operands ().push_back (bv_get_rec (index , bv, i * element_width));
181
176
}
182
177
183
178
return std::move (value);
@@ -195,8 +190,8 @@ exprt boolbvt::bv_get_rec(
195
190
" complex type has two elements of equal bit width" );
196
191
197
192
return complex_exprt{
198
- bv_get_rec (complex_real_exprt{expr}, bv, 0 * sub_width, subtype ),
199
- bv_get_rec (complex_imag_exprt{expr}, bv, 1 * sub_width, subtype ),
193
+ bv_get_rec (complex_real_exprt{expr}, bv, 0 * sub_width),
194
+ bv_get_rec (complex_imag_exprt{expr}, bv, 1 * sub_width),
200
195
to_complex_type (type)};
201
196
}
202
197
}
@@ -274,7 +269,9 @@ exprt boolbvt::bv_get_rec(
274
269
275
270
exprt boolbvt::bv_get (const bvt &bv, const typet &type) const
276
271
{
277
- return bv_get_rec (nil_exprt{}, bv, 0 , type);
272
+ nil_exprt skeleton;
273
+ skeleton.type () = type;
274
+ return bv_get_rec (skeleton, bv, 0 );
278
275
}
279
276
280
277
exprt boolbvt::bv_get_cache (const exprt &expr) const
0 commit comments