Skip to content

Commit c29fcd8

Browse files
author
Daniel Kroening
committed
fix accesses to exprt::opX() in solvers/
This improves type safety.
1 parent afac9c7 commit c29fcd8

27 files changed

+445
-359
lines changed

src/solvers/flattening/arrays.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +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() + "'")
192+
struct_op.id() == ID_symbol || struct_op.id() == ID_nondet_symbol,
193+
("unexpected array expression: member with '" + struct_op.id_string() +
194+
"'")
193195
.c_str());
194196
}
195197
else if(a.id()==ID_constant ||
@@ -209,24 +211,23 @@ void arrayst::collect_arrays(const exprt &a)
209211
}
210212
else if(a.id()==ID_typecast)
211213
{
212-
// cast between array types?
213-
DATA_INVARIANT(
214-
a.operands().size()==1,
215-
"typecast must have one operand");
214+
const auto &typecast_op = to_typecast_expr(a).op();
216215

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

222-
arrays.make_union(a, a.op0());
223-
collect_arrays(a.op0());
222+
arrays.make_union(a, typecast_op);
223+
collect_arrays(typecast_op);
224224
}
225225
else if(a.id()==ID_index)
226226
{
227227
// nested unbounded arrays
228-
arrays.make_union(a, a.op0());
229-
collect_arrays(a.op0());
228+
const auto &array_op = to_index_expr(a).array();
229+
arrays.make_union(a, array_op);
230+
collect_arrays(array_op);
230231
}
231232
else if(a.id() == ID_array_comprehension)
232233
{
@@ -496,16 +497,14 @@ void arrayst::add_array_constraints(
496497
else if(expr.id()==ID_typecast)
497498
{
498499
// we got a=(type[])b
499-
DATA_INVARIANT(
500-
expr.operands().size()==1,
501-
"typecast should have one operand");
500+
const auto &expr_typecast_op = to_typecast_expr(expr).op();
502501

503502
// add a[i]=b[i]
504503
for(const auto &index : index_set)
505504
{
506505
const typet &subtype = expr.type().subtype();
507506
index_exprt index_expr1(expr, index, subtype);
508-
index_exprt index_expr2(expr.op0(), index, subtype);
507+
index_exprt index_expr2(expr_typecast_op, index, subtype);
509508

510509
DATA_INVARIANT(
511510
index_expr1.type()==index_expr2.type(),

src/solvers/flattening/boolbv.cpp

Lines changed: 38 additions & 28 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)
@@ -436,15 +438,20 @@ literalt boolbvt::convert_rest(const exprt &expr)
436438
return convert_verilog_case_equality(to_binary_relation_expr(expr));
437439
else if(expr.id()==ID_notequal)
438440
{
439-
DATA_INVARIANT(expr.operands().size() == 2, "notequal expects two operands");
440-
return !convert_equality(equal_exprt(expr.op0(), expr.op1()));
441+
const auto &notequal_expr = to_notequal_expr(expr);
442+
return !convert_equality(
443+
equal_exprt(notequal_expr.lhs(), notequal_expr.rhs()));
441444
}
442445
else if(expr.id()==ID_ieee_float_equal ||
443446
expr.id()==ID_ieee_float_notequal)
444-
return convert_ieee_float_rel(expr);
447+
{
448+
return convert_ieee_float_rel(to_binary_relation_expr(expr));
449+
}
445450
else if(expr.id()==ID_le || expr.id()==ID_ge ||
446451
expr.id()==ID_lt || expr.id()==ID_gt)
447-
return convert_bv_rel(expr);
452+
{
453+
return convert_bv_rel(to_binary_relation_expr(expr));
454+
}
448455
else if(expr.id()==ID_extractbit)
449456
return convert_extractbit(to_extractbit_expr(expr));
450457
else if(expr.id()==ID_forall)
@@ -505,53 +512,56 @@ literalt boolbvt::convert_rest(const exprt &expr)
505512
return convert_overflow(expr);
506513
else if(expr.id()==ID_isnan)
507514
{
508-
DATA_INVARIANT(expr.operands().size() == 1, "isnan expects one operand");
509-
const bvt &bv=convert_bv(operands[0]);
515+
const auto &op = to_unary_expr(expr).op();
516+
const bvt &bv = convert_bv(op);
510517

511-
if(expr.op0().type().id()==ID_floatbv)
518+
if(op.type().id() == ID_floatbv)
512519
{
513-
float_utilst float_utils(prop, to_floatbv_type(expr.op0().type()));
520+
float_utilst float_utils(prop, to_floatbv_type(op.type()));
514521
return float_utils.is_NaN(bv);
515522
}
516-
else if(expr.op0().type().id() == ID_fixedbv)
523+
else if(op.type().id() == ID_fixedbv)
517524
return const_literal(false);
518525
}
519526
else if(expr.id()==ID_isfinite)
520527
{
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)
528+
const auto &op = to_unary_expr(expr).op();
529+
const bvt &bv = convert_bv(op);
530+
531+
if(op.type().id() == ID_floatbv)
524532
{
525-
float_utilst float_utils(prop, to_floatbv_type(expr.op0().type()));
533+
float_utilst float_utils(prop, to_floatbv_type(op.type()));
526534
return prop.land(
527535
!float_utils.is_infinity(bv),
528536
!float_utils.is_NaN(bv));
529537
}
530-
else if(expr.op0().type().id() == ID_fixedbv)
538+
else if(op.id() == ID_fixedbv)
531539
return const_literal(true);
532540
}
533541
else if(expr.id()==ID_isinf)
534542
{
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)
543+
const auto &op = to_unary_expr(expr).op();
544+
const bvt &bv = convert_bv(op);
545+
546+
if(op.type().id() == ID_floatbv)
538547
{
539-
float_utilst float_utils(prop, to_floatbv_type(expr.op0().type()));
548+
float_utilst float_utils(prop, to_floatbv_type(op.type()));
540549
return float_utils.is_infinity(bv);
541550
}
542-
else if(expr.op0().type().id() == ID_fixedbv)
551+
else if(op.type().id() == ID_fixedbv)
543552
return const_literal(false);
544553
}
545554
else if(expr.id()==ID_isnormal)
546555
{
547-
DATA_INVARIANT(expr.operands().size() == 1, "isnormal expects one operand");
548-
if(expr.op0().type().id()==ID_floatbv)
556+
const auto &op = to_unary_expr(expr).op();
557+
558+
if(op.type().id() == ID_floatbv)
549559
{
550-
const bvt &bv = convert_bv(operands[0]);
551-
float_utilst float_utils(prop, to_floatbv_type(expr.op0().type()));
560+
const bvt &bv = convert_bv(op);
561+
float_utilst float_utils(prop, to_floatbv_type(op.type()));
552562
return float_utils.is_normal(bv);
553563
}
554-
else if(expr.op0().type().id() == ID_fixedbv)
564+
else if(op.type().id() == ID_fixedbv)
555565
return const_literal(true);
556566
}
557567

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ bvt boolbvt::convert_bitwise(const exprt &expr)
1818
if(expr.id()==ID_bitnot)
1919
{
2020
DATA_INVARIANT(expr.operands().size() == 1, "bitnot takes one operand");
21-
const exprt &op0=expr.op0();
21+
const exprt &op0 = to_bitnot_expr(expr).op();
2222
const bvt &op_bv = convert_bv(op0, width);
2323
return bv_utils.inverted(op_bv);
2424
}

0 commit comments

Comments
 (0)