Complement variable processing in v8 generator.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/oliverb-javascript-v8@13753 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
8e0711cbc6
commit
71bee1e78c
4 changed files with 48 additions and 7 deletions
|
|
@ -86,7 +86,13 @@ v8::Handle<v8::ObjectTemplate> ${NAME_MANGLED} = v8::ObjectTemplate::New();%}
|
||||||
SWIGV8_AddClassMethod(SWIGV8_${CLASSNAME_MANGLED}, "${NAME_UNQUALIFIED}", wrap_${NAME_MANGLED});%}
|
SWIGV8_AddClassMethod(SWIGV8_${CLASSNAME_MANGLED}, "${NAME_UNQUALIFIED}", wrap_${NAME_MANGLED});%}
|
||||||
|
|
||||||
%fragment("v8_register_global_function", "templates") %{
|
%fragment("v8_register_global_function", "templates") %{
|
||||||
${CONTEXT}->Set(v8::String::NewSymbol("${NAME_UNQUALIFIED}"), v8::FunctionTemplate::New(wrap_${NAME_MANGLED})->GetFunction());%}
|
SWIGV8_AddGlobalMethod(${CONTEXT}, "${NAME_UNQUALIFIED}", wrap_${NAME_MANGLED});%}
|
||||||
|
|
||||||
|
%fragment("v8_register_member_variable", "templates") %{
|
||||||
|
SWIGV8_AddClassVariable(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") %{
|
%fragment("v8_register_namespace", "templates") %{
|
||||||
${CONTEXT}->Set(v8::String::NewSymbol("${NAME_UNQUALIFIED}", ${NAME_MANGLED}->NewInstance()));%}
|
${CONTEXT}->Set(v8::String::NewSymbol("${NAME_UNQUALIFIED}", ${NAME_MANGLED}->NewInstance()));%}
|
||||||
|
|
|
||||||
|
|
@ -55,15 +55,21 @@ void SWIGV8_AddClassMethod(v8::Handle<v8::FunctionTemplate> class_templ, const c
|
||||||
* Registers a class method with given name for a given class template.
|
* Registers a class method with given name for a given class template.
|
||||||
*/
|
*/
|
||||||
void SWIGV8_AddGlobalMethod(v8::Handle<v8::ObjectTemplate> obj_templ, const char* symbol, v8::InvocationCallback _func) {
|
void SWIGV8_AddGlobalMethod(v8::Handle<v8::ObjectTemplate> obj_templ, const char* symbol, v8::InvocationCallback _func) {
|
||||||
obj_templ->Set(String::New(symbol), FunctionTemplate::New(_func));
|
obj_templ->Set(String::NewSymbol(symbol), v8::FunctionTemplate::New(_func)->GetFunction());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a class property with given name for a given class template.
|
* Registers a class property with given name for a given class template.
|
||||||
*/
|
*/
|
||||||
void SWIGV8_AddProperty(v8::Handle<v8::FunctionTemplate> class_templ, const char* varname, v8::AccessorGetter getter, v8::AccessorSetter setter) {
|
void SWIGV8_AddClassVariable(v8::Handle<v8::FunctionTemplate> class_templ, const char* symbol, v8::AccessorGetter getter, v8::AccessorSetter setter) {
|
||||||
v8::Handle<v8::ObjectTemplate> proto_templ = class_templ->InstanceTemplate();
|
v8::Handle<v8::ObjectTemplate> proto_templ = class_templ->InstanceTemplate();
|
||||||
proto_templ->SetAccessor(v8::String::New(varname), getter, setter);
|
proto_templ->SetAccessor(v8::String::NewSymbol(symbol), getter, setter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
%} // v8_helper_functions
|
%} // v8_helper_functions
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,11 @@
|
||||||
#define V8_RETRIEVE_THIS "v8_retrieve_this"
|
#define V8_RETRIEVE_THIS "v8_retrieve_this"
|
||||||
#define V8_REGISTER_MEMBER_FUNCTION "v8_register_member_function"
|
#define V8_REGISTER_MEMBER_FUNCTION "v8_register_member_function"
|
||||||
#define V8_REGISTER_GLOBAL_FUNCTION "v8_register_global_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_CREATE_NAMESPACE "v8_create_namespace"
|
||||||
#define V8_REGISTER_NAMESPACE "v8_register_namespace"
|
#define V8_REGISTER_NAMESPACE "v8_register_namespace"
|
||||||
|
|
||||||
|
|
||||||
// keywords used in templates
|
// keywords used in templates
|
||||||
#define KW_MODULE_NAME "${MODULE}"
|
#define KW_MODULE_NAME "${MODULE}"
|
||||||
#define KW_MANGLED_NAME "${NAME_MANGLED}"
|
#define KW_MANGLED_NAME "${NAME_MANGLED}"
|
||||||
|
|
@ -30,6 +31,8 @@
|
||||||
#define KW_BASE_CLASS "${BASE_CLASS}"
|
#define KW_BASE_CLASS "${BASE_CLASS}"
|
||||||
#define KW_CONTEXT "${CONTEXT}"
|
#define KW_CONTEXT "${CONTEXT}"
|
||||||
#define KW_WRAPPER "${WRAPPER}"
|
#define KW_WRAPPER "${WRAPPER}"
|
||||||
|
#define KW_GETTER "${GETTER}"
|
||||||
|
#define KW_SETTER "${SETTER}"
|
||||||
|
|
||||||
#define KW_NAME_SPACES "${PART_NAMESPACES}"
|
#define KW_NAME_SPACES "${PART_NAMESPACES}"
|
||||||
#define KW_CLASS_TEMPLATES "${PART_CLASS_TEMPLATES}"
|
#define KW_CLASS_TEMPLATES "${PART_CLASS_TEMPLATES}"
|
||||||
|
|
@ -46,6 +49,7 @@
|
||||||
V8Emitter::V8Emitter()
|
V8Emitter::V8Emitter()
|
||||||
: JSEmitter(),
|
: JSEmitter(),
|
||||||
GLOBAL(NewString("global")),
|
GLOBAL(NewString("global")),
|
||||||
|
NULL_STR(NewString("0")),
|
||||||
namespaces(NewHash())
|
namespaces(NewHash())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -53,6 +57,7 @@ V8Emitter::V8Emitter()
|
||||||
V8Emitter::~V8Emitter()
|
V8Emitter::~V8Emitter()
|
||||||
{
|
{
|
||||||
Delete(GLOBAL);
|
Delete(GLOBAL);
|
||||||
|
Delete(NULL_STR);
|
||||||
Delete(namespaces);
|
Delete(namespaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,6 +176,7 @@ int V8Emitter::CreateNamespace(String* scope) {
|
||||||
// create namespace object and register it to the parent scope
|
// create namespace object and register it to the parent scope
|
||||||
Template t_create_ns(GetTemplate(V8_CREATE_NAMESPACE));
|
Template t_create_ns(GetTemplate(V8_CREATE_NAMESPACE));
|
||||||
t_create_ns.Replace(KW_MANGLED_NAME, scope_mangled);
|
t_create_ns.Replace(KW_MANGLED_NAME, scope_mangled);
|
||||||
|
|
||||||
Template t_register_ns(GetTemplate(V8_REGISTER_NAMESPACE));
|
Template t_register_ns(GetTemplate(V8_REGISTER_NAMESPACE));
|
||||||
t_register_ns.Replace(KW_MANGLED_NAME, scope_mangled)
|
t_register_ns.Replace(KW_MANGLED_NAME, scope_mangled)
|
||||||
.Replace(KW_CONTEXT, parent_scope_mangled)
|
.Replace(KW_CONTEXT, parent_scope_mangled)
|
||||||
|
|
@ -240,6 +246,9 @@ int V8Emitter::EnterVariable(Node* n)
|
||||||
} else {
|
} else {
|
||||||
current_variable_mangled = Swig_string_mangle(Getattr(n, "name"));
|
current_variable_mangled = Swig_string_mangle(Getattr(n, "name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current_getter = NULL_STR;
|
||||||
|
current_setter = NULL_STR;
|
||||||
|
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
|
|
@ -247,8 +256,21 @@ int V8Emitter::EnterVariable(Node* n)
|
||||||
int V8Emitter::ExitVariable(Node* n)
|
int V8Emitter::ExitVariable(Node* n)
|
||||||
{
|
{
|
||||||
|
|
||||||
// TODO: Register variable in context
|
if(GetFlag(n, "ismember")) {
|
||||||
Swig_print_node(n);
|
Template t_register(GetTemplate(V8_REGISTER_MEMBER_VARIABLE));
|
||||||
|
t_register.Replace(KW_CLASSNAME_MANGLED, current_classname_mangled)
|
||||||
|
.Replace(KW_UNQUALIFIED_NAME, current_variable_unqualified)
|
||||||
|
.Replace(KW_GETTER, current_getter)
|
||||||
|
.Replace(KW_SETTER, current_setter);
|
||||||
|
Printv(f_init_wrappers, t_register.str(), 0);
|
||||||
|
} else {
|
||||||
|
Template t_register(GetTemplate(V8_REGISTER_GLOBAL_VARIABLE));
|
||||||
|
t_register.Replace(KW_CONTEXT, current_context)
|
||||||
|
.Replace(KW_UNQUALIFIED_NAME, current_variable_unqualified)
|
||||||
|
.Replace(KW_GETTER, current_getter)
|
||||||
|
.Replace(KW_SETTER, current_setter);
|
||||||
|
Printv(f_init_wrappers, t_register.str(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
Delete(current_variable_mangled);
|
Delete(current_variable_mangled);
|
||||||
Delete(current_variable_unqualified);
|
Delete(current_variable_unqualified);
|
||||||
|
|
@ -320,6 +342,8 @@ int V8Emitter::EmitDtor(Node* n)
|
||||||
int V8Emitter::EmitGetter(Node *n, bool is_member) {
|
int V8Emitter::EmitGetter(Node *n, bool is_member) {
|
||||||
Template t_getter(GetTemplate(V8_GETTER));
|
Template t_getter(GetTemplate(V8_GETTER));
|
||||||
|
|
||||||
|
current_getter = Getattr(n,"wrap:name");
|
||||||
|
|
||||||
Printf(current_wrapper->locals, "%s result;\n", SwigType_str(Getattr(n, "type"), 0));
|
Printf(current_wrapper->locals, "%s result;\n", SwigType_str(Getattr(n, "type"), 0));
|
||||||
|
|
||||||
String* action = emit_action(n);
|
String* action = emit_action(n);
|
||||||
|
|
@ -341,6 +365,8 @@ int V8Emitter::EmitGetter(Node *n, bool is_member) {
|
||||||
int V8Emitter::EmitSetter(Node* n, bool is_member)
|
int V8Emitter::EmitSetter(Node* n, bool is_member)
|
||||||
{
|
{
|
||||||
Template t_setter(GetTemplate(V8_SETTER));
|
Template t_setter(GetTemplate(V8_SETTER));
|
||||||
|
|
||||||
|
current_setter = Getattr(n,"wrap:name");
|
||||||
|
|
||||||
ParmList *params = Getattr(n,"parms");
|
ParmList *params = Getattr(n,"parms");
|
||||||
emit_parameter_variables(params, current_wrapper);
|
emit_parameter_variables(params, current_wrapper);
|
||||||
|
|
|
||||||
|
|
@ -68,10 +68,13 @@ private:
|
||||||
String* current_classname_unqualified;
|
String* current_classname_unqualified;
|
||||||
String* current_variable_mangled;
|
String* current_variable_mangled;
|
||||||
String* current_variable_unqualified;
|
String* current_variable_unqualified;
|
||||||
|
String* current_getter;
|
||||||
|
String* current_setter;
|
||||||
String* current_function_mangled;
|
String* current_function_mangled;
|
||||||
String* current_function_unqualified;
|
String* current_function_unqualified;
|
||||||
|
|
||||||
String* GLOBAL;
|
String* GLOBAL;
|
||||||
|
String* NULL_STR;
|
||||||
Hash* namespaces;
|
Hash* namespaces;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue