Skip to content

Commit 58f8482

Browse files
author
thk123
committed
Add the generic type arguments to the specalised type
This is useful information when trying to output this type without muddying the waters by labeling it as a generic type (which it isn't)
1 parent 7310281 commit 58f8482

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

src/java_bytecode/generate_java_generic_type.cpp

+6-15
Original file line numberDiff line numberDiff line change
@@ -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+
new_tag,
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

@@ -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

-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ class generate_java_generic_typet
3232
const java_generic_class_typet &replacement_type,
3333
const java_generic_typet &generic_reference) const;
3434

35-
java_specialized_generic_class_typet construct_specialised_generic_type(
36-
const irep_idt &new_tag,
37-
const struct_typet::componentst &new_components) const;
38-
3935
type_symbolt build_symbol_from_specialised_class(
4036
const java_class_typet &specialised_class) const;
4137

src/java_bytecode/java_types.h

+22-3
Original file line numberDiff line numberDiff line change
@@ -442,22 +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.
447449
/// \param generic_name: The new name for the class
448450
/// (like Generic<java::Float>)
451+
/// \param tag: The name for the original class (like java::Generic)
449452
/// \param new_components: The specialised components
450453
/// \return The newly constructed class.
451454
java_specialized_generic_class_typet(
452455
const irep_idt &generic_name,
453-
const struct_typet::componentst &new_components)
456+
const irep_idt &tag,
457+
const struct_typet::componentst &new_components,
458+
const generic_type_argumentst &specialised_parameters)
454459
{
455460
set(ID_C_specialized_generic_java_class, true);
456461
set(ID_name, "java::" + id2string(generic_name));
457462
set(ID_base_name, id2string(generic_name));
458463
components() = new_components;
459-
const std::string &class_tag = id2string(new_tag);
460-
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());
461480
}
462481
};
463482

0 commit comments

Comments
 (0)