Skip to content

Commit 8a969cb

Browse files
committed
remove uses of typet::subtype() const
1 parent 637f138 commit 8a969cb

14 files changed

+74
-42
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/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-programs/string_abstraction.cpp

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ bool string_abstractiont::build_wrap(
4646
if(
4747
dest.type() != a_t &&
4848
!(dest.type().id() == ID_array && a_t.id() == ID_pointer &&
49-
dest.type().subtype() == a_t.subtype()))
49+
to_array_type(dest.type()).element_type() ==
50+
to_pointer_type(a_t).base_type()))
5051
{
5152
messaget log{message_handler};
5253
log.warning() << "warning: inconsistent abstract type for "
@@ -59,7 +60,8 @@ bool string_abstractiont::build_wrap(
5960

6061
bool string_abstractiont::is_ptr_string_struct(const typet &type) const
6162
{
62-
return type.id() == ID_pointer && type.subtype() == string_struct;
63+
return type.id() == ID_pointer &&
64+
to_pointer_type(type).base_type() == string_struct;
6365
}
6466

6567
static inline bool is_ptr_argument(const typet &type)
@@ -340,10 +342,16 @@ exprt string_abstractiont::make_val_or_dummy_rec(goto_programt &dest,
340342
{
341343
if(symbol.type.id() == ID_array || symbol.type.id() == ID_pointer)
342344
{
343-
const typet &source_subt =
344-
is_ptr_string_struct(symbol.type) ? source_type : source_type.subtype();
345+
const typet &source_subt = is_ptr_string_struct(symbol.type)
346+
? source_type
347+
: to_type_with_subtype(source_type).subtype();
345348
symbol_exprt sym_expr = add_dummy_symbol_and_value(
346-
dest, ref_instr, symbol, irep_idt(), symbol.type.subtype(), source_subt);
349+
dest,
350+
ref_instr,
351+
symbol,
352+
irep_idt(),
353+
to_type_with_subtype(symbol.type).subtype(),
354+
source_subt);
347355

348356
if(symbol.type.id() == ID_array)
349357
return array_of_exprt(sym_expr, to_array_type(symbol.type));
@@ -435,7 +443,8 @@ symbol_exprt string_abstractiont::add_dummy_symbol_and_value(
435443

436444
// set the value - may be nil
437445
if(
438-
source_type.id() == ID_array && is_char_type(source_type.subtype()) &&
446+
source_type.id() == ID_array &&
447+
is_char_type(to_array_type(source_type).element_type()) &&
439448
type == string_struct)
440449
{
441450
new_symbol.value = struct_exprt(
@@ -570,7 +579,8 @@ void string_abstractiont::abstract_function_call(
570579
abstract_type.id()==ID_pointer)
571580
{
572581
INVARIANT(
573-
str_args.back().type().subtype() == abstract_type.subtype(),
582+
to_array_type(str_args.back().type()).element_type() ==
583+
to_pointer_type(abstract_type).base_type(),
574584
"argument array type differs from formal parameter pointer type");
575585

576586
index_exprt idx(str_args.back(), from_integer(0, c_index_type()));
@@ -712,11 +722,13 @@ const typet &string_abstractiont::build_abstraction_type_rec(const typet &type,
712722
if(type.id() == ID_array || type.id() == ID_pointer)
713723
{
714724
// char* or void* or char[]
715-
if(is_char_type(type.subtype()) || type.subtype().id() == ID_empty)
725+
const auto &subtype = to_type_with_subtype(type);
726+
727+
if(is_char_type(subtype) || subtype.id() == ID_empty)
716728
map_entry.first->second=pointer_type(string_struct);
717729
else
718730
{
719-
const typet &subt = build_abstraction_type_rec(type.subtype(), known);
731+
const typet &subt = build_abstraction_type_rec(subtype, known);
720732
if(!subt.is_nil())
721733
{
722734
if(type.id() == ID_array)
@@ -793,7 +805,8 @@ bool string_abstractiont::build(const exprt &object, exprt &dest, bool write)
793805

794806
return dest.type() != abstract_type ||
795807
(dest.type().id() == ID_array && abstract_type.id() == ID_pointer &&
796-
dest.type().subtype() == abstract_type.subtype());
808+
to_array_type(dest.type()).element_type() ==
809+
to_pointer_type(abstract_type).base_type());
797810
}
798811

799812
if(object.id()==ID_string_constant)
@@ -807,7 +820,9 @@ bool string_abstractiont::build(const exprt &object, exprt &dest, bool write)
807820
return build_symbol_constant(str_len, str_len+1, dest);
808821
}
809822

810-
if(object.id()==ID_array && is_char_type(object.type().subtype()))
823+
if(
824+
object.id() == ID_array &&
825+
is_char_type(to_array_type(object.type()).element_type()))
811826
return build_array(to_array_expr(object), dest, write);
812827

813828
// other constants aren't useful
@@ -926,8 +941,9 @@ bool string_abstractiont::build_pointer(const exprt &object,
926941
dest=address_of_exprt(dest);
927942
return false;
928943
}
929-
else if(ptr.pointer.id()==ID_symbol &&
930-
is_char_type(object.type().subtype()))
944+
else if(
945+
ptr.pointer.id() == ID_symbol &&
946+
is_char_type(to_pointer_type(object.type()).base_type()))
931947
// recursive call; offset will be handled by pointer_offset in SIZE/LENGTH
932948
// checks
933949
return build_wrap(ptr.pointer, dest, write);

src/goto-programs/string_instrumentation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,10 +882,11 @@ void string_instrumentationt::invalidate_buffer(
882882
check->complete_goto(exit);
883883

884884
const plus_exprt b_plus_i(bufp, cntr_sym.symbol_expr());
885-
const dereference_exprt deref(b_plus_i, buf_type.subtype());
885+
const dereference_exprt deref(
886+
b_plus_i, to_type_with_subtype(buf_type).subtype());
886887

887888
const side_effect_expr_nondett nondet(
888-
buf_type.subtype(), target->source_location());
889+
to_type_with_subtype(buf_type).subtype(), target->source_location());
889890

890891
invalidate->code_nonconst() = code_assignt(deref, nondet);
891892
}

src/util/type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ class typet:public irept
4545
}
4646
#endif
4747

48+
protected:
4849
const typet &subtype() const
4950
{
5051
if(get_sub().empty())
5152
return static_cast<const typet &>(get_nil_irep());
5253
return static_cast<const typet &>(get_sub().front());
5354
}
5455

56+
public:
5557
typet &subtype()
5658
{
5759
subt &sub=get_sub();

0 commit comments

Comments
 (0)