12
12
#include < util/byte_operators.h>
13
13
#include < util/arith_tools.h>
14
14
#include < util/c_types.h>
15
+ #include < util/invariant.h>
15
16
16
17
bvt boolbvt::convert_member (const member_exprt &expr)
17
18
{
@@ -20,67 +21,49 @@ bvt boolbvt::convert_member(const member_exprt &expr)
20
21
21
22
const bvt &struct_bv=convert_bv (struct_op);
22
23
23
- if (struct_op_type.id ()==ID_union)
24
- {
25
- return convert_bv (
26
- byte_extract_exprt (byte_extract_id (),
27
- struct_op,
28
- from_integer (0 , index_type ()),
29
- expr.type ()));
30
- }
31
- else if (struct_op_type.id ()==ID_struct)
32
- {
33
- const irep_idt &component_name=expr.get_component_name ();
34
- const struct_typet::componentst &components=
35
- to_struct_type (struct_op_type).components ();
24
+ const irep_idt &component_name = expr.get_component_name ();
25
+ const struct_union_typet::componentst &components =
26
+ to_struct_union_type (struct_op_type).components ();
36
27
37
- std::size_t offset= 0 ;
28
+ std::size_t offset = 0 ;
38
29
39
- for (struct_typet::componentst::const_iterator
40
- it=components.begin ();
41
- it!=components.end ();
42
- it++)
43
- {
44
- const typet &subtype=it->type ();
45
- std::size_t sub_width=boolbv_width (subtype);
30
+ for (struct_union_typet::componentst::const_iterator it = components.begin ();
31
+ it != components.end ();
32
+ ++it)
33
+ {
34
+ const typet &subtype = it->type ();
35
+ const std::size_t sub_width = boolbv_width (subtype);
46
36
47
- if (it->get_name ()==component_name)
37
+ if (it->get_name () == component_name)
38
+ {
39
+ if (!base_type_eq (subtype, expr.type (), ns))
48
40
{
49
- if (!base_type_eq (subtype, expr.type (), ns))
50
- {
51
- #if 0
52
- std::cout << "DEBUG " << expr.pretty() << "\n";
53
- #endif
54
-
55
- error ().source_location =expr.find_source_location ();
56
- error () << " member: component type does not match: "
57
- << subtype.pretty () << " vs. "
58
- << expr.type ().pretty () << eom;
59
- throw 0 ;
60
- }
61
-
62
- bvt bv;
63
- bv.resize (sub_width);
64
- assert (offset+sub_width<=struct_bv.size ());
65
-
66
- for (std::size_t i=0 ; i<sub_width; i++)
67
- bv[i]=struct_bv[offset+i];
68
-
69
- return bv;
41
+ #if 0
42
+ std::cout << "DEBUG " << expr.pretty() << "\n";
43
+ #endif
44
+
45
+ error ().source_location = expr.find_source_location ();
46
+ error () << " member: component type does not match: " << subtype.pretty ()
47
+ << " vs. " << expr.type ().pretty () << eom;
48
+ throw 0 ;
70
49
}
71
50
72
- offset+=sub_width;
51
+ bvt bv;
52
+ bv.resize (sub_width);
53
+ DATA_INVARIANT (
54
+ offset + sub_width <= struct_bv.size (), " member access outside struct" );
55
+
56
+ for (std::size_t i = 0 ; i < sub_width; i++)
57
+ bv[i] = struct_bv[offset + i];
58
+
59
+ return bv;
73
60
}
74
61
75
- error ().source_location =expr.find_source_location ();
76
- error () << " component " << component_name
77
- << " not found in structure" << eom;
78
- throw 0 ;
79
- }
80
- else
81
- {
82
- error ().source_location =expr.find_source_location ();
83
- error () << " member takes struct or union operand" << eom;
84
- throw 0 ;
62
+ if (struct_op_type.id () == ID_struct)
63
+ offset += sub_width;
85
64
}
65
+
66
+ error ().source_location = expr.find_source_location ();
67
+ error () << " component " << component_name << " not found in structure" << eom;
68
+ throw 0 ;
86
69
}
0 commit comments