Skip to content

Commit 00b9bf6

Browse files
author
Thomas Kiley
authored
Merge pull request #2051 from svorenova/generics_tg2717
[TG-2717] Generic inheritance with pointer replacement
2 parents cd4bfc3 + 506faf0 commit 00b9bf6

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/java_bytecode/java_object_factory.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,13 @@ void java_object_factoryt::gen_nondet_pointer_init(
766766
// for java types, technical debt TG-2707
767767
if(!equal_java_types(replacement_pointer_type, pointer_type))
768768
{
769+
// update generic_parameter_specialization_map for the new pointer
770+
generic_parameter_specialization_map_keyst
771+
generic_parameter_specialization_map_keys(
772+
generic_parameter_specialization_map);
773+
generic_parameter_specialization_map_keys.insert_pairs_for_pointer(
774+
replacement_pointer_type, ns.follow(replacement_pointer_type.subtype()));
775+
769776
const symbol_exprt real_pointer_symbol = gen_nondet_subtype_pointer_init(
770777
assignments, alloc_type, replacement_pointer_type, depth);
771778

src/java_bytecode/java_types.h

+13
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,19 @@ class java_generic_symbol_typet : public symbol_typet
604604
{
605605
return (generic_typest &)(add(ID_generic_types).get_sub());
606606
}
607+
608+
/// Check if this symbol has the given generic type. If yes, return its index
609+
/// in the vector of generic types.
610+
/// \param type The type we are looking for.
611+
/// \return The index of the type in the vector of generic types.
612+
optionalt<size_t> generic_type_index(const reference_typet &type) const
613+
{
614+
const auto &type_pointer =
615+
std::find(generic_types().begin(), generic_types().end(), type);
616+
if(type_pointer != generic_types().end())
617+
return type_pointer - generic_types().begin();
618+
return {};
619+
}
607620
};
608621

609622
/// \param type: the type to check

src/util/std_types.h

+11-4
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,22 @@ class class_typet:public struct_typet
396396
bases().push_back(baset(base));
397397
}
398398

399-
bool has_base(const irep_idt &id) const
399+
/// Return the base with the given name, if exists.
400+
/// \param id The name of the base we are looking for.
401+
/// \return The base if exists.
402+
optionalt<baset> get_base(const irep_idt &id) const
400403
{
401404
for(const auto &b : bases())
402405
{
403-
if(to_symbol_type(b.type()).get(ID_identifier)==id)
404-
return true;
406+
if(to_symbol_type(b.type()).get_identifier() == id)
407+
return b;
405408
}
409+
return {};
410+
}
406411

407-
return false;
412+
bool has_base(const irep_idt &id) const
413+
{
414+
return get_base(id).has_value();
408415
}
409416

410417
bool is_abstract() const

0 commit comments

Comments
 (0)