Restored the Python module. Lots of minor fixes and cleanup

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@664 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-08-16 21:47:36 +00:00
commit f470aa1067
11 changed files with 430 additions and 829 deletions

View file

@ -13,8 +13,8 @@ AR = @AR@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
TARGET = libmodules11.a TARGET = libmodules11.a
OBJS = swigmain.o tcl8.o #perl5.o python.o guile.o java.o mzscheme.o ruby.o OBJS = swigmain.o tcl8.o python.o #perl5.o guile.o java.o mzscheme.o ruby.o
SRCS = swigmain.cxx tcl8.cxx #perl5.cxx python.cxx guile.cxx java.cxx mzscheme.cxx ruby.cxx SRCS = swigmain.cxx tcl8.cxx python.cxx #perl5.cxx guile.cxx java.cxx mzscheme.cxx ruby.cxx
INCLUDE = -I$(srcdir)/../Include \ INCLUDE = -I$(srcdir)/../Include \
-I$(srcdir)/../SWIG1.1 \ -I$(srcdir)/../SWIG1.1 \
-I$(srcdir)/../DOH/Include \ -I$(srcdir)/../DOH/Include \

View file

@ -36,8 +36,8 @@ struct Method { // Methods list. Needed to build methods
static Method *head = 0; static Method *head = 0;
static DOHString *const_code = 0; static String *const_code = 0;
static DOHString *shadow_methods = 0; static String *shadow_methods = 0;
static char *module = 0; // Module name static char *module = 0; // Module name
static char *path = (char*)"python"; // Pathname of where to look for library files static char *path = (char*)"python"; // Pathname of where to look for library files
@ -48,13 +48,13 @@ static int have_output;
static int use_kw = 0; static int use_kw = 0;
static int noopt = 1; static int noopt = 1;
static FILE *f_shadow; static FILE *f_shadow;
static DOHHash *hash; static Hash *hash;
static DOHHash *symbols; static Hash *symbols;
static DOHString *classes; static String *classes;
static DOHString *func; static String *func;
static DOHString *vars; static String *vars;
static DOHString *modinit; static String *modinit;
static DOHString *modextern; static String *modextern;
static char *import_file = 0; static char *import_file = 0;
static char *class_name; static char *class_name;
@ -68,7 +68,15 @@ Python Options (available with -python)\n\
-opt - Optimized shadow classes (1.5.2 or later)\n\ -opt - Optimized shadow classes (1.5.2 or later)\n\
-shadow - Generate shadow classes. \n\n"; -shadow - Generate shadow classes. \n\n";
static DOHString *pragma_include = 0; static String *pragma_include = 0;
/* Test to see if a type corresponds to something wrapped with a shadow class */
static DOH *is_shadow(SwigType *t) {
SwigType *lt = Swig_clocal_type(t);
Swig_temp_result(lt);
return Getattr(hash,lt);
}
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// PYTHON::parse_args(int argc, char *argv[]) // PYTHON::parse_args(int argc, char *argv[])
@ -139,8 +147,6 @@ void PYTHON::parse_args(int argc, char *argv[]) {
void void
PYTHON::parse() { PYTHON::parse() {
printf("Generating wrappers for Python\n");
hash = NewHash(); hash = NewHash();
symbols = NewHash(); symbols = NewHash();
@ -189,29 +195,6 @@ void PYTHON::set_module(char *mod_name, char **mod_list) {
module = new char[strlen(mod_name)+1]; module = new char[strlen(mod_name)+1];
strcpy(module,mod_name); strcpy(module,mod_name);
// If there was a mod_list specified, make this incredible hack
if (mod_list) {
Printf(modinit, "#define SWIGMODINIT ");
Printv(modextern,
"#ifdef __cplusplus\n",
"extern \"C\" {\n",
"#endif\n",
0);
i = 0;
while(mod_list[i]) {
Printv(modinit, "swig_add_module(\"", mod_list[i], "\",init", mod_list[i], "); \\\n", 0);
Printv(modextern, "extern void init", mod_list[i], "();\n", 0);
i++;
}
Printv(modextern,
"#ifdef __cplusplus\n",
"}\n",
"#endif\n",
0);
Printf(modinit,"/* End of extern module initialization */\n");
}
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -295,12 +278,15 @@ void PYTHON::headers(void)
Swig_banner(f_runtime); Swig_banner(f_runtime);
Printf(f_runtime,"/* Implementation : PYTHON */\n\n");
Printf(f_runtime,"#define SWIGPYTHON\n"); Printf(f_runtime,"#define SWIGPYTHON\n");
if (NoInclude) if (NoInclude)
Printf(f_runtime,"#define SWIG_NOINCLUDE\n"); Printf(f_runtime,"#define SWIG_NOINCLUDE\n");
if (Swig_insert_file("common.swg", f_runtime) == -1) {
Printf(stderr,"SWIG : Fatal error. Unable to locate common.swg. (Possible installation problem).\n");
SWIG_exit(1);
}
if (Swig_insert_file("python.swg", f_runtime) == -1) { if (Swig_insert_file("python.swg", f_runtime) == -1) {
Printf(stderr,"SWIG : Fatal error. Unable to locate python.swg. (Possible installation problem).\n"); Printf(stderr,"SWIG : Fatal error. Unable to locate python.swg. (Possible installation problem).\n");
SWIG_exit(1); SWIG_exit(1);
@ -454,8 +440,7 @@ void PYTHON::close(void)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
void PYTHON::close_cmodule(void) void PYTHON::close_cmodule(void)
{ {
emit_type_table(f_runtime); SwigType_emit_type_table(f_runtime,f_wrappers);
/* emit_ptr_equivalence(f_init); */
Printf(const_code, "{0}};\n"); Printf(const_code, "{0}};\n");
Printf(f_wrappers,"%s\n",const_code); Printf(f_wrappers,"%s\n",const_code);
@ -493,7 +478,7 @@ void PYTHON::close_cmodule(void)
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// PYTHON::get_pointer(char *iname, char *srcname, char *src, char *target, // PYTHON::get_pointer(char *iname, char *srcname, char *src, char *target,
// DataType *t, DOHString *f, char *ret) // DataType *t, String *f, char *ret)
// //
// Emits code to get a pointer and do type checking. // Emits code to get a pointer and do type checking.
// iname = name of the function/method (used for error messages) // iname = name of the function/method (used for error messages)
@ -513,20 +498,20 @@ void PYTHON::close_cmodule(void)
void void
PYTHON::get_pointer(char *iname, char *srcname, char *src, char *dest, PYTHON::get_pointer(char *iname, char *srcname, char *src, char *dest,
DataType *t, DOHString *f, char *ret) SwigType *t, String *f, char *ret)
{ {
DataType_remember(t); SwigType_remember(t);
// Now get the pointer value from the string and save in dest // Now get the pointer value from the string and save in dest
Printv(f,tab4, "if ((SWIG_ConvertPtr(", src, ",(void **) &", dest, ",", 0); Printv(f,tab4, "if ((SWIG_ConvertPtr(", src, ",(void **) &", dest, ",", 0);
// If we're passing a void pointer, we give the pointer conversion a NULL // If we're passing a void pointer, we give the pointer conversion a NULL
// pointer, otherwise pass in the expected type. // pointer, otherwise pass in the expected type.
if (DataType_type(t) == T_VOID) Printv(f, "0,1)) == -1) return ", ret, ";\n", 0); if (SwigType_type(t) == T_VOID) Printv(f, "0,1)) == -1) return ", ret, ";\n", 0);
else else
Printv(f,"SWIGTYPE", DataType_manglestr(t), ",1)) == -1) return ", ret, ";\n", 0); Printv(f,"SWIGTYPE", SwigType_manglestr(t), ",1)) == -1) return ", ret, ";\n", 0);
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -550,31 +535,6 @@ void PYTHON::emit_function_header(Wrapper *emit_to, char *wname)
Printf(emit_to->code," self = self;\n"); Printf(emit_to->code," self = self;\n");
} }
// ----------------------------------------------------------------------
// PYTHON::convert_self()
//
// Called during the function generation process, to determine what to
// use as the "self" variable during the call. Derived classes may emit code
// to convert the real self pointer into a usable pointer.
//
// Returns the name of the variable to use as the self pointer
// ----------------------------------------------------------------------
char *PYTHON::convert_self(Wrapper *f)
{
// Default behaviour is no translation
return (char*)"";
}
// ----------------------------------------------------------------------
// PYTHON::make_funcname_wrapper()
//
// Called to create a name for a wrapper function
// ----------------------------------------------------------------------
char *PYTHON::make_funcname_wrapper(char *fnName)
{
return Swig_name_wrapper(fnName);
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// PYTHON::create_command(char *cname, char *iname) // PYTHON::create_command(char *cname, char *iname)
// //
@ -586,7 +546,7 @@ void PYTHON::create_command(char *cname, char *iname) {
// Create the name of the wrapper function // Create the name of the wrapper function
char *wname = Swig_name_wrapper(cname); char *wname = Char(Swig_name_wrapper(cname));
// Now register the function with the interpreter. // Now register the function with the interpreter.
@ -609,7 +569,7 @@ void PYTHON::create_command(char *cname, char *iname) {
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l) void PYTHON::create_function(char *name, char *iname, SwigType *d, ParmList *l)
{ {
Parm *p; Parm *p;
int pcount,i,j; int pcount,i,j;
@ -617,13 +577,13 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
char source[64], target[64], temp[256], argnum[20]; char source[64], target[64], temp[256], argnum[20];
char *usage = 0; char *usage = 0;
Wrapper *f; Wrapper *f;
DOHString *parse_args; String *parse_args;
DOHString *arglist; String *arglist;
DOHString *get_pointers; String *get_pointers;
DOHString *cleanup; String *cleanup;
DOHString *outarg; String *outarg;
DOHString *check; String *check;
DOHString *kwargs; String *kwargs;
char *tm; char *tm;
int numopt = 0; int numopt = 0;
@ -642,7 +602,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
// Make a valid name for this function. This removes special symbols // Make a valid name for this function. This removes special symbols
// that would cause problems in the C compiler. // that would cause problems in the C compiler.
strcpy(wname,make_funcname_wrapper(iname)); strcpy(wname,Char(Swig_name_wrapper(iname)));
// Now emit the function declaration for the wrapper function. You // Now emit the function declaration for the wrapper function. You
// should modify this to return the appropriate types and use the // should modify this to return the appropriate types and use the
@ -683,15 +643,14 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
p = l; p = l;
Printf(kwargs,"{ "); Printf(kwargs,"{ ");
while (p != 0) { while (p != 0) {
DataType *pt = Gettype(p); SwigType *pt = Gettype(p);
char *pn = Getname(p); String *pn = Getname(p);
char *pv = Getvalue(p); String *pv = Getvalue(p);
// Generate source and target strings // Generate source and target strings
sprintf(source,"obj%d",i); sprintf(source,"obj%d",i);
sprintf(target,Getlname(p)); sprintf(target,Char(Getlname(p)));
sprintf(argnum,"%d",j+1); sprintf(argnum,"%d",j+1);
// Only consider this argument if it's not ignored // Only consider this argument if it's not ignored
if (!Getignore(p)) { if (!Getignore(p)) {
@ -702,7 +661,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
Putc('|',parse_args); Putc('|',parse_args);
} }
if (strlen(pn)) { if (Len(pn)) {
Printf(kwargs,"\"%s\",", pn); Printf(kwargs,"\"%s\",", pn);
} else { } else {
Printf(kwargs,"\"arg%d\",", j+1); Printf(kwargs,"\"arg%d\",", j+1);
@ -710,7 +669,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
// Look for input typemap // Look for input typemap
if ((tm = typemap_lookup((char*)"in",(char*)"python",pt,pn,source,target,f))) { if ((tm = Swig_typemap_lookup((char*)"in",pt,pn,source,target,f))) {
Putc('O',parse_args); Putc('O',parse_args);
Wrapper_add_localv(f, source, "PyObject *",source,0); Wrapper_add_localv(f, source, "PyObject *",source,0);
Printf(arglist,"&%s",source); Printf(arglist,"&%s",source);
@ -723,7 +682,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
int noarg = 0; int noarg = 0;
// Check if this parameter is a pointer. If not, we'll get values // Check if this parameter is a pointer. If not, we'll get values
switch(DataType_type(pt)) { switch(SwigType_type(pt)) {
case T_INT : case T_UINT: case T_INT : case T_UINT:
Putc('i',parse_args); Putc('i',parse_args);
break; break;
@ -759,7 +718,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
Wrapper_add_localv(f,tempb,"int",tempb,0); Wrapper_add_localv(f,tempb,"int",tempb,0);
else else
Wrapper_add_localv(f,tempb,"int",tempb, "=",tempval,0); Wrapper_add_localv(f,tempb,"int",tempb, "=",tempval,0);
Printv(get_pointers, tab4, target, " = (", DataType_lstr(pt,0), ") ", tempb, ";\n", 0); Printv(get_pointers, tab4, target, " = (", SwigType_lstr(pt,0), ") ", tempb, ";\n", 0);
Printf(arglist,"&%s",tempb); Printf(arglist,"&%s",tempb);
noarg = 1; noarg = 1;
} }
@ -773,14 +732,14 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
Putc('O',parse_args); Putc('O',parse_args);
sprintf(source,"argo%d", i); sprintf(source,"argo%d", i);
sprintf(target,Getlname(p)); sprintf(target,Char(Getlname(p)));
sprintf(temp,"argument %d",i+1); sprintf(temp,"argument %d",i+1);
Wrapper_add_localv(f,source,"PyObject *",source,"=0",0); Wrapper_add_localv(f,source,"PyObject *",source,"=0",0);
Printf(arglist,"&%s",source); Printf(arglist,"&%s",source);
DataType_add_pointer(pt); SwigType_add_pointer(pt);
get_pointer(iname, temp, source, target, pt, get_pointers, (char*)"NULL"); get_pointer(iname, temp, source, target, pt, get_pointers, (char*)"NULL");
DataType_del_pointer(pt); SwigType_del_pointer(pt);
noarg = 1; noarg = 1;
break; break;
@ -797,7 +756,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
Putc('O',parse_args); Putc('O',parse_args);
sprintf(source,"argo%d", i); sprintf(source,"argo%d", i);
sprintf(target,"%s",Getlname(p)); sprintf(target,"%s",Char(Getlname(p)));
sprintf(temp,"argument %d",i+1); sprintf(temp,"argument %d",i+1);
Wrapper_add_localv(f,source,"PyObject *",source,"=0",0); Wrapper_add_localv(f,source,"PyObject *",source,"=0",0);
@ -807,7 +766,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
break; break;
default : default :
Printf(stderr,"%s : Line %d. Unable to use type %s as a function argument.\n",input_file, line_number, DataType_str(pt,0)); Printf(stderr,"%s : Line %d. Unable to use type %s as a function argument.\n",input_file, line_number, SwigType_str(pt,0));
break; break;
} }
@ -819,17 +778,17 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
j++; j++;
} }
// Check if there was any constraint code // Check if there was any constraint code
if ((tm = typemap_lookup((char*)"check",(char*)"python",pt,pn,source,target))) { if ((tm = Swig_typemap_lookup((char*)"check",pt,pn,source,target,0))) {
Printf(check,"%s\n",tm); Printf(check,"%s\n",tm);
Replace(check,"$argnum", argnum, DOH_REPLACE_ANY); Replace(check,"$argnum", argnum, DOH_REPLACE_ANY);
} }
// Check if there was any cleanup code // Check if there was any cleanup code
if ((tm = typemap_lookup((char*)"freearg",(char*)"python",pt,pn,target,source))) { if ((tm = Swig_typemap_lookup((char*)"freearg",pt,pn,target,source,0))) {
Printf(cleanup,"%s\n",tm); Printf(cleanup,"%s\n",tm);
Replace(cleanup,"$argnum", argnum, DOH_REPLACE_ANY); Replace(cleanup,"$argnum", argnum, DOH_REPLACE_ANY);
Replace(cleanup,"$arg",source, DOH_REPLACE_ANY); Replace(cleanup,"$arg",source, DOH_REPLACE_ANY);
} }
if ((tm = typemap_lookup((char*)"argout",(char*)"python",pt,pn,target,(char*)"resultobj"))) { if ((tm = Swig_typemap_lookup((char*)"argout",pt,pn,target,(char*)"resultobj",0))) {
Printf(outarg,"%s\n", tm); Printf(outarg,"%s\n", tm);
Replace(outarg,"$argnum",argnum,DOH_REPLACE_ANY); Replace(outarg,"$argnum",argnum,DOH_REPLACE_ANY);
Replace(outarg,"$arg",source, DOH_REPLACE_ANY); Replace(outarg,"$arg",source, DOH_REPLACE_ANY);
@ -849,26 +808,24 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
arglist, ")) return NULL;\n", arglist, ")) return NULL;\n",
0); 0);
strcpy(self_name,convert_self(f));
/* Now slap the whole first part of the wrapper function together */ /* Now slap the whole first part of the wrapper function together */
Printv(f->code, parse_args, get_pointers, check, 0); Printv(f->code, parse_args, get_pointers, check, 0);
// This function emits code to call the real function. Assuming you read // This function emits code to call the real function. Assuming you read
// the parameters in correctly, this will work. // the parameters in correctly, this will work.
sprintf(call_name,"%s%s",self_name,name); sprintf(call_name,"%s",name);
emit_func_call(call_name,d,l,f); emit_func_call(call_name,d,l,f);
// Now emit code to return the functions return value (if any). // Now emit code to return the functions return value (if any).
// If there was a result, it was saved in result. // If there was a result, it was saved in result.
// If the function is a void type, don't do anything. // If the function is a void type, don't do anything.
if ((tm = typemap_lookup((char*)"out",(char*)"python",d,iname,(char*)"result",(char*)"resultobj"))) { if ((tm = Swig_typemap_lookup((char*)"out",d,iname,(char*)"result",(char*)"resultobj",0))) {
// Yep. Use it instead of the default // Yep. Use it instead of the default
Printf(f->code,"%s\n", tm); Printf(f->code,"%s\n", tm);
} else { } else {
switch(DataType_type(d)) { switch(SwigType_type(d)) {
case T_INT: case T_UINT: case T_BOOL: case T_INT: case T_UINT: case T_BOOL:
Printf(f->code," resultobj = Py_BuildValue(\"i\",result);\n"); Printf(f->code," resultobj = Py_BuildValue(\"i\",result);\n");
break; break;
@ -899,10 +856,10 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
break; break;
case T_USER : case T_USER :
DataType_add_pointer(d); SwigType_add_pointer(d);
DataType_remember(d); SwigType_remember(d);
Printv(f->code,tab4, "resultobj = SWIG_NewPointerObj((void *)result, SWIGTYPE", DataType_manglestr(d), ");\n",0); Printv(f->code,tab4, "resultobj = SWIG_NewPointerObj((void *)result, SWIGTYPE", SwigType_manglestr(d), ");\n",0);
DataType_del_pointer(d); SwigType_del_pointer(d);
break; break;
case T_STRING: case T_STRING:
@ -910,8 +867,8 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
break; break;
case T_POINTER: case T_ARRAY: case T_REFERENCE: case T_POINTER: case T_ARRAY: case T_REFERENCE:
DataType_remember(d); SwigType_remember(d);
Printv(f->code, tab4, "resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE", DataType_manglestr(d), ");\n", 0); Printv(f->code, tab4, "resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE", SwigType_manglestr(d), ");\n", 0);
break; break;
case T_VOID: case T_VOID:
@ -920,7 +877,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
break; break;
default : default :
Printf(stderr,"%s: Line %d. Unable to use return type %s in function %s.\n", input_file, line_number, DataType_str(d,0), name); Printf(stderr,"%s: Line %d. Unable to use return type %s in function %s.\n", input_file, line_number, SwigType_str(d,0), name);
break; break;
} }
} }
@ -937,14 +894,14 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
// Look to see if there is any newfree cleanup code // Look to see if there is any newfree cleanup code
if (NewObject) { if (NewObject) {
if ((tm = typemap_lookup((char*)"newfree",(char*)"python",d,iname,(char*)"result",(char*)""))) { if ((tm = Swig_typemap_lookup((char*)"newfree",d,iname,(char*)"result",(char*)"",0))) {
Printf(f->code,"%s\n",tm); Printf(f->code,"%s\n",tm);
} }
} }
// See if there is any argument cleanup code // See if there is any argument cleanup code
if ((tm = typemap_lookup((char*)"ret",(char*)"python",d,iname,(char*)"result",(char*)""))) { if ((tm = Swig_typemap_lookup((char*)"ret",d,iname,(char*)"result",(char*)"",0))) {
// Yep. Use it instead of the default // Yep. Use it instead of the default
Printf(f->code,"%s\n",tm); Printf(f->code,"%s\n",tm);
} }
@ -981,7 +938,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
// Check return code for modification // Check return code for modification
if ((Getattr(hash,DataType_Getname(d))) && (DataType_is_pointer(d) <=1)) { if (is_shadow(d)) {
need_wrapper = 1; need_wrapper = 1;
munge_return = 1; munge_return = 1;
} }
@ -1000,15 +957,14 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
// If the output of this object has been remapped in any way, we're // If the output of this object has been remapped in any way, we're
// going to return it as a bare object. // going to return it as a bare object.
if (!typemap_check((char*)"out",typemap_lang,d,iname)) { if (!Swig_typemap_search((char*)"out",d,iname)) {
// If there are output arguments, we are going to return the value // If there are output arguments, we are going to return the value
// unchanged. Otherwise, emit some shadow class conversion code. // unchanged. Otherwise, emit some shadow class conversion code.
if (!have_output) { if (!have_output) {
Printv(func, tab4, "if val: val = ", GetChar(hash,DataType_Getname(d)), "Ptr(val)", 0); Printv(func, tab4, "if val: val = ", is_shadow(d), "Ptr(val)", 0);
if (((Getattr(hash,DataType_Getname(d))) && (DataType_is_pointer(d) < 1)) || if ((!SwigType_ispointer(d)) || NewObject)
((Getattr(hash,DataType_Getname(d))) && (DataType_is_pointer(d) == 1) && NewObject))
Printf(func, "; val.thisown = 1\n"); Printf(func, "; val.thisown = 1\n");
else else
Printf(func,"\n"); Printf(func,"\n");
@ -1043,7 +999,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
// variable type. // variable type.
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
void PYTHON::link_variable(char *name, char *iname, DataType *t) { void PYTHON::link_variable(char *name, char *iname, SwigType *t) {
char *wname; char *wname;
static int have_globals = 0; static int have_globals = 0;
@ -1067,7 +1023,7 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
// First make a sanitized version of the function name (in case it's some // First make a sanitized version of the function name (in case it's some
// funky C++ thing). // funky C++ thing).
wname = Swig_name_wrapper(name); wname = Char(Swig_name_wrapper(name));
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Create a function for setting the value of the variable // Create a function for setting the value of the variable
@ -1075,22 +1031,22 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
Printf(setf->def,"static int %s_set(PyObject *val) {", wname); Printf(setf->def,"static int %s_set(PyObject *val) {", wname);
if (!(Status & STAT_READONLY)) { if (!(Status & STAT_READONLY)) {
if ((tm = typemap_lookup((char*)"varin",(char*)"python",t,name,(char*)"val",name))) { if ((tm = Swig_typemap_lookup((char*)"varin",t,name,(char*)"val",name,0))) {
Printf(setf->code,"%s\n",tm); Printf(setf->code,"%s\n",tm);
Replace(setf->code,"$name",iname, DOH_REPLACE_ANY); Replace(setf->code,"$name",iname, DOH_REPLACE_ANY);
} else { } else {
switch(DataType_type(t)) { switch(SwigType_type(t)) {
case T_INT: case T_SHORT: case T_LONG : case T_INT: case T_SHORT: case T_LONG :
case T_UINT: case T_USHORT: case T_ULONG: case T_UINT: case T_USHORT: case T_ULONG:
case T_SCHAR: case T_UCHAR: case T_BOOL: case T_SCHAR: case T_UCHAR: case T_BOOL:
// Get an integer value // Get an integer value
Wrapper_add_localv(setf,"tval",DataType_lstr(t,0),"tval",0); Wrapper_add_localv(setf,"tval",SwigType_lstr(t,0),"tval",0);
Printv(setf->code, Printv(setf->code,
tab4, "tval = (", DataType_lstr(t,0), ") PyInt_AsLong(val);\n", tab4, "tval = (", SwigType_lstr(t,0), ") PyInt_AsLong(val);\n",
tab4, "if (PyErr_Occurred()) {\n", tab4, "if (PyErr_Occurred()) {\n",
tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '", tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '",
iname, "'(", DataType_str(t,0), ")\");\n", iname, "'(", SwigType_str(t,0), ")\");\n",
tab8, "return 1; \n", tab8, "return 1; \n",
tab4, "}\n", tab4, "}\n",
tab4, name, " = tval;\n", tab4, name, " = tval;\n",
@ -1099,12 +1055,12 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
case T_FLOAT: case T_DOUBLE: case T_FLOAT: case T_DOUBLE:
// Get a floating point value // Get a floating point value
Wrapper_add_localv(setf,"tval",DataType_lstr(t,0), "tval",0); Wrapper_add_localv(setf,"tval",SwigType_lstr(t,0), "tval",0);
Printv(setf->code, Printv(setf->code,
tab4, "tval = (", DataType_lstr(t,0), ") PyFloat_AsDouble(val);\n", tab4, "tval = (", SwigType_lstr(t,0), ") PyFloat_AsDouble(val);\n",
tab4, "if (PyErr_Occurred()) {\n", tab4, "if (PyErr_Occurred()) {\n",
tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '", tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '",
iname, "'(", DataType_str(t,0), ")\");\n", iname, "'(", SwigType_str(t,0), ")\");\n",
tab8, "return 1; \n", tab8, "return 1; \n",
tab4, "}\n", tab4, "}\n",
tab4, name, " = tval;\n", tab4, name, " = tval;\n",
@ -1119,18 +1075,18 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
tab4, "tval = (char *) PyString_AsString(val);\n", tab4, "tval = (char *) PyString_AsString(val);\n",
tab4, "if (PyErr_Occurred()) {\n", tab4, "if (PyErr_Occurred()) {\n",
tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '", tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '",
iname, "'(", DataType_str(t,0), ")\");\n", iname, "'(", SwigType_str(t,0), ")\");\n",
tab8, "return 1; \n", tab8, "return 1; \n",
tab4, "}\n", tab4, "}\n",
tab4, name, " = *tval;\n", tab4, name, " = *tval;\n",
0); 0);
break; break;
case T_USER: case T_USER:
DataType_add_pointer(t); SwigType_add_pointer(t);
Wrapper_add_localv(setf,"temp",DataType_lstr(t,0),"temp",0); Wrapper_add_localv(setf,"temp",SwigType_lstr(t,0),"temp",0);
get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf->code,(char*)"1"); get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf->code,(char*)"1");
Printv(setf->code, tab4, name, " = *temp;\n", 0); Printv(setf->code, tab4, name, " = *temp;\n", 0);
DataType_del_pointer(t); SwigType_del_pointer(t);
break; break;
case T_STRING: case T_STRING:
@ -1139,7 +1095,7 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
tab4, "tval = (char *) PyString_AsString(val);\n", tab4, "tval = (char *) PyString_AsString(val);\n",
tab4, "if (PyErr_Occurred()) {\n", tab4, "if (PyErr_Occurred()) {\n",
tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '", tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '",
iname, "'(", DataType_str(t,0), ")\");\n", iname, "'(", SwigType_str(t,0), ")\");\n",
tab8, "return 1; \n", tab8, "return 1; \n",
tab4, "}\n", tab4, "}\n",
0); 0);
@ -1160,13 +1116,13 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
break; break;
case T_POINTER: case T_ARRAY: case T_REFERENCE: case T_POINTER: case T_ARRAY: case T_REFERENCE:
Wrapper_add_localv(setf,"temp", DataType_lstr(t,0), "temp",0); Wrapper_add_localv(setf,"temp", SwigType_lstr(t,0), "temp",0);
get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf->code,(char*)"1"); get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf->code,(char*)"1");
Printv(setf->code,tab4, name, " = temp;\n", 0); Printv(setf->code,tab4, name, " = temp;\n", 0);
break; break;
default: default:
Printf(stderr,"%s : Line %d. Unable to link with type %s.\n", input_file, line_number, DataType_str(t,0)); Printf(stderr,"%s : Line %d. Unable to link with type %s.\n", input_file, line_number, SwigType_str(t,0));
} }
} }
Printf(setf->code," return 0;\n"); Printf(setf->code," return 0;\n");
@ -1191,14 +1147,14 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
Printf(getf->def,"static PyObject *%s_get() {", wname); Printf(getf->def,"static PyObject *%s_get() {", wname);
Wrapper_add_local(getf,"pyobj", "PyObject *pyobj"); Wrapper_add_local(getf,"pyobj", "PyObject *pyobj");
if ((tm = typemap_lookup((char*)"varout",(char*)"python",t,name,name,(char*)"pyobj"))) { if ((tm = Swig_typemap_lookup((char*)"varout",t,name,name,(char*)"pyobj",0))) {
Printf(getf->code,"%s\n",tm); Printf(getf->code,"%s\n",tm);
Replace(getf->code,"$name",iname, DOH_REPLACE_ANY); Replace(getf->code,"$name",iname, DOH_REPLACE_ANY);
} else if ((tm = typemap_lookup((char*)"out",(char*)"python",t,name,name,(char*)"pyobj"))) { } else if ((tm = Swig_typemap_lookup((char*)"out",t,name,name,(char*)"pyobj",0))) {
Printf(getf->code,"%s\n",tm); Printf(getf->code,"%s\n",tm);
Replace(getf->code,"$name",iname, DOH_REPLACE_ANY); Replace(getf->code,"$name",iname, DOH_REPLACE_ANY);
} else { } else {
switch(DataType_type(t)) { switch(SwigType_type(t)) {
case T_INT: case T_UINT: case T_INT: case T_UINT:
case T_SHORT: case T_USHORT: case T_SHORT: case T_USHORT:
case T_LONG: case T_ULONG: case T_LONG: case T_ULONG:
@ -1218,13 +1174,13 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
break; break;
case T_USER: case T_USER:
// Hack this into a pointer // Hack this into a pointer
DataType_add_pointer(t); SwigType_add_pointer(t);
DataType_remember(t); SwigType_remember(t);
Printv(getf->code, Printv(getf->code,
tab4, "pyobj = SWIG_NewPointerObj((void *) &", name , tab4, "pyobj = SWIG_NewPointerObj((void *) &", name ,
", SWIGTYPE", DataType_manglestr(t), ");\n", ", SWIGTYPE", SwigType_manglestr(t), ");\n",
0); 0);
DataType_del_pointer(t); SwigType_del_pointer(t);
break; break;
case T_STRING: case T_STRING:
Printv(getf->code, Printv(getf->code,
@ -1235,15 +1191,15 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
break; break;
case T_POINTER: case T_ARRAY: case T_REFERENCE: case T_POINTER: case T_ARRAY: case T_REFERENCE:
DataType_remember(t); SwigType_remember(t);
Printv(getf->code, Printv(getf->code,
tab4, "pyobj = SWIG_NewPointerObj((void *)", name, tab4, "pyobj = SWIG_NewPointerObj((void *)", name,
", SWIGTYPE", DataType_manglestr(t), ");\n", ", SWIGTYPE", SwigType_manglestr(t), ");\n",
0); 0);
break; break;
default: default:
Printf(stderr,"Unable to link with type %s\n", DataType_str(t,0)); Printf(stderr,"Unable to link with type %s\n", SwigType_str(t,0));
break; break;
} }
} }
@ -1260,9 +1216,9 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
// Output a shadow variable. (If applicable and possible) // Output a shadow variable. (If applicable and possible)
// ---------------------------------------------------------- // ----------------------------------------------------------
if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) { if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) {
if ((Getattr(hash,DataType_Getname(t))) && (DataType_is_pointer(t) <= 1)) { if (is_shadow(t)) {
Printv(vars, Printv(vars,
iname, " = ", GetChar(hash,DataType_Getname(t)), "Ptr(", module, ".", global_name, iname, " = ", is_shadow(t), "Ptr(", module, ".", global_name,
".", iname, ")\n", ".", iname, ")\n",
0); 0);
} }
@ -1280,16 +1236,16 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
// //
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void PYTHON::declare_const(char *name, char *, DataType *type, char *value) { void PYTHON::declare_const(char *name, char *, SwigType *type, char *value) {
char *tm; char *tm;
// Make a static python object // Make a static python object
if ((tm = typemap_lookup((char*)"const",(char*)"python",type,name,value,name))) { if ((tm = Swig_typemap_lookup((char*)"const",type,name,value,name,0))) {
Printf(const_code,"%s\n", tm); Printf(const_code,"%s\n", tm);
} else { } else {
switch(DataType_type(type)) { switch(SwigType_type(type)) {
case T_INT: case T_UINT: case T_BOOL: case T_INT: case T_UINT: case T_BOOL:
case T_SHORT: case T_USHORT: case T_SHORT: case T_USHORT:
case T_LONG: case T_ULONG: case T_LONG: case T_ULONG:
@ -1307,8 +1263,8 @@ void PYTHON::declare_const(char *name, char *, DataType *type, char *value) {
Printv(const_code,tab4, "{ SWIG_PY_STRING, \"", name, "\", 0, 0, (void *) \"", value, "\", 0},\n", 0); Printv(const_code,tab4, "{ SWIG_PY_STRING, \"", name, "\", 0, 0, (void *) \"", value, "\", 0},\n", 0);
break; break;
case T_POINTER: case T_ARRAY: case T_REFERENCE: case T_POINTER: case T_ARRAY: case T_REFERENCE:
DataType_remember(type); SwigType_remember(type);
Printv(const_code, tab4, "{ SWIG_PY_POINTER, \"", name, "\", 0, 0, (void *) ", value, ", &SWIGTYPE", DataType_manglestr(type), "}, \n", 0); Printv(const_code, tab4, "{ SWIG_PY_POINTER, \"", name, "\", 0, 0, (void *) ", value, ", &SWIGTYPE", SwigType_manglestr(type), "}, \n", 0);
break; break;
default: default:
Printf(stderr,"%s : Line %d. Unsupported constant value.\n", input_file, line_number); Printf(stderr,"%s : Line %d. Unsupported constant value.\n", input_file, line_number);
@ -1332,7 +1288,7 @@ void PYTHON::declare_const(char *name, char *, DataType *type, char *value) {
// a string and set this pointer to point to it. // a string and set this pointer to point to it.
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
char *PYTHON::usage_var(char *iname, DataType *) { char *PYTHON::usage_var(char *iname, SwigType *) {
static char temp[512]; static char temp[512];
sprintf(temp,"%s.%s", global_name,iname); sprintf(temp,"%s.%s", global_name,iname);
@ -1349,9 +1305,9 @@ char *PYTHON::usage_var(char *iname, DataType *) {
// //
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
char *PYTHON::usage_func(char *iname, DataType *, ParmList *l) { char *PYTHON::usage_func(char *iname, SwigType *, ParmList *l) {
static DOHString *temp = 0; static String *temp = 0;
Parm *p; Parm *p;
int i; int i;
if (!temp) temp = NewString(""); if (!temp) temp = NewString("");
@ -1366,17 +1322,17 @@ char *PYTHON::usage_func(char *iname, DataType *, ParmList *l) {
i = 0; i = 0;
p = l; p = l;
while (p != 0) { while (p != 0) {
DataType *pt = Gettype(p); SwigType *pt = Gettype(p);
char *pn = Getname(p); String *pn = Getname(p);
if (!Getignore(p)) { if (!Getignore(p)) {
i++; i++;
/* If parameter has been named, use that. Otherwise, just print a type */ /* If parameter has been named, use that. Otherwise, just print a type */
if (DataType_type(pt) != T_VOID) { if (SwigType_type(pt) != T_VOID) {
if (strlen(pn) > 0) { if (Len(pn) > 0) {
Printf(temp,"%s",pn); Printf(temp,"%s",pn);
} else { } else {
Printf(temp,"%s", DataType_str(pt,0)); Printf(temp,"%s", SwigType_str(pt,0));
} }
} }
p = Getnext(p); p = Getnext(p);
@ -1405,7 +1361,7 @@ char *PYTHON::usage_func(char *iname, DataType *, ParmList *l) {
// usage_var() except we'll indicate the value of the constant. // usage_var() except we'll indicate the value of the constant.
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
char *PYTHON::usage_const(char *iname, DataType *, char *value) { char *PYTHON::usage_const(char *iname, SwigType *, char *value) {
static char temp[1024]; static char temp[1024];
sprintf(temp,"%s = %s", iname, value); sprintf(temp,"%s = %s", iname, value);
return temp; return temp;
@ -1417,7 +1373,7 @@ char *PYTHON::usage_const(char *iname, DataType *, char *value) {
// Add a native module name to the methods list. // Add a native module name to the methods list.
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
void PYTHON::add_native(char *name, char *funcname, DataType *, ParmList *) { void PYTHON::add_native(char *name, char *funcname, SwigType *, ParmList *) {
add_method(name, funcname,0); add_method(name, funcname,0);
if (shadow) { if (shadow) {
Printv(func, name, " = ", module, ".", name, "\n\n", 0); Printv(func, name, " = ", module, ".", name, "\n\n", 0);
@ -1433,13 +1389,19 @@ void PYTHON::add_native(char *name, char *funcname, DataType *, ParmList *) {
void PYTHON::cpp_class_decl(char *name, char *rename, char *type) { void PYTHON::cpp_class_decl(char *name, char *rename, char *type) {
char temp[256]; char temp[256];
String *stype;
if (shadow) { if (shadow) {
Setattr(hash,name,rename); stype = NewString(name);
// Add full name of datatype to the hash table SwigType_add_pointer(stype);
if (strlen(type) > 0) { Setattr(hash,stype,rename);
sprintf(temp,"%s %s", type, name); Delete(stype);
Setattr(hash,temp,rename); // Add full name of datatype to the hash table
} if (strlen(type) > 0) {
stype = NewStringf("%s %s", type, name);
SwigType_add_pointer(stype);
Setattr(hash,stype,rename);
Delete(stype);
}
} }
} }
@ -1482,8 +1444,8 @@ void PYTHON::pragma(char *lang, char *cmd, char *value) {
struct PyPragma { struct PyPragma {
DOHString *m_method; String *m_method;
DOHString *m_text; String *m_text;
PyPragma *next; PyPragma *next;
PyPragma(char *method, char *text) { PyPragma(char *method, char *text) {
m_method = NewString(method); m_method = NewString(method);
@ -1515,7 +1477,7 @@ void PYTHON::cpp_pragma(Pragma *plist) {
if (strcmp(Char(plist->lang),(char*)"python") == 0) { if (strcmp(Char(plist->lang),(char*)"python") == 0) {
if (strcmp(Char(plist->name),"addtomethod") == 0) { if (strcmp(Char(plist->name),"addtomethod") == 0) {
// parse value, expected to be in the form "methodName:line" // parse value, expected to be in the form "methodName:line"
DOHString *temp = NewString(plist->value); String *temp = NewString(plist->value);
char* txtptr = strchr(Char(temp), ':'); char* txtptr = strchr(Char(temp), ':');
if (txtptr) { if (txtptr) {
// add name and line to a list in current_class // add name and line to a list in current_class
@ -1558,7 +1520,7 @@ void PYTHON::cpp_pragma(Pragma *plist) {
// Append the text properly spaced to the output string. // Append the text properly spaced to the output string.
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
void PYTHON::emitAddPragmas(DOHString *output, char* name, char* spacing) void PYTHON::emitAddPragmas(String *output, char* name, char* spacing)
{ {
PyPragma *p = pragmas; PyPragma *p = pragmas;
while (p) { while (p) {
@ -1573,15 +1535,15 @@ void PYTHON::emitAddPragmas(DOHString *output, char* name, char* spacing)
* C++ Support + Shadow Classes * C++ Support + Shadow Classes
**************************************************************************/ **************************************************************************/
static DOHString *setattr = 0; static String *setattr = 0;
static DOHString *getattr = 0; static String *getattr = 0;
static DOHString *csetattr = 0; static String *csetattr = 0;
static DOHString *cgetattr = 0; static String *cgetattr = 0;
static DOHString *pyclass = 0; static String *pyclass = 0;
static DOHString *imethod = 0; static String *imethod = 0;
static DOHString *construct = 0; static String *construct = 0;
static DOHString *cinit = 0; static String *cinit = 0;
static DOHString *additional = 0; static String *additional = 0;
static int have_constructor; static int have_constructor;
static int have_destructor; static int have_destructor;
static int have_getattr; static int have_getattr;
@ -1589,7 +1551,7 @@ static int have_setattr;
static int have_repr; static int have_repr;
static char *class_type; static char *class_type;
static char *real_classname; static char *real_classname;
static DOHString *base_class = 0; static String *base_class = 0;
static int class_renamed = 0; static int class_renamed = 0;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -1635,11 +1597,7 @@ void PYTHON::cpp_open_class(char *classname, char *rname, char *ctype, int strip
real_classname = Swig_copy_string(classname); real_classname = Swig_copy_string(classname);
class_type = Swig_copy_string(ctype); class_type = Swig_copy_string(ctype);
// Build up the hash table cpp_class_decl(real_classname,class_name,class_type);
Setattr(hash,real_classname,class_name);
sprintf(temp,"%s %s", class_type, real_classname);
Setattr(hash,temp,class_name);
if (shadow) { if (shadow) {
Printv(setattr, Printv(setattr,
@ -1663,12 +1621,11 @@ void PYTHON::cpp_open_class(char *classname, char *rname, char *ctype, int strip
// Creates a C++ member function // Creates a C++ member function
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
void PYTHON::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l) { void PYTHON::cpp_member_func(char *name, char *iname, SwigType *t, ParmList *l) {
char *realname; char *realname;
int oldshadow; int oldshadow;
char cname[1024]; char cname[1024];
// Create the default member function // Create the default member function
@ -1693,7 +1650,7 @@ void PYTHON::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l)
if (strcmp(realname,"__repr__") == 0) if (strcmp(realname,"__repr__") == 0)
have_repr = 1; have_repr = 1;
if (!((Getattr(hash,DataType_Getname(t))) && (DataType_is_pointer(t) <=1)) && !noopt) { if (!is_shadow(t) && !noopt) {
Printv(imethod, Printv(imethod,
class_name, ".", realname, " = new.instancemethod(", module, ".", Swig_name_member(class_name,realname), ", None, ", class_name, ")\n", class_name, ".", realname, " = new.instancemethod(", module, ".", Swig_name_member(class_name,realname), ", None, ", class_name, ")\n",
0); 0);
@ -1713,15 +1670,15 @@ void PYTHON::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l)
Printv(pyclass, tab8, "val = apply(", module, ".", Swig_name_member(class_name,realname), ",args)\n",0); Printv(pyclass, tab8, "val = apply(", module, ".", Swig_name_member(class_name,realname), ",args)\n",0);
// Check to see if the return type is an object // Check to see if the return type is an object
if ((Getattr(hash,DataType_Getname(t))) && (DataType_is_pointer(t) <= 1)) { if (is_shadow(t)) {
if (!typemap_check((char*)"out",typemap_lang,t,Swig_name_member(class_name,realname))) { if (!Swig_typemap_search((char*)"out",t,Swig_name_member(class_name,realname))) {
if (!have_output) { if (!have_output) {
Printv(pyclass, tab8, "if val: val = ", GetChar(hash,DataType_Getname(t)), "Ptr(val) ", 0); Printv(pyclass, tab8, "if val: val = ", is_shadow(t), "Ptr(val) ", 0);
if (((Getattr(hash,DataType_Getname(t))) && (DataType_is_pointer(t) < 1)) || if ((!SwigType_ispointer(t) || NewObject)) {
((Getattr(hash,DataType_Getname(t))) && (DataType_is_pointer(t) == 1) && NewObject))
Printf(pyclass, "; val.thisown = 1\n"); Printf(pyclass, "; val.thisown = 1\n");
else } else {
Printf(pyclass,"\n"); Printf(pyclass,"\n");
}
} else { } else {
// Do nothing! // Do nothing!
} }
@ -1837,8 +1794,8 @@ void PYTHON::cpp_destructor(char *name, char *newname) {
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
void PYTHON::cpp_close_class() { void PYTHON::cpp_close_class() {
DOHString *ptrclass; String *ptrclass;
DOHString *repr; String *repr;
ptrclass = NewString(""); ptrclass = NewString("");
repr = NewString(""); repr = NewString("");
@ -1954,7 +1911,7 @@ void PYTHON::cpp_inherit(char **baseclass,int) {
// Adds an instance member. // Adds an instance member.
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
void PYTHON::cpp_variable(char *name, char *iname, DataType *t) { void PYTHON::cpp_variable(char *name, char *iname, SwigType *t) {
char *realname; char *realname;
int inhash = 0; int inhash = 0;
int oldshadow = shadow; int oldshadow = shadow;
@ -1981,7 +1938,7 @@ void PYTHON::cpp_variable(char *name, char *iname, DataType *t) {
// Figure out if we've seen this datatype before // Figure out if we've seen this datatype before
if ((Getattr(hash,DataType_Getname(t))) && (DataType_is_pointer(t) <= 1)) inhash = 1; if (is_shadow(t)) inhash = 1;
// Now write some code to set the variable // Now write some code to set the variable
if (Status & STAT_READONLY) { if (Status & STAT_READONLY) {
@ -1991,7 +1948,7 @@ void PYTHON::cpp_variable(char *name, char *iname, DataType *t) {
} }
// Write some code to get the variable // Write some code to get the variable
if (inhash) { if (inhash) {
Printv(cgetattr, tab8, "\"", realname, "\" : lambda x : ", GetChar(hash,DataType_Getname(t)), "Ptr(", module, ".", Swig_name_get(Swig_name_member(class_name,realname)), "(x)),\n", 0); Printv(cgetattr, tab8, "\"", realname, "\" : lambda x : ", is_shadow(t), "Ptr(", module, ".", Swig_name_get(Swig_name_member(class_name,realname)), "(x)),\n", 0);
} else { } else {
Printv(cgetattr, tab8, "\"", realname, "\" : ", module, ".", Swig_name_get(Swig_name_member(class_name,realname)),",\n", 0); Printv(cgetattr, tab8, "\"", realname, "\" : ", module, ".", Swig_name_get(Swig_name_member(class_name,realname)),",\n", 0);
@ -2005,7 +1962,7 @@ void PYTHON::cpp_variable(char *name, char *iname, DataType *t) {
// Add access to a C++ constant // Add access to a C++ constant
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
void PYTHON::cpp_declare_const(char *name, char *iname, DataType *type, char *value) { void PYTHON::cpp_declare_const(char *name, char *iname, SwigType *type, char *value) {
char *realname; char *realname;
int oldshadow = shadow; int oldshadow = shadow;
char cname[512]; char cname[512];
@ -2045,24 +2002,13 @@ void PYTHON::cpp_declare_const(char *name, char *iname, DataType *type, char *va
// //
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
void PYTHON::add_typedef(DataType *t, char *name) { void PYTHON::add_typedef(SwigType *t, char *name) {
if (!shadow) return; if (!shadow) return;
// First check to see if there aren't too many pointers // First check to see if there aren't too many pointers
if (DataType_is_pointer(t) > 1) return; if (is_shadow(t)) {
cpp_class_decl(name,Char(is_shadow(t)),"");
if (Getattr(hash,name)) return; // Already added
// Now look up the datatype in our shadow class hash table
if (Getattr(hash,DataType_Getname(t))) {
// Yep. This datatype is in the hash
// Put this types 'new' name into the hash
Setattr(hash,name, GetChar(hash,DataType_Getname(t)));
} }
} }

View file

@ -23,7 +23,7 @@
class PYTHON : public Language { class PYTHON : public Language {
protected: protected:
void get_pointer(char *iname, char *srcname, char *src, char *dest, SwigType *t, DOHString *f, char *ret); void get_pointer(char *iname, char *srcname, char *src, char *dest, SwigType *t, String *f, char *ret);
void add_method(char *name, char *function, int kw); void add_method(char *name, char *function, int kw);
void print_methods(); void print_methods();
@ -34,9 +34,7 @@ protected:
virtual void initialize_cmodule(); virtual void initialize_cmodule();
virtual void close_cmodule(); virtual void close_cmodule();
virtual void emit_function_header(Wrapper *emit_to, char *wname); virtual void emit_function_header(Wrapper *emit_to, char *wname);
virtual char *convert_self(Wrapper *f); void emitAddPragmas(String *output, char* name, char* spacing);
virtual char *make_funcname_wrapper(char *fnName);
void emitAddPragmas(DOHString *output, char* name, char* spacing);
public : public :

View file

@ -27,11 +27,11 @@ static char cvsroot[] = "$Header$";
#include "swigconfig.h" #include "swigconfig.h"
#include "mod11.h" #include "mod11.h"
#include "tcl8.h" #include "tcl8.h"
#include "python.h"
#ifdef OLD #ifdef OLD
#include "perl5.h" #include "perl5.h"
#include "java.h" #include "java.h"
#include "python.h"
#include "guile.h" #include "guile.h"
#include "mzscheme.h" #include "mzscheme.h"
#include "ruby.h" #include "ruby.h"
@ -78,13 +78,13 @@ int main(int argc, char **argv) {
} else if (strcmp(argv[i],"-tcl8") == 0) { } else if (strcmp(argv[i],"-tcl8") == 0) {
dl = new TCL8; dl = new TCL8;
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i],"-python") == 0) {
dl = new PYTHON;
Swig_mark_arg(i);
#ifdef OLD #ifdef OLD
} else if (strcmp(argv[i],"-perl5") == 0) { } else if (strcmp(argv[i],"-perl5") == 0) {
dl = new PERL5; dl = new PERL5;
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i],"-python") == 0) {
dl = new PYTHON;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-guile") == 0) { } else if (strcmp(argv[i],"-guile") == 0) {
dl = new GUILE; dl = new GUILE;
Swig_mark_arg(i); Swig_mark_arg(i);

File diff suppressed because it is too large Load diff

View file

@ -22,13 +22,7 @@
class TCL8 : public Language { class TCL8 : public Language {
private: private:
void get_pointer(char *iname, char *srcname, char *src, char *dest, SwigType *t,
DOHString *f, char *ret);
char *char_result;
char *usage_func(char *, SwigType *, ParmList *);
char *usage_string(char *, SwigType *, ParmList *); char *usage_string(char *, SwigType *, ParmList *);
char *usage_var(char *, SwigType *);
char *usage_const(char *, SwigType *, char *);
public : public :
virtual void parse_args(int, char *argv[]); virtual void parse_args(int, char *argv[]);
@ -37,12 +31,9 @@ public :
virtual void link_variable(char *, char *, SwigType *); virtual void link_variable(char *, char *, SwigType *);
virtual void declare_const(char *, char *, SwigType *, char *); virtual void declare_const(char *, char *, SwigType *, char *);
virtual void initialize(void); virtual void initialize(void);
virtual void headers(void);
virtual void close(void); virtual void close(void);
virtual void set_module(char *,char **); virtual void set_module(char *,char **);
virtual void set_init(char *);
virtual void add_native(char *, char *, SwigType *, ParmList *); virtual void add_native(char *, char *, SwigType *, ParmList *);
virtual void pragma(char *,char *, char *);
virtual void create_command(char *, char *); virtual void create_command(char *, char *);
// Stubs for processing C++ classes in Tcl // Stubs for processing C++ classes in Tcl
@ -53,11 +44,6 @@ public :
virtual void cpp_variable(char *name, char *iname, SwigType *t); virtual void cpp_variable(char *name, char *iname, SwigType *t);
virtual void cpp_constructor(char *name, char *iname, ParmList *l); virtual void cpp_constructor(char *name, char *iname, ParmList *l);
virtual void cpp_destructor(char *name, char *newname); virtual void cpp_destructor(char *name, char *newname);
virtual void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);
virtual void cpp_declare_const(char *name, char *iname, SwigType *type, char *value);
virtual void add_typedef(SwigType *, char *);
virtual void cpp_class_decl(char *, char *, char *);
}; };

View file

@ -23,13 +23,6 @@ extern "C" {
extern int add_symbol(char *name); extern int add_symbol(char *name);
/* -----------------------------------------------------------------
* Language::set_init()
* ----------------------------------------------------------------- */
void Language::set_init(char *iname) {
set_module(iname,0);
}
/* ----------------------------------------------------------------- /* -----------------------------------------------------------------
* Language::create_command() * Language::create_command()
* ----------------------------------------------------------------- */ * ----------------------------------------------------------------- */

View file

@ -961,15 +961,7 @@ statement : INCLUDE STRING LBRACE {
/* Init directive--to avoid errors in other modules */ /* Init directive--to avoid errors in other modules */
| INIT ID initlist { | INIT ID initlist {
if (!module_init) { Printf(stderr,"%s : Line %d. Warning. %init directive is deprecated (ignored).\n", input_file,line_number);
lang->set_init($2);
module_init = 1;
init_language();
}
if ($3.count > 0) {
Printf(stderr,"%s : Line %d. Warning. Init list no longer supported.\n",
input_file,line_number);
}
for (i = 0; i < $3.count; i++) for (i = 0; i < $3.count; i++)
if ($3.names[i]) free($3.names[i]); if ($3.names[i]) free($3.names[i]);
free($3.names); free($3.names);

View file

@ -134,8 +134,6 @@ struct Pragma {
* set_module(char *modname) * set_module(char *modname)
* Sets the name of the module (%module directive) * Sets the name of the module (%module directive)
* *
* set_init(char *initname)
* Sets name of initialization function (an alternative to set_module)
* add_native(char *name, char *funcname); * add_native(char *name, char *funcname);
* Adds a native wrapper function to the initialize process * Adds a native wrapper function to the initialize process
* *
@ -176,10 +174,8 @@ public:
virtual void link_variable(char *, char *, SwigType *) = 0; virtual void link_variable(char *, char *, SwigType *) = 0;
virtual void declare_const(char *, char *, SwigType *, char *) = 0; virtual void declare_const(char *, char *, SwigType *, char *) = 0;
virtual void initialize(void) = 0; virtual void initialize(void) = 0;
virtual void headers(void) = 0;
virtual void close(void) = 0; virtual void close(void) = 0;
virtual void set_module(char *mod_name,char **mod_list) = 0; virtual void set_module(char *mod_name,char **mod_list) = 0;
virtual void set_init(char *init_name);
virtual void add_native(char *name, char *iname, SwigType *t, ParmList *l); virtual void add_native(char *name, char *iname, SwigType *t, ParmList *l);
virtual void add_typedef(SwigType *t, char *name); virtual void add_typedef(SwigType *t, char *name);
virtual void create_command(char *cname, char *iname); virtual void create_command(char *cname, char *iname);

View file

@ -366,7 +366,7 @@ static void typemap_locals(SwigType *t, String_or_char *pname, DOHString *s, Par
Replace(s,pn,new_name,DOH_REPLACE_ID); Replace(s,pn,new_name,DOH_REPLACE_ID);
} }
} }
p = Getnext(l); p = Getnext(p);
} }
} }

View file

@ -211,12 +211,12 @@ Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *
char *ret; char *ret;
i = 0; i = 0;
while (Wrapper_check_local(w,nname)) { while (Wrapper_check_local(w,nname)) {
Clear(nname); Clear(nname);
i++;
Printf(nname,"%s%d",name,i); Printf(nname,"%s%d",name,i);
i++;
} }
Replace(ndecl, name, nname, DOH_REPLACE_ID); Replace(ndecl, name, nname, DOH_REPLACE_ID);
Setattr(w->localh,nname,ndecl); Setattr(w->localh,nname,ndecl);
Printf(w->locals,"%s;\n", ndecl); Printf(w->locals,"%s;\n", ndecl);