Skip to content

Commit b32e7de

Browse files
committed
Solvers: Replace uses of namespacet::follow
This is deprecated. Use suitable variants of `follow_tag` instead.
1 parent 9411c77 commit b32e7de

File tree

7 files changed

+90
-39
lines changed

7 files changed

+90
-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

@@ -3167,7 +3170,10 @@ void smt2_convt::convert_floatbv_typecast(const floatbv_typecast_exprt &expr)
31673170

31683171
void smt2_convt::convert_struct(const struct_exprt &expr)
31693172
{
3170-
const struct_typet &struct_type = to_struct_type(ns.follow(expr.type()));
3173+
const struct_typet &struct_type =
3174+
expr.type().id() == ID_struct_tag
3175+
? ns.follow_tag(to_struct_tag_type(expr.type()))
3176+
: to_struct_type(expr.type());
31713177

31723178
const struct_typet::componentst &components=
31733179
struct_type.components();
@@ -3270,10 +3276,9 @@ void smt2_convt::flatten_array(const exprt &expr)
32703276

32713277
void smt2_convt::convert_union(const union_exprt &expr)
32723278
{
3273-
const union_typet &union_type = to_union_type(ns.follow(expr.type()));
32743279
const exprt &op=expr.op();
32753280

3276-
std::size_t total_width=boolbv_width(union_type);
3281+
std::size_t total_width = boolbv_width(expr.type());
32773282

32783283
std::size_t member_width=boolbv_width(op.type());
32793284

@@ -4190,7 +4195,10 @@ void smt2_convt::convert_with(const with_exprt &expr)
41904195
}
41914196
else if(expr_type.id() == ID_struct || expr_type.id() == ID_struct_tag)
41924197
{
4193-
const struct_typet &struct_type = to_struct_type(ns.follow(expr_type));
4198+
const struct_typet &struct_type =
4199+
expr_type.id() == ID_struct_tag
4200+
? ns.follow_tag(to_struct_tag_type(expr_type))
4201+
: to_struct_type(expr_type);
41944202

41954203
const exprt &index = expr.where();
41964204
const exprt &value = expr.new_value();
@@ -4261,11 +4269,9 @@ void smt2_convt::convert_with(const with_exprt &expr)
42614269
}
42624270
else if(expr_type.id() == ID_union || expr_type.id() == ID_union_tag)
42634271
{
4264-
const union_typet &union_type = to_union_type(ns.follow(expr_type));
4265-
42664272
const exprt &value = expr.new_value();
42674273

4268-
std::size_t total_width=boolbv_width(union_type);
4274+
std::size_t total_width = boolbv_width(expr_type);
42694275

42704276
std::size_t member_width=boolbv_width(value.type());
42714277

@@ -4407,7 +4413,10 @@ void smt2_convt::convert_member(const member_exprt &expr)
44074413

44084414
if(struct_op_type.id() == ID_struct || struct_op_type.id() == ID_struct_tag)
44094415
{
4410-
const struct_typet &struct_type = to_struct_type(ns.follow(struct_op_type));
4416+
const struct_typet &struct_type =
4417+
struct_op_type.id() == ID_struct_tag
4418+
? ns.follow_tag(to_struct_tag_type(struct_op_type))
4419+
: to_struct_type(struct_op_type);
44114420

44124421
INVARIANT(
44134422
struct_type.has_component(name), "struct should have accessed component");
@@ -4504,7 +4513,9 @@ void smt2_convt::flatten2bv(const exprt &expr)
45044513
if(use_datatypes)
45054514
{
45064515
// concatenate elements
4507-
const struct_typet &struct_type = to_struct_type(ns.follow(type));
4516+
const struct_typet &struct_type =
4517+
type.id() == ID_struct_tag ? ns.follow_tag(to_struct_tag_type(type))
4518+
: to_struct_type(type);
45084519

45094520
const struct_typet::componentst &components=
45104521
struct_type.components();
@@ -4630,7 +4641,9 @@ void smt2_convt::unflatten(
46304641

46314642
out << "(mk-" << smt_typename;
46324643

4633-
const struct_typet &struct_type = to_struct_type(ns.follow(type));
4644+
const struct_typet &struct_type =
4645+
type.id() == ID_struct_tag ? ns.follow_tag(to_struct_tag_type(type))
4646+
: to_struct_type(type);
46344647

46354648
const struct_typet::componentst &components=
46364649
struct_type.components();
@@ -5509,8 +5522,11 @@ void smt2_convt::convert_type(const typet &type)
55095522
else if(type.id() == ID_union || type.id() == ID_union_tag)
55105523
{
55115524
std::size_t width=boolbv_width(type);
5525+
const union_typet &union_type = type.id() == ID_union_tag
5526+
? ns.follow_tag(to_union_tag_type(type))
5527+
: to_union_type(type);
55125528
CHECK_RETURN_WITH_DIAGNOSTICS(
5513-
to_union_type(ns.follow(type)).components().empty() || width != 0,
5529+
union_type.components().empty() || width != 0,
55145530
"failed to get width of union");
55155531

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

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

+8-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,12 +193,16 @@ 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 member_bits_width = (*boolbv_width)(member_expr.type());
199198
const auto offset_bits = [&]() -> std::size_t {
200-
if(can_cast_type<union_typet>(type))
199+
if(compound_type.id() == ID_union || compound_type.id() == ID_union_tag)
201200
return 0;
202-
const auto &struct_type = type_checked_cast<struct_typet>(type);
201+
const auto &struct_type =
202+
compound_type.id() == ID_struct_tag
203+
? ns.get().follow_tag(
204+
type_checked_cast<struct_tag_typet>(compound_type))
205+
: type_checked_cast<struct_typet>(compound_type);
203206
return count_trailing_bit_width(
204207
struct_type, member_expr.get_component_name(), *boolbv_width);
205208
}();

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)