changes to support cast ranking for dispatch and/or overloading
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8044 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
1733655950
commit
84b96ab3ad
13 changed files with 63 additions and 42 deletions
|
|
@ -1,13 +1,14 @@
|
|||
/* Errors in SWIG */
|
||||
#define SWIG_MemoryError 1
|
||||
#define SWIG_IOError 2
|
||||
#define SWIG_RuntimeError 3
|
||||
#define SWIG_IndexError 4
|
||||
#define SWIG_TypeError 5
|
||||
#define SWIG_DivisionByZero 6
|
||||
#define SWIG_OverflowError 7
|
||||
#define SWIG_SyntaxError 8
|
||||
#define SWIG_ValueError 9
|
||||
#define SWIG_SystemError 10
|
||||
#define SWIG_AttributeError 11
|
||||
#define SWIG_UnknownError 99
|
||||
#define SWIG_UnknownError -1
|
||||
#define SWIG_IOError -2
|
||||
#define SWIG_RuntimeError -3
|
||||
#define SWIG_IndexError -4
|
||||
#define SWIG_TypeError -5
|
||||
#define SWIG_DivisionByZero -6
|
||||
#define SWIG_OverflowError -7
|
||||
#define SWIG_SyntaxError -8
|
||||
#define SWIG_ValueError -9
|
||||
#define SWIG_SystemError -10
|
||||
#define SWIG_AttributeError -11
|
||||
#define SWIG_MemoryError -12
|
||||
|
||||
|
|
|
|||
|
|
@ -57,6 +57,12 @@
|
|||
#define SWIG_OK 0
|
||||
#define SWIG_ERROR -1
|
||||
|
||||
/* Flags to manage cast and return states */
|
||||
#define SWIG_MAX_CAST_RANK 4
|
||||
#define SWIG_IsOK(r) (r >= 0)
|
||||
#define SWIG_AddCast(r) (SWIG_IsOK(r) ? (r + 1) : r)
|
||||
#define SWIG_GetCastRank(r) (SWIG_IsOK(r) ? ((r < SWIG_MAX_CAST_RANK) ? (r + 1) : 0) : 0)
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@
|
|||
|
||||
%define Name ## _output_maxsize(TYPEMAP, SIZE)
|
||||
%typemap(in,noblock=1,fragment=SWIG_AsVal_frag(size_t)) (TYPEMAP, SIZE) (size_t size, Char *buff = 0) {
|
||||
if (SWIG_AsVal(size_t)($input, &size) != SWIG_OK) {
|
||||
if (!SWIG_IsOK(SWIG_AsVal(size_t)($input, &size))) {
|
||||
%argument_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
|
||||
}
|
||||
buff= %new_array(size+1, Char);
|
||||
|
|
@ -212,7 +212,7 @@
|
|||
|
||||
%define Name ## _output_withsize(TYPEMAP, SIZE)
|
||||
%typemap(in,noblock=1,fragment=SWIG_AsVal_frag(size_t)) (TYPEMAP, SIZE) (size_t n, Char *buff = 0, $*2_ltype size) {
|
||||
if (SWIG_AsVal(size_t)($input, &n) != SWIG_OK) {
|
||||
if (!SWIG_IsOK(SWIG_AsVal(size_t)($input, &n))) {
|
||||
%argument_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
|
||||
}
|
||||
buff= %new_array(n+1, Char);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
%typemap(in,fragment=SWIG_AsVal_frag(int),noblock=1) const enum SWIGTYPE& (int val, int ecode, $basetype temp) {
|
||||
ecode = SWIG_AsVal(int)($input, &val);
|
||||
if (ecode != SWIG_OK) {
|
||||
if (!SWIG_IsOK(ecode)) {
|
||||
%argument_fail(ecode, "$type", $argnum);
|
||||
} else {
|
||||
temp = %static_cast(val,$basetype);
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
%variable_fail(SWIG_AttributeError,"$type", "arch, read-only $name");
|
||||
} else {
|
||||
int ecode = SWIG_AsVal(int)($input, %reinterpret_cast(&$1,int*));
|
||||
if (ecode != SWIG_OK) {
|
||||
if (!SWIG_IsOK(ecode)) {
|
||||
%variable_fail(ecode, "$type", "$name");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -357,12 +357,11 @@ SWIG_AsVal_dec(Type)(SWIG_Object obj, Type *val)
|
|||
{
|
||||
Base v;
|
||||
int res = SWIG_AsVal(Base)(obj, &v);
|
||||
if (res == SWIG_OK) {
|
||||
if (SWIG_IsOK(res)) {
|
||||
if (OverflowCond) {
|
||||
return SWIG_OverflowError;
|
||||
} else {
|
||||
if (val) *val = %numeric_cast(v, Type);
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
%define %implicit_frag(Type...) ,fragment=SWIG_Traits_frag(Type) %enddef
|
||||
|
||||
%define %implicit_code(Type...)
|
||||
if (swig::asval<Type >(obj, 0) == SWIG_OK) {
|
||||
if (SWIG_IsOK(swig::asval<Type >(obj, 0))) {
|
||||
Type _v;
|
||||
swig::asval<Type >(obj, &_v);
|
||||
if (val) *val = %new_copy(_v, value_type);
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ or you can use the %apply directive :
|
|||
if (!%check_input_ptr($input,&$1,$descriptor,$disown)) {
|
||||
Type val;
|
||||
int ecode = asval_meth($input, &val);
|
||||
if (ecode != SWIG_OK) {
|
||||
if (!SWIG_IsOK(ecode)) {
|
||||
%argument_fail(ecode, "$*ltype",$argnum);
|
||||
}
|
||||
temp = %static_cast(val, $*ltype);
|
||||
|
|
@ -93,7 +93,7 @@ or you can use the %apply directive :
|
|||
if (!%check_input_ptr($input,&$1,$descriptor,$disown)) {
|
||||
Type val;
|
||||
int ecode = asval_meth($input, &val);
|
||||
if (ecode != SWIG_OK) {
|
||||
if (!SWIG_IsOK(ecode)) {
|
||||
%argument_fail(ecode, "$*ltype",$argnum);
|
||||
}
|
||||
temp = %static_cast(val, $*ltype);
|
||||
|
|
@ -103,7 +103,12 @@ or you can use the %apply directive :
|
|||
}
|
||||
%typemap(typecheck,noblock=1,precedence=code,fragment=asval_frag) Type *INPUT, Type &INPUT {
|
||||
void *ptr;
|
||||
$1 = ((asval_meth($input, 0) == SWIG_OK) || (%check_input_ptr($input,&ptr,$1_descriptor,0)));
|
||||
int res = asval_meth($input, 0);
|
||||
if (SWIG_IsOK(res)) {
|
||||
$1 = SWIG_GetCastRank(res);
|
||||
} else {
|
||||
$1 = %check_input_ptr($input,&ptr,$1_descriptor,0);
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
|
|
|||
|
|
@ -106,9 +106,10 @@ SWIGINTERN int
|
|||
SWIG_AsVal_dec(bool)(SWIG_Object obj, bool *val)
|
||||
{
|
||||
long v;
|
||||
if (SWIG_AsVal(long)(obj, val ? &v : 0) == SWIG_OK) {
|
||||
int res = SWIG_IsOK(SWIG_AsVal(long)(obj, val ? &v : 0));
|
||||
if (SWIG_IsOK(res)) {
|
||||
if (val) *val = v ? true : false;
|
||||
return SWIG_OK;
|
||||
return res;
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
|
@ -170,7 +171,7 @@ SWIG_AsVal_dec(size_t)(SWIG_Object obj, size_t *val)
|
|||
{
|
||||
unsigned long v;
|
||||
int res = SWIG_AsVal(unsigned long)(obj, val ? &v : 0);
|
||||
if ((res == SWIG_OK) && val) *val = %numeric_cast(v, size_t);
|
||||
if (SWIG_IsOK(res) && val) *val = %numeric_cast(v, size_t);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
@ -191,7 +192,7 @@ SWIG_AsVal_dec(ptrdiff_t)(SWIG_Object obj, ptrdiff_t *val)
|
|||
{
|
||||
long v;
|
||||
int res = SWIG_AsVal(long)(obj, val ? &v : 0);
|
||||
if ((res == SWIG_OK) && val) *val = %numeric_cast(v, ptrdiff_t);
|
||||
if (SWIG_IsOK(res) && val) *val = %numeric_cast(v, ptrdiff_t);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -540,10 +540,10 @@ SWIGINTERN int
|
|||
SWIG_AsVal_dec(Char)(SWIG_Object obj, Char *val)
|
||||
{
|
||||
int res = SWIG_As##CharName##Array(obj, val, 1);
|
||||
if (res != SWIG_OK) {
|
||||
if (!SWIG_IsOK(res)) {
|
||||
long v;
|
||||
res = SWIG_AsVal(long)(obj, &v);
|
||||
if (res == SWIG_OK) {
|
||||
if (SWIG_IsOK(res)) {
|
||||
if ((CHAR_MIN <= v) && (v <= CHAR_MAX)) {
|
||||
if (val) *val = %numeric_cast(v, Char);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ namespace swig {
|
|||
template <class Type>
|
||||
struct traits_checkval {
|
||||
static bool check SWIG_CHECK_DECL_ARGS(SWIG_Object obj) {
|
||||
return obj && (asval SWIG_AS_CALL_ARGS(obj, (Type *)(0)) == SWIG_OK);
|
||||
return obj && SWIG_IsOK(asval SWIG_AS_CALL_ARGS(obj, (Type *)(0)));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
%define %value_in_typemap(asval_meth,frag,Type...)
|
||||
%typemap(in,noblock=1,fragment=frag) Type (Type val, int ecode = 0) {
|
||||
ecode = asval_meth($input, &val);
|
||||
if (ecode != SWIG_OK) {
|
||||
if (!SWIG_IsOK(ecode)) {
|
||||
%argument_fail(ecode, "$ltype", $argnum);
|
||||
}
|
||||
$1 = %static_cast(val,$ltype);
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
%typemap(freearg) Type "";
|
||||
%typemap(in,noblock=1,fragment=frag) const Type & ($*ltype temp, Type val, int ecode = 0) {
|
||||
ecode = asval_meth($input, &val);
|
||||
if (ecode != SWIG_OK) {
|
||||
if (!SWIG_IsOK(ecode)) {
|
||||
%argument_fail(ecode, "$*ltype", $argnum);
|
||||
}
|
||||
temp = %static_cast(val, $*ltype);
|
||||
|
|
@ -67,7 +67,7 @@
|
|||
%typemap(varin,noblock=1,fragment=frag) Type {
|
||||
Type val;
|
||||
int res = asval_meth($input, &val);
|
||||
if (res != SWIG_OK) {
|
||||
if (!SWIG_IsOK(res)) {
|
||||
%variable_fail(res, "$type", "$name");
|
||||
}
|
||||
$1 = %static_cast(val,$ltype);
|
||||
|
|
@ -110,7 +110,7 @@
|
|||
%typemap(directorargout,noblock=1,fragment=frag) Type *DIRECTOROUT {
|
||||
Type val;
|
||||
int res = asval_meth($input, &val);
|
||||
if (res != SWIG_OK) {
|
||||
if (!SWIG_IsOK(res)) {
|
||||
%dirout_fail(res, "$type");
|
||||
}
|
||||
*$result = %static_cast(val, $type);
|
||||
|
|
@ -118,7 +118,7 @@
|
|||
%typemap(directorout,noblock=1,fragment=frag) Type {
|
||||
Type val;
|
||||
int res = asval_meth($input, &val);
|
||||
if (res != SWIG_OK) {
|
||||
if (!SWIG_IsOK(res)) {
|
||||
%dirout_fail(res, "$type");
|
||||
}
|
||||
$result = %static_cast(val,$type);
|
||||
|
|
@ -126,7 +126,7 @@
|
|||
%typemap(directorout,noblock=1,fragment=frag,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const Type& {
|
||||
Type val;
|
||||
int res = asval_meth($input, &val);
|
||||
if (res != SWIG_OK) {
|
||||
if (!SWIG_IsOK(res)) {
|
||||
%dirout_fail(res, "$type");
|
||||
}
|
||||
$basetype *temp = new $basetype(($basetype)val);
|
||||
|
|
@ -161,7 +161,8 @@
|
|||
|
||||
%define %value_typecheck_typemap(check,asval_meth,frag,Type...)
|
||||
%typemap(typecheck,noblock=1,precedence=check,fragment=frag) Type, const Type& {
|
||||
$1 = (asval_meth($input, 0) == SWIG_OK);
|
||||
int res = asval_meth($input, NULL);
|
||||
$1 = SWIG_GetCastRank(res);
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
|
|
|||
|
|
@ -29,12 +29,17 @@ struct Overloaded {
|
|||
};
|
||||
|
||||
static int fast_dispatch_mode = 0;
|
||||
static int cast_dispatch_mode = 0;
|
||||
|
||||
/* Set fast_dispatch_mode */
|
||||
void Wrapper_fast_dispatch_mode_set(int flag) {
|
||||
fast_dispatch_mode = flag;
|
||||
}
|
||||
|
||||
void Wrapper_cast_dispatch_mode_set(int flag) {
|
||||
cast_dispatch_mode = flag;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_overload_rank()
|
||||
*
|
||||
|
|
@ -367,7 +372,7 @@ Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) {
|
|||
String *sw = NewString("");
|
||||
Printf(f,"{\n");
|
||||
Printf(f,"unsigned long _index = 0;\n");
|
||||
Printf(f,"double _rank = 0;\n");
|
||||
Printf(f,"double _rank = 0; \n");
|
||||
|
||||
/* Get a list of methods ranked by precedence values and argument count */
|
||||
List *dispatch = Swig_overload_rank(n, true);
|
||||
|
|
@ -397,7 +402,7 @@ Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) {
|
|||
Printf(f,"if (%s >= %d) {\n", argc_template_string, num_required);
|
||||
}
|
||||
Printf(f,"double _ranki = 0;\n");
|
||||
Printf(f,"double _pi = pow(4,%d);\n",num_arguments);
|
||||
Printf(f,"double _pi = 1;\n",num_arguments);
|
||||
|
||||
/* create a list with the wrappers that collide with the
|
||||
current one based on argument number */
|
||||
|
|
@ -466,7 +471,7 @@ Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) {
|
|||
|
||||
if (emitcheck) {
|
||||
if (need_v) {
|
||||
Printf(f,"int _v = 1;\n");
|
||||
Printf(f,"int _v;\n");
|
||||
need_v = 0;
|
||||
}
|
||||
if (j >= num_required) {
|
||||
|
|
@ -478,8 +483,8 @@ Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) {
|
|||
Printv(f,"{\n",tm,"}\n",NIL);
|
||||
fn = i + 1;
|
||||
Printf(f, "if (!_v) goto check_%d;\n", fn);
|
||||
Printf(f, "_ranki += _0.25*v*_pi;\n", fn);
|
||||
Printf(f, "_pi *= 0.25;\n", fn);
|
||||
Printf(f, "_ranki += _v*_pi;\n", fn);
|
||||
Printf(f, "_pi *= SWIG_MAX_CAST_RANK;\n", fn);
|
||||
}
|
||||
}
|
||||
if (!Getattr(pj,"tmap:in:SWIGTYPE") && Getattr(pj,"tmap:typecheck:SWIGTYPE")) {
|
||||
|
|
@ -499,7 +504,7 @@ Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) {
|
|||
/* close braces */
|
||||
for (/* empty */; num_braces > 0; num_braces--) Printf(f, "}\n");
|
||||
|
||||
Printf(f,"if (_ranki > _rank) { _rank = _ranki; _index = %d;}\n",i+1);
|
||||
Printf(f,"if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = %d;}\n",i+1);
|
||||
String *lfmt = ReplaceFormat (fmt, num_arguments);
|
||||
Printf(sw, "case %d:\n", i+1);
|
||||
Printf(sw, Char(lfmt),Getattr(ni,"wrap:name"));
|
||||
|
|
|
|||
|
|
@ -321,6 +321,8 @@ void emit_mark_varargs(ParmList *l);
|
|||
void emit_action(Node *n, Wrapper *f);
|
||||
void Swig_overload_check(Node *n);
|
||||
String *Swig_overload_dispatch(Node *n, const String_or_char *fmt, int *);
|
||||
String *Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *);
|
||||
String *Swig_overload_dispatch_fast(Node *n, const String_or_char *fmt, int *);
|
||||
SwigType *cplus_value_type(SwigType *t);
|
||||
|
||||
/* directors.cxx start */
|
||||
|
|
@ -351,6 +353,7 @@ void Wrapper_virtual_elimination_mode_set(int);
|
|||
void Wrapper_director_mode_set(int);
|
||||
void Wrapper_director_protected_mode_set(int);
|
||||
void Wrapper_fast_dispatch_mode_set(int);
|
||||
void Wrapper_cast_dispatch_mode_set(int);
|
||||
|
||||
void clean_overloaded(Node *n);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue