refactor(util/object_ref): move and adjust cnstr_get_ref_t

This commit is contained in:
Sebastian Ullrich 2019-09-08 13:42:47 +02:00
parent 560e7af128
commit 2d04ecc704
2 changed files with 7 additions and 7 deletions

View file

@ -47,13 +47,6 @@ namespace ir {
typedef object_ref lit_val;
typedef object_ref ctor_info;
// TODO(Sebastian): move
template<class T>
inline T const & cnstr_get_ref_t(object_ref const & o, unsigned i) {
static_assert(sizeof(T) == sizeof(object_ref), "unexpected object wrapper size");
return *reinterpret_cast<T const *>(&cnstr_get_ref(o.raw(), i));
}
bool arg_is_irrelevant(arg const & a) { return is_scalar(a.raw()); }
var_id const & arg_var_id(arg const & a) { lean_assert(!arg_is_irrelevant(a)); return cnstr_get_ref_t<var_id>(a, 0); }

View file

@ -137,6 +137,13 @@ inline object_ref const & cnstr_get_ref(object_ref const & ref, unsigned i) {
return cnstr_get_ref(ref.raw(), i);
}
template<class T>
inline T const & cnstr_get_ref_t(object_ref const & o, unsigned i) {
static_assert(sizeof(T) == sizeof(object_ref), "unexpected object wrapper size");
return static_cast<T const &>(cnstr_get_ref(o.raw(), i));
}
/* Given `T` which is a subclass of object_ref that wraps a Lean value of type `Ty`,
convert a value `o` of `Option Ty` into `optional<T>` */
template<typename T> optional<T> to_optional(obj_arg o) {