9 #include <hilti/rt/exception.h>
10 #include <hilti/rt/type-info.h>
11 #include <hilti/rt/types/reference.h>
19 HILTI_EXCEPTION(ContextMismatch, UsageError)
38 : _object(std::move(obj)), _type_info(ti) {}
45 template<
typename Context>
47 if ( ti != _type_info )
48 throw ContextMismatch(
hilti::rt::fmt(
"context mismatch between related units: expected %s, but got %s",
52 return hilti::rt::any_cast<hilti::rt::StrongReference<Context>>(_object);
65 hilti::rt::any _object;
77 template<
typename Context>
79 if ( ti->
tag == hilti::rt::TypeInfo::Tag::StrongReference )
82 return UnitContext(std::move(ctx), ti);
94 template<
typename Context>
100 context = new_ctx->as<Context>(ti);
109 namespace hilti::rt::detail::adl {
112 return "<unit context>";
Definition: optional.h:33
Definition: reference.h:399
const TypeInfo * valueType() const
Definition: type-info.h:206
Definition: unit-context.h:28
UnitContext(hilti::rt::StrongReference< T > obj, const hilti::rt::TypeInfo *ti)
Definition: unit-context.h:37
hilti::rt::StrongReference< Context > as(const hilti::rt::TypeInfo *ti) const
Definition: unit-context.h:46
std::string fmt(const char *fmt, const Args &... args)
Definition: fmt.h:17
std::string to_string(T &&x)
Definition: extension-points.h:26
Definition: type-info.h:1276
const char * display
Definition: type-info.h:1278
Tag tag
Tag indicating which field of below union is set.
Definition: type-info.h:1336