From 7e19fc2e5bfba9475d1d11a8ed65c2772da02e8d Mon Sep 17 00:00:00 2001 From: Chad Austin Date: Sun, 13 Apr 2014 14:45:21 -0700 Subject: class and enum signatures --- system/include/emscripten/bind.h | 143 ++++++++++++++++++++++++++++----------- 1 file changed, 102 insertions(+), 41 deletions(-) (limited to 'system/include') diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index e86e7536..29e6a56e 100644 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -119,31 +119,26 @@ namespace emscripten { void _embind_finalize_value_object(TYPEID structType); - void _embind_register_smart_ptr( - TYPEID pointerType, - TYPEID pointeeType, - const char* pointerName, - sharing_policy sharingPolicy, - GenericFunction getPointee, - GenericFunction constructor, - GenericFunction share, - GenericFunction destructor); - void _embind_register_class( TYPEID classType, TYPEID pointerType, TYPEID constPointerType, TYPEID baseClassType, + const char* getActualTypeSignature, GenericFunction getActualType, + const char* upcastSignature, GenericFunction upcast, + const char* downcastSignature, GenericFunction downcast, const char* className, + const char* destructorSignature, GenericFunction destructor); void _embind_register_class_constructor( TYPEID classType, unsigned argCount, TYPEID argTypes[], + const char* invokerSignature, GenericFunction invoker, GenericFunction constructor); @@ -152,6 +147,7 @@ namespace emscripten { const char* methodName, unsigned argCount, TYPEID argTypes[], + const char* invokerSignature, GenericFunction invoker, void* context); @@ -159,9 +155,11 @@ namespace emscripten { TYPEID classType, const char* fieldName, TYPEID getterReturnType, + const char* getterSignature, GenericFunction getter, void* getterContext, TYPEID setterArgumentType, + const char* setterSignature, GenericFunction setter, void* setterContext); @@ -170,6 +168,7 @@ namespace emscripten { const char* methodName, unsigned argCount, TYPEID argTypes[], + const char* invokerSignature, GenericFunction invoker, GenericFunction method); @@ -179,17 +178,25 @@ namespace emscripten { size_t size, bool isSigned); + void _embind_register_smart_ptr( + TYPEID pointerType, + TYPEID pointeeType, + const char* pointerName, + sharing_policy sharingPolicy, + const char* getPointeeSignature, + GenericFunction getPointee, + const char* constructorSignature, + GenericFunction constructor, + const char* shareSignature, + GenericFunction share, + const char* destructorSignature, + GenericFunction destructor); + void _embind_register_enum_value( TYPEID enumType, const char* valueName, GenericEnumValue value); - void _embind_register_interface( - TYPEID interfaceType, - const char* name, - GenericFunction constructor, - GenericFunction destructor); - void _embind_register_constant( const char* name, TYPEID constantType, @@ -944,13 +951,19 @@ namespace emscripten { } template - static internal::GenericFunction getUpcaster() { - return reinterpret_cast(&convertPointer); + using Upcaster = BaseClass* (*)(ClassType*); + + template + using Downcaster = ClassType* (*)(BaseClass*); + + template + static Upcaster getUpcaster() { + return &convertPointer; } template - static internal::GenericFunction getDowncaster() { - return reinterpret_cast(&convertPointer); + static Downcaster getDowncaster() { + return &convertPointer; } template @@ -989,16 +1002,25 @@ namespace emscripten { BaseSpecifier::template verify(); + auto _getActualType = &getActualType; + auto upcast = BaseSpecifier::template getUpcaster(); + auto downcast = BaseSpecifier::template getDowncaster(); + auto destructor = &raw_destructor; + _embind_register_class( TypeID::get(), TypeID>::get(), TypeID>::get(), BaseSpecifier::get(), - reinterpret_cast(&getActualType), - BaseSpecifier::template getUpcaster(), - BaseSpecifier::template getDowncaster(), + getSignature(_getActualType), + reinterpret_cast(_getActualType), + getSignature(upcast), + reinterpret_cast(upcast), + getSignature(downcast), + reinterpret_cast(downcast), name, - reinterpret_cast(&raw_destructor)); + getSignature(destructor), + reinterpret_cast(destructor)); } template @@ -1010,15 +1032,24 @@ namespace emscripten { static_assert(std::is_same::type>::value, "smart pointer must point to this class"); + auto get = &PointerTrait::get; + auto construct_null = &PointerTrait::construct_null; + auto share = &PointerTrait::share; + auto destructor = &raw_destructor; + _embind_register_smart_ptr( TypeID::get(), TypeID::get(), typeid(PointerType).name(), PointerTrait::get_sharing_policy(), - reinterpret_cast(&PointerTrait::get), - reinterpret_cast(&PointerTrait::construct_null), - reinterpret_cast(&PointerTrait::share), - reinterpret_cast(&raw_destructor)); + getSignature(get), + reinterpret_cast(get), + getSignature(construct_null), + reinterpret_cast(construct_null), + getSignature(share), + reinterpret_cast(share), + getSignature(destructor), + reinterpret_cast(destructor)); return *this; }; @@ -1035,11 +1066,13 @@ namespace emscripten { // TODO: allows all raw pointers... policies need a rethink typename WithPolicies::template ArgTypeList args; + auto invoke = &Invoker::invoke; _embind_register_class_constructor( TypeID::get(), args.count, args.types, - reinterpret_cast(&Invoker::invoke), + getSignature(invoke), + reinterpret_cast(invoke), reinterpret_cast(factory)); return *this; } @@ -1051,11 +1084,13 @@ namespace emscripten { smart_ptr(); typename WithPolicies::template ArgTypeList args; + auto invoke = &Invoker::invoke; _embind_register_class_constructor( TypeID::get(), args.count, args.types, - reinterpret_cast(&Invoker::invoke), + getSignature(invoke), + reinterpret_cast(invoke), reinterpret_cast(factory)); return *this; } @@ -1078,13 +1113,16 @@ namespace emscripten { EMSCRIPTEN_ALWAYS_INLINE const class_& function(const char* methodName, ReturnType (ClassType::*memberFunction)(Args...), Policies...) const { using namespace internal; + auto invoker = &MethodInvoker::invoke; + typename WithPolicies::template ArgTypeList, Args...> args; _embind_register_class_function( TypeID::get(), methodName, args.count, args.types, - reinterpret_cast(&MethodInvoker::invoke), + getSignature(invoker), + reinterpret_cast(invoker), getContext(memberFunction)); return *this; } @@ -1093,13 +1131,16 @@ namespace emscripten { EMSCRIPTEN_ALWAYS_INLINE const class_& function(const char* methodName, ReturnType (ClassType::*memberFunction)(Args...) const, Policies...) const { using namespace internal; + auto invoker = &MethodInvoker::invoke; + typename WithPolicies::template ArgTypeList, Args...> args; _embind_register_class_function( TypeID::get(), methodName, args.count, args.types, - reinterpret_cast(&MethodInvoker::invoke), + getSignature(invoker), + reinterpret_cast(invoker), getContext(memberFunction)); return *this; } @@ -1109,12 +1150,14 @@ namespace emscripten { using namespace internal; typename WithPolicies::template ArgTypeList args; + auto invoke = &FunctionInvoker::invoke; _embind_register_class_function( TypeID::get(), methodName, args.count, args.types, - reinterpret_cast(&FunctionInvoker::invoke), + getSignature(invoke), + reinterpret_cast(invoke), getContext(function)); return *this; } @@ -1122,15 +1165,18 @@ namespace emscripten { template::value>::type> EMSCRIPTEN_ALWAYS_INLINE const class_& property(const char* fieldName, const FieldType ClassType::*field) const { using namespace internal; - + + auto getter = &MemberAccess::template getWire; _embind_register_class_property( TypeID::get(), fieldName, TypeID::get(), - reinterpret_cast(&MemberAccess::template getWire), + getSignature(getter), + reinterpret_cast(getter), getContext(field), 0, 0, + 0, 0); return *this; } @@ -1139,14 +1185,18 @@ namespace emscripten { EMSCRIPTEN_ALWAYS_INLINE const class_& property(const char* fieldName, FieldType ClassType::*field) const { using namespace internal; + auto getter = &MemberAccess::template getWire; + auto setter = &MemberAccess::template setWire; _embind_register_class_property( TypeID::get(), fieldName, TypeID::get(), - reinterpret_cast(&MemberAccess::template getWire), + getSignature(getter), + reinterpret_cast(getter), getContext(field), TypeID::get(), - reinterpret_cast(&MemberAccess::template setWire), + getSignature(setter), + reinterpret_cast(setter), getContext(field)); return *this; } @@ -1155,14 +1205,17 @@ namespace emscripten { EMSCRIPTEN_ALWAYS_INLINE const class_& property(const char* fieldName, Getter getter) const { using namespace internal; typedef GetterPolicy GP; + auto gter = &GP::template get; _embind_register_class_property( TypeID::get(), fieldName, TypeID::get(), - reinterpret_cast(&GP::template get), + getSignature(gter), + reinterpret_cast(gter), GP::getContext(getter), 0, 0, + 0, 0); return *this; } @@ -1172,14 +1225,20 @@ namespace emscripten { using namespace internal; typedef GetterPolicy GP; typedef SetterPolicy SP; + + auto gter = &GP::template get; + auto ster = &SP::template set; + _embind_register_class_property( TypeID::get(), fieldName, TypeID::get(), - reinterpret_cast(&GP::template get), + getSignature(gter), + reinterpret_cast(gter), GP::getContext(getter), TypeID::get(), - reinterpret_cast(&SP::template set), + getSignature(ster), + reinterpret_cast(ster), SP::getContext(setter)); return *this; } @@ -1189,12 +1248,14 @@ namespace emscripten { using namespace internal; typename WithPolicies::template ArgTypeList args; + auto invoke = &internal::Invoker::invoke; _embind_register_class_class_function( TypeID::get(), methodName, args.count, args.types, - reinterpret_cast(&internal::Invoker::invoke), + getSignature(invoke), + reinterpret_cast(invoke), reinterpret_cast(classMethod)); return *this; } -- cgit v1.2.3-18-g5258