Skip to content

Commit ee929f3

Browse files
committed
Remove unnecessary use of ns.follow in flattening
Only structs, unions, enums can be hidden behind tags. And keeping symbol or tag types in the mapping is just fine, there is no need to store the expanded version.
1 parent 9a278f9 commit ee929f3

16 files changed

+88
-130
lines changed

src/solvers/flattening/arrays.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ literalt arrayst::record_array_equality(
5555
}
5656

5757
DATA_INVARIANT(
58-
ns.follow(op0.type()).id()==ID_array,
58+
op0.type().id() == ID_array,
5959
"record_array_equality parameter should be array-typed");
6060

6161
array_equalities.push_back(array_equalityt());
@@ -90,7 +90,7 @@ void arrayst::collect_indices(const exprt &expr)
9090
const index_exprt &e = to_index_expr(expr);
9191
collect_indices(e.index()); // necessary?
9292

93-
const typet &array_op_type=ns.follow(e.array().type());
93+
const typet &array_op_type = e.array().type();
9494

9595
if(array_op_type.id()==ID_array)
9696
{
@@ -107,8 +107,7 @@ void arrayst::collect_indices(const exprt &expr)
107107

108108
void arrayst::collect_arrays(const exprt &a)
109109
{
110-
const array_typet &array_type=
111-
to_array_type(ns.follow(a.type()));
110+
const array_typet &array_type = to_array_type(a.type());
112111

113112
if(a.id()==ID_with)
114113
{
@@ -337,7 +336,7 @@ void arrayst::add_array_Ackermann_constraints()
337336

338337
if(indices_equal_lit!=const_literal(false))
339338
{
340-
const typet &subtype=ns.follow(arrays[i].type()).subtype();
339+
const typet &subtype = arrays[i].type().subtype();
341340
index_exprt index_expr1(arrays[i], *i1, subtype);
342341

343342
index_exprt index_expr2=index_expr1;
@@ -415,10 +414,10 @@ void arrayst::add_array_constraints_equality(
415414

416415
for(const auto &index : index_set)
417416
{
418-
const typet &subtype1=ns.follow(array_equality.f1.type()).subtype();
417+
const typet &subtype1 = array_equality.f1.type().subtype();
419418
index_exprt index_expr1(array_equality.f1, index, subtype1);
420419

421-
const typet &subtype2=ns.follow(array_equality.f2.type()).subtype();
420+
const typet &subtype2 = array_equality.f2.type().subtype();
422421
index_exprt index_expr2(array_equality.f2, index, subtype2);
423422

424423
DATA_INVARIANT(
@@ -477,7 +476,7 @@ void arrayst::add_array_constraints(
477476
// add a[i]=b[i]
478477
for(const auto &index : index_set)
479478
{
480-
const typet &subtype=ns.follow(expr.type()).subtype();
479+
const typet &subtype = expr.type().subtype();
481480
index_exprt index_expr1(expr, index, subtype);
482481
index_exprt index_expr2(expr.op0(), index, subtype);
483482

@@ -514,7 +513,7 @@ void arrayst::add_array_constraints_with(
514513
const exprt &value=expr.new_value();
515514

516515
{
517-
index_exprt index_expr(expr, index, ns.follow(expr.type()).subtype());
516+
index_exprt index_expr(expr, index, expr.type().subtype());
518517

519518
if(index_expr.type()!=value.type())
520519
{
@@ -545,7 +544,7 @@ void arrayst::add_array_constraints_with(
545544

546545
if(guard_lit!=const_literal(true))
547546
{
548-
const typet &subtype=ns.follow(expr.type()).subtype();
547+
const typet &subtype = expr.type().subtype();
549548
index_exprt index_expr1(expr, other_index, subtype);
550549
index_exprt index_expr2(expr.op0(), other_index, subtype);
551550

@@ -584,7 +583,7 @@ void arrayst::add_array_constraints_update(
584583
const exprt &value=expr.new_value();
585584

586585
{
587-
index_exprt index_expr(expr, index, ns.follow(expr.type()).subtype());
586+
index_exprt index_expr(expr, index, expr.type().subtype());
588587

589588
if(index_expr.type()!=value.type())
590589
{
@@ -613,7 +612,7 @@ void arrayst::add_array_constraints_update(
613612

614613
if(guard_lit!=const_literal(true))
615614
{
616-
const typet &subtype=ns.follow(expr.type()).subtype();
615+
const typet &subtype=expr.type().subtype();
617616
index_exprt index_expr1(expr, other_index, subtype);
618617
index_exprt index_expr2(expr.op0(), other_index, subtype);
619618

@@ -643,7 +642,7 @@ void arrayst::add_array_constraints_array_of(
643642

644643
for(const auto &index : index_set)
645644
{
646-
const typet &subtype=ns.follow(expr.type()).subtype();
645+
const typet &subtype = expr.type().subtype();
647646
index_exprt index_expr(expr, index, subtype);
648647

649648
DATA_INVARIANT(
@@ -672,7 +671,7 @@ void arrayst::add_array_constraints_if(
672671

673672
for(const auto &index : index_set)
674673
{
675-
const typet subtype=ns.follow(expr.type()).subtype();
674+
const typet subtype = expr.type().subtype();
676675
index_exprt index_expr1(expr, index, subtype);
677676
index_exprt index_expr2(expr.true_case(), index, subtype);
678677

@@ -690,7 +689,7 @@ void arrayst::add_array_constraints_if(
690689
// now the false case
691690
for(const auto &index : index_set)
692691
{
693-
const typet subtype=ns.follow(expr.type()).subtype();
692+
const typet subtype = expr.type().subtype();
694693
index_exprt index_expr1(expr, index, subtype);
695694
index_exprt index_expr2(expr.false_case(), index, subtype);
696695

src/solvers/flattening/boolbv.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,6 @@ exprt boolbvt::make_free_bv_expr(const typet &type)
628628

629629
bool boolbvt::is_unbounded_array(const typet &type) const
630630
{
631-
if(type.id() == ID_symbol_type)
632-
return is_unbounded_array(ns.follow(type));
633-
634631
if(type.id()!=ID_array)
635632
return false;
636633

src/solvers/flattening/boolbv.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@ class member_exprt;
3232
class boolbvt:public arrayst
3333
{
3434
public:
35-
boolbvt(
36-
const namespacet &_ns,
37-
propt &_prop):
38-
arrayst(_ns, _prop),
39-
unbounded_array(unbounded_arrayt::U_NONE),
40-
boolbv_width(_ns),
41-
bv_utils(_prop),
42-
functions(*this),
43-
map(_prop, _ns, boolbv_width)
35+
boolbvt(const namespacet &_ns, propt &_prop)
36+
: arrayst(_ns, _prop),
37+
unbounded_array(unbounded_arrayt::U_NONE),
38+
boolbv_width(_ns),
39+
bv_utils(_prop),
40+
functions(*this),
41+
map(_prop, boolbv_width)
4442
{
4543
}
4644

src/solvers/flattening/boolbv_add_sub.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ bvt boolbvt::convert_add_sub(const exprt &expr)
1919
expr.id() == ID_plus || expr.id() == ID_minus ||
2020
expr.id() == "no-overflow-plus" || expr.id() == "no-overflow-minus");
2121

22-
const typet &type=ns.follow(expr.type());
22+
const typet &type = expr.type();
2323

2424
if(type.id()!=ID_unsignedbv &&
2525
type.id()!=ID_signedbv &&
@@ -53,9 +53,8 @@ bvt boolbvt::convert_add_sub(const exprt &expr)
5353
bool no_overflow=(expr.id()=="no-overflow-plus" ||
5454
expr.id()=="no-overflow-minus");
5555

56-
typet arithmetic_type=
57-
(type.id()==ID_vector || type.id()==ID_complex)?
58-
ns.follow(type.subtype()):type;
56+
typet arithmetic_type =
57+
(type.id() == ID_vector || type.id() == ID_complex) ? type.subtype() : type;
5958

6059
bv_utilst::representationt rep=
6160
(arithmetic_type.id()==ID_signedbv ||

src/solvers/flattening/boolbv_floatbv_op.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ bvt boolbvt::convert_floatbv_typecast(const floatbv_typecast_exprt &expr)
2323
bvt bv0=convert_bv(op0);
2424
bvt bv1=convert_bv(op1);
2525

26-
const typet &src_type=ns.follow(expr.op0().type());
27-
const typet &dest_type=ns.follow(expr.type());
26+
const typet &src_type = expr.op0().type();
27+
const typet &dest_type = expr.type();
2828

2929
if(src_type==dest_type) // redundant type cast?
3030
return bv0;
@@ -94,17 +94,16 @@ bvt boolbvt::convert_floatbv_op(const exprt &expr)
9494
bvt rhs_as_bv = convert_bv(rhs);
9595
bvt rounding_mode_as_bv = convert_bv(rounding_mode);
9696

97-
const typet &resolved_type = ns.follow(expr.type());
9897
DATA_INVARIANT_WITH_DIAGNOSTICS(
99-
lhs.type() == resolved_type && rhs.type() == resolved_type,
100-
"both operands of a floating point operator must have the same type",
98+
lhs.type() == expr.type() && rhs.type() == expr.type(),
99+
"both operands of a floating point operator must match the expression type",
101100
irep_pretty_diagnosticst{expr});
102101

103102
float_utilst float_utils(prop);
104103

105104
float_utils.set_rounding_mode(rounding_mode_as_bv);
106105

107-
if(resolved_type.id() == ID_floatbv)
106+
if(expr.type().id() == ID_floatbv)
108107
{
109108
float_utils.spec=ieee_float_spect(to_floatbv_type(expr.type()));
110109

@@ -121,15 +120,15 @@ bvt boolbvt::convert_floatbv_op(const exprt &expr)
121120
else
122121
UNREACHABLE;
123122
}
124-
else if(resolved_type.id() == ID_vector || resolved_type.id() == ID_complex)
123+
else if(expr.type().id() == ID_vector || expr.type().id() == ID_complex)
125124
{
126-
const typet &subtype = ns.follow(resolved_type.subtype());
125+
const typet &subtype = expr.type().subtype();
127126

128127
if(subtype.id()==ID_floatbv)
129128
{
130129
float_utils.spec=ieee_float_spect(to_floatbv_type(subtype));
131130

132-
std::size_t width = boolbv_width(resolved_type);
131+
std::size_t width = boolbv_width(expr.type());
133132
std::size_t sub_width=boolbv_width(subtype);
134133

135134
DATA_INVARIANT(

src/solvers/flattening/boolbv_get.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ exprt boolbvt::bv_get_rec(
7171
std::size_t offset,
7272
const typet &type) const
7373
{
74-
if(type.id() == ID_symbol_type)
75-
return bv_get_rec(bv, unknown, offset, ns.follow(type));
76-
7774
std::size_t width=boolbv_width(type);
7875

7976
assert(bv.size()==unknown.size());
@@ -143,7 +140,7 @@ exprt boolbvt::bv_get_rec(
143140

144141
for(const auto &c : components)
145142
{
146-
const typet &subtype = ns.follow(c.type());
143+
const typet &subtype = c.type();
147144
op.push_back(nil_exprt());
148145

149146
std::size_t sub_width=boolbv_width(subtype);
@@ -178,7 +175,7 @@ exprt boolbvt::bv_get_rec(
178175
}
179176
else if(type.id()==ID_vector)
180177
{
181-
const typet &subtype=ns.follow(type.subtype());
178+
const typet &subtype = type.subtype();
182179
std::size_t sub_width=boolbv_width(subtype);
183180

184181
if(sub_width!=0 && width%sub_width==0)
@@ -196,7 +193,7 @@ exprt boolbvt::bv_get_rec(
196193
}
197194
else if(type.id()==ID_complex)
198195
{
199-
const typet &subtype=ns.follow(type.subtype());
196+
const typet &subtype = type.subtype();
200197
std::size_t sub_width=boolbv_width(subtype);
201198

202199
if(sub_width!=0 && width==sub_width*2)

src/solvers/flattening/boolbv_index.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ bvt boolbvt::convert_index(const index_exprt &expr)
2121
const exprt &array=expr.array();
2222
const exprt &index=expr.index();
2323

24-
const typet &array_op_type=ns.follow(array.type());
24+
const typet &array_op_type = array.type();
2525

2626
bvt bv;
2727

@@ -276,8 +276,7 @@ bvt boolbvt::convert_index(
276276
const exprt &array,
277277
const mp_integer &index)
278278
{
279-
const array_typet &array_type=
280-
to_array_type(ns.follow(array.type()));
279+
const array_typet &array_type = to_array_type(array.type());
281280

282281
std::size_t width=boolbv_width(array_type.subtype());
283282

src/solvers/flattening/boolbv_map.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ boolbv_mapt::map_entryt &boolbv_mapt::get_map_entry(
5050
const irep_idt &identifier,
5151
const typet &type)
5252
{
53-
if(type.id() == ID_symbol_type)
54-
return get_map_entry(identifier, ns.follow(type));
55-
5653
std::pair<mappingt::iterator, bool> result=
5754
mapping.insert(std::pair<irep_idt, map_entryt>(
5855
identifier, map_entryt()));

src/solvers/flattening/boolbv_map.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ Author: Daniel Kroening, [email protected]
2323
class boolbv_mapt
2424
{
2525
public:
26-
boolbv_mapt(
27-
propt &_prop,
28-
const namespacet &_ns,
29-
const boolbv_widtht &_boolbv_width):
30-
prop(_prop), ns(_ns), boolbv_width(_boolbv_width)
26+
boolbv_mapt(propt &_prop, const boolbv_widtht &_boolbv_width)
27+
: prop(_prop), boolbv_width(_boolbv_width)
3128
{
3229
}
3330

@@ -81,7 +78,6 @@ class boolbv_mapt
8178

8279
protected:
8380
propt &prop;
84-
const namespacet &ns;
8581
const boolbv_widtht &boolbv_width;
8682
};
8783

src/solvers/flattening/boolbv_power.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Author: Daniel Kroening, [email protected]
1111

1212
bvt boolbvt::convert_power(const binary_exprt &expr)
1313
{
14-
const typet &type=ns.follow(expr.type());
14+
const typet &type = expr.type();
1515

1616
std::size_t width=boolbv_width(type);
1717

src/solvers/flattening/boolbv_typecast.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ Author: Daniel Kroening, [email protected]
1919

2020
bvt boolbvt::convert_bv_typecast(const typecast_exprt &expr)
2121
{
22-
const typet &expr_type=ns.follow(expr.type());
2322
const exprt &op=expr.op();
24-
const typet &op_type=ns.follow(op.type());
2523
const bvt &op_bv=convert_bv(op);
2624

2725
bvt bv;
2826

29-
if(type_conversion(op_type, op_bv, expr_type, bv))
27+
if(type_conversion(op.type(), op_bv, expr.type(), bv))
3028
return conversion_failed(expr);
3129

3230
return bv;
@@ -84,15 +82,9 @@ bool boolbvt::type_conversion(
8482
lower.assign(src.begin(), src.begin()+src.size()/2);
8583
upper.assign(src.begin()+src.size()/2, src.end());
8684
type_conversion(
87-
ns.follow(src_type.subtype()),
88-
lower,
89-
ns.follow(dest_type.subtype()),
90-
lower_res);
85+
src_type.subtype(), lower, dest_type.subtype(), lower_res);
9186
type_conversion(
92-
ns.follow(src_type.subtype()),
93-
upper,
94-
ns.follow(dest_type.subtype()),
95-
upper_res);
87+
src_type.subtype(), upper, dest_type.subtype(), upper_res);
9688
INVARIANT(
9789
lower_res.size() + upper_res.size() == dest_width,
9890
"lower result bitvector size plus upper result bitvector size shall "
@@ -526,17 +518,17 @@ bool boolbvt::type_conversion(
526518
return false;
527519
}
528520
}
529-
else if(dest_type.id()==ID_struct)
521+
else if(ns.follow(dest_type).id() == ID_struct)
530522
{
531-
const struct_typet &dest_struct=to_struct_type(dest_type);
523+
const struct_typet &dest_struct = to_struct_type(ns.follow(dest_type));
532524

533-
if(src_type.id()==ID_struct)
525+
if(ns.follow(src_type).id() == ID_struct)
534526
{
535527
// we do subsets
536528

537529
dest.resize(dest_width, const_literal(false));
538530

539-
const struct_typet &op_struct=to_struct_type(src_type);
531+
const struct_typet &op_struct = to_struct_type(ns.follow(src_type));
540532

541533
const struct_typet::componentst &dest_comp=
542534
dest_struct.components();

src/solvers/flattening/boolbv_unary_minus.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Author: Daniel Kroening, [email protected]
1919

2020
bvt boolbvt::convert_unary_minus(const unary_minus_exprt &expr)
2121
{
22-
const typet &type=ns.follow(expr.type());
22+
const typet &type = expr.type();
2323

2424
std::size_t width=boolbv_width(type);
2525

@@ -36,7 +36,7 @@ bvt boolbvt::convert_unary_minus(const unary_minus_exprt &expr)
3636
if(bvtype==bvtypet::IS_UNKNOWN &&
3737
(type.id()==ID_vector || type.id()==ID_complex))
3838
{
39-
const typet &subtype=ns.follow(type.subtype());
39+
const typet &subtype = type.subtype();
4040

4141
std::size_t sub_width=boolbv_width(subtype);
4242

0 commit comments

Comments
 (0)