Skip to content

Commit ee79ae2

Browse files
authored
Merge pull request #5025 from diffblue/solvers-opX
fix accesses to exprt::opX() in solvers/
2 parents 001b6f9 + dbf0058 commit ee79ae2

26 files changed

+375
-378
lines changed

src/solvers/flattening/arrays.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,12 @@ void arrayst::collect_arrays(const exprt &a)
186186
}
187187
else if(a.id()==ID_member)
188188
{
189+
const auto &struct_op = to_member_expr(a).struct_op();
190+
189191
DATA_INVARIANT(
190-
to_member_expr(a).struct_op().id() == ID_symbol ||
191-
to_member_expr(a).struct_op().id() == ID_nondet_symbol,
192-
("unexpected array expression: member with '" + a.op0().id_string() + "'")
193-
.c_str());
192+
struct_op.id() == ID_symbol || struct_op.id() == ID_nondet_symbol,
193+
"unexpected array expression: member with '" + struct_op.id_string() +
194+
"'");
194195
}
195196
else if(a.id()==ID_constant ||
196197
a.id()==ID_array ||
@@ -209,24 +210,22 @@ void arrayst::collect_arrays(const exprt &a)
209210
}
210211
else if(a.id()==ID_typecast)
211212
{
212-
// cast between array types?
213-
DATA_INVARIANT(
214-
a.operands().size()==1,
215-
"typecast must have one operand");
213+
const auto &typecast_op = to_typecast_expr(a).op();
216214

215+
// cast between array types?
217216
DATA_INVARIANT(
218-
a.op0().type().id()==ID_array,
219-
("unexpected array type cast from "+
220-
a.op0().type().id_string()).c_str());
217+
typecast_op.type().id() == ID_array,
218+
"unexpected array type cast from " + typecast_op.type().id_string());
221219

222-
arrays.make_union(a, a.op0());
223-
collect_arrays(a.op0());
220+
arrays.make_union(a, typecast_op);
221+
collect_arrays(typecast_op);
224222
}
225223
else if(a.id()==ID_index)
226224
{
227225
// nested unbounded arrays
228-
arrays.make_union(a, a.op0());
229-
collect_arrays(a.op0());
226+
const auto &array_op = to_index_expr(a).array();
227+
arrays.make_union(a, array_op);
228+
collect_arrays(array_op);
230229
}
231230
else if(a.id() == ID_array_comprehension)
232231
{
@@ -235,8 +234,7 @@ void arrayst::collect_arrays(const exprt &a)
235234
{
236235
DATA_INVARIANT(
237236
false,
238-
("unexpected array expression (collect_arrays): '" + a.id_string() + "'")
239-
.c_str());
237+
"unexpected array expression (collect_arrays): '" + a.id_string() + "'");
240238
}
241239
}
242240

@@ -496,16 +494,14 @@ void arrayst::add_array_constraints(
496494
else if(expr.id()==ID_typecast)
497495
{
498496
// we got a=(type[])b
499-
DATA_INVARIANT(
500-
expr.operands().size()==1,
501-
"typecast should have one operand");
497+
const auto &expr_typecast_op = to_typecast_expr(expr).op();
502498

503499
// add a[i]=b[i]
504500
for(const auto &index : index_set)
505501
{
506502
const typet &subtype = expr.type().subtype();
507503
index_exprt index_expr1(expr, index, subtype);
508-
index_exprt index_expr2(expr.op0(), index, subtype);
504+
index_exprt index_expr2(expr_typecast_op, index, subtype);
509505

510506
DATA_INVARIANT(
511507
index_expr1.type()==index_expr2.type(),
@@ -524,9 +520,8 @@ void arrayst::add_array_constraints(
524520
{
525521
DATA_INVARIANT(
526522
false,
527-
("unexpected array expression (add_array_constraints): '" +
528-
expr.id_string() + "'")
529-
.c_str());
523+
"unexpected array expression (add_array_constraints): '" +
524+
expr.id_string() + "'");
530525
}
531526
}
532527

src/solvers/flattening/boolbv.cpp

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bool boolbvt::literal(
9797
const typet &subtype = c.type();
9898

9999
if(c.get_name() == component_name)
100-
return literal(expr.op0(), bit+offset, dest);
100+
return literal(member_expr.struct_op(), bit + offset, dest);
101101

102102
std::size_t element_width=boolbv_width(subtype);
103103
CHECK_RETURN(element_width != 0);
@@ -190,7 +190,7 @@ bvt boolbvt::convert_bitvector(const exprt &expr)
190190
else if(expr.id()==ID_with)
191191
return convert_with(to_with_expr(expr));
192192
else if(expr.id()==ID_update)
193-
return convert_update(expr);
193+
return convert_update(to_update_expr(expr));
194194
else if(expr.id()==ID_width)
195195
{
196196
std::size_t result_width=boolbv_width(expr.type());
@@ -201,7 +201,7 @@ bvt boolbvt::convert_bitvector(const exprt &expr)
201201
if(expr.operands().size()!=1)
202202
return conversion_failed(expr);
203203

204-
std::size_t op_width=boolbv_width(expr.op0().type());
204+
std::size_t op_width = boolbv_width(to_unary_expr(expr).op().type());
205205

206206
if(op_width==0)
207207
return conversion_failed(expr);
@@ -240,7 +240,9 @@ bvt boolbvt::convert_bitvector(const exprt &expr)
240240
else if(expr.id()==ID_floatbv_plus || expr.id()==ID_floatbv_minus ||
241241
expr.id()==ID_floatbv_mult || expr.id()==ID_floatbv_div ||
242242
expr.id()==ID_floatbv_rem)
243-
return convert_floatbv_op(expr);
243+
{
244+
return convert_floatbv_op(to_ieee_float_op_expr(expr));
245+
}
244246
else if(expr.id()==ID_floatbv_typecast)
245247
return convert_floatbv_typecast(to_floatbv_typecast_expr(expr));
246248
else if(expr.id()==ID_concatenation)
@@ -425,7 +427,6 @@ bvt boolbvt::convert_function_application(
425427
literalt boolbvt::convert_rest(const exprt &expr)
426428
{
427429
PRECONDITION(expr.type().id() == ID_bool);
428-
const exprt::operandst &operands=expr.operands();
429430

430431
if(expr.id()==ID_typecast)
431432
return convert_typecast(to_typecast_expr(expr));
@@ -436,15 +437,20 @@ literalt boolbvt::convert_rest(const exprt &expr)
436437
return convert_verilog_case_equality(to_binary_relation_expr(expr));
437438
else if(expr.id()==ID_notequal)
438439
{
439-
DATA_INVARIANT(expr.operands().size() == 2, "notequal expects two operands");
440-
return !convert_equality(equal_exprt(expr.op0(), expr.op1()));
440+
const auto &notequal_expr = to_notequal_expr(expr);
441+
return !convert_equality(
442+
equal_exprt(notequal_expr.lhs(), notequal_expr.rhs()));
441443
}
442444
else if(expr.id()==ID_ieee_float_equal ||
443445
expr.id()==ID_ieee_float_notequal)
444-
return convert_ieee_float_rel(expr);
446+
{
447+
return convert_ieee_float_rel(to_binary_relation_expr(expr));
448+
}
445449
else if(expr.id()==ID_le || expr.id()==ID_ge ||
446450
expr.id()==ID_lt || expr.id()==ID_gt)
447-
return convert_bv_rel(expr);
451+
{
452+
return convert_bv_rel(to_binary_relation_expr(expr));
453+
}
448454
else if(expr.id()==ID_extractbit)
449455
return convert_extractbit(to_extractbit_expr(expr));
450456
else if(expr.id()==ID_forall)
@@ -486,10 +492,10 @@ literalt boolbvt::convert_rest(const exprt &expr)
486492
}
487493
else if(expr.id()==ID_sign)
488494
{
489-
DATA_INVARIANT(expr.operands().size() == 1, "sign expects one operand");
490-
const bvt &bv=convert_bv(operands[0]);
495+
const auto &op = to_sign_expr(expr).op();
496+
const bvt &bv = convert_bv(op);
491497
CHECK_RETURN(!bv.empty());
492-
const irep_idt type_id = operands[0].type().id();
498+
const irep_idt type_id = op.type().id();
493499
if(type_id == ID_signedbv || type_id == ID_fixedbv || type_id == ID_floatbv)
494500
return bv[bv.size()-1];
495501
if(type_id == ID_unsignedbv)
@@ -505,53 +511,56 @@ literalt boolbvt::convert_rest(const exprt &expr)
505511
return convert_overflow(expr);
506512
else if(expr.id()==ID_isnan)
507513
{
508-
DATA_INVARIANT(expr.operands().size() == 1, "isnan expects one operand");
509-
const bvt &bv=convert_bv(operands[0]);
514+
const auto &op = to_unary_expr(expr).op();
515+
const bvt &bv = convert_bv(op);
510516

511-
if(expr.op0().type().id()==ID_floatbv)
517+
if(op.type().id() == ID_floatbv)
512518
{
513-
float_utilst float_utils(prop, to_floatbv_type(expr.op0().type()));
519+
float_utilst float_utils(prop, to_floatbv_type(op.type()));
514520
return float_utils.is_NaN(bv);
515521
}
516-
else if(expr.op0().type().id() == ID_fixedbv)
522+
else if(op.type().id() == ID_fixedbv)
517523
return const_literal(false);
518524
}
519525
else if(expr.id()==ID_isfinite)
520526
{
521-
DATA_INVARIANT(expr.operands().size() == 1, "isfinite expects one operand");
522-
const bvt &bv=convert_bv(operands[0]);
523-
if(expr.op0().type().id()==ID_floatbv)
527+
const auto &op = to_unary_expr(expr).op();
528+
const bvt &bv = convert_bv(op);
529+
530+
if(op.type().id() == ID_floatbv)
524531
{
525-
float_utilst float_utils(prop, to_floatbv_type(expr.op0().type()));
532+
float_utilst float_utils(prop, to_floatbv_type(op.type()));
526533
return prop.land(
527534
!float_utils.is_infinity(bv),
528535
!float_utils.is_NaN(bv));
529536
}
530-
else if(expr.op0().type().id() == ID_fixedbv)
537+
else if(op.id() == ID_fixedbv)
531538
return const_literal(true);
532539
}
533540
else if(expr.id()==ID_isinf)
534541
{
535-
DATA_INVARIANT(expr.operands().size() == 1, "isinf expects one operand");
536-
const bvt &bv=convert_bv(operands[0]);
537-
if(expr.op0().type().id()==ID_floatbv)
542+
const auto &op = to_unary_expr(expr).op();
543+
const bvt &bv = convert_bv(op);
544+
545+
if(op.type().id() == ID_floatbv)
538546
{
539-
float_utilst float_utils(prop, to_floatbv_type(expr.op0().type()));
547+
float_utilst float_utils(prop, to_floatbv_type(op.type()));
540548
return float_utils.is_infinity(bv);
541549
}
542-
else if(expr.op0().type().id() == ID_fixedbv)
550+
else if(op.type().id() == ID_fixedbv)
543551
return const_literal(false);
544552
}
545553
else if(expr.id()==ID_isnormal)
546554
{
547-
DATA_INVARIANT(expr.operands().size() == 1, "isnormal expects one operand");
548-
if(expr.op0().type().id()==ID_floatbv)
555+
const auto &op = to_unary_expr(expr).op();
556+
557+
if(op.type().id() == ID_floatbv)
549558
{
550-
const bvt &bv = convert_bv(operands[0]);
551-
float_utilst float_utils(prop, to_floatbv_type(expr.op0().type()));
559+
const bvt &bv = convert_bv(op);
560+
float_utilst float_utils(prop, to_floatbv_type(op.type()));
552561
return float_utils.is_normal(bv);
553562
}
554-
else if(expr.op0().type().id() == ID_fixedbv)
563+
else if(op.type().id() == ID_fixedbv)
555564
return const_literal(true);
556565
}
557566

src/solvers/flattening/boolbv.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class boolbvt:public arrayst
124124
const typet &src_type, const bvt &src,
125125
const typet &dest_type, bvt &dest);
126126

127-
virtual literalt convert_bv_rel(const exprt &expr);
127+
virtual literalt convert_bv_rel(const binary_relation_exprt &);
128128
virtual literalt convert_typecast(const typecast_exprt &expr);
129129
virtual literalt convert_reduction(const unary_exprt &expr);
130130
virtual literalt convert_onehot(const unary_exprt &expr);
@@ -133,7 +133,7 @@ class boolbvt:public arrayst
133133
virtual literalt convert_equality(const equal_exprt &expr);
134134
virtual literalt convert_verilog_case_equality(
135135
const binary_relation_exprt &expr);
136-
virtual literalt convert_ieee_float_rel(const exprt &expr);
136+
virtual literalt convert_ieee_float_rel(const binary_relation_exprt &);
137137
virtual literalt convert_quantifier(const quantifier_exprt &expr);
138138

139139
virtual bvt convert_index(const exprt &array, const mp_integer &index);
@@ -158,11 +158,11 @@ class boolbvt:public arrayst
158158
virtual bvt convert_mult(const mult_exprt &expr);
159159
virtual bvt convert_div(const div_exprt &expr);
160160
virtual bvt convert_mod(const mod_exprt &expr);
161-
virtual bvt convert_floatbv_op(const exprt &expr);
161+
virtual bvt convert_floatbv_op(const ieee_float_op_exprt &);
162162
virtual bvt convert_floatbv_typecast(const floatbv_typecast_exprt &expr);
163163
virtual bvt convert_member(const member_exprt &expr);
164164
virtual bvt convert_with(const with_exprt &expr);
165-
virtual bvt convert_update(const exprt &expr);
165+
virtual bvt convert_update(const update_exprt &);
166166
virtual bvt convert_case(const exprt &expr);
167167
virtual bvt convert_cond(const cond_exprt &);
168168
virtual bvt convert_shift(const binary_exprt &expr);

src/solvers/flattening/boolbv_add_sub.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ bvt boolbvt::convert_add_sub(const exprt &expr)
4141
!operands.empty(),
4242
"operator " + expr.id_string() + " takes at least one operand");
4343

44-
const exprt &op0=expr.op0();
44+
const exprt &op0 = to_multi_ary_expr(expr).op0();
4545
DATA_INVARIANT(
4646
op0.type() == type, "add/sub with mixed types:\n" + expr.pretty());
4747

src/solvers/flattening/boolbv_bitwise.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ bvt boolbvt::convert_bitwise(const exprt &expr)
1717

1818
if(expr.id()==ID_bitnot)
1919
{
20-
DATA_INVARIANT(expr.operands().size() == 1, "bitnot takes one operand");
21-
const exprt &op0=expr.op0();
22-
const bvt &op_bv = convert_bv(op0, width);
20+
const exprt &op = to_bitnot_expr(expr).op();
21+
const bvt &op_bv = convert_bv(op, width);
2322
return bv_utils.inverted(op_bv);
2423
}
2524
else if(expr.id()==ID_bitand || expr.id()==ID_bitor ||

0 commit comments

Comments
 (0)