From 6242ed773b85c2e663afbb2fc2bd4ddb44690777 Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Mon, 10 Jul 2000 21:52:58 +0000 Subject: [PATCH] Removed the WrapperFunction class entirely. Everything uses the C version. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@557 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Source/Modules/test.c | 8 +- SWIG/Source/Modules1.1/guile.cxx | 2 +- SWIG/Source/Modules1.1/java.cxx | 8 +- SWIG/Source/Modules1.1/mzscheme.cxx | 14 +- SWIG/Source/Modules1.1/perl5.cxx | 20 +-- SWIG/Source/Modules1.1/python.cxx | 26 ++-- SWIG/Source/Modules1.1/ruby.cxx | 8 +- SWIG/Source/Modules1.1/tcl8.cxx | 20 +-- SWIG/Source/SWIG1.1/Makefile.in | 5 +- SWIG/Source/SWIG1.1/emit.cxx | 13 +- SWIG/Source/SWIG1.1/swig11.h | 22 +-- SWIG/Source/SWIG1.1/typemap.cxx | 4 +- SWIG/Source/SWIG1.1/wrapfunc.cxx | 205 ---------------------------- SWIG/Source/Swig/swig.h | 15 +- SWIG/Source/Swig/wrapfunc.c | 134 +++++++++++++++--- 15 files changed, 188 insertions(+), 316 deletions(-) delete mode 100644 SWIG/Source/SWIG1.1/wrapfunc.cxx diff --git a/SWIG/Source/Modules/test.c b/SWIG/Source/Modules/test.c index 080e9453b..cefa3fd32 100644 --- a/SWIG/Source/Modules/test.c +++ b/SWIG/Source/Modules/test.c @@ -130,7 +130,7 @@ emit_function(DOH *obj, void *clientdata) { DOHString *name, *scriptname, *type, *storage; DOHList *parms; DOHHash *p; - SwigWrapper *wf; + Wrapper *wf; int numarg = 0, numopt = 0; int i, pn; @@ -151,7 +151,7 @@ emit_function(DOH *obj, void *clientdata) { /* goto function_exit; */ } - wf = NewSwigWrapper(); + wf = NewWrapper(); Printv(wf->def, "static PyObject *", Swig_name_wrapper(scriptname), "(PyObject *self, PyObject *args) {\n", @@ -265,7 +265,7 @@ emit_function(DOH *obj, void *clientdata) { if (vvalue) { Printf(local," = %s", vvalue); } - SwigWrapper_add_local(wf,local,rname); + Wrapper_add_local(wf,rname,local); Delete(local); Delete(rname); } @@ -306,7 +306,7 @@ emit_function(DOH *obj, void *clientdata) { } Printf(wf->code,"}\n"); - SwigWrapper_print(wf,wrappers); + Wrapper_print(wf,wrappers); function_exit: Delete(NewName); diff --git a/SWIG/Source/Modules1.1/guile.cxx b/SWIG/Source/Modules1.1/guile.cxx index fd7ec7d7a..3799921fc 100644 --- a/SWIG/Source/Modules1.1/guile.cxx +++ b/SWIG/Source/Modules1.1/guile.cxx @@ -450,7 +450,7 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l) int numargs = 0; int numopt = 0; - Wrapper_add_local (f,(char*)"SCM", (char*)"gswig_result", 0); + Wrapper_add_local (f,"gswig_result", "SCM gswig_result"); // Now write code to extract the parameters (this is super ugly) diff --git a/SWIG/Source/Modules1.1/java.cxx b/SWIG/Source/Modules1.1/java.cxx index 7635fc15a..952ecd2f5 100644 --- a/SWIG/Source/Modules1.1/java.cxx +++ b/SWIG/Source/Modules1.1/java.cxx @@ -560,7 +560,7 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l) } if(t->type != T_VOID || t->is_pointer) { - Wrapper_add_local(f,jnirettype, (char*)"_jresult", (char*)"0"); + Wrapper_add_localv(f,"_jresult", jnirettype, "_jresult = 0",0); } Printf(f_java, " %s ", method_modifiers); @@ -654,9 +654,9 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l) DOHString *basic_jniptrtype = NewStringf("%s*",basic_jnitype); DOHString *source_length = NewStringf("%s%s)", JNICALL((char*)"GetArrayLength"), source); - target_copy = Swig_copy_string(Wrapper_new_local(f,Char(basic_jniptrtype), target, NULL)); - target_length = Swig_copy_string(Wrapper_new_local(f,(char*)"jsize", target, Char(source_length))); - if(local_i == NULL) local_i = Swig_copy_string(Wrapper_new_local(f,(char*)"int", (char*)"i", NULL)); + target_copy = Swig_copy_string(Wrapper_new_localv(f,target,Char(basic_jniptrtype), target, 0)); + target_length = Swig_copy_string(Wrapper_new_localv(f,target,"jsize", target, "=", Char(source_length),0)); + if(local_i == NULL) local_i = Swig_copy_string(Wrapper_new_local(f,"i","int i")); DOHString *scalarFunc = NewStringf("Get%sArrayElements",scalarType); diff --git a/SWIG/Source/Modules1.1/mzscheme.cxx b/SWIG/Source/Modules1.1/mzscheme.cxx index 47eb363c7..4efd3897d 100644 --- a/SWIG/Source/Modules1.1/mzscheme.cxx +++ b/SWIG/Source/Modules1.1/mzscheme.cxx @@ -328,9 +328,9 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l) int numopt = 0; // adds local variables : type name - Wrapper_add_local (f,(char*)"char *", (char*)"_tempc",0); - Wrapper_add_local (f,(char*)"int", (char*)"_len",0); - Wrapper_add_local (f,(char*)"Scheme_Object *", (char*)"swig_result",0); + Wrapper_add_local (f,"_tempc","char *_tempc"); + Wrapper_add_local (f,"_len", "int _len"); + Wrapper_add_local (f,"swig_result", "Scheme_Object *swig_result"); // Now write code to extract the parameters (this is super ugly) @@ -452,13 +452,13 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l) // returning multiple values if(argout_set) { if(d->type == T_VOID) { - Wrapper_add_local(f,(char*)"int", (char*)"_lenv", (char*)"0"); - Wrapper_add_local(f,(char*)"Scheme_Object *", (char*)"_values[MAXVALUES]",0); + Wrapper_add_local(f,"_lenv","int _lenv = 0"); + Wrapper_add_local(f,"_values", "Scheme_Object * _values[MAXVALUES]"); Printv(f->code, tab4, "swig_result = scheme_values(_lenv, _values);\n", 0); } else { - Wrapper_add_local(f,(char*)"int", (char*)"_lenv", (char*)"1"); - Wrapper_add_local(f,(char*)"Scheme_Object *",(char*) "_values[MAXVALUES]",0); + Wrapper_add_local(f,"_lenv","int _lenv = 1"); + Wrapper_add_local(f,"_values", "Scheme_Object * _values[MAXVALUES]"); Printv(f->code, tab4, "_values[0] = swig_result;\n", 0); Printv(f->code, tab4, "swig_result = scheme_values(_lenv, _values);\n", 0); } diff --git a/SWIG/Source/Modules1.1/perl5.cxx b/SWIG/Source/Modules1.1/perl5.cxx index f816fd776..490616787 100644 --- a/SWIG/Source/Modules1.1/perl5.cxx +++ b/SWIG/Source/Modules1.1/perl5.cxx @@ -766,7 +766,7 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l) pcount = emit_args(d, l, f); numopt = l->numopt(); - Wrapper_add_local(f,(char*)"int",(char*)"argvi = 0",0); + Wrapper_add_local(f,"argvi","int argvi = 0"); // Check the number of arguments @@ -917,7 +917,7 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l) if (num_saved) { sprintf(temp,"_saved[%d]",num_saved); - Wrapper_add_local(f,(char*)"SV *",temp,0); + Wrapper_add_localv(f,"_saved","SV *",temp,0); } // Now write code to make the function call @@ -945,7 +945,7 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l) Printf(f->code," sv_setnv(ST(argvi++), (double) _result);\n"); break; case T_CHAR : - Wrapper_add_local(f,(char*)"char", (char*)"_ctemp[2]",0); + Wrapper_add_local(f,"_ctemp", "char _ctemp[2]"); Printv(f->code, tab4, "_ctemp[0] = _result;\n", tab4, "_ctemp[1] = 0;\n", @@ -1009,7 +1009,7 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l) // Add the dXSARGS last - Wrapper_add_local(f,(char*)"dXSARGS",(char*)"",0); + Wrapper_add_local(f,"dXSARGS","dXSARGS"); // Substitute the cleanup code Replace(f->code,"$cleanup",cleanup,DOH_REPLACE_ANY); @@ -1201,7 +1201,7 @@ void PERL5::link_variable(char *name, char *iname, DataType *t) // Get as a pointer value t->is_pointer++; - Wrapper_add_local(setf,(char*)"void",(char*)"*_temp",0); + Wrapper_add_local(setf,"_temp", "void *_temp"); get_pointer(iname,(char*)"value",(char*)"sv",(char*)"_temp", t, setf->code, (char*)"return(1)"); Printv(setf->code, tab4, name, " = *(", t->print_cast(), " _temp);\n", 0); t->is_pointer--; @@ -1214,7 +1214,7 @@ void PERL5::link_variable(char *name, char *iname, DataType *t) } else { // Have some sort of pointer type here, Process it differently if ((t->type == T_CHAR) && (t->is_pointer == 1)) { - Wrapper_add_local(setf,(char*)"char",(char*)"*_a",0); + Wrapper_add_local(setf,"_a","char *_a"); Printf(setf->code," _a = (char *) SvPV(sv,PL_na);\n"); if (CPlusPlus) @@ -1231,7 +1231,7 @@ void PERL5::link_variable(char *name, char *iname, DataType *t) } else { // Set the value of a pointer - Wrapper_add_local(setf,(char*)"void",(char*)"*_temp",0); + Wrapper_add_local(setf,"_temp","void *_temp"); get_pointer(iname,(char*)"value",(char*)"sv",(char*)"_temp", t, setf->code, (char*)"return(1)"); Printv(setf->code,tab4, name, " = ", t->print_cast(), " _temp;\n", 0); } @@ -1273,7 +1273,7 @@ void PERL5::link_variable(char *name, char *iname, DataType *t) Printv(vinit, tab4, "sv_setnv(sv,(double)", name, ");\n",0); break; case T_CHAR : - Wrapper_add_local(getf,(char*)"char",(char*)"_ptemp[2]",0); + Wrapper_add_local(getf,"_ptemp","char _ptemp[2]"); Printv(getf->code, tab4, "_ptemp[0] = ", name, ";\n", tab4, "_ptemp[1] = 0;\n", @@ -1287,7 +1287,7 @@ void PERL5::link_variable(char *name, char *iname, DataType *t) tab4, "sv_setiv(rsv,(IV) &", name, ");\n", 0); - Wrapper_add_local(getf,(char*)"SV",(char*)"*rsv",0); + Wrapper_add_local(getf,"rsv","SV *rsv"); Printv(vinit, tab4, "sv_setref_pv(sv,\"", t->print_mangle(), "\",(void *) &", name, ");\n",0); t->is_pointer--; @@ -1307,7 +1307,7 @@ void PERL5::link_variable(char *name, char *iname, DataType *t) tab4, "sv_setiv(rsv,(IV) ", name, ");\n", 0); - Wrapper_add_local(getf,(char*)"SV",(char*)"*rsv",0); + Wrapper_add_local(getf,"rsv","SV *rsv"); Printv(vinit, tab4, "sv_setref_pv(sv,\"", t->print_mangle(), "\",(void *) 1);\n",0); } } diff --git a/SWIG/Source/Modules1.1/python.cxx b/SWIG/Source/Modules1.1/python.cxx index bcfc1e96c..3733a115e 100644 --- a/SWIG/Source/Modules1.1/python.cxx +++ b/SWIG/Source/Modules1.1/python.cxx @@ -653,7 +653,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l) emit_function_header(f, wname); - Wrapper_add_local(f,(char*)"PyObject *",(char*)"_resultobj",0); + Wrapper_add_local(f,"_resultobj", "PyObject *_resultobj"); // Get the function usage string for later use @@ -712,7 +712,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l) if ((tm = typemap_lookup((char*)"in",(char*)"python",p->t,p->name,source,target,f))) { Putc('O',parse_args); - Wrapper_add_local(f, (char*)"PyObject *",source,(char*)"0"); + Wrapper_add_localv(f, source, "PyObject *",source,0); Printf(arglist,"&%s",source); if (i >= (pcount-numopt)) Printv(get_pointers, tab4, "if (", source, ")\n", @@ -765,9 +765,9 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l) sprintf(tempb,"tempbool%d",i); Putc('i',parse_args); if (!p->defvalue) - Wrapper_add_local(f,(char*)"int",tempb,0); + Wrapper_add_localv(f,tempb,"int",tempb,0); else - Wrapper_add_local(f,(char*)"int",tempb,tempval); + Wrapper_add_localv(f,tempb,"int",tempb, "=",tempval,0); Printv(get_pointers, tab4, target, " = ", p->t->print_cast(), " ", tempb, ";\n", 0); Printf(arglist,"&%s",tempb); } @@ -813,7 +813,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l) sprintf(target,"_arg%d", i); sprintf(temp,"argument %d",i+1); - Wrapper_add_local(f,(char*)"PyObject *", source,(char*)"0"); + Wrapper_add_localv(f,source,"PyObject *",source,"=0",0); Printf(arglist,"&%s",source); get_pointer(iname, temp, source, target, p->t, get_pointers, (char*)"NULL"); } @@ -1113,7 +1113,7 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) { case T_SINT: case T_SSHORT: case T_SLONG: case T_SCHAR: case T_UCHAR: case T_BOOL: // Get an integer value - Wrapper_add_local(setf,t->print_type(), (char*)"tval",0); + Wrapper_add_localv(setf,"tval",t->print_type(),"tval",0); Printv(setf->code, tab4, "tval = ", t->print_cast(), "PyInt_AsLong(val);\n", tab4, "if (PyErr_Occurred()) {\n", @@ -1127,7 +1127,7 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) { case T_FLOAT: case T_DOUBLE: // Get a floating point value - Wrapper_add_local(setf,t->print_type(), (char*)"tval",0); + Wrapper_add_localv(setf,"tval",t->print_type(), "tval",0); Printv(setf->code, tab4, "tval = ", t->print_cast(), "PyFloat_AsDouble(val);\n", tab4, "if (PyErr_Occurred()) {\n", @@ -1142,7 +1142,7 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) { // A single ascii character case T_CHAR: - Wrapper_add_local(setf,(char*)"char *", (char*)"tval",0); + Wrapper_add_local(setf,"tval","char * tval"); Printv(setf->code, tab4, "tval = (char *) PyString_AsString(val);\n", tab4, "if (PyErr_Occurred()) {\n", @@ -1155,7 +1155,7 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) { break; case T_USER: t->is_pointer++; - Wrapper_add_local(setf,t->print_type(),(char*)"temp",0); + Wrapper_add_localv(setf,"temp",t->print_type(),"temp",0); get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf->code,(char*)"1"); Printv(setf->code, tab4, name, " = *temp;\n", 0); t->is_pointer--; @@ -1168,7 +1168,7 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) { // Parse a pointer value if ((t->type == T_CHAR) && (t->is_pointer == 1)) { - Wrapper_add_local(setf,(char*)"char *", (char*)"tval",0); + Wrapper_add_local(setf,"tval","char * tval"); Printv(setf->code, tab4, "tval = (char *) PyString_AsString(val);\n", tab4, "if (PyErr_Occurred()) {\n", @@ -1195,7 +1195,7 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) { // Is a generic pointer value. - Wrapper_add_local(setf,t->print_type(),(char*)"temp",0); + Wrapper_add_localv(setf,"temp", t->print_type(), "temp",0); get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf->code,(char*)"1"); Printv(setf->code,tab4, name, " = temp;\n", 0); } @@ -1223,7 +1223,7 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) { // ---------------------------------------------------------------- Printf(getf->def,"static PyObject *%s_get() {", wname); - Wrapper_add_local(getf,(char*)"PyObject *",(char*)"pyobj",0); + Wrapper_add_local(getf,"pyobj", "PyObject *pyobj"); if ((tm = typemap_lookup((char*)"varout",(char*)"python",t,name,name,(char*)"pyobj"))) { Printf(getf->code,"%s\n",tm); Replace(getf->code,"$name",iname, DOH_REPLACE_ANY); @@ -1246,7 +1246,7 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) { Printv(getf->code, tab4, "pyobj = PyFloat_FromDouble((double) ", name, ");\n", 0); break; case T_CHAR: - Wrapper_add_local(getf,(char*)"char",(char*)"ptemp[2]",0); + Wrapper_add_local(getf,"ptemp","char ptemp[2]"); Printv(getf->code, tab4, "ptemp[0] = ", name, ";\n", tab4, "ptemp[1] = 0;\n", diff --git a/SWIG/Source/Modules1.1/ruby.cxx b/SWIG/Source/Modules1.1/ruby.cxx index 59edf730c..0130e3ea4 100644 --- a/SWIG/Source/Modules1.1/ruby.cxx +++ b/SWIG/Source/Modules1.1/ruby.cxx @@ -470,11 +470,11 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) { if (!l->get(i)->ignore) { char s[256]; sprintf(s,"varg%d",i); - Wrapper_add_local(f,(char*)"VALUE", s,0); + Wrapper_add_localv(f,s,"VALUE",s,0); } } } - Wrapper_add_local(f,(char*)"VALUE", (char*)"vresult", (char*)"Qnil"); + Wrapper_add_local(f,"vresult","VALUE vresult = Qnil"); int pcount = emit_args(t,l,f); #if 0 @@ -669,7 +669,7 @@ void RUBY::link_variable(char *name, char *iname, DataType *t) { Printv(getf->def, "static VALUE\n", getfname, "(", 0); if (mod_attr) Printf(getf->def, "VALUE self"); Printf(getf->def, ") {"); - Wrapper_add_local(getf,(char*)"VALUE", (char*)"_val",0); + Wrapper_add_local(getf,"_val","VALUE _val"); tm = ruby_typemap_lookup((char*)"varout",t,name,name,(char*)"_val"); if (!tm) tm = ruby_typemap_lookup((char*)"out",t,name,name,(char*)"_val"); @@ -713,7 +713,7 @@ void RUBY::link_variable(char *name, char *iname, DataType *t) { Delete(s); } else if (!t->is_pointer && t->type == T_USER) { t->is_pointer++; - Wrapper_add_local(setf,t->print_type(), (char*)"temp",0); + Wrapper_add_localv(setf,"temp",t->print_type(), "temp",0); Printv(setf->code, tab4, "temp = (", t->print_type(), ")", "SWIG_ConvertPtr(_val, \"", t->print_mangle(), "\");\n", 0); diff --git a/SWIG/Source/Modules1.1/tcl8.cxx b/SWIG/Source/Modules1.1/tcl8.cxx index f8f7374d5..b8b68eacd 100644 --- a/SWIG/Source/Modules1.1/tcl8.cxx +++ b/SWIG/Source/Modules1.1/tcl8.cxx @@ -548,7 +548,7 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l) { char tb[32]; sprintf(tb,"tempb%d",i); - Wrapper_add_local(f,(char*)"int",tb,0); + Wrapper_add_localv(f,tb,"int",tb,0); Printf(args,",&%s",tb); Printv(incode, tab4, target, " = (bool) ", tb, ";\n", 0); } @@ -799,13 +799,13 @@ void TCL8::link_variable(char *name, char *iname, DataType *t) Printv(get->def, "static char *_swig_", t->print_mangle(), "_get(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {",0); t->is_pointer++; - Wrapper_add_local(get,t->print_type(),(char*)"addr",0); - Wrapper_add_local(set,t->print_type(),(char*)"addr",0); + Wrapper_add_localv(get,"addr",t->print_type(),"addr",0); + Wrapper_add_localv(set,"addr",t->print_type(),"addr",0); Printv(set->code, tab4, "addr = ", t->print_cast(), " clientData;\n", 0); Printv(get->code, tab4, "addr = ", t->print_cast(), " clientData;\n", 0); t->is_pointer--; - Wrapper_add_local(set,(char*)"char *",(char*)"value",0); - Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0); + Wrapper_add_local(set, "value", "char *value"); + Wrapper_add_local(get, "value", "Tcl_Obj *value"); Printv(set->code, tab4, "value = Tcl_GetVar2(interp, name1, name2, flags);\n", tab4, "if (!value) return NULL;\n", 0); @@ -891,7 +891,7 @@ void TCL8::link_variable(char *name, char *iname, DataType *t) case T_UCHAR: case T_SCHAR: case T_BOOL: - Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0); + Wrapper_add_local(get,"value","Tcl_Obj *value"); Printv(get->code, tab4, "value = Tcl_NewIntObj((int) *addr);\n", tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", @@ -900,7 +900,7 @@ void TCL8::link_variable(char *name, char *iname, DataType *t) break; case T_FLOAT: case T_DOUBLE: - Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0); + Wrapper_add_local(get,"value","Tcl_Obj *value"); Printv(get->code, tab4, "value = Tcl_NewDoubleObj((double) *addr);\n", tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", @@ -909,14 +909,14 @@ void TCL8::link_variable(char *name, char *iname, DataType *t) break; case T_CHAR: - Wrapper_add_local(get,(char*)"char",(char*)"temp[4]",0); + Wrapper_add_local(get,"temp", "char temp[2]"); Printv(get->code,tab4, "temp[0] = *addr; temp[1] = 0;\n", tab4, "Tcl_SetVar2(interp,name1,name2,temp,flags);\n", 0); break; case T_USER: - Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0); + Wrapper_add_local(get,"value", "Tcl_Obj *value"); t->is_pointer++; t->remember(); Printv(get->code, tab4, "value = SWIG_NewPointerObj(addr, SWIGTYPE", t->print_mangle(), ");\n", @@ -932,7 +932,7 @@ void TCL8::link_variable(char *name, char *iname, DataType *t) if ((t->is_pointer == 1) && (t->type == T_CHAR)) { Printv(get->code, tab4, "Tcl_SetVar2(interp,name1,name2,*addr, flags);\n",0); } else { - Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0); + Wrapper_add_local(get,"value","Tcl_Obj *value"); t->remember(); Printv(get->code, tab4, "value = SWIG_NewPointerObj(*addr, SWIGTYPE", t->print_mangle(), ");\n", diff --git a/SWIG/Source/SWIG1.1/Makefile.in b/SWIG/Source/SWIG1.1/Makefile.in index 5970f8e86..17fab25b9 100644 --- a/SWIG/Source/SWIG1.1/Makefile.in +++ b/SWIG/Source/SWIG1.1/Makefile.in @@ -15,12 +15,11 @@ RANLIB = @RANLIB@ TARGET = libswig11.a OBJS = parser.o main.o scanner.o types.o parms.o \ - emit.o cplus.o lang.o sstring.o wrapfunc.o \ - typemap.o + emit.o cplus.o lang.o sstring.o typemap.o SRCS = main.cxx scanner.cxx types.cxx parms.cxx \ emit.cxx cplus.cxx lang.cxx \ - sstring.cxx wrapfunc.cxx typemap.cxx + sstring.cxx typemap.cxx PARSER = $(srcdir)/parser.yxx INCLUDE = -I$(srcdir)/../Include \ diff --git a/SWIG/Source/SWIG1.1/emit.cxx b/SWIG/Source/SWIG1.1/emit.cxx index 673ae8f4d..5f587d875 100644 --- a/SWIG/Source/SWIG1.1/emit.cxx +++ b/SWIG/Source/SWIG1.1/emit.cxx @@ -199,12 +199,12 @@ int emit_args(DataType *rt, ParmList *l, Wrapper *f) { // Special case for return by "value" rt->is_pointer++; - Wrapper_add_local(f, rt->print_type(), (char*)"_result",0); + Wrapper_add_localv(f, "_result", rt->print_type(), "_result",0); rt->is_pointer--; } else { // Normal return value - Wrapper_add_local(f,rt->print_type(), (char*)"_result",0); + Wrapper_add_localv(f, "_result", rt->print_type(), "_result",0); } } @@ -218,16 +218,13 @@ int emit_args(DataType *rt, ParmList *l, Wrapper *f) { // Figure out default values if (((p->t->is_reference) && (p->defvalue)) || ((p->t->type == T_USER) && (p->call_type == CALL_REFERENCE) && (p->defvalue))) { - char deftmp[1024]; - sprintf(deftmp,"(%s) &%s", p->t->print_type(), p->defvalue); - Wrapper_add_local(f,p->t->print_type(),temp,deftmp); + Wrapper_add_localv(f,temp, p->t->print_type(), temp," = (", p->t->print_type(), ") &", p->defvalue,0); } else { char deftmp[1024]; if (p->defvalue) { - sprintf(deftmp,"(%s) %s", p->t->print_type(), p->defvalue); - Wrapper_add_local(f,p->t->print_type(), temp, deftmp); + Wrapper_add_localv(f,temp, p->t->print_type(), temp, " = (", p->t->print_type(), ") ", p->defvalue, 0); } else { - Wrapper_add_local(f,p->t->print_type(), temp, 0); + Wrapper_add_localv(f,temp, p->t->print_type(), temp, 0); } tm = typemap_lookup((char*)"arginit", typemap_lang, p->t,p->name,(char*)"",temp,f); diff --git a/SWIG/Source/SWIG1.1/swig11.h b/SWIG/Source/SWIG1.1/swig11.h index 57a992e08..d412d23f6 100644 --- a/SWIG/Source/SWIG1.1/swig11.h +++ b/SWIG/Source/SWIG1.1/swig11.h @@ -20,6 +20,10 @@ #include "swigver.h" +extern "C" { +#include "swig.h" +} + /* Global variables. Needs to be cleaned up */ #ifdef MACSWIG @@ -412,24 +416,6 @@ extern "C" { extern char *Swig_copy_string(const char *s); } -// ----------------------------------------------------------------------- -// Structure for Creating Wrapper Functions -// ----------------------------------------------------------------------- - -typedef struct Wrapper { - void *h; - void *localh; - void *def; - void *locals; - void *code; -} Wrapper; - -extern Wrapper *NewWrapper(); -extern void DelWrapper(Wrapper *w); -extern void Wrapper_print(Wrapper *w, void *f); -extern void Wrapper_add_local(Wrapper *w, char *type, char *name, char *defvalue = 0); -extern char *Wrapper_new_local(Wrapper *w, char *type, char *name, char *defvalue = 0); - // Misc extern int emit_args(DataType *, ParmList *, Wrapper *f); diff --git a/SWIG/Source/SWIG1.1/typemap.cxx b/SWIG/Source/SWIG1.1/typemap.cxx index 0e43f7c06..ea317b809 100644 --- a/SWIG/Source/SWIG1.1/typemap.cxx +++ b/SWIG/Source/SWIG1.1/typemap.cxx @@ -516,12 +516,12 @@ static void typemap_locals(DataType *t, char *pname, DOHString *s, ParmList *l, char temp_ip1 = tt->implicit_ptr; tt->is_pointer = 0; tt->implicit_ptr = 0; - new_name = Wrapper_new_local(f,tt->print_type(),Char(str)); + new_name = Wrapper_new_localv(f,str, tt->print_type(), str, 0); tt->is_pointer = temp_ip; tt->implicit_ptr = temp_ip1; } else - new_name = Wrapper_new_local(f,tt->print_full(),Char(str)); + new_name = Wrapper_new_localv(f,str, tt->print_full(), str, 0); if (tt->arraystr) tt->is_pointer++; // Substitute diff --git a/SWIG/Source/SWIG1.1/wrapfunc.cxx b/SWIG/Source/SWIG1.1/wrapfunc.cxx deleted file mode 100644 index 7ca76f286..000000000 --- a/SWIG/Source/SWIG1.1/wrapfunc.cxx +++ /dev/null @@ -1,205 +0,0 @@ -/* ----------------------------------------------------------------------------- - * wrapfunc.cxx - * - * Wrapper function object. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 1998-2000. The University of Chicago - * Copyright (C) 1995-1998. The University of Utah and The Regents of the - * University of California. - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -static char cvsroot[] = "$Header$"; - -// ------------------------------------------------------------------ -// This file defines a class for writing wrappers. Instead of worrying -// about I/O problems, this wrapper class can be used to write functions -// out of order. -// -// Defines 3 string objects. -// def - Wrapper function definition (function name and arguments) -// locals - Local variable definitions -// code - The actual wrapper function code -// -//------------------------------------------------------------------- - -#include "internal.h" -#include - -extern "C" { -#include "doh.h" -} - -Wrapper *NewWrapper() { - Wrapper *w = (Wrapper *) malloc(sizeof(Wrapper)); - w->h = NewHash(); - w->localh = NewHash(); - w->def = NewString(""); - w->locals = NewString(""); - w->code = NewString(""); - return w; -} - -void DelWrapper(Wrapper *w) { - Delete(w->h); - Delete(w->localh); - Delete(w->def); - Delete(w->locals); - Delete(w->code); - free(w); -} - -// ------------------------------------------------------------------- -// isolate the type name. This is a hack (sorry). -// ------------------------------------------------------------------- - -static char type_ext[512]; -static char *isolate_type_name(char *tname) { - static char s[512]; - char *c = s; - - while ((*tname) && (isalnum(*tname) || (*tname == '_') || (*tname == '$') || (*tname == ' ') || (*tname == ':'))) { - *(c++) = *tname; - tname++; - } - *c = 0; - strcpy(type_ext,tname); - return s; -} - -// ------------------------------------------------------------------- -// Print out a wrapper function. -// ------------------------------------------------------------------- - -void Wrapper_print(Wrapper *w, DOHFile *f) { - DOHString *s; - DOH *key; - - key = Firstkey(w->localh); - while (key) { - s = Getattr(w->localh,key); - Delitem(s,DOH_END); - Printv(w->locals,tab4,s,";\n",0); - key = Nextkey(w->localh); - } - Printf(f,"%s\n",w->def); - Printf(f,"%s",w->locals); - Printf(f,"%s\n",w->code); -} - -// ------------------------------------------------------------------- -// Safely add a local variable. -// -// Maintains a hash table to prevent double adding. -// ------------------------------------------------------------------- - -void Wrapper_add_local(Wrapper *w, char *type, char *name, char *defarg) { - char *stored_type; - char new_type[256]; - char temp[256],*c,*t; - - strcpy(new_type,type); - - // Figure out what the name of this variable is - - c = name; - t = temp; - while ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)) { - *(t++) = *c; - c++; - } - *t = 0; - if (Getattr(w->h,temp)) { - // Check to see if a type mismatch has occurred - stored_type = GetChar(w->h,temp); - if (strcmp(type,stored_type) != 0) - fprintf(stderr,"Error. Type %s conflicts with previously declared type of %s\n", - type, stored_type); - return; - } else { - SetChar(w->h,temp,new_type); - } - - // See if any wrappers have been generated with this type - - char *tname = isolate_type_name(type); - DOHString *lstr = Getattr(w->localh,tname); - if (!lstr) { - lstr = NewStringf("%s ", tname); - Setattr(w->localh,tname,lstr); - } - - // Successful, write some wrapper code - - if (!defarg) { - Printv(lstr,type_ext,name,",",0); - } else { - Printv(lstr,type_ext,name, "=", defarg, ",", 0); - } -} - - -// ------------------------------------------------------------------- -// Wrapper_new_local() -// -// A safe way to add a new local variable. type and name are used as -// a starting point, but a new local variable will be created if these -// are already in use. -// ------------------------------------------------------------------- - -char *Wrapper_new_local(Wrapper *w, char *type, char *name, char *defarg) { - char new_type[256]; - static DOHString *new_name = 0; - char *c; - strcpy(new_type,type); - - if (!new_name) new_name = NewString(""); - - strcpy(new_type,type); - Clear(new_name); - c = name; - for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++) - Putc(*c,new_name); - - // Try to add a new local variable - if (Getattr(w->h,new_name)) { - // Local variable already exists, try to generate a new name - int i = 0; - Clear(new_name); - // This is a little funky. We copy characters until we reach a nonvalid - // identifier symbol, add a number, then append the rest. This is - // needed to properly handle arrays. - c = name; - for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++) - Putc(*c,new_name); - Printf(new_name,"%d",i); - while (Getattr(w->h,new_name)) { - i++; - c = name; - Clear(new_name); - for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++) - Putc(*c,new_name); - Printf(new_name,"%d",i); - } - Setattr(w->h,new_name,new_type); - } else { - Setattr(w->h,new_name,new_type); - } - Printf(new_name,"%s",c); - // Successful, write some wrapper code - if (!defarg) - Printv(w->locals,tab4,type, " ", new_name, ";\n"); - else - Printv(w->locals,tab4,type, " ", new_name, " = ", defarg, ";\n"); - - // Need to strip off the array symbols now - - c = Char(new_name); - while ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)) - c++; - *c = 0; - return Char(new_name); -} diff --git a/SWIG/Source/Swig/swig.h b/SWIG/Source/Swig/swig.h index c05983192..8812ee1ab 100644 --- a/SWIG/Source/Swig/swig.h +++ b/SWIG/Source/Swig/swig.h @@ -174,13 +174,16 @@ typedef struct { DOHString *def; DOHString *locals; DOHString *code; -} SwigWrapper; +} Wrapper; -extern SwigWrapper *NewSwigWrapper(); -extern void DelSwigWrapper(SwigWrapper *w); -extern void SwigWrapper_print(SwigWrapper *w, DOHFile *f); -extern int SwigWrapper_add_local(SwigWrapper *w, DOHString_or_char *decl, DOHString_or_char *name); -extern int SwigWrapper_check_local(SwigWrapper *w, DOHString_or_char *name); +extern Wrapper *NewWrapper(); +extern void DelWrapper(Wrapper *w); +extern void Wrapper_print(Wrapper *w, DOHFile *f); +extern int Wrapper_add_local(Wrapper *w, const DOHString_or_char *name, const DOHString_or_char *decl); +extern int Wrapper_add_localv(Wrapper *w, const DOHString_or_char *name, ...); +extern int Wrapper_check_local(Wrapper *w, const DOHString_or_char *name); +extern char *Wrapper_new_local(Wrapper *w, const DOHString_or_char *name, const DOHString_or_char *decl); +extern char *Wrapper_new_localv(Wrapper *w, const DOHString_or_char *name, ...); /* --- Naming functions --- */ diff --git a/SWIG/Source/Swig/wrapfunc.c b/SWIG/Source/Swig/wrapfunc.c index bbb0da247..522bb705b 100644 --- a/SWIG/Source/Swig/wrapfunc.c +++ b/SWIG/Source/Swig/wrapfunc.c @@ -19,15 +19,15 @@ static char cvsroot[] = "$Header$"; #include "swig.h" /* ----------------------------------------------------------------------------- - * NewSwigWrapper() + * NewWrapper() * * Create a new wrapper function object. * ----------------------------------------------------------------------------- */ -SwigWrapper * -NewSwigWrapper() { - SwigWrapper *w; - w = (SwigWrapper *) malloc(sizeof(SwigWrapper)); +Wrapper * +NewWrapper() { + Wrapper *w; + w = (Wrapper *) malloc(sizeof(Wrapper)); w->localh = NewHash(); w->locals = NewString(""); w->code = NewString(""); @@ -36,13 +36,13 @@ NewSwigWrapper() { } /* ----------------------------------------------------------------------------- - * DelSwigWrapper() + * DelWrapper() * * Delete a wrapper function object. * ----------------------------------------------------------------------------- */ void -DelSwigWrapper(SwigWrapper *w) { +DelWrapper(Wrapper *w) { Delete(w->localh); Delete(w->locals); Delete(w->code); @@ -51,13 +51,13 @@ DelSwigWrapper(SwigWrapper *w) { } /* ----------------------------------------------------------------------------- - * SwigWrapper_print() + * Wrapper_print() * * Print out a wrapper function. Does pretty printing as well. * ----------------------------------------------------------------------------- */ void -SwigWrapper_print(SwigWrapper *w, DOHFile *f) { +Wrapper_print(Wrapper *w, DOHFile *f) { DOHString *str, *ts; int level = 0; int c, i; @@ -111,17 +111,18 @@ SwigWrapper_print(SwigWrapper *w, DOHFile *f) { } Delete(ts); Delete(str); + Printf(f,"\n"); } /* ----------------------------------------------------------------------------- - * SwigWrapper_add_local() + * Wrapper_add_local() * * Adds a new local variable declaration to a function. Returns -1 if already * present (which may or may not be okay to the caller). * ----------------------------------------------------------------------------- */ int -SwigWrapper_add_local(SwigWrapper *w, DOHString_or_char *decl, DOHString_or_char *name) { +Wrapper_add_local(Wrapper *w, const DOHString_or_char *name, const DOHString_or_char *decl) { /* See if the local has already been declared */ if (Getattr(w->localh,name)) { return -1; @@ -131,36 +132,127 @@ SwigWrapper_add_local(SwigWrapper *w, DOHString_or_char *decl, DOHString_or_char } /* ----------------------------------------------------------------------------- - * SwigWrapper_check_local() + * Wrapper_add_localv() + * + * Same as add_local(), but allows a NULL terminated list of strings to be + * used as a replacement for decl. This saves the caller the trouble of having + * to manually construct the 'decl' string before calling. + * ----------------------------------------------------------------------------- */ + +int +Wrapper_add_localv(Wrapper *w, const DOHString_or_char *name, ...) { + va_list ap; + int ret; + DOHString *decl; + DOH *obj; + decl = NewString(""); + va_start(ap,name); + + obj = va_arg(ap,void *); + while (obj) { + Printv(decl,obj,0); + Putc(' ', decl); + obj = va_arg(ap, void *); + } + va_end(ap); + + ret = Wrapper_add_local(w,name,decl); + Delete(decl); + return ret; +} + +/* ----------------------------------------------------------------------------- + * Wrapper_check_local() * * Check to see if a local name has already been declared * ----------------------------------------------------------------------------- */ int -SwigWrapper_check_local(SwigWrapper *w, DOHString_or_char *name) { +Wrapper_check_local(Wrapper *w, const DOHString_or_char *name) { if (Getattr(w->localh,name)) { return 1; } return 0; } +/* ----------------------------------------------------------------------------- + * Wrapper_new_local() + * + * Adds a new local variable with a guarantee that a unique local name will be + * used. Returns the name that was actually selected. + * ----------------------------------------------------------------------------- */ + +char * +Wrapper_new_local(Wrapper *w, const DOHString_or_char *name, const DOHString_or_char *decl) { + int i; + DOHString *nname = NewString(name); + DOHString *ndecl = NewString(decl); + char *ret; + + i = 0; + while (Wrapper_check_local(w,nname)) { + Clear(nname); + i++; + Printf(nname,"%s%d",name,i); + } + + Replace(ndecl, name, nname, DOH_REPLACE_ID); + Setattr(w->localh,nname,ndecl); + ret = Char(nname); + Delete(nname); + Delete(ndecl); + return ret; /* Note: nname should still exists in the w->localh hash */ +} + + +/* ----------------------------------------------------------------------------- + * Wrapper_add_localv() + * + * Same as add_local(), but allows a NULL terminated list of strings to be + * used as a replacement for decl. This saves the caller the trouble of having + * to manually construct the 'decl' string before calling. + * ----------------------------------------------------------------------------- */ + +char * +Wrapper_new_localv(Wrapper *w, const DOHString_or_char *name, ...) { + va_list ap; + char *ret; + DOHString *decl; + DOH *obj; + decl = NewString(""); + va_start(ap,name); + + obj = va_arg(ap,void *); + while (obj) { + Printv(decl,obj,0); + Putc(' ',decl); + obj = va_arg(ap, void *); + } + va_end(ap); + + ret = Wrapper_new_local(w,name,decl); + Delete(decl); + return ret; +} + + #ifdef TEST int main() { - SwigWrapper *w; - w = NewSwigWrapper(); + Wrapper *w; + w = NewWrapper(); Printf(w->def,"int foo_wrap(ClientData clientdata, Tcl_Interp *interp, int argc, char *argv[]) {"); - SwigWrapper_add_local(w,"int a", "a"); - SwigWrapper_add_local(w,"int a", "a"); - SwigWrapper_add_local(w,"int b", "b"); - SwigWrapper_add_local(w,"char temp[256]","temp"); + Wrapper_add_local(w,"int a", "a"); + Wrapper_add_local(w,"int a", "a"); + Wrapper_add_local(w,"int b", "b"); + Wrapper_add_local(w,"char temp[256]","temp"); Printf(w->code,"for (i = 0; i < 10; i++) { printf(\"%%d\", i); }\n"); Printf(w->code,"if (1) { foo;\n} else { bar; \n}\n"); Printf(w->code,"}\n"); - SwigWrapper_print(w,stdout); - DelSwigWrapper(w); + Wrapper_print(w,stdout); + DelWrapper(w); } #endif