Skip to content

Commit a702e77

Browse files
authored
Merge pull request #6618 from diffblue/typet_subtype_const2
remove uses of typet::subtype() const
2 parents bd45729 + 9073968 commit a702e77

16 files changed

+107
-74
lines changed

jbmc/src/java_bytecode/ci_lazy_methods_needed.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void ci_lazy_methods_neededt::gather_field_types(
174174
gather_field_types(field.type(), ns);
175175
else if(field.type().id() == ID_pointer)
176176
{
177-
if(field.type().subtype().id() == ID_struct_tag)
177+
if(to_pointer_type(field.type()).base_type().id() == ID_struct_tag)
178178
{
179179
add_all_needed_classes(to_pointer_type(field.type()));
180180
}
@@ -186,7 +186,7 @@ void ci_lazy_methods_neededt::gather_field_types(
186186
// We should therefore only be skipping pointers such as the uint16t*
187187
// in our internal String representation.
188188
INVARIANT(
189-
field.type().subtype().id() != ID_struct,
189+
to_pointer_type(field.type()).base_type().id() != ID_struct,
190190
"struct types should be referred to by symbol at this stage");
191191
}
192192
}

jbmc/src/java_bytecode/convert_java_nondet.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ static bool is_nondet_pointer(exprt expr)
2727
// and we do not want to convert it. If the type is a ptr-to-void or a
2828
// function pointer then we also do not want to convert it.
2929
const typet &type = expr.type();
30-
const bool non_void_non_function_pointer = type.id() == ID_pointer &&
31-
type.subtype().id() != ID_empty &&
32-
type.subtype().id() != ID_code;
30+
const bool non_void_non_function_pointer =
31+
type.id() == ID_pointer &&
32+
to_pointer_type(type).base_type().id() != ID_empty &&
33+
to_pointer_type(type).base_type().id() != ID_code;
3334
return can_cast_expr<side_effect_expr_nondett>(expr) &&
3435
non_void_non_function_pointer;
3536
}

jbmc/src/java_bytecode/expr2java.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,13 @@ std::string expr2javat::convert_java_new(const exprt &src)
340340
convert(static_cast<const exprt &>(src.find(ID_size)));
341341

342342
dest+=' ';
343-
dest+=convert(src.type().subtype());
343+
dest += convert(to_pointer_type(src.type()).base_type());
344344
dest+='[';
345345
dest+=tmp_size;
346346
dest+=']';
347347
}
348348
else
349-
dest="new "+convert(src.type().subtype());
349+
dest = "new " + convert(to_pointer_type(src.type()).base_type());
350350

351351
return dest;
352352
}

jbmc/src/java_bytecode/java_bytecode_parse_tree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ java_bytecode_parse_treet::find_annotation(
102102
[&annotation_type_name](const annotationt &annotation) {
103103
if(annotation.type.id() != ID_pointer)
104104
return false;
105-
const typet &type = annotation.type.subtype();
105+
const typet &type = to_pointer_type(annotation.type).base_type();
106106
return type.id() == ID_struct_tag &&
107107
to_struct_tag_type(type).get_identifier() == annotation_type_name;
108108
});

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ void java_bytecode_parsert::get_class_refs_rec(const typet &src)
600600
get_class_refs_rec(c.type());
601601
}
602602
else if(src.id()==ID_pointer)
603-
get_class_refs_rec(src.subtype());
603+
get_class_refs_rec(to_pointer_type(src).base_type());
604604
}
605605

606606
/// For each of the given annotations, get a reference to its class and

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,16 +1381,16 @@ code_blockt gen_nondet_array_init(
13811381
const size_t max_nondet_array_length)
13821382
{
13831383
PRECONDITION(expr.type().id() == ID_pointer);
1384-
PRECONDITION(expr.type().subtype().id() == ID_struct_tag);
1384+
PRECONDITION(to_pointer_type(expr.type()).base_type().id() == ID_struct_tag);
13851385
PRECONDITION(update_in_place != update_in_placet::MAY_UPDATE_IN_PLACE);
13861386

13871387
code_blockt statements;
13881388

13891389
const namespacet ns(symbol_table);
1390-
const typet &type = ns.follow(expr.type().subtype());
1390+
const typet &type = ns.follow(to_pointer_type(expr.type()).base_type());
13911391
const struct_typet &struct_type = to_struct_type(type);
1392-
const typet &element_type =
1393-
static_cast<const typet &>(expr.type().subtype().find(ID_element_type));
1392+
const typet &element_type = static_cast<const typet &>(
1393+
to_pointer_type(expr.type()).base_type().find(ID_element_type));
13941394

13951395
auto max_length_expr = from_integer(max_nondet_array_length, java_int_type());
13961396

jbmc/src/java_bytecode/java_qualifiers.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ std::string java_qualifierst::as_string() const
9797
for(const java_annotationt &annotation : annotations)
9898
{
9999
out << '@';
100-
out << annotation.get_type().subtype().get(ID_identifier);
100+
out << to_reference_type(annotation.get_type())
101+
.base_type()
102+
.get(ID_identifier);
101103

102104
if(!annotation.get_values().empty())
103105
{

jbmc/src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,8 @@ exprt java_string_library_preprocesst::allocate_fresh_string(
556556
allocate_objectst allocate_objects(ID_java, loc, function_id, symbol_table);
557557

558558
code_blockt tmp;
559-
allocate_objects.allocate_dynamic_object(tmp, str, str.type().subtype());
559+
allocate_objects.allocate_dynamic_object(
560+
tmp, str, to_reference_type(str.type()).base_type());
560561
allocate_objects.declare_created_symbols(code);
561562
code.append(tmp);
562563

jbmc/src/java_bytecode/lambda_synthesis.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,8 @@ static symbol_exprt instantiate_new_object(
586586
"REF_NewInvokeSpecial lambda must refer to a constructor");
587587
const auto &created_type = method_type.parameters().at(0).type();
588588
irep_idt created_class =
589-
to_struct_tag_type(created_type.subtype()).get_identifier();
589+
to_struct_tag_type(to_reference_type(created_type).base_type())
590+
.get_identifier();
590591

591592
// Call static init if it exists:
592593
irep_idt static_init_name = clinit_wrapper_name(created_class);
@@ -612,10 +613,11 @@ static symbol_exprt instantiate_new_object(
612613

613614
/// If \p maybe_boxed_type is a boxed primitive return its unboxing method;
614615
/// otherwise return empty.
615-
static optionalt<irep_idt> get_unboxing_method(const typet &maybe_boxed_type)
616+
static optionalt<irep_idt>
617+
get_unboxing_method(const pointer_typet &maybe_boxed_type)
616618
{
617619
const irep_idt &boxed_type_id =
618-
to_struct_tag_type(maybe_boxed_type.subtype()).get_identifier();
620+
to_struct_tag_type(maybe_boxed_type.base_type()).get_identifier();
619621
const java_boxed_type_infot *boxed_type_info =
620622
get_boxed_type_info_by_name(boxed_type_id);
621623
return boxed_type_info ? boxed_type_info->unboxing_function_name
@@ -633,7 +635,8 @@ exprt make_function_expr(
633635
if(!method_type.has_this())
634636
return function_symbol.symbol_expr();
635637
const irep_idt &declared_on_class_id =
636-
to_struct_tag_type(method_type.get_this()->type().subtype())
638+
to_struct_tag_type(
639+
to_pointer_type(method_type.get_this()->type()).base_type())
637640
.get_identifier();
638641
const auto &this_symbol = symbol_table.lookup_ref(declared_on_class_id);
639642
if(to_java_class_type(this_symbol.type).get_final())
@@ -717,7 +720,8 @@ exprt box_or_unbox_type_if_necessary(
717720

718721
const irep_idt transform_function_id =
719722
original_is_pointer
720-
? get_unboxing_method(original_type) // Use static type if known
723+
? get_unboxing_method(
724+
to_pointer_type(original_type)) // Use static type if known
721725
.value_or(primitive_type_info->unboxing_function_name)
722726
: primitive_type_info->boxed_type_factory_method;
723727

jbmc/src/java_bytecode/simple_method_stubbing.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ void java_simple_method_stubst::create_method_stub_at(
9999

100100
namespacet ns(symbol_table);
101101

102-
const auto &expected_base = ns.follow(expected_type.subtype());
102+
const auto &expected_base =
103+
ns.follow(to_pointer_type(expected_type).base_type());
103104
if(expected_base.id() != ID_struct)
104105
return;
105106

src/cpp/cpp_typecheck_conversions.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -574,13 +574,13 @@ bool cpp_typecheckt::standard_conversion_pointer_to_member(
574574
to_pointer_type(type).base_type().id() == ID_code &&
575575
to_pointer_type(expr.type()).base_type().id() == ID_code)
576576
{
577-
code_typet code1=to_code_type(expr.type().subtype());
577+
code_typet code1 = to_code_type(to_pointer_type(expr.type()).base_type());
578578
assert(!code1.parameters().empty());
579579
code_typet::parametert this1=code1.parameters()[0];
580580
INVARIANT(this1.get_this(), "first parameter should be `this'");
581581
code1.parameters().erase(code1.parameters().begin());
582582

583-
code_typet code2=to_code_type(type.subtype());
583+
code_typet code2 = to_code_type(to_pointer_type(type).base_type());
584584
assert(!code2.parameters().empty());
585585
code_typet::parametert this2=code2.parameters()[0];
586586
INVARIANT(this2.get_this(), "first parameter should be `this'");
@@ -1118,7 +1118,7 @@ bool cpp_typecheckt::reference_related(
11181118
assert(!is_reference(expr.type()));
11191119

11201120
typet from=follow(expr.type());
1121-
typet to=follow(type.subtype());
1121+
typet to = follow(to_reference_type(type).base_type());
11221122

11231123
// need to check #c_type
11241124
if(from.get(ID_C_c_type)!=to.get(ID_C_c_type))
@@ -1667,7 +1667,7 @@ bool cpp_typecheckt::const_typecast(
16671667
if(!expr.get_bool(ID_C_lvalue))
16681668
return false;
16691669

1670-
if(new_expr.type()!=type.subtype())
1670+
if(new_expr.type() != to_reference_type(type).base_type())
16711671
return false;
16721672

16731673
address_of_exprt address_of(expr, to_pointer_type(type));
@@ -1710,21 +1710,21 @@ bool cpp_typecheckt::dynamic_typecast(
17101710

17111711
if(is_reference(type))
17121712
{
1713-
if(type.subtype().id() != ID_struct_tag)
1713+
if(to_reference_type(type).base_type().id() != ID_struct_tag)
17141714
return false;
17151715
}
17161716
else if(type.id()==ID_pointer)
17171717
{
17181718
if(type.find(ID_to_member).is_not_nil())
17191719
return false;
17201720

1721-
if(type.subtype().id()==ID_empty)
1721+
if(to_pointer_type(type).base_type().id() == ID_empty)
17221722
{
17231723
if(!e.get_bool(ID_C_lvalue))
17241724
return false;
17251725
UNREACHABLE; // currently not supported
17261726
}
1727-
else if(type.subtype().id() == ID_struct_tag)
1727+
else if(to_pointer_type(type).base_type().id() == ID_struct_tag)
17281728
{
17291729
if(e.get_bool(ID_C_lvalue))
17301730
{
@@ -1863,7 +1863,7 @@ bool cpp_typecheckt::static_typecast(
18631863
if(reference_binding(e, type, new_expr, rank))
18641864
return true;
18651865

1866-
typet subto=follow(type.subtype());
1866+
typet subto = follow(to_pointer_type(type).base_type());
18671867
typet from=follow(e.type());
18681868

18691869
if(subto.id()==ID_struct && from.id()==ID_struct)
@@ -1875,7 +1875,7 @@ bool cpp_typecheckt::static_typecast(
18751875
qual_from.read(e.type());
18761876

18771877
c_qualifierst qual_to;
1878-
qual_to.read(type.subtype());
1878+
qual_to.read(to_pointer_type(type).base_type());
18791879

18801880
if(!qual_to.is_subset_of(qual_from))
18811881
return false;
@@ -1945,8 +1945,8 @@ bool cpp_typecheckt::static_typecast(
19451945
{
19461946
if(type.find(ID_to_member).is_nil() && e.type().find(ID_to_member).is_nil())
19471947
{
1948-
typet to=follow(type.subtype());
1949-
typet from=follow(e.type().subtype());
1948+
typet to = follow(to_pointer_type(type).base_type());
1949+
typet from = follow(to_pointer_type(e.type()).base_type());
19501950

19511951
if(from.id()==ID_empty)
19521952
{
@@ -1979,7 +1979,9 @@ bool cpp_typecheckt::static_typecast(
19791979
type.find(ID_to_member).is_not_nil() &&
19801980
e.type().find(ID_to_member).is_not_nil())
19811981
{
1982-
if(type.subtype()!=e.type().subtype())
1982+
if(
1983+
to_pointer_type(type).base_type() !=
1984+
to_pointer_type(e.type()).base_type())
19831985
return false;
19841986

19851987
const struct_typet &from_struct = to_struct_type(
@@ -1998,8 +2000,12 @@ bool cpp_typecheckt::static_typecast(
19982000
type.find(ID_to_member).is_nil() &&
19992001
e.type().find(ID_to_member).is_not_nil())
20002002
{
2001-
if(type.subtype() != e.type().subtype())
2003+
if(
2004+
to_pointer_type(type).base_type() !=
2005+
to_pointer_type(e.type()).base_type())
2006+
{
20022007
return false;
2008+
}
20032009

20042010
const struct_typet &from_struct = to_struct_type(
20052011
follow(static_cast<const typet &>(e.type().find(ID_to_member))));

src/cpp/expr2cpp.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ std::string expr2cppt::convert_rec(
258258
dest += "> " + convert(to_template_type(src).subtype());
259259
return dest;
260260
}
261-
else if(src.id()==ID_pointer && src.subtype().id()==ID_nullptr)
261+
else if(
262+
src.id() == ID_pointer &&
263+
to_pointer_type(src).base_type().id() == ID_nullptr)
262264
{
263265
return "std::nullptr_t";
264266
}
@@ -270,9 +272,11 @@ std::string expr2cppt::convert_rec(
270272

271273
std::string dest="("+convert_rec(member, c_qualifierst(), "")+":: *)";
272274

273-
if(src.subtype().id()==ID_code)
275+
const auto &base_type = to_pointer_type(src).base_type();
276+
277+
if(base_type.id() == ID_code)
274278
{
275-
const code_typet &code_type = to_code_type(src.subtype());
279+
const code_typet &code_type = to_code_type(base_type);
276280
const typet &return_type = code_type.return_type();
277281
dest=convert_rec(return_type, c_qualifierst(), "")+" "+dest;
278282

@@ -292,7 +296,7 @@ std::string expr2cppt::convert_rec(
292296
dest+=d;
293297
}
294298
else
295-
dest=convert_rec(src.subtype(), c_qualifierst(), "")+" "+dest+d;
299+
dest = convert_rec(base_type, c_qualifierst(), "") + " " + dest + d;
296300

297301
return dest;
298302
}
@@ -375,13 +379,13 @@ std::string expr2cppt::convert_cpp_new(const exprt &src)
375379
convert(static_cast<const exprt &>(src.find(ID_size)));
376380

377381
dest+=' ';
378-
dest+=convert(src.type().subtype());
382+
dest += convert(to_pointer_type(src.type()).base_type());
379383
dest+='[';
380384
dest+=tmp_size;
381385
dest+=']';
382386
}
383387
else
384-
dest="new "+convert(src.type().subtype());
388+
dest = "new " + convert(to_pointer_type(src.type()).base_type());
385389

386390
return dest;
387391
}

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ size_t memory_snapshot_harness_generatort::pointer_depth(const typet &t) const
201201
if(t.id() != ID_pointer)
202202
return 0;
203203
else
204-
return pointer_depth(t.subtype()) + 1;
204+
return pointer_depth(to_pointer_type(t).base_type()) + 1;
205205
}
206206

207207
code_blockt memory_snapshot_harness_generatort::add_assignments_to_globals(

0 commit comments

Comments
 (0)