Skip to content

Commit 59633e0

Browse files
author
Daniel Kroening
committed
introduce java_reference_typet
References in Java strictly point to objects, i.e., the subtype of this type is always a struct_tag_typet. This change makes this invariant explicit.
1 parent 5e7deb1 commit 59633e0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

jbmc/src/java_bytecode/java_types.h

+42
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,48 @@ inline java_method_typet &to_java_method_type(typet &type)
360360
return static_cast<java_method_typet &>(type);
361361
}
362362

363+
/// This is a specialization of reference_typet.
364+
/// The subtype is guaranteed to be a struct_tag_typet.
365+
class java_reference_typet : public reference_typet
366+
{
367+
public:
368+
explicit java_reference_typet(
369+
const struct_tag_typet &_subtype,
370+
std::size_t _width)
371+
: reference_typet(_subtype, _width)
372+
{
373+
}
374+
375+
struct_tag_typet &subtype()
376+
{
377+
return static_cast<struct_tag_typet &>(reference_typet::subtype());
378+
}
379+
380+
const struct_tag_typet &subtype() const
381+
{
382+
return static_cast<const struct_tag_typet &>(reference_typet::subtype());
383+
}
384+
};
385+
386+
template <>
387+
inline bool can_cast_type<java_reference_typet>(const typet &type)
388+
{
389+
return type.id() == ID_pointer &&
390+
to_type_with_subtype(type).subtype().id() == ID_struct_tag;
391+
}
392+
393+
inline const java_reference_typet &to_java_reference_type(const typet &type)
394+
{
395+
PRECONDITION(can_cast_type<java_reference_typet>(type));
396+
return static_cast<const java_reference_typet &>(type);
397+
}
398+
399+
inline java_reference_typet &to_java_reference_type(typet &type)
400+
{
401+
PRECONDITION(can_cast_type<java_reference_typet>(type));
402+
return static_cast<java_reference_typet &>(type);
403+
}
404+
363405
signedbv_typet java_int_type();
364406
signedbv_typet java_long_type();
365407
signedbv_typet java_short_type();

0 commit comments

Comments
 (0)