Merge replayed as done by c778d16abed35829b103d607a53c8f88e3b2d595
This commit is contained in:
parent
a190288e66
commit
868803ce2a
9 changed files with 179 additions and 66 deletions
|
|
@ -22,7 +22,6 @@ bool js_template_enable_debug = false;
|
|||
#define CTOR_DISPATCHERS "ctor_dispatchers"
|
||||
#define DTOR "dtor"
|
||||
#define ARGCOUNT "wrap:argc"
|
||||
#define FUNCTION_DISPATCHERS "function_dispatchers"
|
||||
|
||||
// variables used in code templates
|
||||
// ATTENTION: be aware of prefix collisions when defining those variables
|
||||
|
|
@ -793,12 +792,6 @@ int JSEmitter::enterFunction(Node *n) {
|
|||
SetFlag(state.function(), IS_STATIC);
|
||||
}
|
||||
|
||||
/* Initialize DOH for collecting function dispatchers */
|
||||
bool is_overloaded = GetFlag(n, "sym:overloaded");
|
||||
if (is_overloaded && state.global(FUNCTION_DISPATCHERS) == 0) {
|
||||
state.global(FUNCTION_DISPATCHERS, NewString(""));
|
||||
}
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
|
|
@ -1061,13 +1054,6 @@ int JSEmitter::emitFunction(Node *n, bool is_member, bool is_static) {
|
|||
.replace(T_ARGCOUNT, Getattr(n, ARGCOUNT))
|
||||
.pretty_print(f_wrappers);
|
||||
|
||||
// handle function overloading
|
||||
if (is_overloaded) {
|
||||
Template t_dispatch_case = getTemplate("js_function_dispatch_case");
|
||||
t_dispatch_case.replace(T_WRAPPER, wrap_name)
|
||||
.replace(T_ARGCOUNT, Getattr(n, ARGCOUNT));
|
||||
Append(state.global(FUNCTION_DISPATCHERS), t_dispatch_case.str());
|
||||
}
|
||||
|
||||
DelWrapper(wrapper);
|
||||
|
||||
|
|
@ -1075,14 +1061,47 @@ int JSEmitter::emitFunction(Node *n, bool is_member, bool is_static) {
|
|||
}
|
||||
|
||||
int JSEmitter::emitFunctionDispatcher(Node *n, bool /*is_member */ ) {
|
||||
Wrapper *wrapper = NewWrapper();
|
||||
|
||||
// Generate call list, go to first node
|
||||
Node *sibl = n;
|
||||
|
||||
while (Getattr(sibl, "sym:previousSibling"))
|
||||
sibl = Getattr(sibl, "sym:previousSibling"); // go all the way up
|
||||
|
||||
do {
|
||||
String *siblname = Getattr(sibl, "wrap:name");
|
||||
|
||||
if (siblname)
|
||||
{
|
||||
// handle function overloading
|
||||
Template t_dispatch_case = getTemplate("js_function_dispatch_case");
|
||||
t_dispatch_case.replace(T_WRAPPER, siblname)
|
||||
.replace(T_ARGCOUNT, Getattr(sibl, ARGCOUNT));
|
||||
|
||||
Append(wrapper->code, t_dispatch_case.str());
|
||||
}
|
||||
|
||||
} while ((sibl = Getattr(sibl, "sym:nextSibling")));
|
||||
|
||||
|
||||
|
||||
|
||||
Template t_function(getTemplate("js_function_dispatcher"));
|
||||
|
||||
Wrapper *wrapper = NewWrapper();
|
||||
String *wrap_name = Swig_name_wrapper(Getattr(n, "name"));
|
||||
Setattr(n, "wrap:name", wrap_name);
|
||||
// String *wrap_name = Swig_name_wrapper(Getattr(n, "name"));
|
||||
|
||||
Append(wrapper->code, state.global(FUNCTION_DISPATCHERS));
|
||||
|
||||
String *fun_name = Getattr(n, "sym:name");
|
||||
|
||||
Node *methodclass = Swig_methodclass(n);
|
||||
String *class_name = Getattr(methodclass, "sym:name");
|
||||
|
||||
String *new_string = NewStringf("%s_%s", class_name, fun_name);
|
||||
String *wrap_name = Swig_name_wrapper(new_string);
|
||||
|
||||
Setattr(n, "wrap:name", wrap_name);
|
||||
state.function(WRAPPER_NAME, wrap_name);
|
||||
|
||||
t_function.replace(T_LOCALS, wrapper->locals)
|
||||
.replace(T_CODE, wrapper->code);
|
||||
|
|
@ -1093,7 +1112,6 @@ int JSEmitter::emitFunctionDispatcher(Node *n, bool /*is_member */ ) {
|
|||
.pretty_print(f_wrappers);
|
||||
|
||||
// Delete the state variable
|
||||
state.global(FUNCTION_DISPATCHERS, NewString(""));
|
||||
DelWrapper(wrapper);
|
||||
|
||||
return SWIG_OK;
|
||||
|
|
@ -1480,7 +1498,7 @@ int JSCEmitter::exitFunction(Node *n) {
|
|||
// handle overloaded functions
|
||||
if (is_overloaded) {
|
||||
if (!Getattr(n, "sym:nextSibling")) {
|
||||
state.function(WRAPPER_NAME, Swig_name_wrapper(Getattr(n, "name")));
|
||||
//state.function(WRAPPER_NAME, Swig_name_wrapper(Getattr(n, "name")));
|
||||
// create dispatcher
|
||||
emitFunctionDispatcher(n, is_member);
|
||||
} else {
|
||||
|
|
@ -1742,6 +1760,7 @@ int V8Emitter::initialize(Node *n)
|
|||
f_init_register_namespaces = NewString("");
|
||||
|
||||
// note: this is necessary for built-in generation of swig runtime code
|
||||
Swig_register_filebyname("begin", f_wrap_cpp);
|
||||
Swig_register_filebyname("runtime", f_runtime);
|
||||
Swig_register_filebyname("header", f_header);
|
||||
Swig_register_filebyname("init", f_init);
|
||||
|
|
@ -1757,7 +1776,8 @@ int V8Emitter::dump(Node *)
|
|||
|
||||
SwigType_emit_type_table(f_runtime, f_wrappers);
|
||||
|
||||
emitUndefined();
|
||||
// Let's not and say we did
|
||||
// emitUndefined();
|
||||
|
||||
Printv(f_wrap_cpp, f_runtime, "\n", 0);
|
||||
Printv(f_wrap_cpp, f_header, "\n", 0);
|
||||
|
|
@ -1859,12 +1879,15 @@ int V8Emitter::exitClass(Node *n)
|
|||
// emit inheritance setup
|
||||
Node* baseClass = getBaseClass(n);
|
||||
if(baseClass) {
|
||||
String *base_name = Getattr(baseClass, "name");
|
||||
|
||||
Template t_inherit = getTemplate("jsv8_inherit");
|
||||
String *base_name_mangled = SwigType_manglestr(Getattr(baseClass, "name"));
|
||||
|
||||
String *base_name_mangled = SwigType_manglestr(base_name);
|
||||
t_inherit.replace(T_NAME_MANGLED, state.clazz(NAME_MANGLED))
|
||||
.replace(T_BASECLASS, base_name_mangled)
|
||||
.trim()
|
||||
.pretty_print(f_init_inheritance);
|
||||
.replace(T_BASECLASS, base_name_mangled)
|
||||
.trim()
|
||||
.pretty_print(f_init_inheritance);
|
||||
Delete(base_name_mangled);
|
||||
}
|
||||
|
||||
|
|
@ -1932,7 +1955,7 @@ int V8Emitter::exitFunction(Node* n)
|
|||
bool is_overloaded = GetFlag(n, "sym:overloaded");
|
||||
if (is_overloaded) {
|
||||
if (!Getattr(n, "sym:nextSibling")) {
|
||||
state.function(WRAPPER_NAME, Swig_name_wrapper(Getattr(n, "name")));
|
||||
//state.function(WRAPPER_NAME, Swig_name_wrapper(Getattr(n, "name")));
|
||||
emitFunctionDispatcher(n, is_member);
|
||||
} else {
|
||||
//don't register wrappers of overloaded functions in function tables
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue