Skip to content

[TG-2717] Generic inheritance with pointer replacement #2051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/java_bytecode/java_object_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,13 @@ void java_object_factoryt::gen_nondet_pointer_init(
// for java types, technical debt TG-2707
if(!equal_java_types(replacement_pointer_type, pointer_type))
{
// update generic_parameter_specialization_map for the new pointer
generic_parameter_specialization_map_keyst
generic_parameter_specialization_map_keys(
generic_parameter_specialization_map);
generic_parameter_specialization_map_keys.insert_pairs_for_pointer(
replacement_pointer_type, ns.follow(replacement_pointer_type.subtype()));

const symbol_exprt real_pointer_symbol = gen_nondet_subtype_pointer_init(
assignments, alloc_type, replacement_pointer_type, depth);

Expand Down
13 changes: 13 additions & 0 deletions src/java_bytecode/java_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,19 @@ class java_generic_symbol_typet : public symbol_typet
{
return (generic_typest &)(add(ID_generic_types).get_sub());
}

/// Check if this symbol has the given generic type. If yes, return its index
/// in the vector of generic types.
/// \param type The type we are looking for.
/// \return The index of the type in the vector of generic types.
optionalt<size_t> generic_type_index(const reference_typet &type) const
{
const auto &type_pointer =
std::find(generic_types().begin(), generic_types().end(), type);
if(type_pointer != generic_types().end())
return type_pointer - generic_types().begin();
return {};
}
};

/// \param type: the type to check
Expand Down
15 changes: 11 additions & 4 deletions src/util/std_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,22 @@ class class_typet:public struct_typet
bases().push_back(baset(base));
}

bool has_base(const irep_idt &id) const
/// Return the base with the given name, if exists.
/// \param id The name of the base we are looking for.
/// \return The base if exists.
optionalt<baset> get_base(const irep_idt &id) const
{
for(const auto &b : bases())
{
if(to_symbol_type(b.type()).get(ID_identifier)==id)
return true;
if(to_symbol_type(b.type()).get_identifier() == id)
return b;
}
return {};
}

return false;
bool has_base(const irep_idt &id) const
{
return get_base(id).has_value();
}

bool is_abstract() const
Expand Down