|
11 | 11 | #include <util/c_types.h>
|
12 | 12 | #include <util/namespace.h>
|
13 | 13 |
|
14 |
| -static bvt convert_member_struct( |
15 |
| - const member_exprt &expr, |
16 |
| - const bvt &struct_bv, |
17 |
| - const std::function<std::size_t(const typet &)> boolbv_width, |
18 |
| - const namespacet &ns) |
19 |
| -{ |
20 |
| - const exprt &struct_op=expr.struct_op(); |
21 |
| - const typet &struct_op_type=ns.follow(struct_op.type()); |
22 |
| - |
23 |
| - const irep_idt &component_name = expr.get_component_name(); |
24 |
| - const struct_typet::componentst &components = |
25 |
| - to_struct_type(struct_op_type).components(); |
26 |
| - |
27 |
| - std::size_t offset = 0; |
28 |
| - |
29 |
| - for(const auto &c : components) |
30 |
| - { |
31 |
| - const typet &subtype = c.type(); |
32 |
| - const std::size_t sub_width = boolbv_width(subtype); |
33 |
| - |
34 |
| - if(c.get_name() == component_name) |
35 |
| - { |
36 |
| - DATA_INVARIANT_WITH_DIAGNOSTICS( |
37 |
| - subtype == expr.type(), |
38 |
| - "component type shall match the member expression type", |
39 |
| - subtype.pretty(), |
40 |
| - expr.type().pretty()); |
41 |
| - INVARIANT( |
42 |
| - offset + sub_width <= struct_bv.size(), |
43 |
| - "bitvector part corresponding to element shall be contained within the " |
44 |
| - "full aggregate bitvector"); |
45 |
| - |
46 |
| - return bvt( |
47 |
| - struct_bv.begin() + offset, struct_bv.begin() + offset + sub_width); |
48 |
| - } |
49 |
| - |
50 |
| - offset += sub_width; |
51 |
| - } |
52 |
| - |
53 |
| - INVARIANT_WITH_DIAGNOSTICS( |
54 |
| - false, |
55 |
| - "struct type shall contain component accessed by member expression", |
56 |
| - expr.find_source_location(), |
57 |
| - id2string(component_name)); |
58 |
| -} |
59 |
| - |
60 | 14 | static bvt convert_member_union(
|
61 | 15 | const member_exprt &expr,
|
62 | 16 | const bvt &union_bv,
|
@@ -94,11 +48,22 @@ bvt boolbvt::convert_member(const member_exprt &expr)
|
94 | 48 | const bvt &compound_bv = convert_bv(expr.compound());
|
95 | 49 |
|
96 | 50 | if(expr.compound().type().id() == ID_struct_tag)
|
97 |
| - return convert_member_struct( |
98 |
| - expr, |
99 |
| - compound_bv, |
100 |
| - [this](const typet &t) { return boolbv_width(t); }, |
101 |
| - ns); |
| 51 | + { |
| 52 | + const struct_typet &struct_op_type = |
| 53 | + ns.follow_tag(to_struct_tag_type(expr.compound().type())); |
| 54 | + |
| 55 | + const auto &member_bits = |
| 56 | + bv_width.get_member(struct_op_type, expr.get_component_name()); |
| 57 | + |
| 58 | + INVARIANT( |
| 59 | + member_bits.offset + member_bits.width <= compound_bv.size(), |
| 60 | + "bitvector part corresponding to element shall be contained within the " |
| 61 | + "full aggregate bitvector"); |
| 62 | + |
| 63 | + return bvt( |
| 64 | + compound_bv.begin() + member_bits.offset, |
| 65 | + compound_bv.begin() + member_bits.offset + member_bits.width); |
| 66 | + } |
102 | 67 | else
|
103 | 68 | {
|
104 | 69 | PRECONDITION(expr.compound().type().id() == ID_union_tag);
|
|
0 commit comments