Skip to content

Commit 5c8512f

Browse files
author
Daniel Kroening
committed
Java object factory: use follow_tag instead of follow
follow_tag(...) is stronger typed than follow(...), which means that some explict upcasts can be dropped.
1 parent e1e2009 commit 5c8512f

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ void initialize_nondet_string_fields(
417417
namespacet ns(symbol_table);
418418

419419
const struct_typet &struct_type =
420-
to_struct_type(ns.follow(struct_expr.type()));
420+
ns.follow_tag(to_struct_tag_type(struct_expr.type()));
421421

422422
// In case the type for String was not added to the symbol table,
423423
// (typically when string refinement is not activated), `struct_type`
@@ -1036,9 +1036,7 @@ void java_object_factoryt::gen_nondet_init(
10361036
update_in_placet update_in_place,
10371037
const source_locationt &location)
10381038
{
1039-
const typet &type=
1040-
override_ ? ns.follow(override_type) : ns.follow(expr.type());
1041-
1039+
const typet &type = override_ ? override_type : expr.type();
10421040

10431041
if(type.id()==ID_pointer)
10441042
{
@@ -1062,22 +1060,23 @@ void java_object_factoryt::gen_nondet_init(
10621060
update_in_place,
10631061
location);
10641062
}
1065-
else if(type.id()==ID_struct)
1063+
else if(type.id() == ID_struct_tag)
10661064
{
1067-
const struct_typet struct_type=to_struct_type(type);
1065+
const struct_tag_typet &struct_tag_type = to_struct_tag_type(type);
1066+
1067+
const struct_typet &struct_type = ns.follow_tag(struct_tag_type);
10681068

10691069
// If we are about to initialize a generic class (as a superclass object
10701070
// for a different object), add its concrete types to the map and delete
10711071
// them on leaving this function scope.
10721072
generic_parameter_specialization_map_keyst
10731073
generic_parameter_specialization_map_keys(
10741074
generic_parameter_specialization_map);
1075+
10751076
if(is_sub)
10761077
{
1077-
const typet &symbol = override_ ? override_type : expr.type();
1078-
PRECONDITION(symbol.id() == ID_struct_tag);
10791078
generic_parameter_specialization_map_keys.insert_pairs_for_symbol(
1080-
to_struct_tag_type(symbol), struct_type);
1079+
struct_tag_type, struct_type);
10811080
}
10821081

10831082
gen_nondet_struct_init(
@@ -1400,8 +1399,9 @@ void java_object_factoryt::gen_nondet_array_init(
14001399
PRECONDITION(expr.type().subtype().id() == ID_struct_tag);
14011400
PRECONDITION(update_in_place != update_in_placet::MAY_UPDATE_IN_PLACE);
14021401

1403-
const typet &type = ns.follow(expr.type().subtype());
1404-
const struct_typet &struct_type = to_struct_type(type);
1402+
const struct_tag_typet &struct_tag_type =
1403+
to_struct_tag_type(expr.type().subtype());
1404+
const struct_typet &struct_type = ns.follow_tag(struct_tag_type);
14051405
const typet &element_type =
14061406
static_cast<const typet &>(expr.type().subtype().find(ID_element_type));
14071407

@@ -1481,7 +1481,8 @@ void java_object_factoryt::gen_nondet_enum_init(
14811481

14821482
// Access members (length and data) of $VALUES array
14831483
dereference_exprt deref_expr(values.symbol_expr());
1484-
const auto &deref_struct_type = to_struct_type(ns.follow(deref_expr.type()));
1484+
const auto &deref_struct_type =
1485+
ns.follow_tag(to_struct_tag_type(deref_expr.type()));
14851486
PRECONDITION(is_valid_java_array(deref_struct_type));
14861487
const auto &comps = deref_struct_type.components();
14871488
const member_exprt length_expr(deref_expr, "length", comps[1].type());

0 commit comments

Comments
 (0)