aboutsummaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-03-06 14:21:43 -0800
committerJukka Jylänki <jujjyl@gmail.com>2013-04-12 14:25:02 +0300
commitba6204bd5ca458a3999b5f6f056b267bb1d92fed (patch)
tree4c0f3a1329c1c5dfa96e859139139dc4d7a71372 /system
parentec62a534e990b20a3ff85cf7aa6da96e6f41e446 (diff)
Rewrite how dependent type registrations are implemented. This reduces code size both in JS and C++. There are some known bugs. I'll get to those soon.
Diffstat (limited to 'system')
-rwxr-xr-xsystem/include/emscripten/bind.h50
-rwxr-xr-xsystem/lib/embind/bind.cpp47
2 files changed, 55 insertions, 42 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h
index 24a7bf71..e8cedbe4 100755
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -106,6 +106,8 @@ namespace emscripten {
TYPEID pointerType,
TYPEID constPointerType,
TYPEID baseClassType,
+ GenericFunction upcast,
+ GenericFunction downcast,
bool isPolymorphic,
const char* className,
GenericFunction destructor);
@@ -159,8 +161,6 @@ namespace emscripten {
GenericFunction destructor);
}
- extern void registerStandardTypes();
-
class BindingsDefinition {
public:
template<typename Function>
@@ -248,9 +248,6 @@ namespace emscripten {
template<typename ReturnType, typename... Args, typename... Policies>
void function(const char* name, ReturnType (*fn)(Args...), Policies...) {
using namespace internal;
-
- registerStandardTypes();
-
typename WithPolicies<Policies...>::template ArgTypeList<ReturnType, Args...> args;
_embind_register_function(
name,
@@ -415,7 +412,6 @@ namespace emscripten {
class value_tuple {
public:
value_tuple(const char* name) {
- internal::registerStandardTypes();
internal::_embind_register_tuple(
internal::TypeID<ClassType>::get(),
name,
@@ -501,7 +497,6 @@ namespace emscripten {
class value_struct {
public:
value_struct(const char* name) {
- internal::registerStandardTypes();
internal::_embind_register_struct(
internal::TypeID<ClassType>::get(),
name,
@@ -562,7 +557,6 @@ namespace emscripten {
using namespace internal;
typedef typename smart_ptr_trait<PointerType>::element_type PointeeType;
- registerStandardTypes();
_embind_register_smart_ptr(
TypeID<PointerType>::get(),
TypeID<PointeeType>::get(),
@@ -613,27 +607,52 @@ namespace emscripten {
namespace internal {
struct NoBaseClass {
+ template<typename ClassType>
+ static void verify() {
+ }
+
static TYPEID get() {
- return 0;
+ return nullptr;
}
template<typename ClassType>
- static void verify() {
+ static GenericFunction getUpcaster() {
+ return nullptr;
+ }
+
+ template<typename ClassType>
+ static GenericFunction getDowncaster() {
+ return nullptr;
}
};
}
template<typename BaseClass>
struct base {
- static internal::TYPEID get() {
- return internal::TypeID<BaseClass>::get();
- }
-
template<typename ClassType>
static void verify() {
static_assert(!std::is_same<ClassType, BaseClass>::value, "Base must not have same type as class");
static_assert(std::is_base_of<BaseClass, ClassType>::value, "Derived class must derive from base");
}
+
+ static internal::TYPEID get() {
+ return internal::TypeID<BaseClass>::get();
+ }
+
+ template<typename ClassType>
+ static internal::GenericFunction getUpcaster() {
+ return reinterpret_cast<internal::GenericFunction>(&convertPointer<ClassType, BaseClass>);
+ }
+
+ template<typename ClassType>
+ static internal::GenericFunction getDowncaster() {
+ return reinterpret_cast<internal::GenericFunction>(&convertPointer<BaseClass, ClassType>);
+ }
+
+ template<typename From, typename To>
+ static To* convertPointer(From* ptr) {
+ return static_cast<To*>(ptr);
+ }
};
template<typename ClassType, typename BaseSpecifier = internal::NoBaseClass>
@@ -644,12 +663,13 @@ namespace emscripten {
BaseSpecifier::template verify<ClassType>();
- registerStandardTypes();
_embind_register_class(
TypeID<ClassType>::get(),
TypeID<AllowedRawPointer<ClassType>>::get(),
TypeID<AllowedRawPointer<const ClassType>>::get(),
BaseSpecifier::get(),
+ BaseSpecifier::template getUpcaster<ClassType>(),
+ BaseSpecifier::template getDowncaster<ClassType>(),
std::is_polymorphic<ClassType>::value,
name,
reinterpret_cast<GenericFunction>(&raw_destructor<ClassType>));
diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp
index cbff7cf1..6c792f78 100755
--- a/system/lib/embind/bind.cpp
+++ b/system/lib/embind/bind.cpp
@@ -66,33 +66,6 @@ namespace __cxxabiv1 {
namespace emscripten {
namespace internal {
- void registerStandardTypes() {
- static bool first = true;
- if (first) {
- first = false;
-
- _embind_register_void(TypeID<void>::get(), "void");
-
- _embind_register_bool(TypeID<bool>::get(), "bool", true, false);
-
- _embind_register_integer(TypeID<char>::get(), "char");
- _embind_register_integer(TypeID<signed char>::get(), "signed char");
- _embind_register_integer(TypeID<unsigned char>::get(), "unsigned char");
- _embind_register_integer(TypeID<signed short>::get(), "short");
- _embind_register_integer(TypeID<unsigned short>::get(), "unsigned short");
- _embind_register_integer(TypeID<signed int>::get(), "int");
- _embind_register_integer(TypeID<unsigned int>::get(), "unsigned int");
- _embind_register_integer(TypeID<signed long>::get(), "long");
- _embind_register_integer(TypeID<unsigned long>::get(), "unsigned long");
-
- _embind_register_float(TypeID<float>::get(), "float");
- _embind_register_float(TypeID<double>::get(), "double");
-
- _embind_register_cstring(TypeID<std::string>::get(), "std::string");
- _embind_register_emval(TypeID<val>::get(), "emscripten::val");
- }
- }
-
// __getDerivationPath returns an array of type_info pointers describing the derivation chain starting with
// the derived type and proceeding toward (and ending with) the base type. Types are only included if they
// appear on all possible derivation paths.
@@ -216,6 +189,26 @@ namespace emscripten {
}
EMSCRIPTEN_BINDINGS(([]() {
+ _embind_register_void(TypeID<void>::get(), "void");
+
+ _embind_register_bool(TypeID<bool>::get(), "bool", true, false);
+
+ _embind_register_integer(TypeID<char>::get(), "char");
+ _embind_register_integer(TypeID<signed char>::get(), "signed char");
+ _embind_register_integer(TypeID<unsigned char>::get(), "unsigned char");
+ _embind_register_integer(TypeID<signed short>::get(), "short");
+ _embind_register_integer(TypeID<unsigned short>::get(), "unsigned short");
+ _embind_register_integer(TypeID<signed int>::get(), "int");
+ _embind_register_integer(TypeID<unsigned int>::get(), "unsigned int");
+ _embind_register_integer(TypeID<signed long>::get(), "long");
+ _embind_register_integer(TypeID<unsigned long>::get(), "unsigned long");
+
+ _embind_register_float(TypeID<float>::get(), "float");
+ _embind_register_float(TypeID<double>::get(), "double");
+
+ _embind_register_cstring(TypeID<std::string>::get(), "std::string");
+ _embind_register_emval(TypeID<val>::get(), "emscripten::val");
+
// We bind __getDerivationPath in order to take advantage of the std::vector to Javascript array
// conversion for the return value. This has the unfortunate side-effect of exposing it to third party
// developers, but perhaps the double underscore will scare them away from calling it.