Several adaptations and fixes on the way to get V8 emitter running.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/oliverb-javascript-v8@13788 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
8d72616e65
commit
78442b2764
6 changed files with 209 additions and 206 deletions
|
|
@ -1,101 +1,131 @@
|
|||
%fragment("v8_initializer", "templates") %{
|
||||
void ${MODULE}_Initialize(v8::Handle<v8::Context> context)
|
||||
%fragment("JS_ctordefn", "templates") %{
|
||||
v8::Handle<v8::Value> $jsmangledname_new(const v8::Arguments& args) {
|
||||
v8::HandleScope scope;
|
||||
v8::Handle<v8::Object> self = args.Holder();
|
||||
$jslocals
|
||||
$jscode
|
||||
self->SetInternalField(0, v8::External::New(result));
|
||||
return scope.Close(self);
|
||||
goto fail;
|
||||
fail:
|
||||
return scope.Close(v8::Undefined);
|
||||
}%}
|
||||
|
||||
%fragment("JS_getproperty", "templates") %{
|
||||
v8::Handle<v8::Value> $jsgetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) {
|
||||
v8::HandleScope scope;
|
||||
v8::Handle<v8::Object> jsresult;
|
||||
$jslocals
|
||||
$jscode
|
||||
return scope.Close(jsresult);
|
||||
goto fail;
|
||||
fail:
|
||||
return scope.Close(v8::Undefined());
|
||||
}%}
|
||||
|
||||
%fragment("JS_setproperty", "templates") %{
|
||||
void $jssetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) {
|
||||
v8::HandleScope scope;
|
||||
$jslocals
|
||||
$jscode
|
||||
goto fail;
|
||||
fail:
|
||||
return;
|
||||
}%}
|
||||
|
||||
%fragment("JS_functionwrapper", "templates") %{
|
||||
v8::Handle<v8::Value> $jswrapper(const v8::Arguments &args) {
|
||||
v8::HandleScope scope;
|
||||
v8::Handle<v8::Object> jsresult;
|
||||
$jslocals
|
||||
$jscode
|
||||
return scope.Close(jsresult);
|
||||
goto fail;
|
||||
fail:
|
||||
return scope.Close(v8::Undefined());
|
||||
}%}
|
||||
|
||||
// TODO: implement ctor overloading properly!
|
||||
%fragment ("JS_mainctordefn", "templates")
|
||||
%{
|
||||
// TODO: implement JS_mainctordefn
|
||||
%}
|
||||
|
||||
%fragment ("JS_ctor_dispatch_case", "templates")
|
||||
%{
|
||||
// TODO: implement JS_ctor_dispatch_case
|
||||
%}
|
||||
|
||||
%fragment ("JS_destructordefn", "templates")
|
||||
%{
|
||||
// TODO: implement JS_destructordefn
|
||||
%}
|
||||
|
||||
%fragment("jsv8_declare_class_template", "templates") %{
|
||||
v8::Persistent<v8::FunctionTemplate> SWIGV8_$jsmangledname;%}
|
||||
|
||||
%fragment("jsv8_define_class_template", "templates") %{
|
||||
SWIGV8_$jsmangledname = SWIGV8_CreateClassTemplate("$jsname" , $jsmangledname_new);%}
|
||||
|
||||
%fragment("jsv8_create_class_instance", "templates") %{
|
||||
v8::Handle<v8::Object> class_$jsmangledname = SWIGV8_$jsmangledname->GetFunction();%}
|
||||
|
||||
%fragment("jsv8_inherit", "templates") %{
|
||||
SWIGV8_$jsmangledname->Inherit(SWIGV8_$jsbaseclass);%}
|
||||
|
||||
%fragment("jsv8_register_class", "templates") %{
|
||||
$jsparent->Set(v8::String::NewSymbol("$jsname"), class_$jsmangledname);%}
|
||||
|
||||
%fragment("jsv8_create_namespace", "templates") %{
|
||||
v8::Handle<v8::ObjectTemplate> $jsmangledname = v8::ObjectTemplate::New();%}
|
||||
|
||||
%fragment("jsv8_register_member_function", "templates") %{
|
||||
SWIGV8_AddMemberFunction(SWIGV8_$jsmangledname, "$jsname", $jswrapper);%}
|
||||
|
||||
%fragment("jsv8_register_static_function", "templates") %{
|
||||
SWIGV8_AddGlobalFunction($jsparent, "$jsname", $jswrapper);%}
|
||||
|
||||
%fragment("jsv8_register_member_variable", "templates") %{
|
||||
SWIGV8_AddMemberVariable(SWIGV8_$jsmangledname, "$jsname", $jsgetter, $jssetter);%}
|
||||
|
||||
%fragment("jsv8_register_static_variable", "templates") %{
|
||||
SWIGV8_AddGlobalVariable($jsparent, "$jsname", $jsgetter, $jssetter);%}
|
||||
|
||||
%fragment("jsv8_register_namespace", "templates") %{
|
||||
$jsparent->Set(v8::String::NewSymbol("$jsname", $jsmangledname->NewInstance()));%}
|
||||
|
||||
%fragment("JS_initializer", "templates") %{
|
||||
|
||||
extern "C" {
|
||||
|
||||
void $jsname_initialize(v8::Handle<v8::Context> context)
|
||||
{
|
||||
v8::HandleScope scope;
|
||||
v8::Local<v8::Object> global = context->Global();
|
||||
|
||||
/* create object templates for namespaces */
|
||||
${PART_NAMESPACES}
|
||||
$jsv8nspaces
|
||||
|
||||
/* create class templates */
|
||||
${PART_CLASS_TEMPLATES}
|
||||
$jsv8classtemplates
|
||||
|
||||
/* register wrapper functions */
|
||||
${PART_WRAPPERS}
|
||||
$jsv8wrappers
|
||||
|
||||
/* setup inheritances */
|
||||
${PART_INHERITANCE}
|
||||
$jsv8inheritance
|
||||
|
||||
/* class instances */
|
||||
${PART_CLASS_INSTANCES}
|
||||
$jsv8classinstances
|
||||
|
||||
/* add static class functions and variables */
|
||||
${PART_STATIC_WRAPPERS}
|
||||
$jsv8staticwrappers
|
||||
|
||||
/* register classes */
|
||||
${PART_REGISTER_CLASSES}
|
||||
$jsv8registerclasses
|
||||
|
||||
/* create and register namespace objects */
|
||||
${PART_REGISTER_NS}
|
||||
$jsv8registernspaces
|
||||
}
|
||||
|
||||
}%}
|
||||
|
||||
%fragment("v8_declare_class_template", "templates") %{
|
||||
v8::Persistent<v8::FunctionTemplate> SWIGV8_${NAME_MANGLED};%}
|
||||
|
||||
%fragment("v8_define_class_template", "templates") %{
|
||||
SWIGV8_${NAME_MANGLED} = SWIGV8_CreateClassTemplate("${NAME_UNQUALIFIED}" , ${NAME_MANGLED}_new);%}
|
||||
|
||||
%fragment("v8_create_class_instance", "templates") %{
|
||||
v8::Handle<v8::Object> class_${NAME_MANGLED} = SWIGV8_${NAME_MANGLED}->GetFunction();%}
|
||||
|
||||
%fragment("v8_inherit", "templates") %{
|
||||
SWIGV8_${NAME_MANGLED}->Inherit(SWIGV8_${BASE_CLASS});%}
|
||||
|
||||
%fragment("v8_register_class", "templates") %{
|
||||
${CONTEXT}->Set(v8::String::NewSymbol("${NAME_UNQUALIFIED}"), class_${NAME_MANGLED});%}
|
||||
|
||||
%fragment("v8_ctor_wrapper", "templates") %{
|
||||
v8::Handle<v8::Value> ${NAME_MANGLED}_new(const v8::Arguments& args) {
|
||||
v8::HandleScope scope;
|
||||
v8::Handle<v8::Object> self = args.Holder();
|
||||
${LOCALS}
|
||||
${CODE}
|
||||
self->SetInternalField(0, v8::External::New(result));
|
||||
return self;
|
||||
}%}
|
||||
|
||||
%fragment("v8_getter", "templates") %{
|
||||
v8::Handle<v8::Value> ${NAME_MANGLED}_get(v8::Local<v8::String> property, const v8::AccessorInfo& info) {
|
||||
v8::HandleScope scope;
|
||||
v8::Handle<v8::Object> jsresult;
|
||||
${LOCALS}
|
||||
${CODE}
|
||||
return scope.Close(jsresult);
|
||||
}%}
|
||||
|
||||
%fragment("v8_setter", "templates") %{
|
||||
void ${NAME_MANGLED}_set(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) {
|
||||
${LOCALS}
|
||||
${CODE}
|
||||
}%}
|
||||
|
||||
%fragment("v8_function", "templates") %{
|
||||
v8::Handle<v8::Value> wrap_${NAME_MANGLED}(const Arguments &args) {
|
||||
v8::HandleScope scope;
|
||||
v8::Handle<v8::Object> jsresult;
|
||||
${LOCALS}
|
||||
${CODE}
|
||||
return scope.Close(jsresult);
|
||||
}%}
|
||||
|
||||
%fragment("v8_create_namespace", "templates") %{
|
||||
v8::Handle<v8::ObjectTemplate> ${NAME_MANGLED} = v8::ObjectTemplate::New();%}
|
||||
|
||||
%fragment("v8_register_member_function", "templates") %{
|
||||
SWIGV8_AddMemberFunction(SWIGV8_${CLASSNAME_MANGLED}, "${NAME_UNQUALIFIED}", wrap_${NAME_MANGLED});%}
|
||||
|
||||
%fragment("v8_register_global_function", "templates") %{
|
||||
SWIGV8_AddGlobalFunction(${CONTEXT}, "${NAME_UNQUALIFIED}", wrap_${NAME_MANGLED});%}
|
||||
|
||||
%fragment("v8_register_member_variable", "templates") %{
|
||||
SWIGV8_AddMemberVariable(SWIGV8_${CLASSNAME_MANGLED}, "${NAME_UNQUALIFIED}", ${GETTER}, ${SETTER});%}
|
||||
|
||||
%fragment("v8_register_global_variable", "templates") %{
|
||||
SWIGV8_AddGlobalVariable(${CONTEXT}, "${NAME_UNQUALIFIED}", ${GETTER}, ${SETTER});%}
|
||||
|
||||
%fragment("v8_register_namespace", "templates") %{
|
||||
${CONTEXT}->Set(v8::String::NewSymbol("${NAME_UNQUALIFIED}", ${NAME_MANGLED}->NewInstance()));%}
|
||||
|
||||
%fragment("v8_this_ptr", "templates") %{
|
||||
arg1 = SWIGV8_UnwrapThisPointer<${TYPE}>(${ARG}.Holder());
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,6 @@ v8::Persistent<v8::FunctionTemplate> SWIGV8_CreateClassTemplate(const char* symb
|
|||
return v8::Persistent<v8::FunctionTemplate>::New(class_templ);
|
||||
}
|
||||
|
||||
v8::Handle<v8::ObjectTemplate> SWIGV8_CreateNamespace(const char* name, v8::Handle<v8::Context> parentContext) {
|
||||
Handle<ObjectTemplate> namespace = ObjectTemplate::New();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a class method with given name for a given class template.
|
||||
*/
|
||||
|
|
@ -29,7 +25,7 @@ void SWIGV8_AddMemberFunction(v8::Handle<v8::FunctionTemplate> class_templ, cons
|
|||
* Registers a class method with given name for a given class template.
|
||||
*/
|
||||
void SWIGV8_AddGlobalFunction(v8::Handle<v8::ObjectTemplate> obj_templ, const char* symbol, v8::InvocationCallback _func) {
|
||||
obj_templ->Set(String::NewSymbol(symbol), v8::FunctionTemplate::New(_func)->GetFunction());
|
||||
obj_templ->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func)->GetFunction());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -44,6 +40,6 @@ void SWIGV8_AddMemberVariable(v8::Handle<v8::FunctionTemplate> class_templ, cons
|
|||
* Registers a class method with given name for a given class template.
|
||||
*/
|
||||
void SWIGV8_AddGlobalVariable(v8::Handle<v8::ObjectTemplate> obj_templ, const char* symbol, v8::AccessorGetter getter, v8::AccessorSetter setter) {
|
||||
obj_templ->SetAccessor(String::NewSymbol(symbol), getter, setter);
|
||||
obj_templ->SetAccessor(v8::String::NewSymbol(symbol), getter, setter);
|
||||
}
|
||||
%} // v8_helper_functions
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ v8::Handle<v8::Value> SWIG_From_dec(long)(long value)
|
|||
SWIGINTERN
|
||||
int SWIG_AsVal_dec(long)(v8::Handle<v8::Value> obj, long* val)
|
||||
{
|
||||
if (!obj->IsInteger()) {
|
||||
if (!obj->IsNumber()) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
if(val) *val = (long) obj->IntegerValue();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
%insert(runtime) %{
|
||||
#include <v8.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
%}
|
||||
|
||||
%insert(runtime) "swigrun.swg"; /* SWIG API */
|
||||
|
|
@ -39,12 +41,12 @@ void SWIG_V8_exception(int code, const char* msg) {
|
|||
|
||||
|
||||
%insert(runtime) %{
|
||||
int SWIG_JSC_ConvertInstancePtr(v8::Handle<v8::Object> objRef, void** ptr, swig_type_info *info, int flags) {
|
||||
int SWIG_V8_ConvertInstancePtr(v8::Handle<v8::Object> objRef, void** ptr, swig_type_info *info, int flags) {
|
||||
|
||||
if(objRef->InternalFieldCount() < 1) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
Handle<Value> cdataRef = objRef->GetInternalField(0);
|
||||
v8::Handle<v8::Value> cdataRef = objRef->GetInternalField(0);
|
||||
|
||||
SWIG_PRV_DATA *cdata = (SWIG_PRV_DATA *) v8::External::Unwrap(cdataRef);
|
||||
if(cdata == NULL) {
|
||||
|
|
@ -80,14 +82,14 @@ int SWIG_V8_ConvertPtr(v8::Handle<v8::Value> valRef, void** ptr, swig_type_info
|
|||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
v8::Handle<v8::object> objRef = valRef->ToObject();
|
||||
v8::Handle<v8::Object> objRef = valRef->ToObject();
|
||||
|
||||
return SWIG_V8_ConvertInstancePtr(context, objRef, ptr, info, flags);
|
||||
return SWIG_V8_ConvertInstancePtr(objRef, ptr, info, flags);
|
||||
}
|
||||
|
||||
v8::Handle<v8::Object> SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int flags) {
|
||||
// TODO: wrap ptr into an v8 object
|
||||
return 0;
|
||||
return v8::Undefined();
|
||||
}
|
||||
|
||||
#define SWIG_ConvertPtr(obj, ptr, info, flags) SWIG_V8_ConvertPtr(obj, ptr, info, flags)
|
||||
|
|
|
|||
0
Lib/javascript/v8/javascriptstrings.swg
Normal file
0
Lib/javascript/v8/javascriptstrings.swg
Normal file
|
|
@ -16,6 +16,8 @@ bool js_template_enable_debug = false;
|
|||
#define GETTER "getter"
|
||||
#define SETTER "setter"
|
||||
#define PARENT "parent"
|
||||
#define CTORS "ctors"
|
||||
#define CTOR_DISPATCHERS "ctor_dispatchers"
|
||||
|
||||
// variables used in code templates
|
||||
// ATTENTION: be aware of prefix collisions when defining those variables
|
||||
|
|
@ -35,6 +37,16 @@ bool js_template_enable_debug = false;
|
|||
#define T_LOCALS "$jslocals"
|
||||
#define T_CODE "$jscode"
|
||||
|
||||
// v8 specific variables used in templates
|
||||
#define V8_NAME_SPACES "$jsv8nspaces"
|
||||
#define V8_CLASS_TEMPLATES "$jsv8classtemplates"
|
||||
#define V8_WRAPPERS "$jsv8wrappers"
|
||||
#define V8_INHERITANCE "$jsv8inheritance"
|
||||
#define V8_CLASS_INSTANCES "$jsv8classinstances"
|
||||
#define V8_STATIC_WRAPPERS "$jsv8staticwrappers"
|
||||
#define V8_REGISTER_CLASSES "$jsv8registerclasses"
|
||||
#define V8_REGISTER_NS "$jsv8registernspaces"
|
||||
|
||||
/**
|
||||
* A convenience class to manage state variables for emitters.
|
||||
* The implementation delegates to swig Hash DOHs and provides
|
||||
|
|
@ -725,6 +737,9 @@ int JSEmitter::enterClass(Node *n) {
|
|||
Delete(type);
|
||||
state.clazz(TYPE_MANGLED, classtype_mangled);
|
||||
|
||||
state.clazz(CTORS, NewString(""));
|
||||
state.clazz(CTOR_DISPATCHERS, NewString(""));
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
|
|
@ -875,8 +890,6 @@ private:
|
|||
#define MEMBER_FUNCTIONS "member_functions"
|
||||
#define STATIC_FUNCTIONS "static_functions"
|
||||
#define STATIC_VARIABLES "static_variables"
|
||||
#define CTORS "ctors"
|
||||
#define CTOR_DISPATCHERS "ctor_dispatchers"
|
||||
|
||||
// keys for function scoped state variables
|
||||
#define FUNCTION_DISPATCHERS "function_dispatchers"
|
||||
|
|
@ -1126,8 +1139,6 @@ int JSCEmitter::enterClass(Node *n) {
|
|||
state.clazz(MEMBER_FUNCTIONS, NewString(""));
|
||||
state.clazz(STATIC_VARIABLES, NewString(""));
|
||||
state.clazz(STATIC_FUNCTIONS, NewString(""));
|
||||
state.clazz(CTORS, NewString(""));
|
||||
state.clazz(CTOR_DISPATCHERS, NewString(""));
|
||||
|
||||
Template t_class_defn = getTemplate("JS_class_definition");
|
||||
t_class_defn.replace(T_NAME_MANGLED, state.clazz(NAME_MANGLED))
|
||||
|
|
@ -1536,7 +1547,6 @@ private:
|
|||
File *f_runtime;
|
||||
File *f_header;
|
||||
File *f_class_templates;
|
||||
File *f_wrapper;
|
||||
File *f_init;
|
||||
|
||||
File *f_init_namespaces;
|
||||
|
|
@ -1555,51 +1565,6 @@ private:
|
|||
String* NULL_STR;
|
||||
};
|
||||
|
||||
// name of templates
|
||||
#define V8_INITIALIZER "v8_initializer"
|
||||
#define V8_DECL_CLASSTEMPLATE "v8_declare_class_template"
|
||||
#define V8_DEFINE_CLASSTEMPLATE "v8_define_class_template"
|
||||
#define V8_CREATE_CLASS_INSTANCE "v8_create_class_instance"
|
||||
#define V8_INHERIT "v8_inherit"
|
||||
#define V8_REGISTER_CLASS "v8_register_class"
|
||||
#define V8_CTOR_WRAPPER "v8_ctor_wrapper"
|
||||
#define V8_GETTER "v8_getter"
|
||||
#define V8_SETTER "v8_setter"
|
||||
#define V8_FUNCTION "v8_function"
|
||||
#define V8_RETRIEVE_THIS "v8_retrieve_this"
|
||||
#define V8_REGISTER_MEMBER_FUNCTION "v8_register_member_function"
|
||||
#define V8_REGISTER_GLOBAL_FUNCTION "v8_register_global_function"
|
||||
#define V8_REGISTER_MEMBER_VARIABLE "v8_register_member_variable"
|
||||
#define V8_REGISTER_GLOBAL_VARIABLE "v8_register_global_variable"
|
||||
#define V8_CREATE_NAMESPACE "v8_create_namespace"
|
||||
#define V8_REGISTER_NAMESPACE "v8_register_namespace"
|
||||
#define V8_THIS_PTR "v8_this_ptr"
|
||||
|
||||
// keywords used in templates
|
||||
#define KW_MODULE_NAME "${MODULE}"
|
||||
#define KW_MANGLED_NAME "${NAME_MANGLED}"
|
||||
#define KW_UNQUALIFIED_NAME "${NAME_UNQUALIFIED}"
|
||||
#define KW_CLASSNAME_MANGLED "${CLASSNAME_MANGLED}"
|
||||
#define KW_BASE_CLASS "${BASE_CLASS}"
|
||||
#define KW_CONTEXT "${CONTEXT}"
|
||||
#define KW_TYPE "${TYPE}"
|
||||
#define KW_ARG "${ARG}"
|
||||
#define KW_WRAPPER "${WRAPPER}"
|
||||
#define KW_GETTER "${GETTER}"
|
||||
#define KW_SETTER "${SETTER}"
|
||||
|
||||
#define KW_NAME_SPACES "${PART_NAMESPACES}"
|
||||
#define KW_CLASS_TEMPLATES "${PART_CLASS_TEMPLATES}"
|
||||
#define KW_WRAPPERS "${PART_WRAPPERS}"
|
||||
#define KW_INHERITANCE "${PART_INHERITANCE}"
|
||||
#define KW_CLASS_INSTANCES "${PART_CLASS_INSTANCES}"
|
||||
#define KW_STATIC_WRAPPERS "${PART_STATIC_WRAPPERS}"
|
||||
#define KW_REGISTER_CLASSES "${PART_REGISTER_CLASSES}"
|
||||
#define KW_REGISTER_NS "${PART_REGISTER_NS}"
|
||||
|
||||
#define KW_LOCALS T_LOCALS
|
||||
#define KW_CODE T_CODE
|
||||
|
||||
V8Emitter::V8Emitter()
|
||||
: JSEmitter(),
|
||||
GLOBAL(NewString("global")),
|
||||
|
|
@ -1628,7 +1593,6 @@ int V8Emitter::initialize(Node *n)
|
|||
f_runtime = NewString("");
|
||||
f_header = NewString("");
|
||||
f_class_templates = NewString("");
|
||||
f_wrapper = NewString("");
|
||||
f_init = NewString("");
|
||||
|
||||
f_init_namespaces = NewString("");
|
||||
|
|
@ -1644,7 +1608,6 @@ int V8Emitter::initialize(Node *n)
|
|||
Swig_register_filebyname("runtime", f_runtime);
|
||||
Swig_register_filebyname("header", f_header);
|
||||
Swig_register_filebyname("init", f_init);
|
||||
Swig_register_filebyname("wrapper", f_wrapper);
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
|
@ -1657,23 +1620,27 @@ int V8Emitter::dump(Node *n)
|
|||
// write the swig banner
|
||||
Swig_banner(f_wrap_cpp);
|
||||
|
||||
SwigType_emit_type_table(f_runtime, f_wrappers);
|
||||
|
||||
Printv(f_wrap_cpp, f_runtime, "\n", 0);
|
||||
Printv(f_wrap_cpp, f_header, "\n", 0);
|
||||
Printv(f_wrap_cpp, f_class_templates, "\n", 0);
|
||||
Printv(f_wrap_cpp, f_wrapper, "\n", 0);
|
||||
Printv(f_wrap_cpp, f_wrappers, "\n", 0);
|
||||
|
||||
emitNamespaces();
|
||||
|
||||
// compose the initializer function using a template
|
||||
// filled with sub-parts
|
||||
Template initializer(getTemplate(V8_INITIALIZER));
|
||||
initializer.replace(KW_MODULE_NAME, module)
|
||||
.replace(KW_NAME_SPACES, f_init_namespaces)
|
||||
.replace(KW_CLASS_TEMPLATES, f_init_class_templates)
|
||||
.replace(KW_WRAPPERS, f_init_wrappers)
|
||||
.replace(KW_INHERITANCE, f_init_inheritance)
|
||||
.replace(KW_CLASS_INSTANCES, f_init_class_instances)
|
||||
.replace(KW_STATIC_WRAPPERS, f_init_static_wrappers)
|
||||
.replace(KW_REGISTER_CLASSES, f_init_register_classes)
|
||||
.replace(KW_REGISTER_NS, f_init_register_namespaces)
|
||||
Template initializer(getTemplate("JS_initializer"));
|
||||
initializer.replace(T_NAME, module)
|
||||
.replace(V8_NAME_SPACES, f_init_namespaces)
|
||||
.replace(V8_CLASS_TEMPLATES, f_init_class_templates)
|
||||
.replace(V8_WRAPPERS, f_init_wrappers)
|
||||
.replace(V8_INHERITANCE, f_init_inheritance)
|
||||
.replace(V8_CLASS_INSTANCES, f_init_class_instances)
|
||||
.replace(V8_STATIC_WRAPPERS, f_init_static_wrappers)
|
||||
.replace(V8_REGISTER_CLASSES, f_init_register_classes)
|
||||
.replace(V8_REGISTER_NS, f_init_register_namespaces)
|
||||
.pretty_print(f_wrap_cpp);
|
||||
|
||||
return SWIG_OK;
|
||||
|
|
@ -1685,7 +1652,6 @@ int V8Emitter::close()
|
|||
Delete(f_runtime);
|
||||
Delete(f_header);
|
||||
Delete(f_class_templates);
|
||||
Delete(f_wrapper);
|
||||
Delete(f_init_namespaces);
|
||||
Delete(f_init_class_templates);
|
||||
Delete(f_init_wrappers);
|
||||
|
|
@ -1707,18 +1673,18 @@ int V8Emitter::enterClass(Node *n)
|
|||
JSEmitter::enterClass(n);
|
||||
|
||||
// emit declaration of a v8 class template
|
||||
Template t_decl_class(getTemplate(V8_DECL_CLASSTEMPLATE));
|
||||
t_decl_class.replace(KW_MANGLED_NAME, state.clazz(NAME_MANGLED))
|
||||
Template t_decl_class(getTemplate("jsv8_declare_class_template"));
|
||||
t_decl_class.replace(T_NAME_MANGLED, state.clazz(NAME_MANGLED))
|
||||
.pretty_print(f_class_templates);
|
||||
|
||||
// emit definition of v8 class template
|
||||
Template t_def_class(getTemplate(V8_DEFINE_CLASSTEMPLATE));
|
||||
t_def_class.replace(KW_MANGLED_NAME, state.clazz(NAME_MANGLED))
|
||||
.replace(KW_UNQUALIFIED_NAME, state.clazz(NAME))
|
||||
Template t_def_class(getTemplate("jsv8_define_class_template"));
|
||||
t_def_class.replace(T_NAME_MANGLED, state.clazz(NAME_MANGLED))
|
||||
.replace(T_NAME, state.clazz(NAME))
|
||||
.pretty_print(f_init_class_templates);
|
||||
|
||||
Template t_class_instance(getTemplate(V8_CREATE_CLASS_INSTANCE));
|
||||
t_class_instance.replace(KW_MANGLED_NAME, state.clazz(NAME_MANGLED))
|
||||
Template t_class_instance(getTemplate("jsv8_create_class_instance"));
|
||||
t_class_instance.replace(T_NAME_MANGLED, state.clazz(NAME_MANGLED))
|
||||
.pretty_print(f_init_class_instances);
|
||||
|
||||
return SWIG_OK;
|
||||
|
|
@ -1729,19 +1695,19 @@ int V8Emitter::exitClass(Node *n)
|
|||
// emit inheritance setup
|
||||
Node* baseClass = getBaseClass(n);
|
||||
if(baseClass) {
|
||||
Template t_inherit(getTemplate(V8_INHERIT));
|
||||
Template t_inherit(getTemplate("jsv8_inherit"));
|
||||
String *base_name_mangled = SwigType_manglestr(Getattr(baseClass, "name"));
|
||||
t_inherit.replace(KW_MANGLED_NAME, state.clazz(NAME_MANGLED))
|
||||
.replace(KW_BASE_CLASS, base_name_mangled)
|
||||
t_inherit.replace(T_NAME_MANGLED, state.clazz(NAME_MANGLED))
|
||||
.replace(T_BASECLASS, base_name_mangled)
|
||||
.pretty_print(f_init_inheritance);
|
||||
Delete(base_name_mangled);
|
||||
}
|
||||
|
||||
// emit registeration of class template
|
||||
Template t_register(getTemplate(V8_REGISTER_CLASS));
|
||||
t_register.replace(KW_MANGLED_NAME, state.clazz(NAME_MANGLED))
|
||||
.replace(KW_UNQUALIFIED_NAME, state.clazz(NAME))
|
||||
.replace(KW_CONTEXT, Getattr(current_namespace, "name_mangled"))
|
||||
Template t_register(getTemplate("jsv8_register_class"));
|
||||
t_register.replace(T_NAME_MANGLED, state.clazz(NAME_MANGLED))
|
||||
.replace(T_NAME, state.clazz(NAME))
|
||||
.replace(T_PARENT, Getattr(current_namespace, "name_mangled"))
|
||||
.pretty_print(f_init_register_classes);
|
||||
|
||||
return SWIG_OK;
|
||||
|
|
@ -1761,29 +1727,31 @@ int V8Emitter::exitVariable(Node* n)
|
|||
{
|
||||
if(GetFlag(n, "ismember")) {
|
||||
if(GetFlag(state.variable(), IS_STATIC)) {
|
||||
Template t_register(getTemplate(V8_REGISTER_GLOBAL_VARIABLE));
|
||||
Template t_register(getTemplate("jsv8_register_static_variable"));
|
||||
String *class_instance = NewString("");
|
||||
Printf(class_instance, "class_%s", state.clazz(NAME_MANGLED));
|
||||
t_register.replace(KW_CONTEXT, class_instance)
|
||||
.replace(KW_UNQUALIFIED_NAME, state.variable(NAME))
|
||||
.replace(KW_GETTER, state.variable(GETTER))
|
||||
.replace(KW_SETTER, state.variable(SETTER))
|
||||
t_register.replace(T_PARENT, class_instance)
|
||||
.replace(T_NAME, state.variable(NAME))
|
||||
.replace(T_GETTER, state.variable(GETTER))
|
||||
.replace(T_SETTER, state.variable(SETTER))
|
||||
.pretty_print(f_init_static_wrappers);
|
||||
Delete(class_instance);
|
||||
} else {
|
||||
Template t_register(getTemplate(V8_REGISTER_MEMBER_VARIABLE));
|
||||
t_register.replace(KW_CLASSNAME_MANGLED, state.clazz(NAME_MANGLED))
|
||||
.replace(KW_UNQUALIFIED_NAME, state.clazz(NAME))
|
||||
.replace(KW_GETTER, state.variable(GETTER))
|
||||
.replace(KW_SETTER, state.variable(SETTER))
|
||||
Template t_register(getTemplate("jsv8_register_member_variable"));
|
||||
t_register.replace(T_NAME_MANGLED, state.clazz(NAME_MANGLED))
|
||||
.replace(T_NAME, state.clazz(NAME))
|
||||
.replace(T_GETTER, state.variable(GETTER))
|
||||
.replace(T_SETTER, state.variable(SETTER))
|
||||
.pretty_print(f_init_wrappers);
|
||||
}
|
||||
} else {
|
||||
Template t_register(getTemplate(V8_REGISTER_GLOBAL_VARIABLE));
|
||||
t_register.replace(KW_CONTEXT, Getattr(current_namespace, "name"))
|
||||
.replace(KW_UNQUALIFIED_NAME, state.variable(NAME))
|
||||
.replace(KW_GETTER, state.variable(GETTER))
|
||||
.replace(KW_SETTER, state.variable(SETTER))
|
||||
// Note: a global variable is treated like a static variable
|
||||
// with the parent being a nspace object (instead of class object)
|
||||
Template t_register(getTemplate("jsv8_register_static_variable"));
|
||||
t_register.replace(T_PARENT, Getattr(current_namespace, "name"))
|
||||
.replace(T_NAME, state.variable(NAME))
|
||||
.replace(T_GETTER, state.variable(GETTER))
|
||||
.replace(T_SETTER, state.variable(SETTER))
|
||||
.pretty_print(f_init_wrappers);
|
||||
}
|
||||
|
||||
|
|
@ -1802,26 +1770,28 @@ int V8Emitter::exitFunction(Node* n)
|
|||
// register the function at the specific context
|
||||
if(GetFlag(n, "ismember")) {
|
||||
if(GetFlag(state.function(), IS_STATIC)) {
|
||||
Template t_register(getTemplate(V8_REGISTER_GLOBAL_FUNCTION));
|
||||
Template t_register(getTemplate("jsv8_register_static_function"));
|
||||
String *class_instance = NewString("");
|
||||
Printf(class_instance, "class_%s", state.clazz(NAME_MANGLED));
|
||||
t_register.replace(KW_CONTEXT, class_instance)
|
||||
.replace(KW_UNQUALIFIED_NAME, state.function(NAME))
|
||||
.replace(KW_MANGLED_NAME, Getattr(n, "wrap:name"));
|
||||
t_register.replace(T_PARENT, class_instance)
|
||||
.replace(T_NAME, state.function(NAME))
|
||||
.replace(T_WRAPPER, Getattr(n, "wrap:name"));
|
||||
Printv(f_init_static_wrappers, t_register.str(), 0);
|
||||
Delete(class_instance);
|
||||
} else {
|
||||
Template t_register(getTemplate(V8_REGISTER_MEMBER_FUNCTION));
|
||||
t_register.replace(KW_CLASSNAME_MANGLED, state.clazz(NAME_MANGLED))
|
||||
.replace(KW_UNQUALIFIED_NAME, state.function(NAME))
|
||||
.replace(KW_MANGLED_NAME, Getattr(n, "wrap:name"));
|
||||
Template t_register(getTemplate("jsv8_register_member_function"));
|
||||
t_register.replace(T_PARENT, state.clazz(NAME_MANGLED))
|
||||
.replace(T_NAME, state.function(NAME))
|
||||
.replace(T_WRAPPER, Getattr(n, "wrap:name"));
|
||||
Printv(f_init_wrappers, t_register.str(), "\n", 0);
|
||||
}
|
||||
} else {
|
||||
Template t_register(getTemplate(V8_REGISTER_GLOBAL_FUNCTION));
|
||||
t_register.replace(KW_CONTEXT, Getattr(current_namespace, "name"))
|
||||
.replace(KW_UNQUALIFIED_NAME, state.function(NAME))
|
||||
.replace(KW_MANGLED_NAME, Getattr(n, "wrap:name"));
|
||||
// Note: a global function is treated like a static function
|
||||
// with the parent being a nspace object instead of class object
|
||||
Template t_register(getTemplate("jsv8_register_static_function"));
|
||||
t_register.replace(T_PARENT, Getattr(current_namespace, "name"))
|
||||
.replace(T_NAME, state.function(NAME))
|
||||
.replace(T_WRAPPER, Getattr(n, "wrap:name"));
|
||||
Printv(f_init_wrappers, t_register.str(), 0);
|
||||
}
|
||||
|
||||
|
|
@ -1844,17 +1814,22 @@ void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Mar
|
|||
|
||||
switch (mode) {
|
||||
case Getter:
|
||||
case Function:
|
||||
if (is_member && !is_static && i == 0) {
|
||||
Printv(arg, "args[0]", 0);
|
||||
Printv(arg, "info.Holder()", 0);
|
||||
} else {
|
||||
Printf(arg, "args[%d]", i - startIdx);
|
||||
}
|
||||
break;
|
||||
case Function:
|
||||
if (is_member && !is_static && i == 0) {
|
||||
Printv(arg, "args.Holder()", 0);
|
||||
} else {
|
||||
Printf(arg, "args[%d]", i - startIdx);
|
||||
}
|
||||
|
||||
break;
|
||||
case Setter:
|
||||
if (is_member && !is_static && i == 0) {
|
||||
Printv(arg, "args[0]", 0);
|
||||
Printv(arg, "value", 0);
|
||||
} else {
|
||||
Printv(arg, "value", 0);
|
||||
}
|
||||
|
|
@ -1891,12 +1866,12 @@ int V8Emitter::emitNamespaces() {
|
|||
/*
|
||||
// create namespace object and register it to the parent scope
|
||||
Template t_create_ns(getTemplate(V8_CREATE_NAMESPACE));
|
||||
t_create_ns.Replace(KW_MANGLED_NAME, scope_mangled);
|
||||
t_create_ns.Replace(V8_MANGLED_NAME, scope_mangled);
|
||||
|
||||
Template t_register_ns(getTemplate(V8_REGISTER_NAMESPACE));
|
||||
t_register_ns.Replace(KW_MANGLED_NAME, scope_mangled)
|
||||
.Replace(KW_CONTEXT, parent_scope_mangled)
|
||||
.Replace(KW_UNQUALIFIED_NAME, scope_unqualified);
|
||||
t_register_ns.Replace(V8_MANGLED_NAME, scope_mangled)
|
||||
.Replace(V8_CONTEXT, parent_scope_mangled)
|
||||
.Replace(V8_UNQUALIFIED_NAME, scope_unqualified);
|
||||
|
||||
Printv(f_init_namespaces, t_create_ns.str(), 0);
|
||||
// prepend in order to achieve reversed order of registration statements
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue