|
21 | 21 | #include "ssa_expr.h"
|
22 | 22 | #include "std_expr.h"
|
23 | 23 |
|
24 |
| -member_offset_iterator::member_offset_iterator( |
25 |
| - const struct_typet &_type, |
26 |
| - const namespacet &_ns): |
27 |
| - current({0, 0}), |
28 |
| - type(_type), |
29 |
| - ns(_ns), |
30 |
| - bit_field_bits(0) |
| 24 | +optionalt<mp_integer> member_offset( |
| 25 | + const struct_typet &type, |
| 26 | + const irep_idt &member, |
| 27 | + const namespacet &ns) |
31 | 28 | {
|
32 |
| -} |
| 29 | + mp_integer result = 0; |
| 30 | + std::size_t bit_field_bits = 0; |
33 | 31 |
|
34 |
| -member_offset_iterator &member_offset_iterator::operator++() |
35 |
| -{ |
36 |
| - if(current.second!=-1) // Already failed? |
| 32 | + for(const auto &comp : type.components()) |
37 | 33 | {
|
38 |
| - const auto &comp=type.components()[current.first]; |
39 |
| - if(comp.type().id()==ID_c_bit_field) |
| 34 | + if(comp.get_name() == member) |
| 35 | + return result; |
| 36 | + |
| 37 | + if(comp.type().id() == ID_c_bit_field) |
40 | 38 | {
|
41 |
| - // take the extra bytes needed |
42 |
| - std::size_t w=to_c_bit_field_type(comp.type()).get_width(); |
| 39 | + const std::size_t w = to_c_bit_field_type(comp.type()).get_width(); |
43 | 40 | bit_field_bits += w;
|
44 |
| - current.second += bit_field_bits / 8; |
| 41 | + result += bit_field_bits / 8; |
| 42 | + bit_field_bits %= 8; |
| 43 | + } |
| 44 | + else if(comp.type().id() == ID_bool) |
| 45 | + { |
| 46 | + ++bit_field_bits; |
| 47 | + result += bit_field_bits / 8; |
45 | 48 | bit_field_bits %= 8;
|
46 | 49 | }
|
47 | 50 | else
|
48 | 51 | {
|
49 | 52 | DATA_INVARIANT(
|
50 | 53 | bit_field_bits == 0, "padding ensures offset at byte boundaries");
|
51 |
| - const typet &subtype=comp.type(); |
52 |
| - |
53 |
| - auto sub_size = pointer_offset_size(subtype, ns); |
54 |
| - |
| 54 | + const auto sub_size = pointer_offset_size(comp.type(), ns); |
55 | 55 | if(!sub_size.has_value())
|
56 |
| - current.second=-1; // give up |
| 56 | + return {}; |
57 | 57 | else
|
58 |
| - current.second += *sub_size; |
| 58 | + result += *sub_size; |
59 | 59 | }
|
60 | 60 | }
|
61 |
| - ++current.first; |
62 |
| - return *this; |
63 |
| -} |
64 | 61 |
|
65 |
| -optionalt<mp_integer> member_offset( |
66 |
| - const struct_typet &type, |
67 |
| - const irep_idt &member, |
68 |
| - const namespacet &ns) |
69 |
| -{ |
70 |
| - const struct_typet::componentst &components=type.components(); |
71 |
| - member_offset_iterator offsets(type, ns); |
72 |
| - |
73 |
| - for(struct_typet::componentst::const_iterator |
74 |
| - it=components.begin(); |
75 |
| - it!=components.end() && offsets->second!=-1; |
76 |
| - ++it, ++offsets) |
77 |
| - { |
78 |
| - if(it->get_name()==member) |
79 |
| - break; |
80 |
| - } |
81 |
| - |
82 |
| - return offsets->second; |
| 62 | + return result; |
83 | 63 | }
|
84 | 64 |
|
85 | 65 | optionalt<mp_integer> member_offset_bits(
|
|
0 commit comments