Skip to content

Commit f18b509

Browse files
authored
Merge pull request #8235 from tautschnig/cleanup/no-follow-solvers
Solvers: Replace uses of namespacet::follow
2 parents 6fca7bb + 8a0782b commit f18b509

File tree

7 files changed

+94
-39
lines changed

7 files changed

+94
-39
lines changed

Diff for: src/solvers/flattening/boolbv_struct.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ Author: Daniel Kroening, [email protected]
1212

1313
bvt boolbvt::convert_struct(const struct_exprt &expr)
1414
{
15-
const struct_typet &struct_type=to_struct_type(ns.follow(expr.type()));
15+
const struct_typet &struct_type =
16+
expr.type().id() == ID_struct_tag
17+
? ns.follow_tag(to_struct_tag_type(expr.type()))
18+
: to_struct_type(expr.type());
1619

1720
std::size_t width=boolbv_width(struct_type);
1821

Diff for: src/solvers/flattening/boolbv_typecast.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -538,17 +538,23 @@ bool boolbvt::type_conversion(
538538
return false;
539539
}
540540
}
541-
else if(ns.follow(dest_type).id() == ID_struct)
541+
else if(dest_type.id() == ID_struct || dest_type.id() == ID_struct_tag)
542542
{
543-
const struct_typet &dest_struct = to_struct_type(ns.follow(dest_type));
543+
const struct_typet &dest_struct =
544+
dest_type.id() == ID_struct_tag
545+
? ns.follow_tag(to_struct_tag_type(dest_type))
546+
: to_struct_type(dest_type);
544547

545-
if(ns.follow(src_type).id() == ID_struct)
548+
if(src_type.id() == ID_struct || src_type.id() == ID_struct_tag)
546549
{
547550
// we do subsets
548551

549552
dest.resize(dest_width, const_literal(false));
550553

551-
const struct_typet &op_struct = to_struct_type(ns.follow(src_type));
554+
const struct_typet &op_struct =
555+
src_type.id() == ID_struct_tag
556+
? ns.follow_tag(to_struct_tag_type(src_type))
557+
: to_struct_type(src_type);
552558

553559
const struct_typet::componentst &dest_comp = dest_struct.components();
554560

Diff for: src/solvers/flattening/boolbv_update.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ void boolbvt::convert_update_rec(
107107
{
108108
const irep_idt &component_name=designator.get(ID_component_name);
109109

110-
if(ns.follow(type).id() == ID_struct)
110+
if(type.id() == ID_struct || type.id() == ID_struct_tag)
111111
{
112-
const struct_typet &struct_type = to_struct_type(ns.follow(type));
112+
const struct_typet &struct_type =
113+
type.id() == ID_struct_tag ? ns.follow_tag(to_struct_tag_type(type))
114+
: to_struct_type(type);
113115

114116
std::size_t struct_offset=0;
115117

@@ -144,9 +146,11 @@ void boolbvt::convert_update_rec(
144146
convert_update_rec(
145147
designators, d+1, new_type, new_offset, new_value, bv);
146148
}
147-
else if(ns.follow(type).id() == ID_union)
149+
else if(type.id() == ID_union || type.id() == ID_union_tag)
148150
{
149-
const union_typet &union_type = to_union_type(ns.follow(type));
151+
const union_typet &union_type = type.id() == ID_union_tag
152+
? ns.follow_tag(to_union_tag_type(type))
153+
: to_union_type(type);
150154

151155
const union_typet::componentt &component=
152156
union_type.get_component(component_name);

Diff for: src/solvers/flattening/bv_pointers.cpp

+21-10
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,23 @@ std::optional<bvt> bv_pointerst::convert_address_of_rec(const exprt &expr)
312312
{
313313
const member_exprt &member_expr=to_member_expr(expr);
314314
const exprt &struct_op = member_expr.compound();
315-
const typet &struct_op_type=ns.follow(struct_op.type());
316315

317316
// recursive call
318317
auto bv_opt = convert_address_of_rec(struct_op);
319318
if(!bv_opt.has_value())
320319
return {};
321320

322321
bvt bv = std::move(*bv_opt);
323-
if(struct_op_type.id()==ID_struct)
322+
if(
323+
struct_op.type().id() == ID_struct ||
324+
struct_op.type().id() == ID_struct_tag)
324325
{
325-
auto offset = member_offset(
326-
to_struct_type(struct_op_type), member_expr.get_component_name(), ns);
326+
const struct_typet &struct_op_type =
327+
struct_op.type().id() == ID_struct_tag
328+
? ns.follow_tag(to_struct_tag_type(struct_op.type()))
329+
: to_struct_type(struct_op.type());
330+
auto offset =
331+
member_offset(struct_op_type, member_expr.get_component_name(), ns);
327332
CHECK_RETURN(offset.has_value());
328333

329334
// add offset
@@ -333,7 +338,8 @@ std::optional<bvt> bv_pointerst::convert_address_of_rec(const exprt &expr)
333338
else
334339
{
335340
INVARIANT(
336-
struct_op_type.id() == ID_union,
341+
struct_op.type().id() == ID_union ||
342+
struct_op.type().id() == ID_union_tag,
337343
"member expression should operate on struct or union");
338344
// nothing to do, all members have offset 0
339345
}
@@ -551,21 +557,26 @@ bvt bv_pointerst::convert_pointer_type(const exprt &expr)
551557
else if(expr.id() == ID_field_address)
552558
{
553559
const auto &field_address_expr = to_field_address_expr(expr);
554-
const typet &compound_type = ns.follow(field_address_expr.compound_type());
560+
const typet &compound_type = field_address_expr.compound_type();
555561

556562
// recursive call
557563
auto bv = convert_bitvector(field_address_expr.base());
558564

559-
if(compound_type.id() == ID_struct)
565+
if(compound_type.id() == ID_struct || compound_type.id() == ID_struct_tag)
560566
{
561-
auto offset = member_offset(
562-
to_struct_type(compound_type), field_address_expr.component_name(), ns);
567+
const struct_typet &struct_type =
568+
compound_type.id() == ID_struct_tag
569+
? ns.follow_tag(to_struct_tag_type(compound_type))
570+
: to_struct_type(compound_type);
571+
auto offset =
572+
member_offset(struct_type, field_address_expr.component_name(), ns);
563573
CHECK_RETURN(offset.has_value());
564574

565575
// add offset
566576
bv = offset_arithmetic(field_address_expr.type(), bv, *offset);
567577
}
568-
else if(compound_type.id() == ID_union)
578+
else if(
579+
compound_type.id() == ID_union || compound_type.id() == ID_union_tag)
569580
{
570581
// nothing to do, all fields have offset 0
571582
}

Diff for: src/solvers/smt2/smt2_conv.cpp

+28-12
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,10 @@ void smt2_convt::convert_address_of_rec(
846846
struct_op_type.id() == ID_struct || struct_op_type.id() == ID_struct_tag,
847847
"member expression operand shall have struct type");
848848

849-
const struct_typet &struct_type = to_struct_type(ns.follow(struct_op_type));
849+
const struct_typet &struct_type =
850+
struct_op_type.id() == ID_struct_tag
851+
? ns.follow_tag(to_struct_tag_type(struct_op_type))
852+
: to_struct_type(struct_op_type);
850853

851854
const irep_idt &component_name = member_expr.get_component_name();
852855

@@ -3159,7 +3162,10 @@ void smt2_convt::convert_floatbv_typecast(const floatbv_typecast_exprt &expr)
31593162

31603163
void smt2_convt::convert_struct(const struct_exprt &expr)
31613164
{
3162-
const struct_typet &struct_type = to_struct_type(ns.follow(expr.type()));
3165+
const struct_typet &struct_type =
3166+
expr.type().id() == ID_struct_tag
3167+
? ns.follow_tag(to_struct_tag_type(expr.type()))
3168+
: to_struct_type(expr.type());
31633169

31643170
const struct_typet::componentst &components=
31653171
struct_type.components();
@@ -3262,10 +3268,9 @@ void smt2_convt::flatten_array(const exprt &expr)
32623268

32633269
void smt2_convt::convert_union(const union_exprt &expr)
32643270
{
3265-
const union_typet &union_type = to_union_type(ns.follow(expr.type()));
32663271
const exprt &op=expr.op();
32673272

3268-
std::size_t total_width=boolbv_width(union_type);
3273+
std::size_t total_width = boolbv_width(expr.type());
32693274

32703275
std::size_t member_width=boolbv_width(op.type());
32713276

@@ -4182,7 +4187,10 @@ void smt2_convt::convert_with(const with_exprt &expr)
41824187
}
41834188
else if(expr_type.id() == ID_struct || expr_type.id() == ID_struct_tag)
41844189
{
4185-
const struct_typet &struct_type = to_struct_type(ns.follow(expr_type));
4190+
const struct_typet &struct_type =
4191+
expr_type.id() == ID_struct_tag
4192+
? ns.follow_tag(to_struct_tag_type(expr_type))
4193+
: to_struct_type(expr_type);
41864194

41874195
const exprt &index = expr.where();
41884196
const exprt &value = expr.new_value();
@@ -4253,11 +4261,9 @@ void smt2_convt::convert_with(const with_exprt &expr)
42534261
}
42544262
else if(expr_type.id() == ID_union || expr_type.id() == ID_union_tag)
42554263
{
4256-
const union_typet &union_type = to_union_type(ns.follow(expr_type));
4257-
42584264
const exprt &value = expr.new_value();
42594265

4260-
std::size_t total_width=boolbv_width(union_type);
4266+
std::size_t total_width = boolbv_width(expr_type);
42614267

42624268
std::size_t member_width=boolbv_width(value.type());
42634269

@@ -4399,7 +4405,10 @@ void smt2_convt::convert_member(const member_exprt &expr)
43994405

44004406
if(struct_op_type.id() == ID_struct || struct_op_type.id() == ID_struct_tag)
44014407
{
4402-
const struct_typet &struct_type = to_struct_type(ns.follow(struct_op_type));
4408+
const struct_typet &struct_type =
4409+
struct_op_type.id() == ID_struct_tag
4410+
? ns.follow_tag(to_struct_tag_type(struct_op_type))
4411+
: to_struct_type(struct_op_type);
44034412

44044413
INVARIANT(
44054414
struct_type.has_component(name), "struct should have accessed component");
@@ -4496,7 +4505,9 @@ void smt2_convt::flatten2bv(const exprt &expr)
44964505
if(use_datatypes)
44974506
{
44984507
// concatenate elements
4499-
const struct_typet &struct_type = to_struct_type(ns.follow(type));
4508+
const struct_typet &struct_type =
4509+
type.id() == ID_struct_tag ? ns.follow_tag(to_struct_tag_type(type))
4510+
: to_struct_type(type);
45004511

45014512
const struct_typet::componentst &components=
45024513
struct_type.components();
@@ -4622,7 +4633,9 @@ void smt2_convt::unflatten(
46224633

46234634
out << "(mk-" << smt_typename;
46244635

4625-
const struct_typet &struct_type = to_struct_type(ns.follow(type));
4636+
const struct_typet &struct_type =
4637+
type.id() == ID_struct_tag ? ns.follow_tag(to_struct_tag_type(type))
4638+
: to_struct_type(type);
46264639

46274640
const struct_typet::componentst &components=
46284641
struct_type.components();
@@ -5501,8 +5514,11 @@ void smt2_convt::convert_type(const typet &type)
55015514
else if(type.id() == ID_union || type.id() == ID_union_tag)
55025515
{
55035516
std::size_t width=boolbv_width(type);
5517+
const union_typet &union_type = type.id() == ID_union_tag
5518+
? ns.follow_tag(to_union_tag_type(type))
5519+
: to_union_type(type);
55045520
CHECK_RETURN_WITH_DIAGNOSTICS(
5505-
to_union_type(ns.follow(type)).components().empty() || width != 0,
5521+
union_type.components().empty() || width != 0,
55065522
"failed to get width of union");
55075523

55085524
out << "(_ BitVec " << width << ")";

Diff for: src/solvers/smt2_incremental/encoding/struct_encoding.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ extricate_updates(const with_exprt &struct_expr)
105105
static exprt encode(const with_exprt &with, const namespacet &ns)
106106
{
107107
const auto tag_type = type_checked_cast<struct_tag_typet>(with.type());
108-
const auto struct_type =
109-
type_checked_cast<struct_typet>(ns.follow(with.type()));
108+
const auto struct_type = ns.follow_tag(tag_type);
110109
const auto updates = extricate_updates(with);
111110
const auto components =
112111
make_range(struct_type.components())
@@ -194,11 +193,19 @@ static std::size_t count_trailing_bit_width(
194193
/// the combined width of the fields which follow the field being selected.
195194
exprt struct_encodingt::encode_member(const member_exprt &member_expr) const
196195
{
197-
const auto &type = ns.get().follow(member_expr.compound().type());
196+
const auto &compound_type = member_expr.compound().type();
198197
const auto offset_bits = [&]() -> std::size_t {
199-
if(can_cast_type<union_typet>(type))
198+
if(
199+
can_cast_type<union_typet>(compound_type) ||
200+
can_cast_type<union_tag_typet>(compound_type))
201+
{
200202
return 0;
201-
const auto &struct_type = type_checked_cast<struct_typet>(type);
203+
}
204+
const auto &struct_type =
205+
compound_type.id() == ID_struct_tag
206+
? ns.get().follow_tag(
207+
type_checked_cast<struct_tag_typet>(compound_type))
208+
: type_checked_cast<struct_typet>(compound_type);
202209
return count_trailing_bit_width(
203210
struct_type, member_expr.get_component_name(), *boolbv_width);
204211
}();

Diff for: src/solvers/strings/string_refinement.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,10 @@ static void add_equations_for_symbol_resolution(
341341
{
342342
if(rhs.type().id() == ID_struct || rhs.type().id() == ID_struct_tag)
343343
{
344-
const struct_typet &struct_type = to_struct_type(ns.follow(rhs.type()));
344+
const struct_typet &struct_type =
345+
rhs.type().id() == ID_struct_tag
346+
? ns.follow_tag(to_struct_tag_type(rhs.type()))
347+
: to_struct_type(rhs.type());
345348
for(const auto &comp : struct_type.components())
346349
{
347350
if(is_char_pointer_type(comp.type()))
@@ -377,7 +380,10 @@ extract_strings_from_lhs(const exprt &lhs, const namespacet &ns)
377380
result.push_back(lhs);
378381
else if(lhs.type().id() == ID_struct || lhs.type().id() == ID_struct_tag)
379382
{
380-
const struct_typet &struct_type = to_struct_type(ns.follow(lhs.type()));
383+
const struct_typet &struct_type =
384+
lhs.type().id() == ID_struct_tag
385+
? ns.follow_tag(to_struct_tag_type(lhs.type()))
386+
: to_struct_type(lhs.type());
381387
for(const auto &comp : struct_type.components())
382388
{
383389
const std::vector<exprt> strings_in_comp = extract_strings_from_lhs(
@@ -439,7 +445,9 @@ static void add_string_equation_to_symbol_resolution(
439445
eq.rhs().type().id() == ID_struct_tag)
440446
{
441447
const struct_typet &struct_type =
442-
to_struct_type(ns.follow(eq.rhs().type()));
448+
eq.rhs().type().id() == ID_struct_tag
449+
? ns.follow_tag(to_struct_tag_type(eq.rhs().type()))
450+
: to_struct_type(eq.rhs().type());
443451
for(const auto &comp : struct_type.components())
444452
{
445453
const member_exprt lhs_data(eq.lhs(), comp.get_name(), comp.type());

0 commit comments

Comments
 (0)