Skip to content

Commit 3db8d84

Browse files
author
Joel Allred
authored
Merge pull request #3530 from allredj/java-struct-tag2
Java now uses struct_tag types (2nd edition)
2 parents fc2a86e + 0b2d3b1 commit 3db8d84

File tree

61 files changed

+551
-513
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+551
-513
lines changed

jbmc/src/java_bytecode/ci_lazy_methods.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ci_lazy_methodst::ci_lazy_methodst(
6565
/// class
6666
static bool references_class_model(const exprt &expr)
6767
{
68-
static const symbol_typet class_type("java::java.lang.Class");
68+
static const struct_tag_typet class_type("java::java.lang.Class");
6969

7070
for(auto it = expr.depth_begin(); it != expr.depth_end(); ++it)
7171
{

jbmc/src/java_bytecode/ci_lazy_methods_needed.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void ci_lazy_methods_neededt::initialize_instantiated_classes_from_pointer(
101101
const pointer_typet &pointer_type,
102102
const namespacet &ns)
103103
{
104-
const symbol_typet &class_type = to_symbol_type(pointer_type.subtype());
104+
const auto &class_type = to_struct_tag_type(pointer_type.subtype());
105105
const auto &param_classid = class_type.get_identifier();
106106

107107
// Note here: different arrays may have different element types, so we should
@@ -139,10 +139,10 @@ void ci_lazy_methods_neededt::gather_field_types(
139139
{
140140
// If class_type is not a symbol this may be a reference array,
141141
// but we can't tell what type.
142-
if(class_type.id() == ID_symbol_type)
142+
if(class_type.id() == ID_struct_tag)
143143
{
144144
const typet &element_type =
145-
java_array_element_type(to_symbol_type(class_type));
145+
java_array_element_type(to_struct_tag_type(class_type));
146146
if(element_type.id() == ID_pointer)
147147
{
148148
// This is a reference array -- mark its element type available.
@@ -154,11 +154,11 @@ void ci_lazy_methods_neededt::gather_field_types(
154154
{
155155
for(const auto &field : underlying_type.components())
156156
{
157-
if(field.type().id() == ID_struct || field.type().id() == ID_symbol_type)
157+
if(field.type().id() == ID_struct || field.type().id() == ID_struct_tag)
158158
gather_field_types(field.type(), ns);
159159
else if(field.type().id() == ID_pointer)
160160
{
161-
if(field.type().subtype().id() == ID_symbol_type)
161+
if(field.type().subtype().id() == ID_struct_tag)
162162
{
163163
add_all_needed_classes(to_pointer_type(field.type()));
164164
}

jbmc/src/java_bytecode/generic_parameter_specialization_map_keys.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,29 +136,30 @@ void generic_parameter_specialization_map_keyst::insert_pairs_for_pointer(
136136
/// in the form of a symbol rather than a pointer (as opposed to the function
137137
/// insert_pairs_for_pointer). Own the keys and pop from their stack
138138
/// on destruction; otherwise do nothing.
139-
/// \param symbol_type symbol type to get the specialized generic types from
139+
/// \param struct_tag_type symbol type to get the specialized generic types from
140140
/// \param symbol_struct struct type of the symbol type, must be generic if
141141
/// the symbol is generic
142142
void generic_parameter_specialization_map_keyst::insert_pairs_for_symbol(
143-
const symbol_typet &symbol_type,
143+
const struct_tag_typet &struct_tag_type,
144144
const typet &symbol_struct)
145145
{
146146
// If the struct is:
147147
// - an incomplete class or
148148
// - a class that is neither generic nor implicitly generic (this
149149
// may be due to unsupported class signature)
150-
// then ignore the generic types in the symbol_type and do not add any pairs.
150+
// then ignore the generic types in the struct_tag_type and do not add any
151+
// pairs.
151152
// TODO TG-1996 should decide how mocking and generics should work
152153
// together. Currently an incomplete class is never marked as generic. If
153154
// this changes in TG-1996 then the condition below should be updated.
154155
if(
155-
is_java_generic_symbol_type(symbol_type) &&
156+
is_java_generic_struct_tag_type(struct_tag_type) &&
156157
!to_java_class_type(symbol_struct).get_is_stub() &&
157158
(is_java_generic_class_type(symbol_struct) ||
158159
is_java_implicitly_generic_class_type(symbol_struct)))
159160
{
160-
const java_generic_symbol_typet &generic_symbol =
161-
to_java_generic_symbol_type(symbol_type);
161+
const java_generic_struct_tag_typet &generic_symbol =
162+
to_java_generic_struct_tag_type(struct_tag_type);
162163

163164
const std::vector<java_generic_parametert> &generic_parameters =
164165
get_all_generic_parameters(symbol_struct);

jbmc/src/java_bytecode/generic_parameter_specialization_map_keys.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/// Author: Diffblue Ltd.
23

34
#ifndef CPROVER_JAVA_BYTECODE_GENERIC_PARAMETER_SPECIALIZATION_MAP_KEYS_H
@@ -50,9 +51,8 @@ class generic_parameter_specialization_map_keyst
5051
void insert_pairs_for_pointer(
5152
const pointer_typet &pointer_type,
5253
const typet &pointer_subtype_struct);
53-
void insert_pairs_for_symbol(
54-
const symbol_typet &symbol_type,
55-
const typet &symbol_struct);
54+
void
55+
insert_pairs_for_symbol(const struct_tag_typet &, const typet &symbol_struct);
5656

5757
private:
5858
/// Generic parameter specialization map to modify

jbmc/src/java_bytecode/java_bytecode_concurrency_instrumentation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static void instrument_synchronized_code(
230230

231231
// Create the finally block with the same label targeted in the catch-push
232232
const symbolt &tmp_symbol = get_fresh_aux_symbol(
233-
java_reference_type(symbol_typet("java::java.lang.Throwable")),
233+
java_reference_type(struct_tag_typet("java::java.lang.Throwable")),
234234
id2string(symbol.name),
235235
"caught-synchronized-exception",
236236
code.source_location(),

jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ void java_bytecode_convert_classt::convert(
338338

339339
if(!c.super_class.empty())
340340
{
341-
const symbol_typet base("java::" + id2string(c.super_class));
341+
const struct_tag_typet base("java::" + id2string(c.super_class));
342342

343343
// if the superclass is generic then the class has the superclass reference
344344
// including the generic info in its signature
@@ -350,7 +350,7 @@ void java_bytecode_convert_classt::convert(
350350
{
351351
try
352352
{
353-
const java_generic_symbol_typet generic_base(
353+
const java_generic_struct_tag_typet generic_base(
354354
base, superclass_ref.value(), qualified_classname);
355355
class_type.add_base(generic_base);
356356
}
@@ -378,7 +378,7 @@ void java_bytecode_convert_classt::convert(
378378
// interfaces are recorded as bases
379379
for(const auto &interface : c.implements)
380380
{
381-
const symbol_typet base("java::" + id2string(interface));
381+
const struct_tag_typet base("java::" + id2string(interface));
382382

383383
// if the interface is generic then the class has the interface reference
384384
// including the generic info in its signature
@@ -390,7 +390,7 @@ void java_bytecode_convert_classt::convert(
390390
{
391391
try
392392
{
393-
const java_generic_symbol_typet generic_base(
393+
const java_generic_struct_tag_typet generic_base(
394394
base, interface_ref.value(), qualified_classname);
395395
class_type.add_base(generic_base);
396396
}
@@ -774,26 +774,27 @@ void java_bytecode_convert_classt::add_array_types(symbol_tablet &symbol_table)
774774

775775
for(const char l : letters)
776776
{
777-
symbol_typet symbol_type=
778-
to_symbol_type(java_array_type(l).subtype());
777+
struct_tag_typet struct_tag_type =
778+
to_struct_tag_type(java_array_type(l).subtype());
779779

780-
const irep_idt &symbol_type_identifier=symbol_type.get_identifier();
781-
if(symbol_table.has_symbol(symbol_type_identifier))
780+
const irep_idt &struct_tag_type_identifier =
781+
struct_tag_type.get_identifier();
782+
if(symbol_table.has_symbol(struct_tag_type_identifier))
782783
return;
783784

784785
java_class_typet class_type;
785786
// we have the base class, java.lang.Object, length and data
786787
// of appropriate type
787-
class_type.set_tag(symbol_type_identifier);
788+
class_type.set_tag(struct_tag_type_identifier);
788789
// Note that non-array types don't have "java::" at the beginning of their
789790
// tag, and their name is "java::" + their tag. Since arrays do have
790791
// "java::" at the beginning of their tag we set the name to be the same as
791792
// the tag.
792-
class_type.set_name(symbol_type_identifier);
793+
class_type.set_name(struct_tag_type_identifier);
793794

794795
class_type.components().reserve(3);
795796
class_typet::componentt base_class_component(
796-
"@java.lang.Object", symbol_typet("java::java.lang.Object"));
797+
"@java.lang.Object", struct_tag_typet("java::java.lang.Object"));
797798
base_class_component.set_pretty_name("@java.lang.Object");
798799
base_class_component.set_base_name("@java.lang.Object");
799800
class_type.components().push_back(base_class_component);
@@ -809,16 +810,16 @@ void java_bytecode_convert_classt::add_array_types(symbol_tablet &symbol_table)
809810
data_component.set_base_name("data");
810811
class_type.components().push_back(data_component);
811812

812-
class_type.add_base(symbol_typet("java::java.lang.Object"));
813+
class_type.add_base(struct_tag_typet("java::java.lang.Object"));
813814

814815
INVARIANT(
815816
is_valid_java_array(class_type),
816817
"Constructed a new type representing a Java Array "
817818
"object that doesn't match expectations");
818819

819820
symbolt symbol;
820-
symbol.name=symbol_type_identifier;
821-
symbol.base_name=symbol_type.get(ID_C_base_name);
821+
symbol.name = struct_tag_type_identifier;
822+
symbol.base_name = struct_tag_type.get(ID_C_base_name);
822823
symbol.is_type=true;
823824
symbol.type = class_type;
824825
symbol.mode = ID_java;
@@ -827,13 +828,13 @@ void java_bytecode_convert_classt::add_array_types(symbol_tablet &symbol_table)
827828
// Also provide a clone method:
828829
// ----------------------------
829830

830-
const irep_idt clone_name=
831-
id2string(symbol_type_identifier)+".clone:()Ljava/lang/Object;";
831+
const irep_idt clone_name =
832+
id2string(struct_tag_type_identifier) + ".clone:()Ljava/lang/Object;";
832833
java_method_typet::parametert this_param;
833834
this_param.set_identifier(id2string(clone_name)+"::this");
834835
this_param.set_base_name("this");
835836
this_param.set_this();
836-
this_param.type()=java_reference_type(symbol_type);
837+
this_param.type() = java_reference_type(struct_tag_type);
837838
const java_method_typet clone_type({this_param}, java_lang_object_type());
838839

839840
parameter_symbolt this_symbol;
@@ -850,7 +851,7 @@ void java_bytecode_convert_classt::add_array_types(symbol_tablet &symbol_table)
850851
local_symbol.name=local_name;
851852
local_symbol.base_name="cloned_array";
852853
local_symbol.pretty_name=local_symbol.base_name;
853-
local_symbol.type=java_reference_type(symbol_type);
854+
local_symbol.type = java_reference_type(struct_tag_type);
854855
local_symbol.mode=ID_java;
855856
symbol_table.add(local_symbol);
856857
const auto &local_symexpr=local_symbol.symbol_expr();
@@ -860,9 +861,9 @@ void java_bytecode_convert_classt::add_array_types(symbol_tablet &symbol_table)
860861
source_locationt location;
861862
location.set_function(local_name);
862863
side_effect_exprt java_new_array(
863-
ID_java_new_array, java_reference_type(symbol_type), location);
864-
dereference_exprt old_array(this_symbol.symbol_expr(), symbol_type);
865-
dereference_exprt new_array(local_symexpr, symbol_type);
864+
ID_java_new_array, java_reference_type(struct_tag_type), location);
865+
dereference_exprt old_array(this_symbol.symbol_expr(), struct_tag_type);
866+
dereference_exprt new_array(local_symexpr, struct_tag_type);
866867
member_exprt old_length(
867868
old_array, length_component.get_name(), length_component.type());
868869
java_new_array.copy_to_operands(old_length);
@@ -923,8 +924,8 @@ void java_bytecode_convert_classt::add_array_types(symbol_tablet &symbol_table)
923924

924925
symbolt clone_symbol;
925926
clone_symbol.name=clone_name;
926-
clone_symbol.pretty_name=
927-
id2string(symbol_type_identifier)+".clone:()";
927+
clone_symbol.pretty_name =
928+
id2string(struct_tag_type_identifier) + ".clone:()";
928929
clone_symbol.base_name="clone";
929930
clone_symbol.type=clone_type;
930931
clone_symbol.value=clone_body;
@@ -1053,9 +1054,10 @@ static void find_and_replace_parameters(
10531054
find_and_replace_parameters(argument, replacement_parameters);
10541055
}
10551056
}
1056-
else if(is_java_generic_symbol_type(type))
1057+
else if(is_java_generic_struct_tag_type(type))
10571058
{
1058-
java_generic_symbol_typet &generic_base = to_java_generic_symbol_type(type);
1059+
java_generic_struct_tag_typet &generic_base =
1060+
to_java_generic_struct_tag_type(type);
10591061
std::vector<reference_typet> &gen_types = generic_base.generic_types();
10601062
for(auto &gen_type : gen_types)
10611063
{

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ void java_bytecode_convert_method_lazy(
380380
{
381381
java_method_typet::parameterst &parameters = member_type.parameters();
382382
java_method_typet::parametert this_p;
383-
const reference_typet object_ref_type=
384-
java_reference_type(symbol_typet(class_symbol.name));
383+
const reference_typet object_ref_type =
384+
java_reference_type(struct_tag_typet(class_symbol.name));
385385
this_p.type()=object_ref_type;
386386
this_p.set_this();
387387
parameters.insert(parameters.begin(), this_p);
@@ -655,7 +655,7 @@ static irep_idt get_if_cmp_operator(const irep_idt &stmt)
655655

656656
static member_exprt to_member(const exprt &pointer, const exprt &fieldref)
657657
{
658-
symbol_typet class_type(fieldref.get(ID_class));
658+
struct_tag_typet class_type(fieldref.get(ID_class));
659659

660660
const typecast_exprt pointer2(pointer, java_reference_type(class_type));
661661

@@ -1181,9 +1181,11 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
11811181
{
11821182
if(cur_pc==it->handler_pc)
11831183
{
1184-
if(catch_type != typet() || it->catch_type == symbol_typet(irep_idt()))
1184+
if(
1185+
catch_type != typet() ||
1186+
it->catch_type == struct_tag_typet(irep_idt()))
11851187
{
1186-
catch_type=symbol_typet("java::java.lang.Throwable");
1188+
catch_type = struct_tag_typet("java::java.lang.Throwable");
11871189
break;
11881190
}
11891191
else
@@ -1617,7 +1619,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
16171619
const typecast_exprt pointer(op[0], java_array_type(statement[0]));
16181620

16191621
dereference_exprt array(pointer, pointer.type().subtype());
1620-
PRECONDITION(pointer.type().subtype().id() == ID_symbol_type);
1622+
PRECONDITION(pointer.type().subtype().id() == ID_struct_tag);
16211623
array.set(ID_java_member_access, true);
16221624

16231625
const member_exprt length(array, "length", java_int_type());
@@ -2088,7 +2090,7 @@ void java_bytecode_convert_methodt::convert_invoke(
20882090
if(parameters.empty() || !parameters[0].get_this())
20892091
{
20902092
irep_idt classname = arg0.get(ID_C_class);
2091-
typet thistype = symbol_typet(classname);
2093+
typet thistype = struct_tag_typet(classname);
20922094
// Note invokespecial is used for super-method calls as well as
20932095
// constructors.
20942096
if(statement == "invokespecial")
@@ -2504,7 +2506,7 @@ void java_bytecode_convert_methodt::convert_new(
25042506
c = code_assignt(tmp, java_new_expr);
25052507
c.add_source_location() = location;
25062508
codet clinit_call =
2507-
get_clinit_call(to_symbol_type(arg0.type()).get_identifier());
2509+
get_clinit_call(to_struct_tag_type(arg0.type()).get_identifier());
25082510
if(clinit_call.get_statement() != ID_skip)
25092511
{
25102512
c = code_blockt({clinit_call, c});
@@ -2518,10 +2520,10 @@ code_blockt java_bytecode_convert_methodt::convert_putstatic(
25182520
const exprt::operandst &op,
25192521
const symbol_exprt &symbol_expr)
25202522
{
2521-
if(needed_lazy_methods && arg0.type().id() == ID_symbol_type)
2523+
if(needed_lazy_methods && arg0.type().id() == ID_struct_tag)
25222524
{
25232525
needed_lazy_methods->add_needed_class(
2524-
to_symbol_type(arg0.type()).get_identifier());
2526+
to_struct_tag_type(arg0.type()).get_identifier());
25252527
}
25262528

25272529
code_blockt block;
@@ -2566,18 +2568,18 @@ void java_bytecode_convert_methodt::convert_getstatic(
25662568
{
25672569
if(needed_lazy_methods)
25682570
{
2569-
if(arg0.type().id() == ID_symbol_type)
2571+
if(arg0.type().id() == ID_struct_tag)
25702572
{
25712573
needed_lazy_methods->add_needed_class(
2572-
to_symbol_type(arg0.type()).get_identifier());
2574+
to_struct_tag_type(arg0.type()).get_identifier());
25732575
}
25742576
else if(arg0.type().id() == ID_pointer)
25752577
{
25762578
const auto &pointer_type = to_pointer_type(arg0.type());
2577-
if(pointer_type.subtype().id() == ID_symbol_type)
2579+
if(pointer_type.subtype().id() == ID_struct_tag)
25782580
{
25792581
needed_lazy_methods->add_needed_class(
2580-
to_symbol_type(pointer_type.subtype()).get_identifier());
2582+
to_struct_tag_type(pointer_type.subtype()).get_identifier());
25812583
}
25822584
}
25832585
else if(is_assertions_disabled_field)

jbmc/src/java_bytecode/java_bytecode_instrument.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ code_ifthenelset java_bytecode_instrumentt::throw_exception(
108108
struct_union_typet::componentst{});
109109
}
110110

111-
pointer_typet exc_ptr_type=
112-
pointer_type(symbol_typet(exc_class_name));
111+
pointer_typet exc_ptr_type = pointer_type(struct_tag_typet(exc_class_name));
113112

114113
// Allocate and throw an instance of the exception class:
115114

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static void infer_opaque_type_fields(
362362
static symbol_exprt get_or_create_class_literal_symbol(
363363
const irep_idt &class_id, symbol_tablet &symbol_table)
364364
{
365-
symbol_typet java_lang_Class("java::java.lang.Class");
365+
struct_tag_typet java_lang_Class("java::java.lang.Class");
366366
symbol_exprt symbol_expr(
367367
id2string(class_id) + JAVA_CLASS_MODEL_SUFFIX,
368368
java_lang_Class);

jbmc/src/java_bytecode/java_bytecode_parse_tree.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ java_bytecode_parse_treet::find_annotation(
105105
if(annotation.type.id() != ID_pointer)
106106
return false;
107107
const typet &type = annotation.type.subtype();
108-
return type.id() == ID_symbol_type &&
109-
to_symbol_type(type).get_identifier() == annotation_type_name;
108+
return type.id() == ID_struct_tag &&
109+
to_struct_tag_type(type).get_identifier() == annotation_type_name;
110110
});
111111
if(annotation_it == annotations.end())
112112
return {};

jbmc/src/java_bytecode/java_bytecode_parse_tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct java_bytecode_parse_treet
117117
std::size_t start_pc;
118118
std::size_t end_pc;
119119
std::size_t handler_pc;
120-
symbol_typet catch_type;
120+
struct_tag_typet catch_type;
121121
};
122122

123123
typedef std::vector<exceptiont> exception_tablet;

0 commit comments

Comments
 (0)