diff options
author | Bill Welden <bwelden@imvu.com> | 2012-12-22 10:19:52 -0800 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:22:43 +0300 |
commit | 2308f2a5b19e92d9f974b4a7ee733d5c6f3da4bb (patch) | |
tree | 87cc47a16987dd783f2186e0300e4a6ca4fcf162 /system | |
parent | ea98beba7402b83a05434342d5b2af85aae3dd42 (diff) |
More work on auto downcasting.
Diffstat (limited to 'system')
-rwxr-xr-x | system/include/emscripten/bind.h | 26 | ||||
-rwxr-xr-x | system/lib/embind/bind.cpp | 24 |
2 files changed, 31 insertions, 19 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 90dca77c..c37aed24 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -95,6 +95,7 @@ namespace emscripten { void _embind_register_smart_ptr( TYPEID pointerType, TYPEID pointeeType, + bool isPolymorphic, const char* pointerName, GenericFunction destructor, GenericFunction getPointee); @@ -124,14 +125,17 @@ namespace emscripten { void _embind_register_cast_method( TYPEID classType, + bool isPolymorphic, const char* methodName, TYPEID returnType, GenericFunction invoker); void _embind_register_pointer_cast_method( - TYPEID classType, - const char* methodName, + TYPEID pointerType, TYPEID returnType, + TYPEID returnPointeeType, + bool isPolymorphic, + const char* methodName, GenericFunction invoker); void _embind_register_class_field( @@ -269,16 +273,16 @@ namespace emscripten { extern "C" { int __getDynamicPointerType(int p); - int __dynamicPointerCast(int p, int from, int to); + int __dynamicPointerCast(int p, int to); } template<typename FromType, typename ToType> - ToType& performCast(FromType& from) { - return *dynamic_cast<ToType*>(&from); + ToType& performRawStaticCast(FromType& from) { + return *static_cast<ToType*>(&from); }; template<typename FromRawType, typename ToRawType> - std::shared_ptr<ToRawType> performPointerCast(std::shared_ptr<FromRawType> from) { + std::shared_ptr<ToRawType> performSharedStaticCast(std::shared_ptr<FromRawType> from) { return std::shared_ptr<ToRawType>(from, static_cast<ToRawType*>(from.get())); }; @@ -598,6 +602,7 @@ namespace emscripten { _embind_register_smart_ptr( TypeID<PointerType>::get(), TypeID<PointeeType>::get(), + std::is_polymorphic<PointeeType>::value, name, reinterpret_cast<GenericFunction>(&raw_destructor<PointerType>), reinterpret_cast<GenericFunction>(&get_pointee<PointerType>)); @@ -611,9 +616,11 @@ namespace emscripten { typedef typename PointerType::element_type PointeeType; _embind_register_pointer_cast_method( TypeID<PointerType>::get(), - methodName, TypeID<ReturnType>::get(), - reinterpret_cast<GenericFunction>(&performPointerCast<PointeeType,ReturnPointeeType>)); + TypeID<ReturnPointeeType>::get(), + std::is_polymorphic<PointeeType>::value, + methodName, + reinterpret_cast<GenericFunction>(&performSharedStaticCast<PointeeType,ReturnPointeeType>)); return *this; } }; @@ -756,9 +763,10 @@ namespace emscripten { _embind_register_cast_method( TypeID<ClassType>::get(), + std::is_polymorphic<ClassType>::value, methodName, TypeID<ReturnType>::get(), - reinterpret_cast<GenericFunction>(&performCast<ClassType,ReturnType>)); + reinterpret_cast<GenericFunction>(&performRawStaticCast<ClassType,ReturnType>)); return *this; } }; diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp index de03052a..bc1e09ee 100755 --- a/system/lib/embind/bind.cpp +++ b/system/lib/embind/bind.cpp @@ -138,19 +138,19 @@ namespace emscripten { return derivationPath;
}
- void* EMSCRIPTEN_KEEPALIVE __staticPointerCast(void* p, int dv, int bs) {
+ void* EMSCRIPTEN_KEEPALIVE __staticPointerCast(void* p, int from, int to) {
std::vector<std::vector<const __cxxabiv1::__class_type_info*>> paths;
int direction = 1;
- const std::type_info* dv1 = (std::type_info*)dv;
- const std::type_info* bs1 = (std::type_info*)bs;
- const __cxxabiv1::__class_type_info* dv2 = dynamic_cast<const __cxxabiv1::__class_type_info*>(dv1);
- const __cxxabiv1::__class_type_info* bs2 = dynamic_cast<const __cxxabiv1::__class_type_info*>(bs1);
+ const std::type_info* from1 = (std::type_info*)from;
+ const std::type_info* to1 = (std::type_info*)to;
+ const __cxxabiv1::__class_type_info* from2 = dynamic_cast<const __cxxabiv1::__class_type_info*>(from1);
+ const __cxxabiv1::__class_type_info* to2 = dynamic_cast<const __cxxabiv1::__class_type_info*>(to1);
- if (dv2 && bs2) {
- __cxxabiv1::__getDerivationPaths(dv2, bs2, std::vector<const __cxxabiv1::__class_type_info*>(), paths);
+ if (from2 && to2) {
+ __cxxabiv1::__getDerivationPaths(from2, to2, std::vector<const __cxxabiv1::__class_type_info*>(), paths);
if (paths.size() == 0) {
- __cxxabiv1::__getDerivationPaths(bs2, dv2, std::vector<const __cxxabiv1::__class_type_info*>(), paths);
+ __cxxabiv1::__getDerivationPaths(to2, from2, std::vector<const __cxxabiv1::__class_type_info*>(), paths);
direction = -1;
}
}
@@ -189,10 +189,14 @@ namespace emscripten { // __dynamicPointerCast performs a C++ dynamic_cast<>() operation, but allowing run-time specification of
// the from and to pointer types.
- int EMSCRIPTEN_KEEPALIVE __dynamicPointerCast(int p, int from, int to) {
+ int EMSCRIPTEN_KEEPALIVE __dynamicPointerCast(int p, int to) {
// The final parameter is a place-holder for a hint, a feature which is not currently implemented
// in the emscripten runtime. The compiler passes a dummy value of -1, and so do we.
- return (int)__dynamic_cast((void *)p, (const std::type_info*)from, (const std::type_info *)to, -1);
+ int ret = (int)__staticPointerCast((void *)p, __getDynamicPointerType(p), to);
+ if (ret < 0) {
+ return 0;
+ }
+ return ret;
}
const char* EMSCRIPTEN_KEEPALIVE __typeName(int p) {
|