Skip to content

Commit 1cc22f5

Browse files
author
Thomas Kiley
authored
Merge pull request diffblue#1651 from thk123/bugfix/TG-1157/store-generic-info-in-specialized-class
[TG-1157] Store generic info in specialised class
2 parents 0393027 + 3a46525 commit 1cc22f5

File tree

3 files changed

+39
-35
lines changed

3 files changed

+39
-35
lines changed

src/java_bytecode/generate_java_generic_type.cpp

+10-19
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ symbolt generate_java_generic_typet::operator()(
4242
const java_generic_class_typet &generic_class_definition =
4343
to_java_generic_class_type(to_java_class_type(pointer_subtype));
4444

45-
const irep_idt new_tag =
46-
build_generic_tag(existing_generic_type, generic_class_definition);
45+
const irep_idt generic_name =
46+
build_generic_name(existing_generic_type, generic_class_definition);
4747
struct_union_typet::componentst replacement_components =
4848
generic_class_definition.components();
4949

@@ -73,8 +73,12 @@ symbolt generate_java_generic_typet::operator()(
7373
pre_modification_size==after_modification_size,
7474
"All components in the original class should be in the new class");
7575

76-
const java_specialized_generic_class_typet new_java_class =
77-
construct_specialised_generic_type(new_tag, replacement_components);
76+
const java_specialized_generic_class_typet new_java_class{
77+
generic_name,
78+
generic_class_definition.get_tag(),
79+
replacement_components,
80+
existing_generic_type.generic_type_arguments()};
81+
7882
const type_symbolt &class_symbol =
7983
build_symbol_from_specialised_class(new_java_class);
8084

@@ -86,7 +90,7 @@ symbolt generate_java_generic_typet::operator()(
8690
<< " already exists" << messaget::eom;
8791
}
8892

89-
const auto expected_symbol="java::"+id2string(new_tag);
93+
const auto expected_symbol="java::"+id2string(generic_name);
9094
auto symbol=symbol_table.lookup(expected_symbol);
9195
INVARIANT(symbol, "New class not created");
9296
return *symbol;
@@ -184,7 +188,7 @@ typet generate_java_generic_typet::substitute_type(
184188
/// \param existing_generic_type The type we want to concretise
185189
/// \param original_class
186190
/// \return A tag for the new generic we want a unique tag for.
187-
irep_idt generate_java_generic_typet::build_generic_tag(
191+
irep_idt generate_java_generic_typet::build_generic_name(
188192
const java_generic_typet &existing_generic_type,
189193
const java_class_typet &original_class) const
190194
{
@@ -227,19 +231,6 @@ irep_idt generate_java_generic_typet::build_generic_tag(
227231
return new_tag_buffer.str();
228232
}
229233

230-
/// Build the specialised version of the specific class, with the specified
231-
/// parameters and name.
232-
/// \param new_tag: The new name for the class (like Generic<java::Float>)
233-
/// \param new_components: The specialised components
234-
/// \return The newly constructed class.
235-
java_specialized_generic_class_typet
236-
generate_java_generic_typet::construct_specialised_generic_type(
237-
const irep_idt &new_tag,
238-
const struct_typet::componentst &new_components) const
239-
{
240-
return java_specialized_generic_class_typet{new_tag, new_components};
241-
}
242-
243234
/// Construct the symbol to be moved into the symbol table
244235
/// \param specialised_class: The newly constructed specialised class
245236
/// \return The symbol to add to the symbol table

src/java_bytecode/generate_java_generic_type.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
class generate_java_generic_typet
1818
{
1919
public:
20-
generate_java_generic_typet(
21-
message_handlert &message_handler);
20+
explicit generate_java_generic_typet(message_handlert &message_handler);
2221

2322
symbolt operator()(
2423
const java_generic_typet &existing_generic_type,
2524
symbol_tablet &symbol_table) const;
2625
private:
27-
irep_idt build_generic_tag(
26+
irep_idt build_generic_name(
2827
const java_generic_typet &existing_generic_type,
2928
const java_class_typet &original_class) const;
3029

@@ -33,10 +32,6 @@ class generate_java_generic_typet
3332
const java_generic_class_typet &replacement_type,
3433
const java_generic_typet &generic_reference) const;
3534

36-
java_specialized_generic_class_typet construct_specialised_generic_type(
37-
const irep_idt &new_tag,
38-
const struct_typet::componentst &new_components) const;
39-
4035
type_symbolt build_symbol_from_specialised_class(
4136
const java_class_typet &specialised_class) const;
4237

src/java_bytecode/java_types.h

+27-9
Original file line numberDiff line numberDiff line change
@@ -442,23 +442,41 @@ void get_dependencies_from_generic_parameters(
442442
class java_specialized_generic_class_typet : public java_class_typet
443443
{
444444
public:
445+
typedef std::vector<reference_typet> generic_type_argumentst;
446+
445447
/// Build the specialised version of the specific class, with the specified
446448
/// parameters and name.
447-
/// \param new_tag: The new name for the class (like Generic<java::Float>)
449+
/// \param generic_name: The new name for the class
450+
/// (like Generic<java::Float>)
451+
/// \param tag: The name for the original class (like java::Generic)
448452
/// \param new_components: The specialised components
449453
/// \return The newly constructed class.
450454
java_specialized_generic_class_typet(
451-
const irep_idt &new_tag,
452-
const struct_typet::componentst &new_components)
455+
const irep_idt &generic_name,
456+
const irep_idt &tag,
457+
const struct_typet::componentst &new_components,
458+
const generic_type_argumentst &specialised_parameters)
453459
{
454460
set(ID_C_specialized_generic_java_class, true);
455-
// We are specialising the logic - so we don't want to be marked as generic
456-
set(ID_C_java_generics_class_type, false);
457-
set(ID_name, "java::" + id2string(new_tag));
458-
set(ID_base_name, id2string(new_tag));
461+
set(ID_name, "java::" + id2string(generic_name));
462+
set(ID_base_name, id2string(generic_name));
459463
components() = new_components;
460-
const std::string &class_tag = id2string(new_tag);
461-
set_tag(class_tag.substr(0, class_tag.find('<')));
464+
set_tag(tag);
465+
466+
generic_type_arguments() = specialised_parameters;
467+
}
468+
469+
/// \return vector of type variables
470+
const generic_type_argumentst &generic_type_arguments() const
471+
{
472+
return (const generic_type_argumentst &)(find(ID_type_variables).get_sub());
473+
}
474+
475+
private:
476+
/// \return vector of type variables
477+
generic_type_argumentst &generic_type_arguments()
478+
{
479+
return (generic_type_argumentst &)(add(ID_type_variables).get_sub());
462480
}
463481
};
464482

0 commit comments

Comments
 (0)