|
21 | 21 | #include <util/simplify_expr.h>
|
22 | 22 | #include <util/string_constant.h>
|
23 | 23 |
|
24 |
| -/// Determine the member of maximum fixed bit width in a union type. If no |
25 |
| -/// member, or no member of fixed and non-zero width can be found, return |
26 |
| -/// nullopt. |
27 |
| -/// \param union_type: Type to determine the member of. |
28 |
| -/// \param ns: Namespace to resolve tag types. |
29 |
| -/// \return Pair of a componentt pointing to the maximum fixed bit-width |
30 |
| -/// member of \p union_type and the bit width of that member. |
31 |
| -static optionalt<std::pair<struct_union_typet::componentt, mp_integer>> |
32 |
| -find_widest_union_component(const union_typet &union_type, const namespacet &ns) |
33 |
| -{ |
34 |
| - const union_typet::componentst &components = union_type.components(); |
35 |
| - |
36 |
| - mp_integer max_width = 0; |
37 |
| - typet max_comp_type; |
38 |
| - irep_idt max_comp_name; |
39 |
| - |
40 |
| - for(const auto &comp : components) |
41 |
| - { |
42 |
| - auto element_width = pointer_offset_bits(comp.type(), ns); |
43 |
| - |
44 |
| - if(!element_width.has_value() || *element_width <= max_width) |
45 |
| - continue; |
46 |
| - |
47 |
| - max_width = *element_width; |
48 |
| - max_comp_type = comp.type(); |
49 |
| - max_comp_name = comp.get_name(); |
50 |
| - } |
51 |
| - |
52 |
| - if(max_width == 0) |
53 |
| - return {}; |
54 |
| - else |
55 |
| - return std::make_pair( |
56 |
| - struct_union_typet::componentt{max_comp_name, max_comp_type}, max_width); |
57 |
| -} |
58 |
| - |
59 | 24 | static exprt bv_to_expr(
|
60 | 25 | const exprt &bitvector_expr,
|
61 | 26 | const typet &target_type,
|
@@ -155,7 +120,7 @@ static union_exprt bv_to_union_expr(
|
155 | 120 | if(components.empty())
|
156 | 121 | return union_exprt{irep_idt{}, nil_exprt{}, union_type};
|
157 | 122 |
|
158 |
| - const auto widest_member = find_widest_union_component(union_type, ns); |
| 123 | + const auto widest_member = union_type.find_widest_union_component(ns); |
159 | 124 |
|
160 | 125 | std::size_t component_bits;
|
161 | 126 | if(widest_member.has_value())
|
@@ -1222,7 +1187,7 @@ exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns)
|
1222 | 1187 | {
|
1223 | 1188 | const union_typet &union_type = to_union_type(ns.follow(src.type()));
|
1224 | 1189 |
|
1225 |
| - const auto widest_member = find_widest_union_component(union_type, ns); |
| 1190 | + const auto widest_member = union_type.find_widest_union_component(ns); |
1226 | 1191 |
|
1227 | 1192 | if(widest_member.has_value())
|
1228 | 1193 | {
|
@@ -2029,7 +1994,7 @@ static exprt lower_byte_update_union(
|
2029 | 1994 | const optionalt<exprt> &non_const_update_bound,
|
2030 | 1995 | const namespacet &ns)
|
2031 | 1996 | {
|
2032 |
| - const auto widest_member = find_widest_union_component(union_type, ns); |
| 1997 | + const auto widest_member = union_type.find_widest_union_component(ns); |
2033 | 1998 |
|
2034 | 1999 | PRECONDITION_WITH_DIAGNOSTICS(
|
2035 | 2000 | widest_member.has_value(),
|
|
0 commit comments