add castmode in python and cleaning the castdispatch mechanism

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8051 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-12-23 09:22:17 +00:00
commit 5a76bc68fc
16 changed files with 461 additions and 101 deletions

View file

@ -372,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,"SWIG_TypeRank _rank = 0; \n");
/* Get a list of methods ranked by precedence values and argument count */
List *dispatch = Swig_overload_rank(n, true);
@ -401,8 +401,8 @@ Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) {
} else {
Printf(f,"if (%s >= %d) {\n", argc_template_string, num_required);
}
Printf(f,"double _ranki = 0;\n");
Printf(f,"double _pi = 1;\n",num_arguments);
Printf(f,"SWIG_TypeRank _ranki = 0;\n");
Printf(f,"SWIG_TypeRank _pi = 1;\n",num_arguments);
/* create a list with the wrappers that collide with the
current one based on argument number */
@ -471,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;\n");
Printf(f,"int _v = 0;\n");
need_v = 0;
}
if (j >= num_required) {
@ -631,7 +631,7 @@ Swig_overload_dispatch_fast(Node *n, const String_or_char *fmt, int *maxargs) {
if (emitcheck) {
if (need_v) {
Printf(f,"int _v = 1;\n");
Printf(f,"int _v = 0;\n");
need_v = 0;
}
if (j >= num_required) {

View file

@ -69,6 +69,7 @@ static int proxydel = 1;
static int fastunpack = 0;
static int modernargs = 0;
static int aliasobj0 = 0;
static int castmode = 0;
/* flags for the make_autodoc function */
enum autodoc_t {
@ -114,6 +115,8 @@ Python Options (available with -python)\n\
-nofastunpack - Use traditional UnpackTuple method to parse the argument functions (default) \n\
-aliasobj0 - Alias obj0 when using fastunpack, needed for some old typemaps \n\
-noaliasobj0 - Don't generate an obj0 alias when using fastunpack (default) \n\
-castmode - Enable the casting mode, which allows implicit cast between types\n\
-nocastmode - Disable the casting mode (default)\n\
-O - Enable all the optimizations options: \n\
-modern -fastdispatch -dirvtable -nosafecstrings -fvirtual -noproxydel -fastunpack -modernargs\n\
\n";
@ -294,6 +297,12 @@ public:
} else if (strcmp(argv[i],"-nofastunpack") == 0) {
fastunpack = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-castmode") == 0) {
castmode = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-nocastmode") == 0) {
castmode = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-modernargs") == 0) {
modernargs = 1;
Swig_mark_arg(i);
@ -394,6 +403,12 @@ public:
if (Getattr(options, "threads")) {
threads = 1;
}
if (Getattr(options, "castmode")) {
castmode = 1;
}
if (Getattr(options, "nocastmode")) {
castmode = 0;
}
mod_docstring = Getattr(options, "docstring");
package = Getattr(options, "package");
}
@ -464,6 +479,10 @@ public:
Printf(f_runtime,"#define SWIG_PYTHON_DIRECTOR_NO_VTABLE\n");
}
if (castmode) {
Printf(f_runtime,"#define SWIG_PYTHON_CAST_MODE\n");
}
/* Set module name */
module = Copy(Getattr(n,"name"));
@ -1301,11 +1320,14 @@ public:
int allow_thread = threads_enable(n);
String *tmp = NewString("");
String *dispatch = funpack ?
Swig_overload_dispatch(n,"return %s(self, argv);",&maxargs)
: Swig_overload_dispatch(n,"return %s(self, args);",&maxargs);
String *dispatch;
const char *dispatch_code = funpack ? "return %s(self, argv);" : "return %s(self, args);";
if (castmode) {
dispatch = Swig_overload_dispatch_cast(n,dispatch_code,&maxargs);
} else {
dispatch = Swig_overload_dispatch(n,dispatch_code,&maxargs);
}
/* Generate a dispatch wrapper for all overloaded functions */