|
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; |
45 | 42 | bit_field_bits %= 8;
|
46 | 43 | }
|
47 | 44 | else if(comp.type().id() == ID_bool)
|
48 | 45 | {
|
49 | 46 | ++bit_field_bits;
|
50 |
| - current.second += bit_field_bits / 8; |
| 47 | + result += bit_field_bits / 8; |
51 | 48 | bit_field_bits %= 8;
|
52 | 49 | }
|
53 | 50 | else
|
54 | 51 | {
|
55 | 52 | DATA_INVARIANT(
|
56 | 53 | bit_field_bits == 0, "padding ensures offset at byte boundaries");
|
57 |
| - const typet &subtype=comp.type(); |
58 |
| - |
59 |
| - auto sub_size = pointer_offset_size(subtype, ns); |
60 |
| - |
| 54 | + const auto sub_size = pointer_offset_size(comp.type(), ns); |
61 | 55 | if(!sub_size.has_value())
|
62 |
| - current.second=-1; // give up |
| 56 | + return {}; |
63 | 57 | else
|
64 |
| - current.second += *sub_size; |
| 58 | + result += *sub_size; |
65 | 59 | }
|
66 | 60 | }
|
67 |
| - ++current.first; |
68 |
| - return *this; |
69 |
| -} |
70 | 61 |
|
71 |
| -optionalt<mp_integer> member_offset( |
72 |
| - const struct_typet &type, |
73 |
| - const irep_idt &member, |
74 |
| - const namespacet &ns) |
75 |
| -{ |
76 |
| - const struct_typet::componentst &components=type.components(); |
77 |
| - member_offset_iterator offsets(type, ns); |
78 |
| - |
79 |
| - for(struct_typet::componentst::const_iterator |
80 |
| - it=components.begin(); |
81 |
| - it!=components.end() && offsets->second!=-1; |
82 |
| - ++it, ++offsets) |
83 |
| - { |
84 |
| - if(it->get_name()==member) |
85 |
| - break; |
86 |
| - } |
87 |
| - |
88 |
| - return offsets->second; |
| 62 | + return result; |
89 | 63 | }
|
90 | 64 |
|
91 | 65 | optionalt<mp_integer> member_offset_bits(
|
|
0 commit comments