mirror of https://github.com/swig/swig
remove hacks and implement default arguments
This commit is contained in:
parent
d9bf838de4
commit
721a4808b8
|
@ -229,7 +229,7 @@ struct Except {
|
|||
%}
|
||||
|
||||
// Default parameters in static class methods
|
||||
#ifdef SWIGPYTHON
|
||||
#if defined(SWIGPYTHON) || defined(SWIGJAVASCRIPT)
|
||||
%rename(staticMethod) staticmethod;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
var default_args_c = require("default_args_c");
|
||||
|
||||
if (default_args_c.foo1() != 1) {
|
||||
throw new Error("failed");
|
||||
}
|
||||
if (default_args_c.foo43() != 43) {
|
||||
throw new Error("failed");
|
||||
}
|
||||
|
||||
f = new default_args_c.FooStruct();
|
||||
f.no_arg();
|
||||
f.one_req(null);
|
||||
f.one_opt();
|
||||
f.one_opt(null);
|
||||
f.two_arg(null);
|
||||
f.two_arg(null, null);
|
||||
|
||||
default_args_c.StaticStruct.no_arg();
|
||||
default_args_c.StaticStruct.one_req(null);
|
||||
default_args_c.StaticStruct.one_opt();
|
||||
default_args_c.StaticStruct.one_opt(null);
|
||||
default_args_c.StaticStruct.two_arg(null);
|
||||
default_args_c.StaticStruct.two_arg(null, null);
|
||||
|
||||
default_args_c.global_opts1();
|
||||
default_args_c.global_opts1(null);
|
||||
default_args_c.global_opts2(null);
|
||||
default_args_c.global_opts2(null, null);
|
|
@ -0,0 +1,216 @@
|
|||
var default_args = require('default_args');
|
||||
ec = new default_args.EnumClass();
|
||||
if (!ec.blah()) {
|
||||
throw new Error("EnumClass::blah() default arguments don't work");
|
||||
}
|
||||
|
||||
de = new default_args.DerivedEnumClass();
|
||||
de.accelerate();
|
||||
de.accelerate(default_args.EnumClass.SLOW);
|
||||
|
||||
if (default_args.Statics.staticMethod() != 60) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (default_args.cfunc1(1) != 2) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (default_args.cfunc2(1) != 3) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (default_args.cfunc3(1) != 4) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
f = new default_args.Foo();
|
||||
|
||||
f.newname();
|
||||
f.newname(1);
|
||||
f.defaulted1();
|
||||
f.defaulted2();
|
||||
|
||||
if (f.double_if_void_ptr_is_null(2, null) != 4) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (f.double_if_void_ptr_is_null(3) != 6) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (f.double_if_handle_is_null(4, null) != 8) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (f.double_if_handle_is_null(5) != 10) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (f.double_if_dbl_ptr_is_null(6, null) != 12) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (f.double_if_dbl_ptr_is_null(7) != 14) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
try {
|
||||
f = default_args.Foo(1);
|
||||
error = 1;
|
||||
} catch {
|
||||
error = 0;
|
||||
}
|
||||
if (error) {
|
||||
throw new Error("Foo::Foo ignore is not working");
|
||||
}
|
||||
|
||||
try {
|
||||
f = default_args.Foo(1, 2);
|
||||
error = 1;
|
||||
} catch {
|
||||
error = 0;
|
||||
}
|
||||
if (error) {
|
||||
throw new Error("Foo::Foo ignore is not working");
|
||||
}
|
||||
|
||||
try {
|
||||
f = default_args.Foo(1, 2, 3);
|
||||
error = 1;
|
||||
} catch {
|
||||
error = 0;
|
||||
}
|
||||
if (error) {
|
||||
throw new Error("Foo::Foo ignore is not working");
|
||||
}
|
||||
|
||||
try {
|
||||
m = f.meth(1);
|
||||
error = 1;
|
||||
} catch {
|
||||
error = 0;
|
||||
}
|
||||
if (error) {
|
||||
throw new Error("Foo::meth ignore is not working");
|
||||
}
|
||||
|
||||
try {
|
||||
m = f.meth(1, 2);
|
||||
error = 1;
|
||||
} catch {
|
||||
error = 0;
|
||||
}
|
||||
if (error) {
|
||||
throw new Error("Foo::meth ignore is not working");
|
||||
}
|
||||
|
||||
try {
|
||||
m = f.meth(1, 2, 3);
|
||||
error = 1;
|
||||
} catch {
|
||||
error = 0;
|
||||
}
|
||||
if (error) {
|
||||
throw new Error("Foo::meth ignore is not working");
|
||||
}
|
||||
|
||||
Klass_inc = default_args.Klass.inc;
|
||||
|
||||
if (Klass_inc(100, new default_args.Klass(22)).val != 122) {
|
||||
throw new Error("Klass::inc failed");
|
||||
}
|
||||
|
||||
if (Klass_inc(100).val != 99) {
|
||||
throw new Error("Klass::inc failed");
|
||||
}
|
||||
|
||||
if (Klass_inc().val != 0) {
|
||||
throw new Error("Klass::inc failed");
|
||||
}
|
||||
|
||||
tricky = new default_args.TrickyInPython();
|
||||
if (tricky.value_m1(10) != -1) {
|
||||
throw new Error("trickyvalue_m1 failed");
|
||||
}
|
||||
if (tricky.value_m1(10, 10) != 10) {
|
||||
throw new Error("trickyvalue_m1 failed");
|
||||
}
|
||||
if (tricky.value_0xabcdef(10) != 0xabcdef) {
|
||||
throw new Error("trickyvalue_0xabcdef failed");
|
||||
}
|
||||
if (tricky.value_0644(10) != 420) {
|
||||
throw new Error("trickyvalue_0644 failed");
|
||||
}
|
||||
if (tricky.value_perm(10) != 420) {
|
||||
throw new Error("trickyvalue_perm failed");
|
||||
}
|
||||
if (tricky.value_m01(10) != -1) {
|
||||
throw new Error("trickyvalue_m01 failed");
|
||||
}
|
||||
if (!tricky.booltest2()) {
|
||||
throw new Error("booltest2 failed");
|
||||
}
|
||||
|
||||
if (tricky.max_32bit_int1() != 0x7FFFFFFF) {
|
||||
throw new Error("max_32bit_int1 failed");
|
||||
}
|
||||
if (tricky.min_32bit_int1() != -2147483648) {
|
||||
throw new Error("min_32bit_int1 failed");
|
||||
}
|
||||
if (tricky.max_32bit_int2() != 0x7FFFFFFF) {
|
||||
throw new Error("max_32bit_int2 failed");
|
||||
}
|
||||
|
||||
tricky.too_big_32bit_int1();
|
||||
tricky.too_small_32bit_int1();
|
||||
tricky.too_big_32bit_int2();
|
||||
tricky.too_small_32bit_int2();
|
||||
|
||||
default_args.seek();
|
||||
default_args.seek(10);
|
||||
|
||||
if (!default_args.booltest()) {
|
||||
throw new Error("booltest failed");
|
||||
}
|
||||
|
||||
if (default_args.slightly_off_square(10) != 102) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (default_args.slightly_off_square() != 291) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if ((new default_args.CDA()).cdefaultargs_test1() != 1) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if ((new default_args.CDA()).cdefaultargs_test2() != 1) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (default_args.chartest1() != "x") {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
// JavaScriptCore cannot accept a '\0' string
|
||||
if (default_args.chartest2() != "\0" && default_args.chartest2() != '') {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (default_args.chartest3() != "\1") {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (default_args.chartest4() != "\n") {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (default_args.chartest5() != "B") {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (default_args.chartest6() != "C") {
|
||||
throw new Error;
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
* - $jslocals: locals part of wrapper
|
||||
* - $jscode: code part of wrapper
|
||||
* - $jsargcount: number of arguments
|
||||
* - $jsargrequired: required number of arguments
|
||||
* - $jsmangledtype: mangled type of class
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%fragment ("js_ctor", "templates")
|
||||
|
@ -11,7 +12,7 @@
|
|||
static JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
$jslocals
|
||||
if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||
if (argc < $jsargrequired || argc > $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||
|
||||
$jscode
|
||||
return SWIG_JSC_NewPointerObj(context, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
|
||||
|
@ -67,6 +68,7 @@ static JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
|
|||
* - $jslocals: locals part of wrapper
|
||||
* - $jscode: code part of wrapper
|
||||
* - $jsargcount: number of arguments
|
||||
* - $jsargrequired: required number of arguments
|
||||
* - $jsmangledtype: mangled type of class
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%fragment ("js_overloaded_ctor", "templates")
|
||||
|
@ -86,13 +88,14 @@ static JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size
|
|||
/* -----------------------------------------------------------------------------
|
||||
* js_ctor_dispatch_case: template for a dispatch case for calling an overloaded ctor.
|
||||
* - $jsargcount: number of arguments of called ctor
|
||||
* - $jsargrequired: required number of arguments
|
||||
* - $jswrapper: wrapper of called ctor
|
||||
*
|
||||
* Note: a try-catch-like mechanism is used to switch cases
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%fragment ("js_ctor_dispatch_case", "templates")
|
||||
%{
|
||||
if(argc == $jsargcount) {
|
||||
if(argc >= $jsargrequired && argc <= $jsargcount) {
|
||||
thisObject = $jswrapper(context, NULL, argc, argv, exception);
|
||||
if(thisObject != NULL) { *exception=0; return thisObject; } /* reset exception and return */
|
||||
}
|
||||
|
@ -187,9 +190,11 @@ static bool $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStringRef
|
|||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* js_function: template for function wrappers
|
||||
* - $jswrapper: wrapper function name
|
||||
* - $jslocals: locals part of wrapper
|
||||
* - $jscode: code part of wrapper
|
||||
* - $jswrapper: wrapper function name
|
||||
* - $jslocals: locals part of wrapper
|
||||
* - $jsargcount: number of arguments
|
||||
* - $jsargrequired: required number of arguments
|
||||
* - $jscode: code part of wrapper
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%fragment ("js_function", "templates")
|
||||
%{
|
||||
|
@ -198,7 +203,7 @@ static JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjec
|
|||
$jslocals
|
||||
JSValueRef jsresult;
|
||||
|
||||
if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||
if (argc < $jsargrequired || argc > $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||
|
||||
$jscode
|
||||
return jsresult;
|
||||
|
@ -236,9 +241,11 @@ static JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjec
|
|||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* js_overloaded_function: template for a overloaded function
|
||||
* - $jswrapper: wrapper function name
|
||||
* - $jslocals: locals part of wrapper
|
||||
* - $jscode: code part of wrapper
|
||||
* - $jswrapper: wrapper function name
|
||||
* - $jslocals: locals part of wrapper
|
||||
* - $jsargcount: required number of arguments
|
||||
* - $jsargrequired: required number of arguments
|
||||
* - $jscode: code part of wrapper
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%fragment ("js_overloaded_function", "templates")
|
||||
%{
|
||||
|
@ -247,7 +254,7 @@ static int $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef th
|
|||
$jslocals
|
||||
JSValueRef jsresult;
|
||||
|
||||
if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||
if (argc < $jsargrequired || argc > $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||
|
||||
$jscode
|
||||
*p_result = jsresult;
|
||||
|
@ -261,18 +268,26 @@ static int $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef th
|
|||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* js_function_dispatch_case: template for a case used in the function dispatcher
|
||||
* - $jswrapper: wrapper function name
|
||||
* - $jsargcount: number of arguments of overloaded function
|
||||
* - $jscode: code part of wrapper
|
||||
* - $jswrapper: wrapper function name
|
||||
* - $jsargcount: number of arguments of overloaded function
|
||||
* - $jsargrequired: required number of arguments
|
||||
* - $jscode: code part of wrapper
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%fragment ("js_function_dispatch_case", "templates")
|
||||
%{
|
||||
if(argc == $jsargcount) {
|
||||
if(argc >= $jsargrequired && argc <= $jsargcount) {
|
||||
res = $jswrapper(context, function, thisObject, argc, argv, exception, &jsresult);
|
||||
if(res == SWIG_OK) { *exception = 0; return jsresult; }
|
||||
}
|
||||
%}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* js_check_arg: template for checking if an argument exists
|
||||
* - $jsarg: number of argument
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%fragment ("js_check_arg", "templates")
|
||||
%{if(argc > $jsarg)%}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* jsc_variable_declaration: template for a variable table entry
|
||||
* - $jsname: name of the variable
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* - $jslocals: locals part of wrapper
|
||||
* - $jscode: code part of wrapper
|
||||
* - $jsargcount: number of arguments
|
||||
* - $jsargrequired: required number of arguments
|
||||
* - $jsmangledtype: mangled type of class
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -14,7 +15,7 @@ static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) {
|
|||
SWIGV8_OBJECT self = args.Holder();
|
||||
$jslocals
|
||||
if(self->InternalFieldCount() < 1) SWIG_exception_fail(SWIG_ERROR, "Illegal call of constructor $jswrapper.");
|
||||
if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||
if(args.Length() < $jsargrequired || args.Length() > $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||
$jscode
|
||||
|
||||
SWIGV8_SetPrivateData(self, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
|
||||
|
@ -73,6 +74,7 @@ fail:
|
|||
* - $jslocals: locals part of wrapper
|
||||
* - $jscode: code part of wrapper
|
||||
* - $jsargcount: number of arguments
|
||||
* - $jsargrequired: required number of arguments
|
||||
* - $jsmangledtype: mangled type of class
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%fragment("js_overloaded_ctor", "templates") %{
|
||||
|
@ -82,7 +84,7 @@ static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args, V8ErrorHandler
|
|||
SWIGV8_OBJECT self = args.Holder();
|
||||
$jslocals
|
||||
if(self->InternalFieldCount() < 1) SWIG_exception_fail(SWIG_ERROR, "Illegal call of constructor $jswrapper.");
|
||||
if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||
if(args.Length() < $jsargrequired || args.Length() > $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||
$jscode
|
||||
|
||||
SWIGV8_SetPrivateData(self, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
|
||||
|
@ -97,13 +99,14 @@ fail:
|
|||
/* -----------------------------------------------------------------------------
|
||||
* js_ctor_dispatch_case: template for a dispatch case for calling an overloaded ctor.
|
||||
* - $jsargcount: number of arguments of called ctor
|
||||
* - $jsargrequired: required number of arguments
|
||||
* - $jswrapper: wrapper of called ctor
|
||||
*
|
||||
* Note: a try-catch-like mechanism is used to switch cases
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%fragment ("js_ctor_dispatch_case", "templates")
|
||||
%{
|
||||
if(args.Length() == $jsargcount) {
|
||||
if(args.Length() >= $jsargrequired && args.Length() <= $jsargcount) {
|
||||
errorHandler.err.Clear();
|
||||
$jswrapper(args, errorHandler);
|
||||
if(errorHandler.err.IsEmpty()) {
|
||||
|
@ -195,9 +198,11 @@ fail:
|
|||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* js_function: template for function wrappers
|
||||
* - $jswrapper: wrapper function name
|
||||
* - $jslocals: locals part of wrapper
|
||||
* - $jscode: code part of wrapper
|
||||
* - $jswrapper: wrapper function name
|
||||
* - $jslocals: locals part of wrapper
|
||||
* - $jscode: code part of wrapper
|
||||
* - $jsargcount: number of arguments
|
||||
* - $jsargrequired: required number of arguments
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%fragment("js_function", "templates")
|
||||
%{
|
||||
|
@ -206,7 +211,7 @@ static SwigV8ReturnValue $jswrapper(const SwigV8Arguments &args) {
|
|||
|
||||
SWIGV8_VALUE jsresult;
|
||||
$jslocals
|
||||
if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||
if (args.Length() < $jsargrequired || args.Length() > $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
|
||||
|
||||
$jscode
|
||||
SWIGV8_RETURN(jsresult);
|
||||
|
@ -266,14 +271,15 @@ fail:
|
|||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* js_function_dispatch_case: template for a case used in the function dispatcher
|
||||
* - $jswrapper: wrapper function name
|
||||
* - $jsargcount: number of arguments of overloaded function
|
||||
* - $jscode: code part of wrapper
|
||||
* - $jswrapper: wrapper function name
|
||||
* - $jsargcount: number of arguments of overloaded function
|
||||
* - $jsargrequired: required number of arguments
|
||||
* - $jscode: code part of wrapper
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%fragment ("js_function_dispatch_case", "templates")
|
||||
%{
|
||||
|
||||
if(args.Length() == $jsargcount) {
|
||||
if(args.Length() >= $jsargrequired && args.Length() <= $jsargcount) {
|
||||
errorHandler.err.Clear();
|
||||
$jswrapper(args, errorHandler);
|
||||
if(errorHandler.err.IsEmpty()) {
|
||||
|
@ -282,6 +288,13 @@ fail:
|
|||
}
|
||||
%}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* js_check_arg: template for checking if an argument exists
|
||||
* - $jsarg: number of argument
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%fragment ("js_check_arg", "templates")
|
||||
%{if(args.Length() > $jsarg)%}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* jsv8_declare_class_template: template for a class template declaration.
|
||||
* - $jsmangledname: mangled class name
|
||||
|
|
|
@ -24,6 +24,7 @@ static bool js_template_enable_debug = false;
|
|||
// keywords used for state variables
|
||||
#define NAME "name"
|
||||
#define NAME_MANGLED "name_mangled"
|
||||
#define INDEX "idx"
|
||||
#define TYPE "type"
|
||||
#define TYPE_MANGLED "type_mangled"
|
||||
#define WRAPPER_NAME "wrapper"
|
||||
|
@ -39,6 +40,7 @@ static bool js_template_enable_debug = false;
|
|||
#define CTOR_DISPATCHERS "ctor_dispatchers"
|
||||
#define DTOR "dtor"
|
||||
#define ARGCOUNT "wrap:argc"
|
||||
#define ARGREQUIRED "wrap:argmin"
|
||||
#define HAS_TEMPLATES "has_templates"
|
||||
#define FORCE_CPP "force_cpp"
|
||||
#define RESET true
|
||||
|
@ -865,10 +867,6 @@ int JSEmitter::emitCtor(Node *n) {
|
|||
ParmList *params = Getattr(n, "parms");
|
||||
emit_parameter_variables(params, wrapper);
|
||||
emit_attach_parmmaps(params, wrapper);
|
||||
// HACK: in test-case `ignore_parameter` emit_attach_parmmaps generated an extra line of applied typemaps.
|
||||
// Deleting wrapper->code here, to reset, and as it seemed to have no side effect elsewhere
|
||||
Delete(wrapper->code);
|
||||
wrapper->code = NewString("");
|
||||
|
||||
Printf(wrapper->locals, "%sresult;", SwigType_str(Getattr(n, "type"), 0));
|
||||
|
||||
|
@ -883,11 +881,13 @@ int JSEmitter::emitCtor(Node *n) {
|
|||
.replace("$jslocals", wrapper->locals)
|
||||
.replace("$jscode", wrapper->code)
|
||||
.replace("$jsargcount", Getattr(n, ARGCOUNT))
|
||||
.replace("$jsargrequired", Getattr(n, ARGREQUIRED))
|
||||
.pretty_print(f_wrappers);
|
||||
|
||||
Template t_ctor_case(getTemplate("js_ctor_dispatch_case"));
|
||||
t_ctor_case.replace("$jswrapper", wrap_name)
|
||||
.replace("$jsargcount", Getattr(n, ARGCOUNT));
|
||||
.replace("$jsargcount", Getattr(n, ARGCOUNT))
|
||||
.replace("$jsargrequired", Getattr(n, ARGREQUIRED));
|
||||
Append(state.clazz(CTOR_DISPATCHERS), t_ctor_case.str());
|
||||
|
||||
DelWrapper(wrapper);
|
||||
|
@ -1184,11 +1184,6 @@ int JSEmitter::emitFunction(Node *n, bool is_member, bool is_static) {
|
|||
emit_parameter_variables(params, wrapper);
|
||||
emit_attach_parmmaps(params, wrapper);
|
||||
|
||||
// HACK: in test-case `ignore_parameter` emit_attach_parmmaps generates an extra line of applied typemap.
|
||||
// Deleting wrapper->code here fixes the problem, and seems to have no side effect elsewhere
|
||||
Delete(wrapper->code);
|
||||
wrapper->code = NewString("");
|
||||
|
||||
marshalInputArgs(n, params, wrapper, Function, is_member, is_static);
|
||||
String *action = emit_action(n);
|
||||
marshalOutput(n, params, wrapper, action);
|
||||
|
@ -1199,9 +1194,9 @@ int JSEmitter::emitFunction(Node *n, bool is_member, bool is_static) {
|
|||
.replace("$jslocals", wrapper->locals)
|
||||
.replace("$jscode", wrapper->code)
|
||||
.replace("$jsargcount", Getattr(n, ARGCOUNT))
|
||||
.replace("$jsargrequired", Getattr(n, ARGREQUIRED))
|
||||
.pretty_print(f_wrappers);
|
||||
|
||||
|
||||
DelWrapper(wrapper);
|
||||
|
||||
return SWIG_OK;
|
||||
|
@ -1223,7 +1218,8 @@ int JSEmitter::emitFunctionDispatcher(Node *n, bool /*is_member */ ) {
|
|||
// handle function overloading
|
||||
Template t_dispatch_case = getTemplate("js_function_dispatch_case");
|
||||
t_dispatch_case.replace("$jswrapper", siblname)
|
||||
.replace("$jsargcount", Getattr(sibl, ARGCOUNT));
|
||||
.replace("$jsargcount", Getattr(sibl, ARGCOUNT))
|
||||
.replace("$jsargrequired", Getattr(sibl, ARGREQUIRED));
|
||||
|
||||
Append(wrapper->code, t_dispatch_case.str());
|
||||
}
|
||||
|
@ -1269,9 +1265,40 @@ int JSEmitter::emitFunctionDispatcher(Node *n, bool /*is_member */ ) {
|
|||
}
|
||||
|
||||
String *JSEmitter::emitInputTypemap(Node *n, Parm *p, Wrapper *wrapper, String *arg) {
|
||||
String *code = NewString("");
|
||||
// Get input typemap for current param
|
||||
String *tm = Getattr(p, "tmap:in");
|
||||
String *tm_def = Getattr(p, "tmap:default");
|
||||
SwigType *type = Getattr(p, "type");
|
||||
int argmin = -1;
|
||||
int argidx = -1;
|
||||
bool is_optional = false;
|
||||
|
||||
if (Getattr(n, ARGREQUIRED)) {
|
||||
argmin = GetInt(n, ARGREQUIRED);
|
||||
}
|
||||
if (Getattr(p, INDEX)) {
|
||||
argidx = GetInt(p, INDEX);
|
||||
}
|
||||
|
||||
if (tm_def != NULL) {
|
||||
is_optional = true;
|
||||
}
|
||||
if (argmin >= 0 && argidx >= 0 && argidx >= argmin) {
|
||||
is_optional = true;
|
||||
}
|
||||
if (is_optional && Getattr(p, INDEX) == NULL) {
|
||||
Printf(stderr, "Argument %s in %s cannot be a default argument\n",
|
||||
Getattr(p, NAME), state.function(NAME));
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
if (is_optional) {
|
||||
Template t_check_default(getTemplate("js_check_arg"));
|
||||
|
||||
t_check_default.replace("$jsarg", Getattr(p, INDEX)).pretty_print(code);
|
||||
Printf(code, "{\n");
|
||||
}
|
||||
|
||||
if (tm != NULL) {
|
||||
Replaceall(tm, "$input", arg);
|
||||
|
@ -1283,12 +1310,23 @@ String *JSEmitter::emitInputTypemap(Node *n, Parm *p, Wrapper *wrapper, String *
|
|||
Replaceall(tm, "$disown", "0");
|
||||
}
|
||||
Replaceall(tm, "$symname", Getattr(n, "sym:name"));
|
||||
Printf(wrapper->code, "%s\n", tm);
|
||||
if (!checkAttribute(p, "tmap:in:noblock", "1")) {
|
||||
Printf(code, "{\n");
|
||||
}
|
||||
Printf(code, "%s", tm);
|
||||
if (!checkAttribute(p, "tmap:in:noblock", "1")) {
|
||||
Printf(code, "\n}\n");
|
||||
}
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(type, 0));
|
||||
}
|
||||
|
||||
return tm;
|
||||
if (is_optional) {
|
||||
Printf(code, "}\n");
|
||||
}
|
||||
|
||||
Append(wrapper->code, code);
|
||||
return code;
|
||||
}
|
||||
|
||||
String *JSEmitter::emitCheckTypemap(Node *, Parm *p, Wrapper *wrapper, String *arg) {
|
||||
|
@ -1521,7 +1559,7 @@ JSCEmitter::~JSCEmitter() {
|
|||
|
||||
void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, MarshallingMode mode, bool is_member, bool is_static) {
|
||||
Parm *p;
|
||||
String *tm;
|
||||
String *tm = NULL;
|
||||
|
||||
// determine an offset index, as members have an extra 'this' argument
|
||||
// except: static members and ctors.
|
||||
|
@ -1533,7 +1571,9 @@ void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Ma
|
|||
int num_args = emit_num_arguments(parms) - startIdx;
|
||||
String *argcount = NewString("");
|
||||
Printf(argcount, "%d", num_args);
|
||||
Setattr(n, ARGCOUNT, argcount);
|
||||
Setattr(n, ARGCOUNT, argcount);
|
||||
int num_required = emit_num_required(parms) - startIdx;
|
||||
SetInt(n, ARGREQUIRED, num_required);
|
||||
|
||||
// process arguments
|
||||
int i = 0;
|
||||
|
@ -1552,7 +1592,8 @@ void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Ma
|
|||
Printv(arg, "thisObject", 0);
|
||||
i++;
|
||||
} else {
|
||||
Printf(arg, "argv[%d]", i - startIdx);
|
||||
Printf(arg, "argv[%d]", i - startIdx);
|
||||
SetInt(p, INDEX, i - startIdx);
|
||||
i += GetInt(p, "tmap:in:numinputs");
|
||||
}
|
||||
break;
|
||||
|
@ -1567,14 +1608,20 @@ void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Ma
|
|||
break;
|
||||
case Ctor:
|
||||
Printf(arg, "argv[%d]", i);
|
||||
SetInt(p, INDEX, i);
|
||||
i += GetInt(p, "tmap:in:numinputs");
|
||||
break;
|
||||
default:
|
||||
Printf(stderr, "Illegal MarshallingMode.");
|
||||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
tm = emitInputTypemap(n, p, wrapper, arg);
|
||||
|
||||
// numinputs=0 typemaps are emitted by the legacy code in
|
||||
// emit_attach_parmmaps() in emit.cxx, check the comment there
|
||||
if (!checkAttribute(p, "tmap:in:numinputs", "0"))
|
||||
tm = emitInputTypemap(n, p, wrapper, arg);
|
||||
Delete(arg);
|
||||
|
||||
if (tm) {
|
||||
p = Getattr(p, "tmap:in:next");
|
||||
} else {
|
||||
|
@ -2174,7 +2221,7 @@ int V8Emitter::exitFunction(Node *n) {
|
|||
|
||||
void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, MarshallingMode mode, bool is_member, bool is_static) {
|
||||
Parm *p;
|
||||
String *tm;
|
||||
String *tm = NULL;
|
||||
|
||||
int startIdx = 0;
|
||||
if (is_member && !is_static && mode != Ctor) {
|
||||
|
@ -2185,6 +2232,8 @@ void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Mar
|
|||
String *argcount = NewString("");
|
||||
Printf(argcount, "%d", num_args);
|
||||
Setattr(n, ARGCOUNT, argcount);
|
||||
int num_required = emit_num_required(parms) - startIdx;
|
||||
SetInt(n, ARGREQUIRED, num_required);
|
||||
|
||||
int i = 0;
|
||||
for (p = parms; p;) {
|
||||
|
@ -2202,6 +2251,7 @@ void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Mar
|
|||
i++;
|
||||
} else {
|
||||
Printf(arg, "args[%d]", i - startIdx);
|
||||
SetInt(p, INDEX, i - startIdx);
|
||||
i += GetInt(p, "tmap:in:numinputs");
|
||||
}
|
||||
break;
|
||||
|
@ -2210,7 +2260,8 @@ void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Mar
|
|||
Printv(arg, "args.Holder()", 0);
|
||||
i++;
|
||||
} else {
|
||||
Printf(arg, "args[%d]", i - startIdx);
|
||||
Printf(arg, "args[%d]", i - startIdx);
|
||||
SetInt(p, INDEX, i - startIdx);
|
||||
i += GetInt(p, "tmap:in:numinputs");
|
||||
}
|
||||
break;
|
||||
|
@ -2225,6 +2276,7 @@ void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Mar
|
|||
break;
|
||||
case Ctor:
|
||||
Printf(arg, "args[%d]", i);
|
||||
SetInt(p, INDEX, i);
|
||||
i += GetInt(p, "tmap:in:numinputs");
|
||||
break;
|
||||
default:
|
||||
|
@ -2232,7 +2284,11 @@ void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Mar
|
|||
Exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
tm = emitInputTypemap(n, p, wrapper, arg);
|
||||
// numinputs=0 typemaps are emitted by the legacy code in
|
||||
// emit_attach_parmmaps() in emit.cxx, check the comment there
|
||||
// All language backends work around this
|
||||
if (!checkAttribute(p, "tmap:in:numinputs", "0"))
|
||||
tm = emitInputTypemap(n, p, wrapper, arg);
|
||||
Delete(arg);
|
||||
|
||||
if (tm) {
|
||||
|
|
Loading…
Reference in New Issue