Skip to content

Commit 982f69c

Browse files
author
svorenova
committed
Utility functions for generic types
These will be used in test generator to convert generic pointer types.
1 parent 0ad0673 commit 982f69c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/java_bytecode/java_types.h

+14
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,20 @@ class java_generic_symbol_typet : public symbol_typet
507507
{
508508
return (generic_typest &)(add(ID_generic_types).get_sub());
509509
}
510+
511+
/// Check if this symbol has the given generic type. If yes, return its index
512+
/// in the vector of generic types.
513+
/// \param type The type we are looking for.
514+
/// \return The index of the type in the vector of generic types.
515+
optionalt<size_t> generic_type(const reference_typet &type) const
516+
{
517+
const size_t &index =
518+
std::find(generic_types().begin(), generic_types().end(), type) -
519+
generic_types().begin();
520+
if(index < generic_types().size())
521+
return index;
522+
return {};
523+
}
510524
};
511525

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

src/util/std_types.h

+16
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,22 @@ class class_typet:public struct_typet
401401
return false;
402402
}
403403

404+
/// Return the base with the given name, if exists.
405+
/// \param id The name of the base we are looking for.
406+
/// \return The base if exists.
407+
optionalt<baset> get_base(const irep_idt &id) const
408+
{
409+
if(has_base(id))
410+
{
411+
for(const auto &b : bases())
412+
{
413+
if(to_symbol_type(b.type()).get(ID_identifier) == id)
414+
return b;
415+
}
416+
}
417+
return {};
418+
}
419+
404420
bool is_abstract() const
405421
{
406422
return get_bool(ID_abstract);

0 commit comments

Comments
 (0)