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