Skip to content

Commit 74cfc8b

Browse files
committed
JBMC: Replace uses of namespacet::follow
This is deprecated. Use suitable variants of `follow_tag` instead.
1 parent 1939544 commit 74cfc8b

11 files changed

+57
-56
lines changed

Diff for: jbmc/src/java_bytecode/assignments_from_json.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ static java_class_typet
6767
followed_class_type(const exprt &expr, const symbol_table_baset &symbol_table)
6868
{
6969
const pointer_typet &pointer_type = to_pointer_type(expr.type());
70-
const java_class_typet &java_class_type = to_java_class_type(
71-
namespacet{symbol_table}.follow(pointer_type.base_type()));
72-
return java_class_type;
70+
return to_java_class_type(namespacet{symbol_table}.follow_tag(
71+
to_struct_tag_type(pointer_type.base_type())));
7372
}
7473

7574
static bool
@@ -530,8 +529,8 @@ static code_with_references_listt assign_struct_components_from_json(
530529
const jsont &json,
531530
object_creation_infot &info)
532531
{
533-
const java_class_typet &java_class_type =
534-
to_java_class_type(namespacet{info.symbol_table}.follow(expr.type()));
532+
const java_class_typet &java_class_type = to_java_class_type(
533+
namespacet{info.symbol_table}.follow_tag(to_struct_tag_type(expr.type())));
535534
code_with_references_listt result;
536535
for(const auto &component : java_class_type.components())
537536
{
@@ -576,7 +575,7 @@ static code_with_references_listt assign_struct_from_json(
576575
{
577576
const namespacet ns{info.symbol_table};
578577
const java_class_typet &java_class_type =
579-
to_java_class_type(ns.follow(expr.type()));
578+
to_java_class_type(ns.follow_tag(to_struct_tag_type(expr.type())));
580579
code_with_references_listt result;
581580
if(is_java_string_type(java_class_type))
582581
{
@@ -641,8 +640,8 @@ static code_with_references_listt assign_enum_from_json(
641640

642641
dereference_exprt values_struct{
643642
info.symbol_table.lookup_ref(values_name).symbol_expr()};
644-
const auto &values_struct_type =
645-
to_struct_type(namespacet{info.symbol_table}.follow(values_struct.type()));
643+
const auto &values_struct_type = namespacet{info.symbol_table}.follow_tag(
644+
to_struct_tag_type(values_struct.type()));
646645
PRECONDITION(is_valid_java_array(values_struct_type));
647646
const member_exprt values_data = member_exprt{
648647
values_struct, "data", values_struct_type.components()[2].type()};

Diff for: jbmc/src/java_bytecode/expr2java.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ std::string expr2javat::convert_struct(
105105
const exprt &src,
106106
unsigned &precedence)
107107
{
108-
const typet &full_type=ns.follow(src.type());
108+
const typet &full_type = src.type().id() == ID_struct_tag
109+
? ns.follow_tag(to_struct_tag_type(src.type()))
110+
: src.type();
109111

110112
if(full_type.id()!=ID_struct)
111113
return convert_norep(src, precedence);

Diff for: jbmc/src/java_bytecode/java_bytecode_concurrency_instrumentation.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,8 @@ static void instrument_get_monitor_count(
409409
PRECONDITION(f_code.arguments().size() == 1);
410410

411411
const namespacet ns(symbol_table);
412-
const auto &followed_type =
413-
ns.follow(to_pointer_type(f_code.arguments()[0].type()).base_type());
414-
const auto &object_type = to_struct_type(followed_type);
412+
const auto &object_type = ns.follow_tag(to_struct_tag_type(
413+
to_pointer_type(f_code.arguments()[0].type()).base_type()));
415414
code_assignt code_assign(
416415
f_code.lhs(),
417416
member_exprt(

Diff for: jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ static member_exprt to_member(
667667

668668
exprt accessed_object = checked_dereference(typed_pointer);
669669
const auto type_of = [&ns](const exprt &object) {
670-
return to_struct_type(ns.follow(object.type()));
670+
return ns.follow_tag(to_struct_tag_type(object.type()));
671671
};
672672

673673
// The field access is described as being against a particular type, but it

Diff for: jbmc/src/java_bytecode/java_bytecode_language.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ static void infer_opaque_type_fields(
507507
"') should have an opaque superclass");
508508
const auto &superclass_type = class_type->bases().front().type();
509509
class_symbol_id = superclass_type.get_identifier();
510-
class_type = &to_java_class_type(ns.follow(superclass_type));
510+
class_type = &to_java_class_type(
511+
ns.follow_tag(to_struct_tag_type(superclass_type)));
511512
}
512513
}
513514
}
@@ -1502,8 +1503,8 @@ bool java_bytecode_languaget::convert_single_method_code(
15021503
// TODO(tkiley): ci_lazy_methods_neededt, but this needs further
15031504
// TODO(tkiley): investigation
15041505
namespacet ns{symbol_table};
1505-
const java_class_typet &underlying_type =
1506-
to_java_class_type(ns.follow(pointer_return_type->base_type()));
1506+
const java_class_typet &underlying_type = to_java_class_type(
1507+
ns.follow_tag(to_struct_tag_type(pointer_return_type->base_type())));
15071508

15081509
if(!underlying_type.is_abstract())
15091510
needed_lazy_methods->add_all_needed_classes(*pointer_return_type);

Diff for: jbmc/src/java_bytecode/java_object_factory.cpp

+20-22
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,8 @@ void java_object_factoryt::gen_pointer_target_init(
199199
PRECONDITION(update_in_place != update_in_placet::MAY_UPDATE_IN_PLACE);
200200

201201
const namespacet ns(symbol_table);
202-
const typet &followed_target_type = ns.follow(target_type);
203-
PRECONDITION(followed_target_type.id() == ID_struct);
204-
205-
const auto &target_class_type = to_java_class_type(followed_target_type);
202+
const auto &target_class_type =
203+
to_java_class_type(ns.follow_tag(to_struct_tag_type(target_type)));
206204
if(target_class_type.get_tag().starts_with("java::array["))
207205
{
208206
assignments.append(gen_nondet_array_init(
@@ -374,7 +372,7 @@ void initialize_nondet_string_fields(
374372
{
375373
namespacet ns(symbol_table);
376374
const struct_typet &struct_type =
377-
to_struct_type(ns.follow(struct_expr.type()));
375+
ns.follow_tag(to_struct_tag_type(struct_expr.type()));
378376
PRECONDITION(is_java_string_type(struct_type));
379377

380378
// We allow type StringBuffer and StringBuilder to be initialized
@@ -481,9 +479,6 @@ void java_object_factoryt::gen_nondet_pointer_init(
481479
{
482480
PRECONDITION(expr.type().id()==ID_pointer);
483481
const namespacet ns(symbol_table);
484-
const typet &subtype = pointer_type.base_type();
485-
const typet &followed_subtype = ns.follow(subtype);
486-
PRECONDITION(followed_subtype.id() == ID_struct);
487482
const pointer_typet &replacement_pointer_type =
488483
pointer_type_selector.convert_pointer_type(
489484
pointer_type, generic_parameter_specialization_map, ns);
@@ -501,7 +496,7 @@ void java_object_factoryt::gen_nondet_pointer_init(
501496
generic_parameter_specialization_map);
502497
generic_parameter_specialization_map_keys.insert(
503498
replacement_pointer_type,
504-
ns.follow(replacement_pointer_type.base_type()));
499+
ns.follow_tag(to_struct_tag_type(replacement_pointer_type.base_type())));
505500

506501
const symbol_exprt real_pointer_symbol = gen_nondet_subtype_pointer_init(
507502
assignments, lifetime, replacement_pointer_type, depth, location);
@@ -529,7 +524,9 @@ void java_object_factoryt::gen_nondet_pointer_init(
529524
// When we visit for 2nd time a type AND the maximum depth is exceeded, we set
530525
// the pointer to NULL instead of recursively initializing the struct to which
531526
// it points.
532-
const struct_typet &struct_type = to_struct_type(followed_subtype);
527+
const struct_tag_typet &tag_type =
528+
to_struct_tag_type(pointer_type.base_type());
529+
const struct_typet &struct_type = ns.follow_tag(tag_type);
533530
const irep_idt &struct_tag = struct_type.get_tag();
534531

535532
// If this is a recursive type of some kind AND the depth is exceeded, set
@@ -564,7 +561,7 @@ void java_object_factoryt::gen_nondet_pointer_init(
564561
// ci_lazy_methodst::initialize_instantiated_classes.
565562
if(
566563
const auto class_type =
567-
type_try_dynamic_cast<java_class_typet>(followed_subtype))
564+
type_try_dynamic_cast<java_class_typet>(struct_type))
568565
{
569566
if(class_type->get_base("java::java.lang.Enum"))
570567
{
@@ -581,13 +578,13 @@ void java_object_factoryt::gen_nondet_pointer_init(
581578
// if the initialization mode is MAY_UPDATE or MUST_UPDATE in place, then we
582579
// emit to `update_in_place_assignments` code for in-place initialization of
583580
// the object pointed by `expr`, assuming that such object is of type
584-
// `subtype`
581+
// `tag_type`
585582
if(update_in_place!=update_in_placet::NO_UPDATE_IN_PLACE)
586583
{
587584
gen_pointer_target_init(
588585
update_in_place_assignments,
589586
expr,
590-
subtype,
587+
tag_type,
591588
lifetime,
592589
depth,
593590
update_in_placet::MUST_UPDATE_IN_PLACE,
@@ -610,7 +607,7 @@ void java_object_factoryt::gen_nondet_pointer_init(
610607
gen_pointer_target_init(
611608
non_null_inst,
612609
expr,
613-
subtype,
610+
tag_type,
614611
lifetime,
615612
depth,
616613
update_in_placet::NO_UPDATE_IN_PLACE,
@@ -773,7 +770,7 @@ void java_object_factoryt::gen_nondet_struct_init(
773770
const source_locationt &location)
774771
{
775772
const namespacet ns(symbol_table);
776-
PRECONDITION(ns.follow(expr.type()).id()==ID_struct);
773+
PRECONDITION(expr.type().id() == ID_struct_tag);
777774

778775
typedef struct_typet::componentst componentst;
779776
const irep_idt &struct_tag=struct_type.get_tag();
@@ -1008,7 +1005,6 @@ void java_object_factoryt::gen_nondet_init(
10081005
{
10091006
const typet &type = override_type.has_value() ? *override_type : expr.type();
10101007
const namespacet ns(symbol_table);
1011-
const typet &followed_type = ns.follow(type);
10121008

10131009
if(type.id()==ID_pointer)
10141010
{
@@ -1021,7 +1017,8 @@ void java_object_factoryt::gen_nondet_init(
10211017
generic_parameter_specialization_map_keys(
10221018
generic_parameter_specialization_map);
10231019
generic_parameter_specialization_map_keys.insert(
1024-
pointer_type, ns.follow(pointer_type.base_type()));
1020+
pointer_type,
1021+
ns.follow_tag(to_struct_tag_type(pointer_type.base_type())));
10251022

10261023
gen_nondet_pointer_init(
10271024
assignments,
@@ -1032,9 +1029,9 @@ void java_object_factoryt::gen_nondet_init(
10321029
update_in_place,
10331030
location);
10341031
}
1035-
else if(followed_type.id() == ID_struct)
1032+
else if(type.id() == ID_struct_tag)
10361033
{
1037-
const struct_typet struct_type = to_struct_type(followed_type);
1034+
const struct_typet struct_type = ns.follow_tag(to_struct_tag_type(type));
10381035

10391036
// If we are about to initialize a generic class (as a superclass object
10401037
// for a different object), add its concrete types to the map and delete
@@ -1388,8 +1385,8 @@ code_blockt gen_nondet_array_init(
13881385
code_blockt statements;
13891386

13901387
const namespacet ns(symbol_table);
1391-
const typet &type = ns.follow(to_pointer_type(expr.type()).base_type());
1392-
const struct_typet &struct_type = to_struct_type(type);
1388+
const struct_typet &struct_type =
1389+
ns.follow_tag(to_struct_tag_type(to_pointer_type(expr.type()).base_type()));
13931390
const typet &element_type = static_cast<const typet &>(
13941391
to_pointer_type(expr.type()).base_type().find(ID_element_type));
13951392

@@ -1492,7 +1489,8 @@ bool java_object_factoryt::gen_nondet_enum_init(
14921489

14931490
// Access members (length and data) of $VALUES array
14941491
dereference_exprt deref_expr(values.symbol_expr());
1495-
const auto &deref_struct_type = to_struct_type(ns.follow(deref_expr.type()));
1492+
const auto &deref_struct_type =
1493+
ns.follow_tag(to_struct_tag_type(deref_expr.type()));
14961494
PRECONDITION(is_valid_java_array(deref_struct_type));
14971495
const auto &comps = deref_struct_type.components();
14981496
const member_exprt length_expr(deref_expr, "length", comps[1].type());

Diff for: jbmc/src/java_bytecode/java_pointer_casts.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ bool find_superclass_with_type(
3737
PRECONDITION(ptr.type().id() == ID_pointer);
3838
while(true)
3939
{
40-
const typet ptr_base = ns.follow(to_pointer_type(ptr.type()).base_type());
41-
42-
if(ptr_base.id()!=ID_struct)
40+
const typet &ptr_base = to_pointer_type(ptr.type()).base_type();
41+
if(ptr_base.id() != ID_struct_tag)
4342
return false;
44-
45-
const struct_typet &base_struct=to_struct_type(ptr_base);
43+
const struct_typet &base_struct =
44+
ns.follow_tag(to_struct_tag_type(ptr_base));
4645

4746
if(base_struct.components().empty())
4847
return false;
@@ -60,7 +59,11 @@ bool find_superclass_with_type(
6059

6160
// Compare the real (underlying) type, as target_type is already a non-
6261
// symbolic type.
63-
if(ns.follow(first_field_type)==target_type)
62+
const typet &underlying_type =
63+
first_field_type.id() == ID_struct_tag
64+
? ns.follow_tag(to_struct_tag_type(first_field_type))
65+
: first_field_type;
66+
if(underlying_type == target_type)
6467
return true;
6568
}
6669
}
@@ -88,8 +91,6 @@ exprt make_clean_pointer_cast(
8891
return typecast_exprt(ptr, target_type);
8992
}
9093

91-
const typet &target_base = ns.follow(target_type.base_type());
92-
9394
exprt bare_ptr=ptr;
9495
while(bare_ptr.id()==ID_typecast)
9596
{
@@ -112,6 +113,10 @@ exprt make_clean_pointer_cast(
112113
// recorded on the pointer, not the pointee), so it may still be necessary
113114
// to use a cast to reintroduce the qualifier (for example, the base might
114115
// be recorded as a List, when we're looking for a List<E>)
116+
const typet &target_base =
117+
target_type.base_type().id() == ID_struct_tag
118+
? ns.follow_tag(to_struct_tag_type(target_type.base_type()))
119+
: target_type.base_type();
115120
if(find_superclass_with_type(superclass_ptr, target_base, ns))
116121
return typecast_exprt::conditional_cast(superclass_ptr, target_type);
117122

Diff for: jbmc/src/java_bytecode/java_string_library_preprocess.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,8 @@ codet java_string_library_preprocesst::code_assign_components_to_java_string(
807807
{
808808
// Initialise the supertype with the appropriate classid:
809809
namespacet ns(symbol_table);
810-
const struct_typet &lhs_type = to_struct_type(ns.follow(deref.type()));
810+
const struct_typet &lhs_type =
811+
ns.follow_tag(to_struct_tag_type(deref.type()));
811812
auto zero_base_object = *zero_initializer(
812813
lhs_type.components().front().type(), source_locationt{}, ns);
813814
set_class_identifier(

Diff for: jbmc/src/java_bytecode/java_string_literals.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ symbol_exprt get_or_create_string_literal_symbol(
7070
// Regardless of string refinement setting, at least initialize
7171
// the literal with @clsid = String
7272
struct_tag_typet jlo_symbol("java::java.lang.Object");
73-
const auto &jlo_struct = to_struct_type(ns.follow(jlo_symbol));
73+
const auto &jlo_struct = ns.follow_tag(jlo_symbol);
7474
struct_exprt jlo_init({}, jlo_symbol);
75-
const auto &jls_struct = to_struct_type(ns.follow(string_type));
75+
const auto &jls_struct = ns.follow_tag(string_type);
7676
java_root_class_init(jlo_init, jlo_struct, "java::java.lang.String");
7777

7878
// If string refinement *is* around, populate the actual

Diff for: jbmc/src/java_bytecode/remove_java_new.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
144144
source_locationt location = rhs.source_location();
145145
struct_tag_typet object_type =
146146
to_struct_tag_type(to_pointer_type(rhs.type()).base_type());
147-
PRECONDITION(ns.follow(object_type).id() == ID_struct);
148147

149148
// build size expression
150149
const auto object_size = size_of_expr(object_type, ns);
@@ -160,7 +159,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
160159
goto_programt::make_assignment(code_assignt(lhs, malloc_expr), location);
161160
goto_programt::targett next = std::next(target);
162161

163-
const struct_typet &struct_type = to_struct_type(ns.follow(object_type));
162+
const struct_typet &struct_type = ns.follow_tag(object_type);
164163

165164
PRECONDITION(is_valid_java_array(struct_type));
166165

Diff for: jbmc/src/java_bytecode/simple_method_stubbing.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,10 @@ void java_simple_method_stubst::create_method_stub_at(
9797
"Nondet initializer result type: expected a pointer",
9898
expected_type);
9999

100-
namespacet ns(symbol_table);
101-
102-
const auto &expected_base =
103-
ns.follow(to_pointer_type(expected_type).base_type());
104-
if(expected_base.id() != ID_struct)
100+
if(to_pointer_type(expected_type).base_type().id() != ID_struct_tag)
105101
return;
106102

103+
namespacet ns(symbol_table);
107104
const exprt cast_ptr =
108105
make_clean_pointer_cast(ptr, to_pointer_type(expected_type), ns);
109106

0 commit comments

Comments
 (0)