Skip to content

Commit 2c5a408

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 ddbefaa commit 2c5a408

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ void initialize_nondet_string_fields(
415415
namespacet ns(symbol_table);
416416

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

420420
// In case the type for String was not added to the symbol table,
421421
// (typically when string refinement is not activated), `struct_type`
@@ -541,7 +541,8 @@ void java_object_factoryt::gen_nondet_pointer_init(
541541
generic_parameter_specialization_map_keys(
542542
generic_parameter_specialization_map);
543543
generic_parameter_specialization_map_keys.insert_pairs_for_pointer(
544-
replacement_pointer_type, ns.follow(replacement_pointer_type.subtype()));
544+
replacement_pointer_type,
545+
ns.follow(to_struct_tag_type(replacement_pointer_type.subtype())));
545546

546547
const symbol_exprt real_pointer_symbol = gen_nondet_subtype_pointer_init(
547548
assignments, lifetime, replacement_pointer_type, depth, location);
@@ -570,7 +571,7 @@ void java_object_factoryt::gen_nondet_pointer_init(
570571
// When we visit for 2nd time a type AND the maximum depth is exceeded, we set
571572
// the pointer to NULL instead of recursively initializing the struct to which
572573
// it points.
573-
const typet &subtype=ns.follow(pointer_type.subtype());
574+
const typet &subtype = ns.follow(to_struct_tag_type(pointer_type.subtype()));
574575
if(subtype.id()==ID_struct)
575576
{
576577
const struct_typet &struct_type=to_struct_type(subtype);
@@ -831,7 +832,7 @@ void java_object_factoryt::gen_nondet_struct_init(
831832
const update_in_placet &update_in_place,
832833
const source_locationt &location)
833834
{
834-
PRECONDITION(ns.follow(expr.type()).id()==ID_struct);
835+
PRECONDITION(expr.type().id() == ID_struct_tag);
835836
PRECONDITION(struct_type.id()==ID_struct);
836837

837838
typedef struct_typet::componentst componentst;
@@ -1044,7 +1045,7 @@ void java_object_factoryt::gen_nondet_init(
10441045
generic_parameter_specialization_map_keys(
10451046
generic_parameter_specialization_map);
10461047
generic_parameter_specialization_map_keys.insert_pairs_for_pointer(
1047-
pointer_type, ns.follow(pointer_type.subtype()));
1048+
pointer_type, ns.follow_tag(to_struct_tag_type(pointer_type.subtype())));
10481049

10491050
gen_nondet_pointer_init(
10501051
assignments,
@@ -1055,23 +1056,23 @@ void java_object_factoryt::gen_nondet_init(
10551056
update_in_place,
10561057
location);
10571058
}
1058-
else if(type.id()==ID_struct)
1059+
else if(type.id() == ID_struct_tag)
10591060
{
1060-
const struct_typet struct_type=to_struct_type(type);
1061+
const struct_tag_typet &struct_tag_type = to_struct_tag_type(type);
1062+
1063+
const struct_typet &struct_type = ns.follow_tag(struct_tag_type);
10611064

10621065
// If we are about to initialize a generic class (as a superclass object
10631066
// for a different object), add its concrete types to the map and delete
10641067
// them on leaving this function scope.
10651068
generic_parameter_specialization_map_keyst
10661069
generic_parameter_specialization_map_keys(
10671070
generic_parameter_specialization_map);
1071+
10681072
if(is_sub)
10691073
{
1070-
const typet &symbol =
1071-
override_type.has_value() ? *override_type : expr.type();
1072-
PRECONDITION(symbol.id() == ID_struct_tag);
10731074
generic_parameter_specialization_map_keys.insert_pairs_for_symbol(
1074-
to_struct_tag_type(symbol), struct_type);
1075+
struct_tag_type, struct_type);
10751076
}
10761077

10771078
gen_nondet_struct_init(
@@ -1392,8 +1393,9 @@ void java_object_factoryt::gen_nondet_array_init(
13921393
PRECONDITION(expr.type().subtype().id() == ID_struct_tag);
13931394
PRECONDITION(update_in_place != update_in_placet::MAY_UPDATE_IN_PLACE);
13941395

1395-
const typet &type = ns.follow(expr.type().subtype());
1396-
const struct_typet &struct_type = to_struct_type(type);
1396+
const struct_tag_typet &struct_tag_type =
1397+
to_struct_tag_type(expr.type().subtype());
1398+
const struct_typet &struct_type = ns.follow_tag(struct_tag_type);
13971399
const typet &element_type =
13981400
static_cast<const typet &>(expr.type().subtype().find(ID_element_type));
13991401

@@ -1476,7 +1478,8 @@ void java_object_factoryt::gen_nondet_enum_init(
14761478

14771479
// Access members (length and data) of $VALUES array
14781480
dereference_exprt deref_expr(values.symbol_expr());
1479-
const auto &deref_struct_type = to_struct_type(ns.follow(deref_expr.type()));
1481+
const auto &deref_struct_type =
1482+
ns.follow_tag(to_struct_tag_type(deref_expr.type()));
14801483
PRECONDITION(is_valid_java_array(deref_struct_type));
14811484
const auto &comps = deref_struct_type.components();
14821485
const member_exprt length_expr(deref_expr, "length", comps[1].type());

0 commit comments

Comments
 (0)