15
15
16
16
#include " bv_endianness_map.h"
17
17
18
- bvt boolbvt::convert_with (const exprt &expr)
18
+ bvt boolbvt::convert_with (const with_exprt &expr)
19
19
{
20
- if (expr.operands ().size ()<3 )
21
- {
22
- log.error ().source_location = expr.find_source_location ();
23
- log.error () << " with takes at least three operands" << messaget::eom;
24
- throw 0 ;
25
- }
26
-
27
- if ((expr.operands ().size ()%2 )!=1 )
28
- {
29
- log.error ().source_location = expr.find_source_location ();
30
- log.error () << " with takes an odd number of operands" << messaget::eom;
31
- throw 0 ;
32
- }
33
-
34
- bvt bv=convert_bv (expr.op0 ());
20
+ bvt bv = convert_bv (expr.old ());
35
21
36
22
std::size_t width=boolbv_width (expr.type ());
37
23
@@ -44,12 +30,10 @@ bvt boolbvt::convert_with(const exprt &expr)
44
30
return conversion_failed (expr);
45
31
}
46
32
47
- if (bv.size ()!=width)
48
- {
49
- log.error ().source_location = expr.find_source_location ();
50
- log.error () << " unexpected operand 0 width" << messaget::eom;
51
- throw 0 ;
52
- }
33
+ DATA_INVARIANT_WITH_DIAGNOSTICS (
34
+ bv.size () == width,
35
+ " unexpected operand 0 width" ,
36
+ irep_pretty_diagnosticst{expr});
53
37
54
38
bvt prev_bv;
55
39
prev_bv.resize (width);
@@ -60,12 +44,7 @@ bvt boolbvt::convert_with(const exprt &expr)
60
44
{
61
45
bv.swap (prev_bv);
62
46
63
- convert_with (
64
- expr.op0 ().type (),
65
- ops[op_no],
66
- ops[op_no+1 ],
67
- prev_bv,
68
- bv);
47
+ convert_with (expr.old ().type (), ops[op_no], ops[op_no + 1 ], prev_bv, bv);
69
48
}
70
49
71
50
return bv;
@@ -100,9 +79,8 @@ void boolbvt::convert_with(
100
79
return convert_with (
101
80
ns.follow_tag (to_union_tag_type (type)), op1, op2, prev_bv, next_bv);
102
81
103
- log.error ().source_location = type.source_location ();
104
- log.error () << " unexpected with type: " << type.id () << messaget::eom;
105
- throw 0 ;
82
+ DATA_INVARIANT_WITH_DIAGNOSTICS (
83
+ false , " unexpected with type" , irep_pretty_diagnosticst{type});
106
84
}
107
85
108
86
void boolbvt::convert_with_array (
@@ -112,36 +90,27 @@ void boolbvt::convert_with_array(
112
90
const bvt &prev_bv,
113
91
bvt &next_bv)
114
92
{
115
- if (is_unbounded_array (type))
116
- {
117
- // can't do this
118
- log.error ().source_location = type.source_location ();
119
- log.error () << " convert_with_array called for unbounded array"
120
- << messaget::eom;
121
- throw 0 ;
122
- }
93
+ // can't do this
94
+ DATA_INVARIANT_WITH_DIAGNOSTICS (
95
+ !is_unbounded_array (type),
96
+ " convert_with_array called for unbounded array" ,
97
+ irep_pretty_diagnosticst{type});
123
98
124
99
const exprt &array_size=type.size ();
125
100
126
101
const auto size = numeric_cast<mp_integer>(array_size);
127
102
128
- if (!size.has_value ())
129
- {
130
- log.error ().source_location = type.source_location ();
131
- log.error () << " convert_with_array expects constant array size"
132
- << messaget::eom;
133
- throw 0 ;
134
- }
103
+ DATA_INVARIANT_WITH_DIAGNOSTICS (
104
+ size.has_value (),
105
+ " convert_with_array expects constant array size" ,
106
+ irep_pretty_diagnosticst{type});
135
107
136
108
const bvt &op2_bv=convert_bv (op2);
137
109
138
- if (*size * op2_bv.size () != prev_bv.size ())
139
- {
140
- log.error ().source_location = type.source_location ();
141
- log.error () << " convert_with_array: unexpected operand 2 width"
142
- << messaget::eom;
143
- throw 0 ;
144
- }
110
+ DATA_INVARIANT_WITH_DIAGNOSTICS (
111
+ *size * op2_bv.size () == prev_bv.size (),
112
+ " convert_with_array: unexpected operand 2 width" ,
113
+ irep_pretty_diagnosticst{type});
145
114
146
115
// Is the index a constant?
147
116
if (const auto op1_value = numeric_cast<mp_integer>(op1))
@@ -232,22 +201,17 @@ void boolbvt::convert_with_struct(
232
201
233
202
if (c.get_name () == component_name)
234
203
{
235
- if (subtype != op2.type ())
236
- {
237
- log.error ().source_location = type.source_location ();
238
- log.error () << " with/struct: component `" << component_name
239
- << " ' type does not match: " << subtype.pretty () << " vs. "
240
- << op2.type ().pretty () << messaget::eom;
241
- throw 0 ;
242
- }
243
-
244
- if (sub_width!=op2_bv.size ())
245
- {
246
- log.error ().source_location = type.source_location ();
247
- log.error () << " convert_with_struct: unexpected operand op2 width"
248
- << messaget::eom;
249
- throw 0 ;
250
- }
204
+ DATA_INVARIANT_WITH_DIAGNOSTICS (
205
+ subtype == op2.type (),
206
+ " with/struct: component `" + id2string (component_name) +
207
+ " ' type does not match" ,
208
+ irep_pretty_diagnosticst{subtype},
209
+ irep_pretty_diagnosticst{op2.type ()});
210
+
211
+ DATA_INVARIANT_WITH_DIAGNOSTICS (
212
+ sub_width == op2_bv.size (),
213
+ " convert_with_struct: unexpected operand op2 width" ,
214
+ irep_pretty_diagnosticst{type});
251
215
252
216
for (std::size_t i=0 ; i<sub_width; i++)
253
217
next_bv[offset+i]=op2_bv[i];
@@ -269,13 +233,10 @@ void boolbvt::convert_with_union(
269
233
270
234
const bvt &op2_bv=convert_bv (op2);
271
235
272
- if (next_bv.size ()<op2_bv.size ())
273
- {
274
- log.error ().source_location = type.source_location ();
275
- log.error () << " convert_with_union: unexpected operand op2 width"
276
- << messaget::eom;
277
- throw 0 ;
278
- }
236
+ DATA_INVARIANT_WITH_DIAGNOSTICS (
237
+ next_bv.size () >= op2_bv.size (),
238
+ " convert_with_union: unexpected operand op2 width" ,
239
+ irep_pretty_diagnosticst{type});
279
240
280
241
if (config.ansi_c .endianness ==configt::ansi_ct::endiannesst::IS_LITTLE_ENDIAN)
281
242
{
0 commit comments