Skip to content
Merged
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
13 changes: 11 additions & 2 deletions src/util/std_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,12 @@ class code_typet:public typet
}
};

template <>
inline bool can_cast_type<code_typet>(const typet &type)
{
return type.id() == ID_code;
}

/*! \brief Cast a generic typet to a \ref code_typet
*
* This is an unchecked conversion. \a type must be known to be \ref
Expand All @@ -986,7 +992,8 @@ class code_typet:public typet
*/
inline const code_typet &to_code_type(const typet &type)
{
PRECONDITION(type.id()==ID_code);
PRECONDITION(can_cast_type<code_typet>(type));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is what I meant

validate_type(type);
return static_cast<const code_typet &>(type);
}

Expand All @@ -995,10 +1002,12 @@ inline const code_typet &to_code_type(const typet &type)
*/
inline code_typet &to_code_type(typet &type)
{
PRECONDITION(type.id()==ID_code);
PRECONDITION(can_cast_type<code_typet>(type));
validate_type(type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh - never heard of this before - any reason not to stick this in the can_cast_type?

Copy link
Contributor Author

@NathanJPhillips NathanJPhillips Jul 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this fails it doesn't mean that the type is not the right type, it means that there's an internal inconsistency.
Since it's run by try_cast and friends it seemed good to put it here too.

return static_cast<code_typet &>(type);
}


/*! \brief arrays with given size
*/
class array_typet:public type_with_subtypet
Expand Down