diff --git a/Source/DOH/Doh/hash.c b/Source/DOH/Doh/hash.c index 5ce1484b0..246242c20 100644 --- a/Source/DOH/Doh/hash.c +++ b/Source/DOH/Doh/hash.c @@ -549,3 +549,4 @@ NewHash() { h->line = 0; return DohObjMalloc(DOHTYPE_HASH,h); } + diff --git a/Source/Modules1.1/guile.cxx b/Source/Modules1.1/guile.cxx index 9412fe95e..c76dcd582 100644 --- a/Source/Modules1.1/guile.cxx +++ b/Source/Modules1.1/guile.cxx @@ -363,18 +363,18 @@ get_pointer (char *iname, int parm, SwigType *t, { SwigType_remember(t); /* Pointers are smobs */ - Printf(f->code, " if (SWIG_Guile_GetPtr(s_%d,(void **) &arg%d", parm, parm); + Printf(f, " if (SWIG_Guile_GetPtr(s_%d,(void **) &arg%d", parm, parm); if (SwigType_type(t) == T_VOID) - Printf(f->code, ", NULL)) {\n"); + Printf(f, ", NULL)) {\n"); else - Printv(f->code, ", SWIGTYPE", SwigType_manglestr(t), ")) {\n", 0); + Printv(f, ", SWIGTYPE", SwigType_manglestr(t), ")) {\n", 0); /* Raise exception */ - Printv(f->code, + Printv(f, tab8, "scm_wrong_type_arg(\"",proc_name, "\", ", 0); - Printf(f->code,"%d, s_%d);\n", num_scheme_parm, parm); - Printv(f->code, tab4, "}\n", 0); + Printf(f,"%d, s_%d);\n", num_scheme_parm, parm); + Printv(f, tab4, "}\n", 0); } /* Return true iff T is a pointer type */ @@ -497,7 +497,7 @@ GUILE::function (DOH *node) { proc_name = NewString(iname); Replace(proc_name,"_", "-", DOH_REPLACE_ANY); - /* Emit locals etc. into f->code; figure out which args to ignore */ + /* Emit locals etc. into f; figure out which args to ignore */ emit_args (node, f); /* Declare return variable */ @@ -509,10 +509,23 @@ GUILE::function (DOH *node) { 0, proc_name, f); /* Open prototype and signature */ + + /* The function prototype must be produced first */ + + Printv(f, "static SCM\n", wname," (", 0); + for (p = l, i = 0; p; p = Getnext(p), i++) { + if (i != 0) Printf(f,", "); + Printf(f,"SCM s_%d", i); + } + Printf(f,")\n{\n"); + Printf(f,"$locals\n"); + + /* Define the scheme name in C. This define is used by several Guile + macros. */ + + Printv(f,"#define FUNC_NAME \"", proc_name, "\"\n", 0); - Printv(f->def, "static SCM\n", wname," (", 0); Printv(signature, "(", proc_name, 0); - /* Now write code to extract the parameters */ for (p = l, i = 0; p; p=Getnext(p), i++) { @@ -528,16 +541,14 @@ GUILE::function (DOH *node) { // Handle parameter types. if (Getignore(p)) - Printv(f->code, "/* ", pn, " ignored... */\n", 0); + Printv(f, "/* ", pn, " ignored... */\n", 0); else { - if (numargs!=0) Printf(f->def,", "); - Printf(f->def,"SCM s_%d", i); if (opt_p) { numopt++; - Printf(f->code," if (s_%d != GH_NOT_PASSED) {\n", i); + Printf(f," if (s_%d != GH_NOT_PASSED) {\n", i); } ++numargs; - if (guile_do_typemap(f->code, "in", pt, pn, + if (guile_do_typemap(f, "in", pt, pn, source, target, numargs, proc_name, f, 0)) { /* nothing to do */ } @@ -554,12 +565,12 @@ GUILE::function (DOH *node) { numargs, proc_name, f); } if (opt_p) - Printf(f->code," }\n"); + Printf(f," }\n"); } /* Check if there are any constraints. */ - guile_do_typemap(f->code, "check", pt, pn, + guile_do_typemap(f, "check", pt, pn, source, target, numargs, proc_name, f, 0); /* Pass output arguments back to the caller. */ @@ -591,27 +602,23 @@ GUILE::function (DOH *node) { /* Close prototype and signature */ Printv(signature, ")\n", 0); - Printf(f->def, ")\n{\n"); - /* Define the scheme name in C. This define is used by several Guile - macros. */ - Printv(f->def, "#define FUNC_NAME \"", proc_name, "\"\n", 0); // Now write code to make the function call - Printv(f->code, tab4, "gh_defer_ints();\n", 0); + Printv(f, tab4, "gh_defer_ints();\n", 0); emit_func_call (node, f); - Printv(f->code, tab4, "gh_allow_ints();\n", 0); + Printv(f, tab4, "gh_allow_ints();\n", 0); // Now have return value, figure out what to do with it. - if (guile_do_typemap(f->code, "out", d, name, + if (guile_do_typemap(f, "out", d, name, (char*)"result", (char*)"gswig_result", 0, proc_name, f, 0)) { /* nothing */ } else if (is_a_pointer(d)) { SwigType_remember(d); - Printv(f->code, tab4, + Printv(f, tab4, "gswig_result = SWIG_Guile_MakePtr (", "result, ", "SWIGTYPE", SwigType_manglestr(d), @@ -623,33 +630,33 @@ GUILE::function (DOH *node) { } // Dump the argument output code - Printv(f->code,outarg,0); + Printv(f,outarg,0); // Dump the argument cleanup code - Printv(f->code,cleanup,0); + Printv(f,cleanup,0); // Look for any remaining cleanup if (NewObject) { - guile_do_typemap(f->code, "newfree", d, iname, + guile_do_typemap(f, "newfree", d, iname, (char*)"result", (char*)"", 0, proc_name, f, 0); } // Free any memory allocated by the function being wrapped.. - guile_do_typemap(f->code, "ret", d, name, + guile_do_typemap(f, "ret", d, name, (char*)"result", (char*)"", 0, proc_name, f, 0); // Wrap things up (in a manner of speaking) - Printv(f->code, "return gswig_result;\n", 0); + Printv(f, "return gswig_result;\n", 0); // Undefine the scheme name - Printf(f->code, "#undef FUNC_NAME\n"); - Printf(f->code, "}\n"); + Printf(f, "#undef FUNC_NAME\n"); + Printf(f, "}\n"); - Wrapper_print (f, f_wrappers); + Printf(f_wrappers,"%s", f); if (numargs > 10) { int i; @@ -722,7 +729,7 @@ GUILE::function (DOH *node) { Delete(signature); Delete(returns); Delete(tmp); - DelWrapper(f); + Delete(f); delete[] wname; } @@ -888,7 +895,7 @@ GUILE::variable (DOH *node) input_file, line_number, SwigType_str(t,0)); } Delete(proc_name); - DelWrapper(f); + Delete(f); } // ----------------------------------------------------------------------- @@ -965,7 +972,7 @@ GUILE::constant(DOH *node) } Delete(proc_name); Delete(rvalue); - DelWrapper(f); + Delete(f); } void GUILE::cpp_variable(DOH *node) diff --git a/Source/Modules1.1/mzscheme.cxx b/Source/Modules1.1/mzscheme.cxx index f4cb88741..c6a05c43a 100644 --- a/Source/Modules1.1/mzscheme.cxx +++ b/Source/Modules1.1/mzscheme.cxx @@ -234,9 +234,9 @@ MZSCHEME::get_pointer (String *name, int parm, SwigType *t, Wrapper *f) { char p[256]; sprintf(p, "%d", parm); - Printv(f->code, tab4, "if (!swig_get_c_pointer(argv[", p, "], \"", SwigType_manglestr(t), + Printv(f, tab4, "if (!swig_get_c_pointer(argv[", p, "], \"", SwigType_manglestr(t), "\", (void **) &arg", p, "))\n",0); - Printv(f->code, tab8, "scheme_wrong_type(\"", name, + Printv(f, tab8, "scheme_wrong_type(\"", name, "\", \"", SwigType_manglestr(t), "\", ", p, ", argc, argv);\n",0); } // ---------------------------------------------------------------------- @@ -302,9 +302,10 @@ MZSCHEME::function(DOH *node) Replace(proc_name, "_", "-", DOH_REPLACE_ANY); // writing the function wrapper function - Printv(f->def, "static Scheme_Object *", wname, " (", 0); - Printv(f->def, "int argc, Scheme_Object **argv", 0); - Printv(f->def, ")\n{", 0); + Printv(f, "static Scheme_Object *", wname, " (", 0); + Printv(f, "int argc, Scheme_Object **argv", 0); + Printv(f, ")\n{\n", 0); + Printf(f, "$locals\n"); // Declare return variable and arguments // number of parameters @@ -336,13 +337,13 @@ MZSCHEME::function(DOH *node) // Handle parameter types. if (Getignore(p)) - Printv(f->code, "/* ", Char(Getname(p)), " ignored... */\n", 0); + Printv(f, "/* ", Char(Getname(p)), " ignored... */\n", 0); else { ++numargs; if ((tm = Swig_typemap_lookup ((char*)"in", Gettype(p), Getname(p), source, target, f))) { - Printv(f->code, tm, "\n", 0); - mreplace (f->code, argnum, arg, proc_name); + Printv(f, tm, "\n", 0); + mreplace (f, argnum, arg, proc_name); } // no typemap found // check if typedef and resolve @@ -363,8 +364,8 @@ MZSCHEME::function(DOH *node) if ((tm = Swig_typemap_lookup ((char*)"check", Gettype(p), Getname(p), source, target, f))) { // Yep. Use it instead of the default - Printv(f->code, tm, "\n", 0); - mreplace (f->code, argnum, arg, proc_name); + Printv(f, tm, "\n", 0); + mreplace (f, argnum, arg, proc_name); } // Pass output arguments back to the caller. @@ -395,18 +396,18 @@ MZSCHEME::function(DOH *node) if (SwigType_type(d) == T_VOID) { if(!argout_set) - Printv(f->code, tab4, "swig_result = scheme_void;\n",0); + Printv(f, tab4, "swig_result = scheme_void;\n",0); } else if ((tm = Swig_typemap_lookup ((char*)"out", d, name, (char*)"result", (char*)"swig_result", f))) { - Printv(f->code, tm, "\n",0); - mreplace (f->code, argnum, arg, proc_name); + Printv(f, tm, "\n",0); + mreplace (f, argnum, arg, proc_name); } // no typemap found and not void then create a Scheme_Object holding // the C pointer and return it else if (SwigType_ispointer(d)) { - Printv(f->code, tab4, + Printv(f, tab4, "swig_result = swig_make_c_pointer(", "result, \"", SwigType_manglestr(d), @@ -417,18 +418,18 @@ MZSCHEME::function(DOH *node) } // Dump the argument output code - Printv(f->code, Char(outarg),0); + Printv(f, Char(outarg),0); // Dump the argument cleanup code - Printv(f->code, Char(cleanup),0); + Printv(f, Char(cleanup),0); // Look for any remaining cleanup if (NewObject) { if ((tm = Swig_typemap_lookup ((char*)"newfree", d, iname, (char*)"result", (char*)"", f))) { - Printv(f->code, tm, "\n",0); - mreplace (f->code, argnum, arg, proc_name); + Printv(f, tm, "\n",0); + mreplace (f, argnum, arg, proc_name); } } @@ -437,8 +438,8 @@ MZSCHEME::function(DOH *node) if ((tm = Swig_typemap_lookup ((char*)"ret", d, name, (char*)"result", (char*)"", f))) { // Yep. Use it instead of the default - Printv(f->code, tm, "\n",0); - mreplace (f->code, argnum, arg, proc_name); + Printv(f, tm, "\n",0); + mreplace (f, argnum, arg, proc_name); } // returning multiple values @@ -446,22 +447,22 @@ MZSCHEME::function(DOH *node) if(SwigType_type(d) == T_VOID) { 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); + Printv(f, tab4, "swig_result = scheme_values(_lenv, _values);\n",0); } else { 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); + Printv(f, tab4, "_values[0] = swig_result;\n",0); + Printv(f, tab4, "swig_result = scheme_values(_lenv, _values);\n",0); } } // Wrap things up (in a manner of speaking) - Printv(f->code, tab4, "return swig_result;\n",0); - Printv(f->code, "}\n",0); + Printv(f, tab4, "return swig_result;\n",0); + Printv(f, "}\n",0); - Wrapper_print(f, f_wrappers); + Printf(f_wrappers,"%s", f); // Now register the function char temp[256]; @@ -479,7 +480,7 @@ MZSCHEME::function(DOH *node) Delete(outarg); Delete(cleanup); Delete(build); - DelWrapper(f); + Delete(f); } // ----------------------------------------------------------------------- diff --git a/Source/Modules1.1/perl5.cxx b/Source/Modules1.1/perl5.cxx index 1943ad5b1..b1aaba458 100644 --- a/Source/Modules1.1/perl5.cxx +++ b/Source/Modules1.1/perl5.cxx @@ -521,7 +521,8 @@ PERL5::function(DOH *node) cleanup = NewString(""); outarg = NewString(""); - Printv(f->def, "XS(", Swig_name_wrapper(iname), ") {\n", 0); + Printv(f, "XS(", Swig_name_wrapper(iname), ") {\n", 0); + Printf(f, "$locals\n"); pcount = emit_args(node, f); numopt = check_numopt(l); @@ -530,8 +531,8 @@ PERL5::function(DOH *node) /* Check the number of arguments */ - Printf(f->code," if ((items < %d) || (items > %d)) \n", pcount-numopt, ParmList_numarg(l)); - Printf(f->code," croak(\"Usage: %s\");\n", usage_func(iname,d,l)); + Printf(f," if ((items < %d) || (items > %d)) \n", pcount-numopt, ParmList_numarg(l)); + Printf(f," croak(\"Usage: %s\");\n", usage_func(iname,d,l)); /* Write code to extract parameters. */ i = 0; @@ -549,12 +550,12 @@ PERL5::function(DOH *node) if (!Getignore(p)) { /* Check for optional argument */ if (j>= (pcount-numopt)) - Printf(f->code," if (items > %d) {\n", j); + Printf(f," if (items > %d) {\n", j); if ((tm = Swig_typemap_lookup((char*)"in",pt,pn,source,target,f))) { - Printf(f->code,"%s\n",tm); - Replace(f->code,"$argnum",argnum,DOH_REPLACE_ANY); - Replace(f->code,"$arg",source,DOH_REPLACE_ANY); + Printf(f,"%s\n",tm); + Replace(f,"$argnum",argnum,DOH_REPLACE_ANY); + Replace(f,"$arg",source,DOH_REPLACE_ANY); } else { switch(SwigType_type(pt)) { case T_BOOL: @@ -566,16 +567,16 @@ PERL5::function(DOH *node) case T_USHORT: case T_ULONG: case T_UCHAR: - Printf(f->code," %s = (%s)SvIV(ST(%d));\n", target, SwigType_lstr(pt,0),j); + Printf(f," %s = (%s)SvIV(ST(%d));\n", target, SwigType_lstr(pt,0),j); break; case T_CHAR : - Printf(f->code," %s = (char) *SvPV(ST(%d),PL_na);\n", target, j); + Printf(f," %s = (char) *SvPV(ST(%d),PL_na);\n", target, j); break; case T_DOUBLE : case T_FLOAT : - Printf(f->code," %s = (%s)SvNV(ST(%d));\n", target, SwigType_lstr(pt,0), j); + Printf(f," %s = (%s)SvNV(ST(%d));\n", target, SwigType_lstr(pt,0), j); break; case T_VOID : @@ -584,18 +585,18 @@ PERL5::function(DOH *node) case T_USER: SwigType_add_pointer(pt); sprintf(temp,"argument %d", i+1); - get_pointer(iname, temp, source, target, pt, f->code, (char *)"XSRETURN(1)"); + get_pointer(iname, temp, source, target, pt, f, (char *)"XSRETURN(1)"); SwigType_del_pointer(pt); break; case T_STRING: - Printf(f->code," if (! SvOK((SV*) ST(%d))) { %s = 0; }\n", j, target); - Printf(f->code," else { %s = (char *) SvPV(ST(%d),PL_na); }\n", target,j); + Printf(f," if (! SvOK((SV*) ST(%d))) { %s = 0; }\n", j, target); + Printf(f," else { %s = (char *) SvPV(ST(%d),PL_na); }\n", target,j); break; case T_POINTER: case T_ARRAY: case T_REFERENCE: sprintf(temp,"argument %d", i+1); - get_pointer(iname,temp,source,target, pt, f->code, (char*)"XSRETURN(1)"); + get_pointer(iname,temp,source,target, pt, f, (char*)"XSRETURN(1)"); break; default : @@ -606,7 +607,7 @@ PERL5::function(DOH *node) /* The source is going to be an array of saved values. */ sprintf(temp,"_saved[%d]",num_saved); if (j>= (pcount-numopt)) - Printf(f->code," } \n"); + Printf(f," } \n"); j++; } else { temp[0] = 0; @@ -614,8 +615,8 @@ PERL5::function(DOH *node) /* Check if there is any constraint code */ if ((tm = Swig_typemap_lookup((char*)"check",pt,pn,source,target,0))) { - Printf(f->code,"%s\n", tm); - Replace(f->code,"$argnum",argnum, DOH_REPLACE_ANY); + Printf(f,"%s\n", tm); + Replace(f,"$argnum",argnum, DOH_REPLACE_ANY); } need_save = 0; @@ -636,7 +637,7 @@ PERL5::function(DOH *node) /* If we need a saved variable, we need to emit to emit some code for that This only applies if the argument actually existed (not ignore) */ if ((need_save) && (!Getignore(p))) { - Printv(f->code, tab4, temp, " = ", source, ";\n", 0); + Printv(f, tab4, temp, " = ", source, ";\n", 0); num_saved++; } i++; @@ -653,24 +654,24 @@ PERL5::function(DOH *node) emit_func_call(node,f); if ((tm = Swig_typemap_lookup((char*)"out",d,iname,(char*)"result",(char*)"ST(argvi)",0))) { - Printf(f->code, "%s\n", tm); + Printf(f, "%s\n", tm); } else { if (SwigType_type(d) != T_VOID) { - Printf(f->code," ST(argvi) = sv_newmortal();\n"); + Printf(f," ST(argvi) = sv_newmortal();\n"); switch (SwigType_type(d)) { case T_INT: case T_BOOL: case T_UINT: case T_SHORT: case T_USHORT: case T_LONG : case T_ULONG: case T_SCHAR: case T_UCHAR : - Printf(f->code," sv_setiv(ST(argvi++),(IV) result);\n"); + Printf(f," sv_setiv(ST(argvi++),(IV) result);\n"); break; case T_DOUBLE : case T_FLOAT : - Printf(f->code," sv_setnv(ST(argvi++), (double) result);\n"); + Printf(f," sv_setnv(ST(argvi++), (double) result);\n"); break; case T_CHAR : Wrapper_add_local(f,"_ctemp", "char ctemp[2]"); - Printv(f->code, + Printv(f, tab4, "ctemp[0] = result;\n", tab4, "ctemp[1] = 0;\n", tab4, "sv_setpv((SV*)ST(argvi++),ctemp);\n", @@ -680,18 +681,18 @@ PERL5::function(DOH *node) case T_USER: SwigType_add_pointer(d); SwigType_remember(d); - Printv(f->code, + Printv(f, tab4, "SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE", SwigType_manglestr(d),");\n", 0); SwigType_del_pointer(d); break; case T_STRING: - Printf(f->code," sv_setpv((SV*)ST(argvi++),(char *) result);\n"); + Printf(f," sv_setpv((SV*)ST(argvi++),(char *) result);\n"); break; case T_POINTER: case T_ARRAY: case T_REFERENCE: SwigType_remember(d); - Printv(f->code, tab4, "SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE", SwigType_manglestr(d), ");\n", 0); + Printv(f, tab4, "SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE", SwigType_manglestr(d), ");\n", 0); break; default : @@ -703,35 +704,35 @@ PERL5::function(DOH *node) /* If there were any output args, take care of them. */ - Printv(f->code,outarg,0); + Printv(f,outarg,0); /* If there was any cleanup, do that. */ - Printv(f->code,cleanup,0); + Printv(f,cleanup,0); if (NewObject) { if ((tm = Swig_typemap_lookup((char*)"newfree",d,iname,(char*)"result",(char*)"",0))) { - Printf(f->code,"%s\n",tm); + Printf(f,"%s\n",tm); } } if ((tm = Swig_typemap_lookup((char*)"ret",d,iname,(char*)"result",(char*)"",0))) { - Printf(f->code,"%s\n", tm); + Printf(f,"%s\n", tm); } - Printf(f->code," XSRETURN(argvi);\n}\n"); + Printf(f," XSRETURN(argvi);\n}\n"); /* Add the dXSARGS last */ Wrapper_add_local(f,"dXSARGS","dXSARGS"); /* Substitute the cleanup code */ - Replace(f->code,"$cleanup",cleanup,DOH_REPLACE_ANY); - Replace(f->code,"$name",iname,DOH_REPLACE_ANY); + Replace(f,"$cleanup",cleanup,DOH_REPLACE_ANY); + Replace(f,"$name",iname,DOH_REPLACE_ANY); /* Dump the wrapper function */ - Wrapper_print(f,f_wrappers); + Printf(f_wrappers,"%s", f); /* Now register the function */ @@ -844,7 +845,7 @@ PERL5::function(DOH *node) } Delete(cleanup); Delete(outarg); - DelWrapper(f); + Delete(f); } /* ----------------------------------------------------------------------------- @@ -878,57 +879,58 @@ void PERL5::variable(DOH *node) { /* Create a Perl function for setting the variable value */ if (!(Status & STAT_READONLY)) { - Printf(setf->def,"SWIGCLASS_STATIC int %s(SV* sv, MAGIC *mg) {\n", set_name); - Printv(setf->code, + Printf(setf,"SWIGCLASS_STATIC int %s(SV* sv, MAGIC *mg) {\n", set_name); + Printf(setf,"$locals\n"); + Printv(setf, tab4, "MAGIC_PPERL\n", tab4, "mg = mg;\n", 0); /* Check for a few typemaps */ if ((tm = Swig_typemap_lookup((char*)"varin",t,(char*)"",(char*)"sv",name,0))) { - Printf(setf->code,"%s\n", tm); + Printf(setf,"%s\n", tm); } else if ((tm = Swig_typemap_lookup((char*)"in",t,(char*)"",(char*)"sv",name,0))) { - Printf(setf->code,"%s\n", tm); + Printf(setf,"%s\n", tm); } else { switch(SwigType_type(t)) { case T_INT : case T_BOOL: case T_UINT: case T_SHORT : case T_USHORT: case T_LONG : case T_ULONG: case T_UCHAR: case T_SCHAR: - Printv(setf->code,tab4, name, " = (", SwigType_str(t,0), ") SvIV(sv);\n", 0); + Printv(setf,tab4, name, " = (", SwigType_str(t,0), ") SvIV(sv);\n", 0); break; case T_DOUBLE : case T_FLOAT : - Printv(setf->code, tab4, name, " = (", SwigType_str(t,0), ") SvNV(sv);\n", 0); + Printv(setf, tab4, name, " = (", SwigType_str(t,0), ") SvNV(sv);\n", 0); break; case T_CHAR : - Printv(setf->code, tab4, name, " = (char) *SvPV(sv,PL_na);\n", 0); + Printv(setf, tab4, name, " = (char) *SvPV(sv,PL_na);\n", 0); break; case T_USER: SwigType_add_pointer(t); 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, " = *((", SwigType_str(t,0), ") _temp);\n", 0); + get_pointer(iname,(char*)"value",(char*)"sv",(char*)"_temp", t, setf, (char*)"return(1)"); + Printv(setf, tab4, name, " = *((", SwigType_str(t,0), ") _temp);\n", 0); SwigType_del_pointer(t); break; case T_STRING: Wrapper_add_local(setf,"_a","char *_a"); - Printf(setf->code," _a = (char *) SvPV(sv,PL_na);\n"); + Printf(setf," _a = (char *) SvPV(sv,PL_na);\n"); if (CPlusPlus) - Printv(setf->code, + Printv(setf, tab4, "if (", name, ") delete [] ", name, ";\n", tab4, name, " = new char[strlen(_a)+1];\n", 0); else - Printv(setf->code, + Printv(setf, tab4, "if (", name, ") free((char*)", name, ");\n", tab4, name, " = (char *) malloc(strlen(_a)+1);\n", 0); - Printv(setf->code,"strcpy((char*)", name, ",_a);\n", 0); + Printv(setf,"strcpy((char*)", name, ",_a);\n", 0); break; case T_ARRAY: @@ -939,7 +941,7 @@ void PERL5::variable(DOH *node) { if (SwigType_type(ta) == T_CHAR) { String *dim = SwigType_array_getdim(aop,0); if (dim && Len(dim)) { - Printf(setf->code, "strncpy(%s,(char*) SvPV(sv,PL_na), %s);\n", name,dim); + Printf(setf, "strncpy(%s,(char*) SvPV(sv,PL_na), %s);\n", name,dim); setable = 1; } else { setable = 0; @@ -954,8 +956,8 @@ void PERL5::variable(DOH *node) { case T_POINTER: case T_REFERENCE: 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, " = (", SwigType_str(t,0), ") _temp;\n", 0); + get_pointer(iname,(char*)"value",(char*)"sv",(char*)"_temp", t, setf, (char*)"return(1)"); + Printv(setf,tab4, name, " = (", SwigType_str(t,0), ") _temp;\n", 0); break; default : @@ -963,24 +965,25 @@ void PERL5::variable(DOH *node) { return; } } - Printf(setf->code," return 1;\n}\n"); - Replace(setf->code,"$name",iname, DOH_REPLACE_ANY); - Wrapper_print(setf,magic); + Printf(setf," return 1;\n}\n"); + Replace(setf,"$name",iname, DOH_REPLACE_ANY); + Printf(magic,"%s", setf); } /* Now write a function to evaluate the variable */ - Printf(getf->def,"SWIGCLASS_STATIC int %s(SV *sv, MAGIC *mg) {\n", val_name); - Printv(getf->code, + Printf(getf,"SWIGCLASS_STATIC int %s(SV *sv, MAGIC *mg) {\n", val_name); + Printf(getf,"$locals\n"); + Printv(getf, tab4, "MAGIC_PPERL\n", tab4, "mg = mg;\n", 0); if ((tm = Swig_typemap_lookup((char*)"varout",t,(char*)"",name, (char*)"sv",0))) { - Printf(getf->code,"%s\n", tm); + Printf(getf,"%s\n", tm); } else if ((tm = Swig_typemap_lookup((char*)"out",t,(char*)"",name,(char*)"sv",0))) { - Printf(getf->code,"%s\n", tm); + Printf(getf,"%s\n", tm); } else { switch(SwigType_type(t)) { @@ -988,17 +991,17 @@ void PERL5::variable(DOH *node) { case T_SHORT : case T_USHORT: case T_LONG : case T_ULONG: case T_UCHAR: case T_SCHAR: - Printv(getf->code,tab4, "sv_setiv(sv, (IV) ", name, ");\n", 0); + Printv(getf,tab4, "sv_setiv(sv, (IV) ", name, ");\n", 0); Printv(vinit, tab4, "sv_setiv(sv,(IV)", name, ");\n",0); break; case T_DOUBLE : case T_FLOAT : - Printv(getf->code, tab4,"sv_setnv(sv, (double) ", name, ");\n", 0); + Printv(getf, tab4,"sv_setnv(sv, (double) ", name, ");\n", 0); Printv(vinit, tab4, "sv_setnv(sv,(double)", name, ");\n",0); break; case T_CHAR : Wrapper_add_local(getf,"_ptemp","char _ptemp[2]"); - Printv(getf->code, + Printv(getf, tab4, "_ptemp[0] = ", name, ";\n", tab4, "_ptemp[1] = 0;\n", tab4, "sv_setpv((SV*) sv, _ptemp);\n", @@ -1006,7 +1009,7 @@ void PERL5::variable(DOH *node) { break; case T_USER: SwigType_add_pointer(t); - Printv(getf->code, + Printv(getf, tab4, "rsv = SvRV(sv);\n", tab4, "sv_setiv(rsv,(IV) &", name, ");\n", 0); @@ -1018,7 +1021,7 @@ void PERL5::variable(DOH *node) { break; case T_STRING: - Printv(getf->code, tab4, "sv_setpv((SV*) sv, ", name, ");\n", 0); + Printv(getf, tab4, "sv_setpv((SV*) sv, ", name, ");\n", 0); break; case T_ARRAY: @@ -1027,7 +1030,7 @@ void PERL5::variable(DOH *node) { SwigType *ta = Copy(t); aop = SwigType_pop(ta); if (SwigType_type(ta) == T_CHAR) { - Printv(getf->code, "sv_setpv((SV*)sv, ", name, ");\n", 0); + Printv(getf, "sv_setpv((SV*)sv, ", name, ");\n", 0); Delete(ta); Delete(aop); break; @@ -1037,7 +1040,7 @@ void PERL5::variable(DOH *node) { } /* No break here is intentional */ case T_POINTER: case T_REFERENCE: - Printv(getf->code, + Printv(getf, tab4, "rsv = SvRV(sv);\n", tab4, "sv_setiv(rsv,(IV) ", name, ");\n", 0); @@ -1050,10 +1053,10 @@ void PERL5::variable(DOH *node) { break; } } - Printf(getf->code," return 1;\n}\n"); + Printf(getf," return 1;\n}\n"); - Replace(getf->code,"$name",iname, DOH_REPLACE_ANY); - Wrapper_print(getf,magic); + Replace(getf,"$name",iname, DOH_REPLACE_ANY); + Printf(magic,"%s", getf); /* Now add symbol to the PERL interpreter */ if ((Status & STAT_READONLY) || (!setable)) { @@ -1082,8 +1085,8 @@ void PERL5::variable(DOH *node) { if (export_all) Printf(exported,"$%s ", name); } - DelWrapper(setf); - DelWrapper(getf); + Delete(setf); + Delete(getf); } /* ----------------------------------------------------------------------------- diff --git a/Source/Modules1.1/python.cxx b/Source/Modules1.1/python.cxx index 2b2044d35..c4d9a37e5 100644 --- a/Source/Modules1.1/python.cxx +++ b/Source/Modules1.1/python.cxx @@ -361,17 +361,17 @@ PYTHON::function(DOH *node) { strcpy(wname,Char(Swig_name_wrapper(iname))); if (!use_kw) { - Printv(f->def, + Printv(f, "static PyObject *", wname, "(PyObject *self, PyObject *args) {", 0); } else { - Printv(f->def, + Printv(f, "static PyObject *", wname, "(PyObject *self, PyObject *args, PyObject *kwargs) {", 0); } - + Printf(f,"$locals\n"); Wrapper_add_local(f,"resultobj", "PyObject *resultobj"); /* Get the function usage string for later use */ @@ -538,7 +538,8 @@ PYTHON::function(DOH *node) { Printf(kwargs," NULL }"); if (use_kw) { - Printv(f->locals,tab4, "char *kwnames[] = ", kwargs, ";\n", 0); + Wrapper_add_localv(f,"kwnames","char *kwnames[] = ", kwargs, ";\n", 0); + /* Printv(f->locals,tab4, "char *kwnames[] = ", kwargs, ";\n", 0); */ } Printf(parse_args,":%s\"", iname); @@ -547,45 +548,45 @@ PYTHON::function(DOH *node) { 0); /* Now slap the whole first part of the wrapper function together */ - Printv(f->code, parse_args, get_pointers, check, 0); + Printv(f, parse_args, get_pointers, check, 0); /* Emit the function call */ emit_func_call(node,f); /* Return the function value */ if ((tm = Swig_typemap_lookup((char*)"out",d,iname,(char*)"result",(char*)"resultobj",0))) { - Printf(f->code,"%s\n", tm); + Printf(f,"%s\n", tm); } else { switch(SwigType_type(d)) { case T_INT: case T_UINT: case T_BOOL: case T_SHORT: case T_USHORT: case T_LONG : case T_ULONG: case T_SCHAR: case T_UCHAR : - Printf(f->code," resultobj = PyInt_FromLong((long)result);\n"); + Printf(f," resultobj = PyInt_FromLong((long)result);\n"); break; case T_DOUBLE : case T_FLOAT : - Printf(f->code," resultobj = PyFloat_FromDouble(result);\n"); + Printf(f," resultobj = PyFloat_FromDouble(result);\n"); break; case T_CHAR : - Printf(f->code," resultobj = Py_BuildValue(\"c\",result);\n"); + Printf(f," resultobj = Py_BuildValue(\"c\",result);\n"); break; case T_USER : SwigType_add_pointer(d); SwigType_remember(d); - Printv(f->code,tab4, "resultobj = SWIG_NewPointerObj((void *)result, SWIGTYPE", SwigType_manglestr(d), ");\n",0); + Printv(f,tab4, "resultobj = SWIG_NewPointerObj((void *)result, SWIGTYPE", SwigType_manglestr(d), ");\n",0); SwigType_del_pointer(d); break; case T_STRING: - Printf(f->code," resultobj = Py_BuildValue(\"s\",result);\n"); + Printf(f," resultobj = Py_BuildValue(\"s\",result);\n"); break; case T_POINTER: case T_ARRAY: case T_REFERENCE: SwigType_remember(d); - Printv(f->code, tab4, "resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE", SwigType_manglestr(d), ");\n", 0); + Printv(f, tab4, "resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE", SwigType_manglestr(d), ");\n", 0); break; case T_VOID: - Printf(f->code," Py_INCREF(Py_None);\n"); - Printf(f->code," resultobj = Py_None;\n"); + Printf(f," Py_INCREF(Py_None);\n"); + Printf(f," resultobj = Py_None;\n"); break; default : Printf(stderr,"%s: Line %d. Unable to use return type %s in function %s.\n", input_file, line_number, SwigType_str(d,0), name); @@ -594,33 +595,33 @@ PYTHON::function(DOH *node) { } /* Output argument output code */ - Printv(f->code,outarg,0); + Printv(f,outarg,0); /* Output cleanup code */ - Printv(f->code,cleanup,0); + Printv(f,cleanup,0); /* Look to see if there is any newfree cleanup code */ if (NewObject) { if ((tm = Swig_typemap_lookup((char*)"newfree",d,iname,(char*)"result",(char*)"",0))) { - Printf(f->code,"%s\n",tm); + Printf(f,"%s\n",tm); } } /* See if there is any return cleanup code */ if ((tm = Swig_typemap_lookup((char*)"ret",d,iname,(char*)"result",(char*)"",0))) { - Printf(f->code,"%s\n",tm); + Printf(f,"%s\n",tm); } - Printf(f->code," return resultobj;\n}\n"); + Printf(f," return resultobj;\n}\n"); /* Substitute the cleanup code */ - Replace(f->code,"$cleanup",cleanup, DOH_REPLACE_ANY); + Replace(f,"$cleanup",cleanup, DOH_REPLACE_ANY); /* Substitute the function name */ - Replace(f->code,"$name",iname, DOH_REPLACE_ANY); + Replace(f,"$name",iname, DOH_REPLACE_ANY); /* Dump the function out */ - Wrapper_print(f,f_wrappers); + Printf(f_wrappers,"%s",f); /* Now register the function with the interpreter. */ add_method(iname, wname, use_kw); @@ -674,7 +675,7 @@ PYTHON::function(DOH *node) { Delete(outarg); Delete(check); Delete(kwargs); - DelWrapper(f); + Delete(f); } /* ----------------------------------------------------------------------------- @@ -711,11 +712,12 @@ PYTHON::variable(DOH *node) { /* Create a function for setting the value of the variable */ - Printf(setf->def,"static int %s_set(PyObject *val) {", wname); + Printf(setf,"static int %s_set(PyObject *val) {\n", wname); + Printf(setf,"$locals\n"); if (!(Status & STAT_READONLY)) { if ((tm = Swig_typemap_lookup((char*)"varin",t,name,(char*)"val",name,0))) { - Printf(setf->code,"%s\n",tm); - Replace(setf->code,"$name",iname, DOH_REPLACE_ANY); + Printf(setf,"%s\n",tm); + Replace(setf,"$name",iname, DOH_REPLACE_ANY); } else { switch(SwigType_type(t)) { @@ -723,7 +725,7 @@ PYTHON::variable(DOH *node) { case T_UINT: case T_USHORT: case T_ULONG: case T_SCHAR: case T_UCHAR: case T_BOOL: Wrapper_add_localv(setf,"tval",SwigType_lstr(t,0),"tval",0); - Printv(setf->code, + Printv(setf, tab4, "tval = (", SwigType_lstr(t,0), ") PyInt_AsLong(val);\n", tab4, "if (PyErr_Occurred()) {\n", tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '", @@ -736,7 +738,7 @@ PYTHON::variable(DOH *node) { case T_FLOAT: case T_DOUBLE: Wrapper_add_localv(setf,"tval",SwigType_lstr(t,0), "tval",0); - Printv(setf->code, + Printv(setf, tab4, "tval = (", SwigType_lstr(t,0), ") PyFloat_AsDouble(val);\n", tab4, "if (PyErr_Occurred()) {\n", tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '", @@ -749,7 +751,7 @@ PYTHON::variable(DOH *node) { case T_CHAR: Wrapper_add_local(setf,"tval","char * tval"); - Printv(setf->code, + Printv(setf, tab4, "tval = (char *) PyString_AsString(val);\n", tab4, "if (PyErr_Occurred()) {\n", tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '", @@ -763,14 +765,14 @@ PYTHON::variable(DOH *node) { case T_USER: SwigType_add_pointer(t); Wrapper_add_localv(setf,"temp",SwigType_lstr(t,0),"temp",0); - get_pointer((char*)"val",(char*)"temp",t,setf->code,(char*)"1"); - Printv(setf->code, tab4, name, " = *temp;\n", 0); + get_pointer((char*)"val",(char*)"temp",t,setf,(char*)"1"); + Printv(setf, tab4, name, " = *temp;\n", 0); SwigType_del_pointer(t); break; case T_STRING: Wrapper_add_local(setf,"tval","char * tval"); - Printv(setf->code, + Printv(setf, tab4, "tval = (char *) PyString_AsString(val);\n", tab4, "if (PyErr_Occurred()) {\n", tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '", @@ -780,13 +782,13 @@ PYTHON::variable(DOH *node) { 0); if (CPlusPlus) { - Printv(setf->code, + Printv(setf, tab4, "if (", name, ") delete [] ", name, ";\n", tab4, name, " = new char[strlen(tval)+1];\n", tab4, "strcpy((char *)", name, ",tval);\n", 0); } else { - Printv(setf->code, + Printv(setf, tab4, "if (", name, ") free((char*)", name, ");\n", tab4, name, " = (char *) malloc(strlen(tval)+1);\n", tab4, "strcpy((char *)", name, ",tval);\n", @@ -803,12 +805,12 @@ PYTHON::variable(DOH *node) { if (SwigType_type(ta) == T_CHAR) { String *dim = SwigType_array_getdim(aop,0); if (dim && Len(dim)) { - Printf(setf->code, "strncpy(%s,PyString_AsString(val), %s);\n", name,dim); + Printf(setf, "strncpy(%s,PyString_AsString(val), %s);\n", name,dim); setable = 1; } } if (!setable) { - Printv(setf->code, + Printv(setf, tab4, "PyErr_SetString(PyExc_TypeError,\"Variable ", iname, " is read-only.\");\n", tab4, "return 1;\n", @@ -821,50 +823,51 @@ PYTHON::variable(DOH *node) { case T_POINTER: case T_REFERENCE: Wrapper_add_localv(setf,"temp", SwigType_lstr(t,0), "temp",0); - get_pointer((char*)"val",(char*)"temp",t,setf->code,(char*)"1"); - Printv(setf->code,tab4, name, " = temp;\n", 0); + get_pointer((char*)"val",(char*)"temp",t,setf,(char*)"1"); + Printv(setf,tab4, name, " = temp;\n", 0); break; default: 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," return 0;\n"); } else { /* Is a readonly variable. Issue an error */ - Printv(setf->code, + Printv(setf, tab4, "PyErr_SetString(PyExc_TypeError,\"Variable ", iname, " is read-only.\");\n", tab4, "return 1;\n", 0); } - Printf(setf->code,"}\n"); - Wrapper_print(setf,f_wrappers); + Printf(setf,"}\n"); + Printf(f_wrappers,"%s", setf); /* Create a function for getting the value of a variable */ - Printf(getf->def,"static PyObject *%s_get() {", wname); + Printf(getf,"static PyObject *%s_get() {\n", wname); + Printf(getf,"$locals\n"); Wrapper_add_local(getf,"pyobj", "PyObject *pyobj"); if ((tm = Swig_typemap_lookup((char*)"varout",t,name,name,(char*)"pyobj",0))) { - Printf(getf->code,"%s\n",tm); - Replace(getf->code,"$name",iname, DOH_REPLACE_ANY); + Printf(getf,"%s\n",tm); + Replace(getf,"$name",iname, DOH_REPLACE_ANY); } else if ((tm = Swig_typemap_lookup((char*)"out",t,name,name,(char*)"pyobj",0))) { - Printf(getf->code,"%s\n",tm); - Replace(getf->code,"$name",iname, DOH_REPLACE_ANY); + Printf(getf,"%s\n",tm); + Replace(getf,"$name",iname, DOH_REPLACE_ANY); } else { switch(SwigType_type(t)) { case T_INT: case T_UINT: case T_SHORT: case T_USHORT: case T_LONG: case T_ULONG: case T_SCHAR: case T_UCHAR: case T_BOOL: - Printv(getf->code, tab4, "pyobj = PyInt_FromLong((long) ", name, ");\n", 0); + Printv(getf, tab4, "pyobj = PyInt_FromLong((long) ", name, ");\n", 0); break; case T_FLOAT: case T_DOUBLE: - Printv(getf->code, tab4, "pyobj = PyFloat_FromDouble((double) ", name, ");\n", 0); + Printv(getf, tab4, "pyobj = PyFloat_FromDouble((double) ", name, ");\n", 0); break; case T_CHAR: Wrapper_add_local(getf,"ptemp","char ptemp[2]"); - Printv(getf->code, + Printv(getf, tab4, "ptemp[0] = ", name, ";\n", tab4, "ptemp[1] = 0;\n", tab4, "pyobj = PyString_FromString(ptemp);\n", @@ -873,14 +876,14 @@ PYTHON::variable(DOH *node) { case T_USER: SwigType_add_pointer(t); SwigType_remember(t); - Printv(getf->code, + Printv(getf, tab4, "pyobj = SWIG_NewPointerObj((void *) &", name , ", SWIGTYPE", SwigType_manglestr(t), ");\n", 0); SwigType_del_pointer(t); break; case T_STRING: - Printv(getf->code, + Printv(getf, tab4, "if (", name, ")\n", tab8, "pyobj = PyString_FromString(", name, ");\n", tab4, "else pyobj = PyString_FromString(\"(NULL)\");\n", @@ -889,7 +892,7 @@ PYTHON::variable(DOH *node) { case T_POINTER: case T_ARRAY: case T_REFERENCE: SwigType_remember(t); - Printv(getf->code, + Printv(getf, tab4, "pyobj = SWIG_NewPointerObj((void *)", name, ", SWIGTYPE", SwigType_manglestr(t), ");\n", 0); @@ -901,8 +904,8 @@ PYTHON::variable(DOH *node) { } } - Printf(getf->code," return pyobj;\n}\n"); - Wrapper_print(getf,f_wrappers); + Printf(getf," return pyobj;\n}\n"); + Printf(f_wrappers,"%s", getf); /* Now add this to the variable linking mechanism */ @@ -917,8 +920,8 @@ PYTHON::variable(DOH *node) { 0); } } - DelWrapper(setf); - DelWrapper(getf); + Delete(setf); + Delete(getf); } /* ----------------------------------------------------------------------------- diff --git a/Source/Modules1.1/ruby.cxx b/Source/Modules1.1/ruby.cxx index cd66d7ccb..b9586a3a4 100644 --- a/Source/Modules1.1/ruby.cxx +++ b/Source/Modules1.1/ruby.cxx @@ -449,7 +449,7 @@ void RUBY::function(DOH *node) { if (current == DESTRUCTOR) { Wrapper *dummy = NewWrapper(); emit_func_call(node,dummy); - DelWrapper(dummy); + Delete(dummy); return; } @@ -502,20 +502,21 @@ void RUBY::function(DOH *node) { int vararg = (numoptreal != 0); /* Now write the wrapper function itself */ - Printv(f->def, "static VALUE\n", wname, "(", 0); + Printv(f, "static VALUE\n", wname, "(", 0); if (vararg) { - Printv(f->def, "int argc, VALUE *argv, VALUE self",0); + Printv(f, "int argc, VALUE *argv, VALUE self",0); } else { - Printv(f->def, "VALUE self", 0); + Printv(f, "VALUE self", 0); p = l; for (i = 0; i < start; i++) p = Getnext(p); for (i = start; p; i++, p = Getnext(p)) { if (!Getignore(p)) { - Printf(f->def,", VALUE varg%d", i); + Printf(f,", VALUE varg%d", i); } } } - Printf(f->def,") {"); + Printf(f,") {\n"); + Printf(f,"$locals\n"); /* Emit all of the local variables for holding arguments. */ if (vararg) { @@ -538,14 +539,14 @@ void RUBY::function(DOH *node) { for (i = start; p; i++, p = Getnext(p)) { if (!Getignore(p)) numscan++; } - Printf(f->code,"rb_scan_args(argc, argv, \"%d%d\"", (numarg-numoptreal), numscan - (numarg-numoptreal)); + Printf(f,"rb_scan_args(argc, argv, \"%d%d\"", (numarg-numoptreal), numscan - (numarg-numoptreal)); for (p = l, i = 0; i < start; i++) p = Getnext(p); for (i = start; p; i++, p = Getnext(p)) { if (!Getignore(p)) { - Printf(f->code,", &varg%d", i); + Printf(f,", &varg%d", i); } } - Printf(f->code,");\n"); + Printf(f,");\n"); } /* Now walk the function parameter list and generate code */ @@ -569,7 +570,7 @@ void RUBY::function(DOH *node) { if (!Getignore(p)) { char *tab = (char*)tab4; if (j >= (pcount-numopt)) { /* Check if parsing an optional argument */ - Printf(f->code," if (argc > %d) {\n", j - start); + Printf(f," if (argc > %d) {\n", j - start); tab = (char*)tab8; } @@ -577,15 +578,15 @@ void RUBY::function(DOH *node) { tm = ruby_typemap_lookup((char*)"in",pt,pn,source,target,f); if (tm) { String *s = NewString(tm); - Printv(f->code, s, 0); - Replace(f->code, "$arg", source, DOH_REPLACE_ANY); + Printv(f, s, 0); + Replace(f, "$arg", source, DOH_REPLACE_ANY); Delete(s); } else { Printf(stderr,"%s : Line %d. No typemapping for datatype %s\n", input_file,line_number, SwigType_str(pt,0)); } if (j >= (pcount-numopt)) - Printv(f->code, tab4, "} \n", 0); + Printv(f, tab4, "} \n", 0); j++; } @@ -593,8 +594,8 @@ void RUBY::function(DOH *node) { tm = ruby_typemap_lookup((char*)"check",pt,pn,source,target); if (tm) { String *s = NewString(tm); - Printv(f->code, s, 0); - Replace(f->code, "$arg", source, DOH_REPLACE_ANY); + Printv(f, s, 0); + Replace(f, "$arg", source, DOH_REPLACE_ANY); Delete(s); } @@ -625,12 +626,12 @@ void RUBY::function(DOH *node) { if (SwigType_type(t) != T_VOID) { need_result = 1; if (predicate) { - Printv(f->code, tab4, "vresult = (result ? Qtrue : Qfalse);\n", 0); + Printv(f, tab4, "vresult = (result ? Qtrue : Qfalse);\n", 0); } else { tm = ruby_typemap_lookup((char*)"out",t,name,(char*)"result",(char*)"vresult"); if (tm) { String *s = NewString(tm); - Printv(f->code, s, 0); + Printv(f, s, 0); Delete(s); } else { Printf(stderr,"%s : Line %d. No return typemap for datatype %s\n", @@ -640,52 +641,52 @@ void RUBY::function(DOH *node) { } /* Dump argument output code; */ - Printv(f->code,outarg,0); + Printv(f,outarg,0); /* Dump the argument cleanup code */ - Printv(f->code,cleanup,0); + Printv(f,cleanup,0); /* Look for any remaining cleanup. This processes the %new directive */ if (NewObject) { tm = ruby_typemap_lookup((char*)"newfree",t,name,(char*)"result",(char*)""); if (tm) { String *s = NewString(tm); - Printv(f->code,s, 0); + Printv(f,s, 0); Delete(s); } } /* free pragma */ if (current == MEMBER_FUNC && Getattr(klass->freemethods, mname)) { - Printv(f->code, tab4, "DATA_PTR(self) = 0;\n", 0); + Printv(f, tab4, "DATA_PTR(self) = 0;\n", 0); } /* Special processing on return value. */ tm = ruby_typemap_lookup((char*)"ret",t,name,(char*)"result",(char*)""); if (tm) { String *s = NewString(tm); - Printv(f->code,s, 0); + Printv(f,s, 0); } /* Wrap things up (in a manner of speaking) */ if (need_result) { Wrapper_add_local(f,"vresult","VALUE vresult = Qnil"); - Printv(f->code, tab4, "return vresult;\n}\n", 0); + Printv(f, tab4, "return vresult;\n}\n", 0); } else { - Printv(f->code, tab4, "return Qnil;\n}\n", 0); + Printv(f, tab4, "return Qnil;\n}\n", 0); } /* Substitute the cleanup code */ - Replace(f->code,"$cleanup",cleanup, DOH_REPLACE_ANY); + Replace(f,"$cleanup",cleanup, DOH_REPLACE_ANY); /* Emit the function */ - Wrapper_print(f,f_wrappers); + Printf(f_wrappers,"%s", f); /* Now register the function with the language */ create_command(name, iname, (vararg ? -1 : numarg)); Delete(cleanup); Delete(outarg); - DelWrapper(f); + Delete(f); } /* --------------------------------------------------------------------- @@ -713,9 +714,10 @@ void RUBY::variable(DOH *node) { /* create getter */ getfname = NewString(Swig_name_get(name)); Replace(getfname,"::", "_", DOH_REPLACE_ANY); /* FIXME: Swig_name_get bug? */ - Printv(getf->def, "static VALUE\n", getfname, "(", 0); - Printf(getf->def, "VALUE self"); - Printf(getf->def, ") {"); + Printv(getf, "static VALUE\n", getfname, "(", 0); + Printf(getf, "VALUE self"); + Printf(getf, ") {\n"); + Printf(getf, "$locals\n"); Wrapper_add_local(getf,"_val","VALUE _val"); if (SwigType_type(t) == T_USER) { @@ -732,14 +734,14 @@ void RUBY::variable(DOH *node) { tm = ruby_typemap_lookup((char*)"out",t,name,source,(char*)"_val"); if (tm) { String *s = NewString(tm); - Printv(getf->code,s, 0); + Printv(getf,s, 0); Delete(s); } else { Printf(stderr,"%s: Line %d. Unable to link with variable type %s\n", input_file,line_number,SwigType_str(t,0)); } - Printv(getf->code, tab4, "return _val;\n}\n", 0); - Wrapper_print(getf,f_wrappers); + Printv(getf, tab4, "return _val;\n}\n", 0); + Printf(f_wrappers,"%s", getf); if (Status & STAT_READONLY) { setfname = NewString("NULL"); @@ -749,8 +751,9 @@ void RUBY::variable(DOH *node) { setfname = NewString(Swig_name_set(name)); Replace(setfname,"::", "_", DOH_REPLACE_ANY); /* FIXME: Swig_name_get bug? */ - Printv(setf->def, "static VALUE\n", setfname, "(VALUE self, ", 0); - Printf(setf->def, "VALUE _val) {"); + Printv(setf, "static VALUE\n", setfname, "(VALUE self, ", 0); + Printf(setf, "VALUE _val) {\n"); + Printf(setf, "$locals\n"); if (SwigType_type(t) == T_USER) { SwigType_add_pointer(t); @@ -766,18 +769,18 @@ void RUBY::variable(DOH *node) { tm = ruby_typemap_lookup((char*)"in",t,name,(char*)"_val",target); if (tm) { String *s = NewString(tm); - Printv(setf->code,s,0); + Printv(setf,s,0); Delete(s); } else { Printf(stderr,"%s: Line %d. Unable to link with variable type %s\n", input_file,line_number,SwigType_str(t,0)); } if (SwigType_type(t) == T_USER) { - Printv(setf->code, name, " = *temp;\n",0); + Printv(setf, name, " = *temp;\n",0); } - Printv(setf->code, tab4, "return _val;\n",0); - Printf(setf->code,"}\n"); - Wrapper_print(setf,f_wrappers); + Printv(setf, tab4, "return _val;\n",0); + Printf(setf,"}\n"); + Printf(f_wrappers,"%s", setf); } /* define accessor method */ @@ -823,8 +826,8 @@ void RUBY::variable(DOH *node) { } Delete(getfname); Delete(setfname); - DelWrapper(setf); - DelWrapper(getf); + Delete(setf); + Delete(getf); } diff --git a/Source/Modules1.1/tcl8.cxx b/Source/Modules1.1/tcl8.cxx index 7c051ddcd..7b536aa5e 100644 --- a/Source/Modules1.1/tcl8.cxx +++ b/Source/Modules1.1/tcl8.cxx @@ -287,9 +287,10 @@ TCL8::function(DOH *node) { args = NewString(""); f = NewWrapper(); - Printv(f->def, - "static int\n ", Swig_name_wrapper(iname), "(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {", + Printv(f, + "static int\n ", Swig_name_wrapper(iname), "(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {\n", 0); + Printf(f,"$locals\n"); /* Print out variables for storing arguments. */ pcount = emit_args(node, f); @@ -433,18 +434,18 @@ TCL8::function(DOH *node) { } Printf(argstr,":%s\"",usage_string(iname,d,l)); - Printv(f->code, + Printv(f, "if (SWIG_GetArgs(interp, objc, objv,", argstr, args, ") == TCL_ERROR) return TCL_ERROR;\n", 0); - Printv(f->code,incode,0); + Printv(f,incode,0); /* Now write code to make the function call */ emit_func_call(node,f); /* Return value if necessary */ if ((tm = Swig_typemap_lookup((char*)"out",d,name,(char*)"result",(char*)"tcl_result",0))) { - Printf(f->code,"%s\n", tm); + Printf(f,"%s\n", tm); } else { switch(SwigType_type(d)) { case T_BOOL: @@ -456,17 +457,17 @@ TCL8::function(DOH *node) { case T_USHORT: case T_ULONG: case T_UCHAR: - Printv(f->code, "Tcl_SetObjResult(interp,Tcl_NewIntObj((long) result));\n",0); + Printv(f, "Tcl_SetObjResult(interp,Tcl_NewIntObj((long) result));\n",0); break; /* Is a single character. We return it as a string */ case T_CHAR : - Printv(f->code, "Tcl_SetObjResult(interp,Tcl_NewStringObj(&result,1));\n",0); + Printv(f, "Tcl_SetObjResult(interp,Tcl_NewStringObj(&result,1));\n",0); break; case T_DOUBLE : case T_FLOAT : - Printv(f->code, "Tcl_SetObjResult(interp,Tcl_NewDoubleObj((double) result));\n",0); + Printv(f, "Tcl_SetObjResult(interp,Tcl_NewDoubleObj((double) result));\n",0); break; case T_USER : @@ -475,18 +476,18 @@ TCL8::function(DOH *node) { Probably dangerous, but safe programming is for wimps. */ SwigType_add_pointer(d); SwigType_remember(d); - Printv(f->code, "Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) result,SWIGTYPE", + Printv(f, "Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) result,SWIGTYPE", SwigType_manglestr(d), "));\n", 0); SwigType_del_pointer(d); break; case T_STRING: - Printv(f->code, "Tcl_SetObjResult(interp,Tcl_NewStringObj(result,-1));\n",0); + Printv(f, "Tcl_SetObjResult(interp,Tcl_NewStringObj(result,-1));\n",0); break; case T_POINTER: case T_REFERENCE: case T_ARRAY: SwigType_remember(d); - Printv(f->code, "Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) result,SWIGTYPE", + Printv(f, "Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) result,SWIGTYPE", SwigType_manglestr(d), "));\n", 0); break; @@ -502,29 +503,29 @@ TCL8::function(DOH *node) { } /* Dump output argument code */ - Printv(f->code,outarg,0); + Printv(f,outarg,0); /* Dump the argument cleanup code */ - Printv(f->code,cleanup,0); + Printv(f,cleanup,0); /* Look for any remaining cleanup */ if (NewObject) { if ((tm = Swig_typemap_lookup((char*)"newfree",d,iname,(char*)"result",(char*)"",0))) { - Printf(f->code,"%s\n", tm); + Printf(f,"%s\n", tm); } } if ((tm = Swig_typemap_lookup((char*)"ret",d,name,(char*)"result",(char*)"",0))) { - Printf(f->code,"%s\n", tm); + Printf(f,"%s\n", tm); } - Printv(f->code, "return TCL_OK;\n}", 0); + Printv(f, "return TCL_OK;\n}\n", 0); /* Substitute the cleanup code */ - Replace(f->code,"$cleanup",cleanup,DOH_REPLACE_ANY); - Replace(f->code,"$name", iname, DOH_REPLACE_ANY); + Replace(f,"$cleanup",cleanup,DOH_REPLACE_ANY); + Replace(f,"$name", iname, DOH_REPLACE_ANY); /* Dump out the function */ - Wrapper_print(f,f_wrappers); + Printf(f_wrappers,"%s",f); /* Register the function with Tcl */ Printv(cmd_info, tab4, "{ SWIG_prefix \"", iname, "\", ", Swig_name_wrapper(iname), ", NULL},\n", 0); @@ -534,7 +535,7 @@ TCL8::function(DOH *node) { Delete(outarg); Delete(argstr); Delete(args); - DelWrapper(f); + Delete(f); } /* ----------------------------------------------------------------------------- @@ -584,23 +585,25 @@ TCL8::variable(DOH *node) { getname = NewStringf("swig_%s_get", Swig_string_mangle(t)); get = NewWrapper(); set = NewWrapper(); - Printv(set->def, "static char *", setname, "(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {",0); + Printv(set, "static char *", setname, "(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {\n",0); + Printf(set,"$locals\n"); + Printv(get, "static char *", getname, "(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {\n",0); + Printf(get,"$locals\n"); - Printv(get->def, "static char *", getname, "(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {",0); SwigType *lt = Swig_clocal_type(t); if ((tc != T_USER) && (!isarray)) SwigType_add_pointer(lt); Wrapper_add_localv(get,"addr",SwigType_lstr(lt,"addr"),0); Wrapper_add_localv(set,"addr",SwigType_lstr(lt,"addr"),0); - Printv(set->code, "addr = (", SwigType_lstr(lt,0), ") clientData;\n", 0); - Printv(get->code, "addr = (", SwigType_lstr(lt,0), ") clientData;\n", 0); + Printv(set, "addr = (", SwigType_lstr(lt,0), ") clientData;\n", 0); + Printv(get, "addr = (", SwigType_lstr(lt,0), ") clientData;\n", 0); if ((tc != T_USER) && (!isarray)) SwigType_del_pointer(lt); Delete(lt); Wrapper_add_local(set, "value", "char *value"); Wrapper_add_local(get, "value", "Tcl_Obj *value"); - Printv(set->code, "value = Tcl_GetVar2(interp, name1, name2, flags);\n", + Printv(set, "value = Tcl_GetVar2(interp, name1, name2, flags);\n", "if (!value) return NULL;\n", 0); switch(tc) { @@ -611,9 +614,9 @@ TCL8::variable(DOH *node) { case T_UCHAR: case T_SCHAR: case T_BOOL: - Printv(set->code, "*(addr) = (", SwigType_str(t,0), ") atol(value);\n", 0); + Printv(set, "*(addr) = (", SwigType_str(t,0), ") atol(value);\n", 0); Wrapper_add_local(get,"value","Tcl_Obj *value"); - Printv(get->code, + Printv(get, "value = Tcl_NewIntObj((int) *addr);\n", "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", "Tcl_DecrRefCount(value);\n", @@ -622,9 +625,9 @@ TCL8::variable(DOH *node) { case T_UINT: case T_ULONG: - Printv(set->code, "*(addr) = (", SwigType_str(t,0), ") strtoul(value,0,0);\n",0); + Printv(set, "*(addr) = (", SwigType_str(t,0), ") strtoul(value,0,0);\n",0); Wrapper_add_local(get,"value","Tcl_Obj *value"); - Printv(get->code, + Printv(get, "value = Tcl_NewIntObj((int) *addr);\n", "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", "Tcl_DecrRefCount(value);\n", @@ -633,9 +636,9 @@ TCL8::variable(DOH *node) { case T_FLOAT: case T_DOUBLE: - Printv(set->code, "*(addr) = (", SwigType_str(t,0), ") atof(value);\n",0); + Printv(set, "*(addr) = (", SwigType_str(t,0), ") atof(value);\n",0); Wrapper_add_local(get,"value","Tcl_Obj *value"); - Printv(get->code, + Printv(get, "value = Tcl_NewDoubleObj((double) *addr);\n", "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", "Tcl_DecrRefCount(value);\n", @@ -643,9 +646,9 @@ TCL8::variable(DOH *node) { break; case T_CHAR: - Printv(set->code, "*(addr) = *value;\n",0); + Printv(set, "*(addr) = *value;\n",0); Wrapper_add_local(get,"temp", "char temp[2]"); - Printv(get->code, "temp[0] = *addr; temp[1] = 0;\n", + Printv(get, "temp[0] = *addr; temp[1] = 0;\n", "Tcl_SetVar2(interp,name1,name2,temp,flags);\n", 0); break; @@ -654,7 +657,7 @@ TCL8::variable(DOH *node) { /* User defined type. We return it as a pointer */ SwigType_add_pointer(t); SwigType_remember(t); - Printv(set->code, "{\n", + Printv(set, "{\n", "void *ptr;\n", "if (SWIG_ConvertPtrFromString(interp,value,&ptr,SWIGTYPE", SwigType_manglestr(t), ") != TCL_OK) {\n", "return \"Type Error\";\n", @@ -667,7 +670,7 @@ TCL8::variable(DOH *node) { Wrapper_add_local(get,"value", "Tcl_Obj *value"); SwigType_add_pointer(t); SwigType_remember(t); - Printv(get->code, "value = SWIG_NewPointerObj(addr, SWIGTYPE", SwigType_manglestr(t), ");\n", + Printv(get, "value = SWIG_NewPointerObj(addr, SWIGTYPE", SwigType_manglestr(t), ");\n", "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", "Tcl_DecrRefCount(value);\n",0); SwigType_del_pointer(t); @@ -675,11 +678,11 @@ TCL8::variable(DOH *node) { break; case T_STRING: - Printv(set->code, "if (*addr) free(*addr);\n", + Printv(set, "if (*addr) free(*addr);\n", "*addr = (char *) malloc(strlen(value)+1);\n", "strcpy(*addr,value);\n", 0); - Printv(get->code, "Tcl_SetVar2(interp,name1,name2,*addr, flags);\n",0); + Printv(get, "Tcl_SetVar2(interp,name1,name2,*addr, flags);\n",0); break; case T_ARRAY: @@ -693,16 +696,16 @@ TCL8::variable(DOH *node) { if (SwigType_type(ta) == T_CHAR) { String *dim = SwigType_array_getdim(aop,0); if (dim && Len(dim)) { - Printf(set->code, "strncpy(addr,value,%s);\n", dim); + Printf(set, "strncpy(addr,value,%s);\n", dim); setable = 1; readonly = Status & STAT_READONLY; } - Printv(get->code, "Tcl_SetVar2(interp,name1,name2,addr, flags);\n",0); + Printv(get, "Tcl_SetVar2(interp,name1,name2,addr, flags);\n",0); } else { Printf(stderr,"%s:%d: Array variable '%s' will be read-only.\n", input_file, line_number, name); Wrapper_add_local(get,"value","Tcl_Obj *value"); SwigType_remember(t); - Printv(get->code, + Printv(get, "value = SWIG_NewPointerObj(addr, SWIGTYPE", SwigType_manglestr(t), ");\n", "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", "Tcl_DecrRefCount(value);\n", @@ -715,7 +718,7 @@ TCL8::variable(DOH *node) { case T_POINTER: case T_REFERENCE: SwigType_remember(t); - Printv(set->code, "{\n", + Printv(set, "{\n", "void *ptr;\n", "if (SWIG_ConvertPtrFromString(interp,value,&ptr,SWIGTYPE", SwigType_manglestr(t), ") != TCL_OK) {\n", "return \"Type Error\";\n", @@ -725,7 +728,7 @@ TCL8::variable(DOH *node) { 0); Wrapper_add_local(get,"value","Tcl_Obj *value"); - Printv(get->code, + Printv(get, "value = SWIG_NewPointerObj(*addr, SWIGTYPE", SwigType_manglestr(t), ");\n", "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", "Tcl_DecrRefCount(value);\n", @@ -739,16 +742,16 @@ TCL8::variable(DOH *node) { Printf(stderr,"TCL8::link_variable. Unknown type %s!\n", SwigType_str(t,0)); break; } - Printv(set->code, "return NULL;\n", "}\n",0); - Printv(get->code, "return NULL;\n", "}\n",0); - Wrapper_print(get,f_wrappers); + Printv(set, "return NULL;\n", "}\n",0); + Printv(get, "return NULL;\n", "}\n",0); + Printf(f_wrappers,"%s",get); Setattr(getf,Copy(t),getname); if (setable) { - Wrapper_print(set,f_wrappers); + Printf(f_wrappers,"%s",set); Setattr(setf,Copy(t),setname); } - DelWrapper(get); - DelWrapper(set); + Delete(get); + Delete(set); } Printv(var_info, tab4,"{ SWIG_prefix \"", iname, "\", (void *) ", isarray ? "" : "&", name, ",", getname, ",", 0); @@ -756,11 +759,12 @@ TCL8::variable(DOH *node) { static int readonlywrap = 0; if (!readonlywrap) { Wrapper *ro = NewWrapper(); - Printf(ro->def, "static char *swig_readonly(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {"); - Printv(ro->code, "return \"Variable is read-only\";\n", "}\n", 0); - Wrapper_print(ro,f_wrappers); + Printf(ro, "static char *swig_readonly(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {\n"); + Printf(ro,"$locals\n"); + Printv(ro, "return \"Variable is read-only\";\n", "}\n", 0); + Printf(f_wrappers,"%s",ro); readonlywrap = 1; - DelWrapper(ro); + Delete(ro); } Printf(var_info, "swig_readonly},\n"); } else { diff --git a/Source/SWIG1.1/cplus.cxx b/Source/SWIG1.1/cplus.cxx index f1b04d22a..0d9bdafc7 100644 --- a/Source/SWIG1.1/cplus.cxx +++ b/Source/SWIG1.1/cplus.cxx @@ -189,7 +189,6 @@ public: char *base; // Base class where this was defined int inherited; // Was this member inherited? CPP_member *next; // Next member (for building linked lists) - int id; // type id when created String *signature; CPP_member() { @@ -231,7 +230,6 @@ public: line = line_number; file = input_file; signature = NewStringf("%s(%s)", n, ParmList_str(l)); - id = cpp_id; if (AddMethods) { if (strlen(Char(CCode))) code = Swig_copy_string(Char(CCode)); @@ -317,7 +315,6 @@ public: next = 0; line = line_number; file = input_file; - id = 0; if (AddMethods) { if (strlen(Char(CCode))) code = Swig_copy_string(Char(CCode)); @@ -369,7 +366,6 @@ public: inherited = 0; line = line_number; file = input_file; - id = 0; if (AddMethods) { if (strlen(Char(CCode))) code = Swig_copy_string(Char(CCode)); @@ -425,11 +421,6 @@ public: new_method = AddMethods; line = line_number; file = input_file; - if (Inherit_mode) { - id = cpp_id; - } else { - id = 0; - } code = 0; inherited = 0; } @@ -513,10 +504,6 @@ public: next = 0; line = line_number; file = input_file; - if (Inherit_mode) - id = cpp_id; - else - id = 0; code = 0; inherited = 0; } @@ -652,7 +639,6 @@ public: m = members; while (m) { inherit_base_class = m->base; - cpp_id = m->id; m->inherit(mode); m = m->next; } @@ -668,7 +654,6 @@ public: abstract = is_abstract; /* Printf(stdout,"class %s. Abstract = %d\n", classname, is_abstract); */ while (m) { - cpp_id = m->id; m->emit(); m = m->next; } @@ -1580,7 +1565,7 @@ void cplus_emit_member_func(char *classname, char *classtype, char *classrename, bc = classname; } - /* Printf(key,"%s+%s",Wrapper_Getname(w), ParmList_protostr(l));*/ + /* Printf(key,"%s+%s",Getname(w), ParmList_protostr(l));*/ Printf(key,"%s+%s", Swig_name_member(bc,mrename), ParmList_protostr(l)); /* Printf(stdout,"virtual = %d, bc = %s, mkey = %s\n", IsVirtual, bc, key); */ @@ -1593,13 +1578,14 @@ void cplus_emit_member_func(char *classname, char *classtype, char *classrename, if (!prev_wrap) { if (mode && ccode) { /* Produce an actual C wrapper */ - Wrapper_print(w,f_wrappers); + Printf(f_wrappers,"%s",w); } else if (!mode) { /* Nah. Just produce a string that does the work for us */ - emit_set_action(Swig_cmethod_call(mname, Wrapper_Getparms(w))); + emit_set_action(Swig_cmethod_call(mname, Getparms(w))); } - new_create_function(Wrapper_Getname(w), iname, Wrapper_Gettype(w), Wrapper_Getparms(w)); - DelWrapper(w); + Setattr(w,"scriptname",iname); + lang->function(w); + Delete(w); } else { lang->create_command(prev_wrap, iname); } @@ -1704,9 +1690,10 @@ void cplus_emit_static_func(char *classname, char *, char *classrename, new_create_function(cname,iname, type, l); } else { Wrapper *w = Swig_cfunction_wrapper(cname, type, l, ccode); - Wrapper_print(w,f_wrappers); - new_create_function(cname,iname, Wrapper_Gettype(w), Wrapper_Getparms(w)); - DelWrapper(w); + Printf(f_wrappers,"%s", w); + Setattr(w,"scriptname",iname); + lang->function(w); + Delete(w); } } } else { @@ -1770,19 +1757,20 @@ void cplus_emit_destructor(char *classname, char *classtype, char *classrename, } else { w = Swig_cdestructor_wrapper(fclassname, ccode); } + Setattr(w,"scriptname",iname); if (mode && ccode) { - Wrapper_print(w,f_wrappers); - new_create_function(Wrapper_Getname(w),iname,Wrapper_Gettype(w), Wrapper_Getparms(w)); + Printf(f_wrappers,"%s",w); + lang->function(w); } else if (mode) { - new_create_function(Wrapper_Getname(w),iname,Wrapper_Gettype(w), Wrapper_Getparms(w)); + lang->function(w); } else { if (CPlusPlus) emit_set_action(Swig_cppdestructor_call()); else emit_set_action(Swig_cdestructor_call()); - new_create_function(cname, iname, Wrapper_Gettype(w), Wrapper_Getparms(w)); + lang->function(w); } - DelWrapper(w); + Delete(w); } // ----------------------------------------------------------------------------- @@ -1828,7 +1816,7 @@ void cplus_emit_constructor(char *classname, char *classtype, char *classrename, } else { w = Swig_cconstructor_wrapper(fclassname, l, ccode); } - + Setattr(w,"scriptname",iname); if (!mode) { if (CPlusPlus) { emit_set_action(Swig_cppconstructor_call(fclassname, l)); @@ -1837,11 +1825,11 @@ void cplus_emit_constructor(char *classname, char *classtype, char *classrename, } } else { if (ccode) { - Wrapper_print(w,f_wrappers); + Printf(f_wrappers,"%s", w); } } - new_create_function(Wrapper_Getname(w), iname, Wrapper_Gettype(w), Wrapper_Getparms(w)); - DelWrapper(w); + lang->function(w); + Delete(w); } // ----------------------------------------------------------------------------- @@ -1922,20 +1910,20 @@ void cplus_emit_variable_get(char *classname, char *classtype, char *classrename sprintf(fclassname,"%s%s", classtype, classname); w = Swig_cmemberget_wrapper(fclassname,mname,type,ccode); - + Setattr(w,"scriptname",iname); // Only generate code if already existing wrapper doesn't exist if (!prev_wrap) { if ((mode) && (ccode)) { - Wrapper_print(w,f_wrappers); + Printf(f_wrappers,"%s", w); } else if (!mode) { emit_set_action(Swig_cmemberget_call(mname, type)); } - new_create_function(Wrapper_Getname(w),iname, Wrapper_Gettype(w), Wrapper_Getparms(w)); + lang->function(w); } else { // Already wrapped this function. Just patch it up lang->create_command(prev_wrap,iname); } - DelWrapper(w); + Delete(w); } // ----------------------------------------------------------------------------- @@ -2024,11 +2012,12 @@ void cplus_emit_variable_set(char *classname, char *classtype, char *classrename sprintf(fclassname,"%s%s",classtype,classname); w = Swig_cmemberset_wrapper(fclassname,mname,type,ccode); + Setattr(w,"scriptname",iname); // Only generate code if already existing wrapper doesn't exist if (!prev_wrap) { if ((mode) && (ccode)) { - Wrapper_print(w,f_wrappers); + Printf(f_wrappers,"%s",w); } else if (!mode) { /* Check for a member in typemap here */ String *target = NewStringf("%s->%s", Swig_cparm_name(0,0),mname); @@ -2039,11 +2028,11 @@ void cplus_emit_variable_set(char *classname, char *classtype, char *classrename emit_set_action(tm); Delete(target); } - new_create_function(Wrapper_Getname(w),iname, Wrapper_Gettype(w), Wrapper_Getparms(w)); + lang->function(w); } else { lang->create_command(prev_wrap,iname); } - DelWrapper(w); + Delete(w); } // ----------------------------------------------------------------------------- diff --git a/Source/SWIG1.1/emit.cxx b/Source/SWIG1.1/emit.cxx index 857f58133..a08102ffc 100644 --- a/Source/SWIG1.1/emit.cxx +++ b/Source/SWIG1.1/emit.cxx @@ -74,16 +74,16 @@ int emit_args(DOH *node, Wrapper *f) { tm = Swig_typemap_lookup((char*)"arginit",pt,pname,(char*)"",lname,f); if (tm) { - Printv(f->code,tm,"\n",0); + Printv(f,tm,"\n",0); } /* Check for ignore or default typemaps */ tm = Swig_typemap_lookup((char*)"default",pt,pname,(char*)"",lname,f); if (tm) { - Printv(f->code,tm,"\n",0); + Printv(f,tm,"\n",0); } tm = Swig_typemap_lookup((char*)"ignore",pt,pname,(char*)"",lname,f); if (tm) { - Printv(f->code,tm,"\n",0); + Printv(f,tm,"\n",0); Setignore(p,1); } i++; @@ -122,13 +122,13 @@ void emit_func_call(DOH *node, Wrapper *f) { l = Getattr(node,"parms"); if ((tm = Swig_typemap_lookup((char*)"except",t,decl,(char*)"result",(char*)"",0))) { - Printv(f->code,tm,0); - Replace(f->code,"$name",decl,DOH_REPLACE_ANY); + Printv(f,tm,0); + Replace(f,"$name",decl,DOH_REPLACE_ANY); } else if ((tm = Swig_except_lookup())) { - Printv(f->code,tm,0); - Replace(f->code,"$name",decl,DOH_REPLACE_ANY); + Printv(f,tm,0); + Replace(f,"$name",decl,DOH_REPLACE_ANY); } else { - Printv(f->code,"$function",0); + Printv(f,"$function",0); } if (!fcall) fcall = NewString(Swig_cfunction_call(decl,l)); @@ -200,21 +200,21 @@ void emit_set_get(DOH *node) { code = c_str; } w = Swig_cvarset_wrapper(name, t, code); - Wrapper_print(w,f_header); + Printf(f_header,"%s", w); new_iname = Swig_name_set(iname); DohIncref(new_iname); - new_create_function(Wrapper_Getname(w), Char(new_iname), Wrapper_Gettype(w), Wrapper_Getparms(w)); + new_create_function(GetChar(w,"name"), Char(new_iname), Gettype(w), Getparms(w)); Delete(new_iname); - DelWrapper(w); + Delete(w); } w = Swig_cvarget_wrapper(name,t,0); - Wrapper_print(w,f_header); + Printf(f_header,"%s", w); new_iname = Swig_name_get(iname); DohIncref(new_iname); - new_create_function(Wrapper_Getname(w), Char(new_iname), Wrapper_Gettype(w), Wrapper_Getparms(w)); + new_create_function(GetChar(w,"name"), Char(new_iname), Gettype(w), Getparms(w)); Delete(new_iname); - DelWrapper(w); + Delete(w); } /* ------------------------------------------------------------------ diff --git a/Source/SWIG1.1/lang.cxx b/Source/SWIG1.1/lang.cxx index 6d164e991..c637c0101 100644 --- a/Source/SWIG1.1/lang.cxx +++ b/Source/SWIG1.1/lang.cxx @@ -41,9 +41,11 @@ Language::nativefunction(DOH *node) { Printf(stderr,"%s : Line %d. Adding native function %s not supported (ignored).\n", input_file, line_number, Getattr(node,"scriptname")); } -static char *ClassName = 0; /* This is the real name of the current class */ -static char *ClassRename = 0; /* This is non-NULL if the class has been renamed */ -static char *ClassType = 0; /* Type of class (ie. union, struct, class) */ +static String *ClassName = 0; /* This is the real name of the current class */ +static String *ClassRename = 0; /* This is non-NULL if the class has been renamed */ +static String *ClassType = 0; /* Type of class (ie. union, struct, class) */ +static String *ClassFullname = 0; /* Full name of the class */ +static String *ClassPrefix = 0; /* Prefix used on wrappers */ /* ----------------------------------------------------------------------------- * Language::cpp_open_class() @@ -53,24 +55,32 @@ void Language::cpp_open_class(char *classname, char *classrename, char *ctype, i /* Copy the class name */ - if (ClassName) free(ClassName); - ClassName = Swig_copy_string(classname); + if (ClassName) Delete(ClassName); + ClassName = NewString(classname); /* Copy the class renaming */ - if (ClassRename) free(ClassRename); + if (ClassRename) Delete(ClassRename); if (classrename) { - ClassRename = Swig_copy_string(classrename); + ClassRename = NewString(classrename); } else { ClassRename = 0; /* No renaming */ } /* Make the class type*/ - if (ClassType) free(ClassType); - ClassType = (char *) malloc(strlen(ctype)+2); - if (strip) ClassType[0] = 0; - else sprintf(ClassType,"%s ",ctype); + if (ClassType) Delete(ClassType); + if (strip) ClassType = NewString(""); + else ClassType = NewStringf("%s ", ctype); + + if (ClassFullname) Delete(ClassFullname); + ClassFullname = NewStringf("%s%s", ClassType, ClassName); + + if (ClassRename) { + ClassPrefix = ClassRename; + } else { + ClassPrefix = ClassName; + } } /* ----------------------------------------------------------------------------- @@ -88,41 +98,44 @@ void Language::cpp_close_class() { * ----------------------------------------------------------------------------- */ void Language::cpp_memberfunction(DOH *node) { - char *name, *iname; - SwigType *t; - ParmList *l; - char new_name[256]; - char *prefix; + String *name; + String *iname; + String *ccode; + String *script_name; + SwigType *type; + ParmList *parms; + Wrapper *w; - name = GetChar(node,"name"); - iname = GetChar(node,"scriptname"); - t = Getattr(node,"type"); - l = Getattr(node,"parms"); + name = Getattr(node,"name"); + iname = Getattr(node,"scriptname"); + type = Getattr(node,"type"); + parms = Getattr(node,"parms"); + ccode = Getattr(node,"ccode"); /* Generate the C wrapper function name and interpreter name of this function*/ - - /* Set the classname prefix */ - if (ClassRename) { - prefix = ClassRename; - } else { - prefix = ClassName; - } /* Create the actual function name */ - if (iname) { - strcpy(new_name, Char(Swig_name_member(prefix,iname))); - } else { - strcpy(new_name, Char(Swig_name_member(prefix,name))); - } + script_name = Swig_name_member(ClassPrefix, iname ? iname : name); /* Now do a symbol table lookup on it : */ - - if (add_symbol(new_name)) { + if (add_symbol(Char(script_name))) { Printf(stderr,"%s : Line %d. Function %s (member %s) multiply defined (2nd definition ignored).\n", input_file, line_number, iname, name); return; } - cplus_emit_member_func(ClassName, ClassType, ClassRename, name, iname, t, l, AddMethods); + + /* Create the C wrapper function for this */ + w = Swig_cmethod_wrapper(ClassFullname, name, type, parms, ccode); + if (AddMethods && ccode) { + /* Dump the C wrappers */ + Printf(f_wrappers,"%s",w); + } else if (!AddMethods) { + /* Just create a string that does what we want */ + emit_set_action(Swig_cmethod_call(name, Getparms(w))); + } + Setattr(w,"scriptname",script_name); + lang->function(w); + Delete(w); } /* ----------------------------------------------------------------------------- @@ -132,32 +145,21 @@ void Language::cpp_memberfunction(DOH *node) { void Language::cpp_constructor(DOH *node) { char *name, *iname; ParmList *l; - char *prefix, *cname; + char *cname; name = GetChar(node,"name"); iname = GetChar(node,"scriptname"); l = Getattr(node,"parms"); - if ((strcmp(name,ClassName)) && (!ObjCClass)) { + if ((strcmp(name,Char(ClassName))) && (!ObjCClass)) { Printf(stderr,"%s : Line %d. Function %s must have a return type.\n", input_file, line_number, name); return; } - - /* Set the prefix */ - - if (ClassRename) - prefix = ClassRename; - else - prefix = ClassName; - - if (iname) - cname = Char(Swig_name_construct(iname)); - else - cname = Char(Swig_name_construct(prefix)); + + cname = Char(Swig_name_construct(iname ? iname : ClassPrefix)); /* Add this function to the SWIG symbol table */ - if (add_symbol(cname)) { Printf(stderr,"%s : Line %d. Constructor %s multiply defined (2nd definition ignored).\n", input_file, line_number, cname); @@ -165,8 +167,7 @@ void Language::cpp_constructor(DOH *node) { } /* Call our default method */ - - cplus_emit_constructor(ClassName, ClassType, ClassRename, name, iname, l, AddMethods); + cplus_emit_constructor(Char(ClassName), Char(ClassType), Char(ClassRename), name, iname, l, AddMethods); } @@ -180,10 +181,7 @@ void Language::cpp_destructor(DOH *node) { name = GetChar(node,"name"); iname = GetChar(node,"scriptname"); - if (ClassRename) - cname = Char(Swig_name_destroy(ClassRename)); - else - cname = Char(Swig_name_destroy(ClassName)); + cname = Char(Swig_name_destroy(ClassRename ? ClassRename : ClassName)); /* Add this function to the SWIG symbol table */ @@ -196,7 +194,7 @@ void Language::cpp_destructor(DOH *node) { /* Call our default method */ - cplus_emit_destructor(ClassName, ClassType, ClassRename, name, iname, AddMethods); + cplus_emit_destructor(Char(ClassName), Char(ClassType), Char(ClassRename), name, iname, AddMethods); } @@ -233,41 +231,29 @@ void Language::cpp_inherit(char **baseclass, int mode) { void Language::cpp_variable(DOH *node) { char *name, *iname; SwigType *t; - char *prefix, *cname; + char *cname; name = GetChar(node,"name"); iname = GetChar(node,"scriptname"); t = Getattr(node,"type"); /* Set the class prefix */ - - if (ClassRename) { - prefix = ClassRename; - } else { - prefix = ClassName; - } - if (iname) - cname = Char(Swig_name_get(Swig_name_member(prefix,iname))); - else - cname = Char(Swig_name_get(Swig_name_member(prefix,name))); + cname = Char(Swig_name_get(Swig_name_member(ClassPrefix, iname ? iname : name))); /* Check the symbol table */ - if (add_symbol(cname)) { Printf(stderr,"%s : Line %d. Variable %s multiply defined (2nd definition ignored).\n", input_file, line_number, cname); return; } /* Create a function to set the value of the variable */ - if (!(Status & STAT_READONLY)) { - cplus_emit_variable_set(ClassName, ClassType, ClassRename, name, iname, t, AddMethods); + cplus_emit_variable_set(Char(ClassName), Char(ClassType), Char(ClassRename), name, iname, t, AddMethods); } /* Create a function to get the value of a variable */ - - cplus_emit_variable_get(ClassName,ClassType, ClassRename, name, iname, t, AddMethods); + cplus_emit_variable_get(Char(ClassName),Char(ClassType), Char(ClassRename), name, iname, t, AddMethods); } @@ -279,8 +265,6 @@ void Language::cpp_staticfunction(DOH *node) { char *name, *iname; SwigType *t; ParmList *l; - char *prefix; - char *mname; char *cname; name = GetChar(node,"name"); @@ -288,21 +272,9 @@ void Language::cpp_staticfunction(DOH *node) { t = Getattr(node,"type"); l = Getattr(node,"parms"); - /* Set the classname prefix */ - - if (ClassRename) - prefix = ClassRename; - else - prefix = ClassName; - /* Set the member function name */ - if (iname) - mname = iname; - else - mname = name; - - cname = Char(Swig_name_member(prefix,mname)); + cname = Char(Swig_name_member(ClassPrefix,iname ? iname : name)); /* Now do a symbol table lookup on it : */ @@ -315,8 +287,7 @@ void Language::cpp_staticfunction(DOH *node) { input_file, line_number, cname); return; } - cplus_emit_static_func(ClassName,ClassType, ClassRename, name, iname, t, l, AddMethods); - + cplus_emit_static_func(Char(ClassName),Char(ClassType), Char(ClassRename), name, iname, t, l, AddMethods); } /* ----------------------------------------------------------------------------- @@ -330,31 +301,18 @@ void Language::cpp_constant(DOH *node) char *cname; char mname[256]; - char *new_value; - char *prefix; + String *new_value; name = GetChar(node,"name"); iname = GetChar(node,"scriptname"); value = GetChar(node,"value"); type = Getattr(node,"type"); - /* Set the classname prefix */ - - if (ClassRename) { - prefix = ClassRename; - } else { - prefix = ClassName; - } - /* Set the constant name */ - if (iname) - cname = Char(Swig_name_member(prefix,iname)); - else - cname = Char(Swig_name_member(prefix,name)); + cname = Char(Swig_name_member(ClassPrefix, iname ? iname : name)); /* Now do a symbol table lookup on it : */ - if (add_symbol(cname)) { Printf(stderr,"%s : Line %d. Constant %s (member %s) multiply defined (2nd definition ignored).\n", input_file, line_number, cname, name); @@ -362,15 +320,13 @@ void Language::cpp_constant(DOH *node) } /* Form correct C++ name */ - sprintf(mname,"%s::%s",ClassName,name); /* Declare a constant */ if (!value) { - new_value = (char *) malloc(strlen(ClassName)+strlen(name)+3); - sprintf(new_value,"%s::%s",ClassName,name); + new_value = NewStringf("%s::%s", ClassName, name); } else { - new_value = value; + new_value = NewString(value); } Hash *n; n = NewHash(); @@ -380,10 +336,7 @@ void Language::cpp_constant(DOH *node) Setattr(n,"value",new_value); lang->constant(n); Delete(n); - - if (!value) { - free(new_value); - } + Delete(new_value); } /* ----------------------------------------------------------------------------- @@ -395,29 +348,16 @@ void Language::cpp_staticvariable(DOH *node) { SwigType *t; char *cname; char mname[256]; - char *prefix; name = GetChar(node,"name"); iname = GetChar(node,"scriptname"); t = Getattr(node,"type"); - /* Set the classname prefix */ - - if (ClassRename) { - prefix = ClassRename; - } else { - prefix = ClassName; - } - /* Create the variable name */ - - if (iname) - cname = Char(Swig_name_member(prefix,iname)); - else - cname = Char(Swig_name_member(prefix,name)); + + cname = Char(Swig_name_member(ClassPrefix, iname ? iname : name)); /* Now do a symbol table lookup on it : */ - if (add_symbol(cname)) { Printf(stderr,"%s : Line %d. Variable %s (member %s) multiply defined (2nd definition ignored).\n", input_file, line_number, cname, name); @@ -425,7 +365,6 @@ void Language::cpp_staticvariable(DOH *node) { } /* Form correct C++ name */ - sprintf(mname,"%s::%s",ClassName,name); /* Link with this variable */ diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index efa006550..b4c524299 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -215,8 +215,8 @@ void Swig_cresult(Wrapper *w, SwigType *t, String_or_char *name, String_or_char Printf(fcall,"%s = (%s) &_result_ref;\n", name, SwigType_lstr(t,0)); } - if (Replace(w->code,"$function",fcall, DOH_REPLACE_ANY) == 0) { - Printv(w->code, fcall, 0); + if (Replace(w,"$function",fcall, DOH_REPLACE_ANY) == 0) { + Printv(w, fcall, 0); } Delete(fcall); } @@ -278,8 +278,8 @@ void Swig_cppresult(Wrapper *w, SwigType *t, String_or_char *name, String_or_cha break; } - if (Replace(w->code,"$function",fcall, DOH_REPLACE_ANY) == 0) { - Printv(w->code, fcall, 0); + if (Replace(w,"$function",fcall, DOH_REPLACE_ANY) == 0) { + Printv(w, fcall, 0); } Delete(fcall); } @@ -519,18 +519,19 @@ Swig_cfunction_wrapper(String_or_char *funcname, w = NewWrapper(); /* Set the name of the function */ - Wrapper_Setname(w,funcname); + Setname(w,funcname); l = CopyParmList(parms); fix_parm_names(l); - Printf(w->def,"%s %s(%s) {", SwigType_str(rtype,0), funcname, ParmList_str(l)); + Printf(w,"%s %s(%s) {\n", SwigType_str(rtype,0), funcname, ParmList_str(l)); + Printf(w,"$locals\n"); if (code) { - Printv(w->code, code, "\n", 0); + Printv(w, code, "\n", 0); } - Printf(w->code,"}\n"); - Wrapper_Settype(w,rtype); - Wrapper_Setparms(w,l); + Printf(w,"}\n"); + Setattr(w,"type",rtype); + Setattr(w,"parms",l); Delete(l); return w; } @@ -557,7 +558,7 @@ Swig_cmethod_wrapper(String_or_char *classname, w = NewWrapper(); /* Set the name of the function */ - Wrapper_Setname(w,Swig_name_member(classname, methodname)); + Setname(w,Swig_name_member(classname, methodname)); l = CopyParmList(parms); t = NewString(classname); @@ -569,30 +570,31 @@ Swig_cmethod_wrapper(String_or_char *classname, l = p; fix_parm_names(l); - Printf(w->def,"%s %s(%s) {", SwigType_str(rtype,0), Swig_name_member(classname, methodname), ParmList_str(l)); + Printf(w,"%s %s(%s) {\n", SwigType_str(rtype,0), Swig_name_member(classname, methodname), ParmList_str(l)); + Printf(w,"$locals\n"); if (!code) { /* No code supplied. Write a function manually */ if (SwigType_type(rtype) != T_VOID) { - Printf(w->code,"return "); + Printf(w,"return "); } - Printf(w->code,"self->%s(", methodname); + Printf(w,"self->%s(", methodname); p = Getnext(l); while (p) { - Printf(w->code,"%s", Getname(p)); + Printf(w,"%s", Getname(p)); p = Getnext(p); if (p) - Printf(w->code,","); + Printf(w,","); } - Printf(w->code,");\n"); - Printf(w->code,"}\n"); + Printf(w,");\n"); + Printf(w,"}\n"); } else { - Printv(w->code, code, "\n", 0); - Printf(w->code,"}\n"); + Printv(w, code, "\n", 0); + Printf(w,"}\n"); } - Wrapper_Settype(w,rtype); - Wrapper_Setparms(w,l); + Setattr(w,"type",rtype); + Setattr(w,"parms",l); Delete(l); return w; } @@ -616,7 +618,7 @@ Swig_cconstructor_wrapper(String_or_char *classname, w = NewWrapper(); /* Set the name of the function */ - Wrapper_Setname(w,Swig_name_construct(classname)); + Setname(w,Swig_name_construct(classname)); l = CopyParmList(parms); t = NewString(classname); @@ -625,17 +627,18 @@ Swig_cconstructor_wrapper(String_or_char *classname, /* Patch up the argument names */ fix_parm_names(l); - Printf(w->def,"%s %s(%s) {", SwigType_str(t,0), Swig_name_construct(classname), ParmList_str(l)); + Printf(w,"%s %s(%s) {\n", SwigType_str(t,0), Swig_name_construct(classname), ParmList_str(l)); + Printf(w,"$locals\n"); if (!code) { /* No code supplied. Write a function manually */ - Printf(w->code,"return (%s) calloc(1,sizeof(%s));\n", SwigType_str(t,0), classname); + Printf(w,"return (%s) calloc(1,sizeof(%s));\n", SwigType_str(t,0), classname); } else { - Printv(w->code, code, "\n", 0); + Printv(w, code, "\n", 0); } - Printf(w->code,"}\n"); - Wrapper_Settype(w,t); - Wrapper_Setparms(w,l); + Printf(w,"}\n"); + Setattr(w,"type",t); + Setattr(w,"parms",l); Delete(l); Delete(t); return w; @@ -660,7 +663,7 @@ Swig_cppconstructor_wrapper(String_or_char *classname, w = NewWrapper(); /* Set the name of the function */ - Wrapper_Setname(w,Swig_name_construct(classname)); + Setname(w,Swig_name_construct(classname)); l = CopyParmList(parms); t = NewString(classname); @@ -669,29 +672,30 @@ Swig_cppconstructor_wrapper(String_or_char *classname, /* Patch up the argument names */ fix_parm_names(l); - Printf(w->def,"%s %s(%s) {", SwigType_str(t,0), Swig_name_construct(classname), ParmList_str(l)); + Printf(w,"%s %s(%s) {\n", SwigType_str(t,0), Swig_name_construct(classname), ParmList_str(l)); + Printf(w,"$locals\n"); if (!code) { /* No code supplied. Write a function manually */ - Printf(w->code,"return new %s", SwigType_str(t,0)); + Printf(w,"return new %s", SwigType_str(t,0)); p = l; if (p) { - Printf(w->code,"("); + Printf(w,"("); while (p) { - Printf(w->code,"%s", Getname(p)); + Printf(w,"%s", Getname(p)); p = Getnext(p); if (p) - Printf(w->code,","); + Printf(w,","); } - Printf(w->code,")"); + Printf(w,")"); } - Printf(w->code,";\n"); + Printf(w,";\n"); } else { - Printv(w->code, code, "\n", 0); + Printv(w, code, "\n", 0); } - Printf(w->code,"}\n"); - Wrapper_Settype(w,t); - Wrapper_Setparms(w,l); + Printf(w,"}\n"); + Setattr(w,"type",t); + Setattr(w,"parms",l); Delete(l); Delete(t); return w; @@ -716,7 +720,7 @@ Swig_cdestructor_wrapper(String_or_char *classname, w = NewWrapper(); /* Set the name of the function */ - Wrapper_Setname(w,Swig_name_destroy(classname)); + Setname(w, Swig_name_destroy(classname)); t = NewString(classname); SwigType_add_pointer(t); @@ -726,17 +730,18 @@ Swig_cdestructor_wrapper(String_or_char *classname, t = NewString("void"); - Printf(w->def,"%s %s(%s) {", SwigType_str(t,0), Swig_name_destroy(classname), ParmList_str(l)); + Printf(w,"%s %s(%s) {\n", SwigType_str(t,0), Swig_name_destroy(classname), ParmList_str(l)); + Printf(w,"$locals\n"); if (!code) { /* No code supplied. Write a function manually */ - Printf(w->code,"free((char *) self);\n"); + Printf(w,"free((char *) self);\n"); } else { - Printv(w->code, code, "\n", 0); + Printv(w, code, "\n", 0); } - Printf(w->code,"}\n"); - Wrapper_Settype(w,t); - Wrapper_Setparms(w,l); + Printf(w,"}\n"); + Setattr(w,"type",t); + Setattr(w,"parms",l); Delete(l); Delete(t); return w; @@ -761,7 +766,7 @@ Swig_cppdestructor_wrapper(String_or_char *classname, w = NewWrapper(); /* Set the name of the function */ - Wrapper_Setname(w,Swig_name_destroy(classname)); + Setname(w, Swig_name_destroy(classname)); t = NewString(classname); SwigType_add_pointer(t); @@ -772,17 +777,18 @@ Swig_cppdestructor_wrapper(String_or_char *classname, t = NewString("void"); - Printf(w->def,"%s %s(%s) {", SwigType_str(t,0), Swig_name_destroy(classname), ParmList_str(l)); + Printf(w,"%s %s(%s) {\n", SwigType_str(t,0), Swig_name_destroy(classname), ParmList_str(l)); + Printf(w,"$locals\n"); if (!code) { /* No code supplied. Write a function manually */ - Printf(w->code,"delete self;\n"); + Printf(w,"delete self;\n"); } else { - Printv(w->code, code, "\n", 0); + Printv(w, code, "\n", 0); } - Printf(w->code,"}\n"); - Wrapper_Settype(w,t); - Wrapper_Setparms(w,l); + Printf(w,"}\n"); + Setattr(w,"type",t); + Setattr(w,"parms",l); Delete(l); Delete(t); return w; @@ -809,7 +815,7 @@ Swig_cmemberset_wrapper(String_or_char *classname, w = NewWrapper(); /* Set the name of the function */ - Wrapper_Setname(w,Swig_name_member(classname, Swig_name_set(membername))); + Setname(w, Swig_name_member(classname, Swig_name_set(membername))); t = NewString(classname); SwigType_add_pointer(t); @@ -821,20 +827,20 @@ Swig_cmemberset_wrapper(String_or_char *classname, p = NewParm(lt,"value"); Setnext(l,p); - /* Printf(w->def,"%s %s(%s) {", SwigType_str(lt,0), Wrapper_Getname(w), ParmList_str(l)); */ - Printf(w->def,"void %s(%s) {", Wrapper_Getname(w), ParmList_str(l)); + Printf(w,"void %s(%s) {\n", Getname(w), ParmList_str(l)); + Printf(w,"$locals\n"); if (!code) { /* No code supplied. Write a function manually */ - Printf(w->code,"self->%s = %s;\n", membername, Swig_clocal_deref(lt,"value")); - Printf(w->code,"return %s self->%s;\n", Swig_clocal_assign(lt,""), membername); + Printf(w,"self->%s = %s;\n", membername, Swig_clocal_deref(lt,"value")); + Printf(w,"return %s self->%s;\n", Swig_clocal_assign(lt,""), membername); } else { - Printv(w->code, code, "\n", 0); + Printv(w, code, "\n", 0); } - Printf(w->code,"}\n"); + Printf(w,"}\n"); /* Wrapper_Settype(w,lt); */ - Wrapper_Settype(w,"void"); - Wrapper_Setparms(w,l); + Setattr(w,"type","void"); + Setattr(w,"parms", l); Delete(l); Delete(lt); return w; @@ -862,7 +868,7 @@ Swig_cmemberget_wrapper(String_or_char *classname, w = NewWrapper(); /* Set the name of the function */ - Wrapper_Setname(w,Swig_name_member(classname, Swig_name_get(membername))); + Setname(w,Swig_name_member(classname, Swig_name_get(membername))); t = NewString(classname); SwigType_add_pointer(t); @@ -871,17 +877,18 @@ Swig_cmemberget_wrapper(String_or_char *classname, Delete(t); lt = Swig_clocal_type(type); - Printf(w->def,"%s %s(%s) {", SwigType_str(lt,0), Wrapper_Getname(w), ParmList_str(l)); + Printf(w,"%s %s(%s) {\n", SwigType_str(lt,0), Getname(w), ParmList_str(l)); + Printf(w,"$locals\n"); if (!code) { /* No code supplied. Write a function manually */ - Printf(w->code,"return %s self->%s;", Swig_clocal_assign(lt,""), membername); + Printf(w,"return %s self->%s;", Swig_clocal_assign(lt,""), membername); } else { - Printv(w->code, code, "\n", 0); + Printv(w, code, "\n", 0); } - Printf(w->code,"}\n"); - Wrapper_Settype(w,lt); - Wrapper_Setparms(w,l); + Printf(w,"}\n"); + Setattr(w,"type",lt); + Setattr(w,"parms",l); Delete(l); Delete(lt); return w; @@ -906,28 +913,29 @@ Swig_cvarset_wrapper(String_or_char *varname, w = NewWrapper(); /* Set the name of the function */ - Wrapper_Setname(w,Swig_name_set(varname)); + Setname(w,Swig_name_set(varname)); lt = Swig_clocal_type(type); p = NewParm(lt,"value"); l = p; - Printf(w->def,"%s %s(%s) {", SwigType_str(lt,0), Wrapper_Getname(w), ParmList_str(l)); + Printf(w,"%s %s(%s) {\n", SwigType_str(lt,0), Getname(w), ParmList_str(l)); + Printf(w,"$locals"); if (!code) { /* No code supplied. Write a function manually */ - Printf(w->code,"%s = %s;\n", varname, Swig_clocal_deref(lt,"value")); - Printf(w->code,"return %s;\n", Swig_clocal_assign(lt,varname)); + Printf(w,"%s = %s;\n", varname, Swig_clocal_deref(lt,"value")); + Printf(w,"return %s;\n", Swig_clocal_assign(lt,varname)); } else { - Printv(w->code, code, "\n", 0); - Replace(w->code,"$target",varname, DOH_REPLACE_ANY); - Replace(w->code,"$source","value", DOH_REPLACE_ANY); - Replace(w->code,"$ltype", SwigType_str(lt,""), DOH_REPLACE_ANY); - Replace(w->code,"$rtype", SwigType_str(type,""), DOH_REPLACE_ANY); + Printv(w, code, "\n", 0); + Replace(w,"$target",varname, DOH_REPLACE_ANY); + Replace(w,"$source","value", DOH_REPLACE_ANY); + Replace(w,"$ltype", SwigType_str(lt,""), DOH_REPLACE_ANY); + Replace(w,"$rtype", SwigType_str(type,""), DOH_REPLACE_ANY); } - Printf(w->code,"}\n"); - Wrapper_Settype(w,lt); - Wrapper_Setparms(w,l); + Printf(w,"}\n"); + Setattr(w,"type",lt); + Setattr(w,"parms",l); Delete(l); Delete(lt); return w; @@ -951,21 +959,22 @@ Swig_cvarget_wrapper(String_or_char *varname, w = NewWrapper(); /* Set the name of the function */ - Wrapper_Setname(w, Swig_name_get(varname)); + Setname(w,Swig_name_get(varname)); lt = Swig_clocal_type(type); - Printf(w->def,"%s %s(%s) {", SwigType_str(lt,0), Wrapper_Getname(w), ParmList_str(l)); + Printf(w,"%s %s(%s) {\n", SwigType_str(lt,0), Getname(w), ParmList_str(l)); + Printf(w,"$locals"); if (!code) { /* No code supplied. Write a function manually */ - Printf(w->code,"return %s;", Swig_clocal_assign(type,varname)); + Printf(w,"return %s;", Swig_clocal_assign(type,varname)); } else { - Printv(w->code, code, "\n", 0); + Printv(w, code, "\n", 0); } - Printf(w->code,"}\n"); - Wrapper_Settype(w,lt); - Wrapper_Setparms(w,l); + Printf(w,"}\n"); + Setattr(w,"type",lt); + Setattr(w,"parms",l); Delete(l); Delete(lt); return w; diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 1236c2401..92442c9f9 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -263,31 +263,15 @@ extern void Swig_dump_rules(); /* -- Wrapper function Object */ -typedef struct { - SwigType *_type; - ParmList *_parms; - String *_name; - Hash *localh; - String *def; - String *locals; - String *code; -} Wrapper; +typedef DOH Wrapper; extern Wrapper *NewWrapper(); -extern void DelWrapper(Wrapper *w); extern void Wrapper_pretty_print(String *str, File *f); -extern void Wrapper_print(Wrapper *w, File *f); extern int Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *decl); extern int Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...); extern int Wrapper_check_local(Wrapper *w, const String_or_char *name); extern char *Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *decl); extern char *Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...); -extern SwigType *Wrapper_Gettype(Wrapper *w); -extern void Wrapper_Settype(Wrapper *w, SwigType *t); -extern ParmList *Wrapper_Getparms(Wrapper *w); -extern void Wrapper_Setparms(Wrapper *w, ParmList *l); -extern char *Wrapper_Getname(Wrapper *w); -extern void Wrapper_Setname(Wrapper *w, String_or_char *name); /* --- Naming functions --- */ diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 34e99e937..78d635a49 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -429,7 +429,7 @@ char *Swig_typemap_lookup(char *op, SwigType *type, String_or_char *pname, Strin DOHString *dim = SwigType_array_getdim(type,i); sprintf(temp,"$dim%d",i); if (f) - Replace(f->locals,temp,dim, DOH_REPLACE_ANY); + Replace(Getattr(f,"locals"),temp,dim, DOH_REPLACE_ANY); Replace(s,temp,dim,DOH_REPLACE_ANY); } } diff --git a/Source/Swig/wrapfunc.c b/Source/Swig/wrapfunc.c index f080b2597..9fd036e83 100644 --- a/Source/Swig/wrapfunc.c +++ b/Source/Swig/wrapfunc.c @@ -19,42 +19,25 @@ static char cvsroot[] = "$Header$"; #include "swig.h" #include -/* ----------------------------------------------------------------------------- - * NewWrapper() - * - * Create a new wrapper function object. - * ----------------------------------------------------------------------------- */ +#include "dohobj.h" -Wrapper * -NewWrapper() { - Wrapper *w; - w = (Wrapper *) malloc(sizeof(Wrapper)); - w->localh = NewHash(); - w->locals = NewString(""); - w->code = NewString(""); - w->def = NewString(""); - w->_type = 0; - w->_parms = 0; - w->_name = 0; - return w; -} +typedef struct { + Hash *attr; /* Attributes */ + Hash *localh; /* Hash of local variable names */ + String *code; /* Code string */ +} WrapObj; /* ----------------------------------------------------------------------------- * DelWrapper() - * - * Delete a wrapper function object. * ----------------------------------------------------------------------------- */ -void -DelWrapper(Wrapper *w) { +static void +DelWrapper(DOH *wo) { + WrapObj *w = (WrapObj *) ObjData(wo); Delete(w->localh); - Delete(w->locals); Delete(w->code); - Delete(w->def); - Delete(w->_type); - Delete(w->_parms); - Delete(w->_name); - free(w); + Delete(w->attr); + DohFree(w); } /* ----------------------------------------------------------------------------- @@ -139,20 +122,37 @@ Wrapper_pretty_print(String *str, File *f) { /* ----------------------------------------------------------------------------- - * Wrapper_print() + * Wrapper_str() * - * Print out a wrapper function. Does pretty printing as well. + * Create a string representation of the wrapper function. * ----------------------------------------------------------------------------- */ -void -Wrapper_print(Wrapper *w, File *f) { - String *str; +static String * +Wrapper_str(DOH *wo) { + String *s, *s1; + WrapObj *w = (WrapObj *) ObjData(wo); + s = NewString(w->code); + s1 = NewString(""); + Replace(s,"$locals", Getattr(w->attr,"locals"), DOH_REPLACE_ANY); + Wrapper_pretty_print(s,s1); + Delete(s); + return s1; +} - str = NewString(""); - Printf(str,"%s\n", w->def); - Printf(str,"%s\n", w->locals); - Printf(str,"%s\n", w->code); - Wrapper_pretty_print(str,f); +/* ----------------------------------------------------------------------------- + * Wrapper_dump() + * + * Serialize on out + * ----------------------------------------------------------------------------- */ + +static int +Wrapper_dump(DOH *wo, DOH *out) { + String *s; + int len; + s = Wrapper_str(wo); + len = Dump(s,out); + Delete(s); + return len; } /* ----------------------------------------------------------------------------- @@ -163,13 +163,14 @@ Wrapper_print(Wrapper *w, File *f) { * ----------------------------------------------------------------------------- */ int -Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *decl) { +Wrapper_add_local(Wrapper *wo, const String_or_char *name, const String_or_char *decl) { + WrapObj *w = (WrapObj *) ObjData(wo); /* See if the local has already been declared */ if (Getattr(w->localh,name)) { return -1; } Setattr(w->localh,name,decl); - Printf(w->locals,"%s;\n", decl); + Printf(Getattr(w->attr,"locals"),"%s;\n", decl); return 0; } @@ -182,11 +183,12 @@ Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char * * ----------------------------------------------------------------------------- */ int -Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) { +Wrapper_add_localv(Wrapper *wo, const String_or_char *name, ...) { va_list ap; int ret; String *decl; DOH *obj; + WrapObj *w = (WrapObj *) ObjData(wo); decl = NewString(""); va_start(ap,name); @@ -198,7 +200,7 @@ Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) { } va_end(ap); - ret = Wrapper_add_local(w,name,decl); + ret = Wrapper_add_local(wo,name,decl); Delete(decl); return ret; } @@ -210,7 +212,8 @@ Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) { * ----------------------------------------------------------------------------- */ int -Wrapper_check_local(Wrapper *w, const String_or_char *name) { +Wrapper_check_local(Wrapper *wo, const String_or_char *name) { + WrapObj *w = (WrapObj *) ObjData(wo); if (Getattr(w->localh,name)) { return 1; } @@ -225,12 +228,12 @@ Wrapper_check_local(Wrapper *w, const String_or_char *name) { * ----------------------------------------------------------------------------- */ char * -Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *decl) { +Wrapper_new_local(Wrapper *wo, const String_or_char *name, const String_or_char *decl) { int i; + char *ret; String *nname = NewString(name); String *ndecl = NewString(decl); - char *ret; - + WrapObj *w = (WrapObj *) ObjData(wo); i = 0; while (Wrapper_check_local(w,nname)) { @@ -240,7 +243,7 @@ Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char * } Replace(ndecl, name, nname, DOH_REPLACE_ID); Setattr(w->localh,nname,ndecl); - Printf(w->locals,"%s;\n", ndecl); + Printf(Getattr(w->attr,"locals"),"%s;\n", ndecl); ret = Char(nname); Delete(nname); Delete(ndecl); @@ -257,11 +260,12 @@ Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char * * ----------------------------------------------------------------------------- */ char * -Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...) { +Wrapper_new_localv(Wrapper *wo, const String_or_char *name, ...) { va_list ap; char *ret; String *decl; DOH *obj; + WrapObj *w = (WrapObj *) ObjData(wo); decl = NewString(""); va_start(ap,name); @@ -273,71 +277,188 @@ Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...) { } va_end(ap); - ret = Wrapper_new_local(w,name,decl); + ret = Wrapper_new_local(wo,name,decl); Delete(decl); return ret; } /* ----------------------------------------------------------------------------- - * Wrapper_Gettype() + * Wrapper_Getattr() * ----------------------------------------------------------------------------- */ -SwigType * -Wrapper_Gettype(Wrapper *w) { - return w->_type; +static DOH * +Wrapper_getattr(Wrapper *wo, DOH *k) { + WrapObj *w = (WrapObj *) ObjData(wo); + return Getattr(w->attr,k); } /* ----------------------------------------------------------------------------- - * Wrapper_Settype() + * Wrapper_Delattr() * ----------------------------------------------------------------------------- */ -void -Wrapper_Settype(Wrapper *w, SwigType *t) { - Delete(w->_type); - w->_type = NewString(t); +static int +Wrapper_delattr(Wrapper *wo, DOH *k) { + WrapObj *w = (WrapObj *) ObjData(wo); + Delattr(w->attr,k); + return 0; } /* ----------------------------------------------------------------------------- - * Wrapper_Getparms() + * Wrapper_Setattr() * ----------------------------------------------------------------------------- */ -ParmList * -Wrapper_Getparms(Wrapper *w) { - return w->_parms; +static int +Wrapper_setattr(Wrapper *wo, DOH *k, DOH *obj) { + WrapObj *w = (WrapObj *) ObjData(wo); + return Setattr(w->attr,k,obj); } /* ----------------------------------------------------------------------------- - * Wrapper_Setparms() + * Wrapper_firstkey() * ----------------------------------------------------------------------------- */ -void -Wrapper_Setparms(Wrapper *w, ParmList *l) { - Delete(w->_parms); - w->_parms = l; - DohIncref(l); +static DOH * +Wrapper_firstkey(Wrapper *wo) { + WrapObj *w = (WrapObj *) ObjData(wo); + return Firstkey(w->attr); } /* ----------------------------------------------------------------------------- - * Wrapper_Getname() + * Wrapper_firstkey() * ----------------------------------------------------------------------------- */ -char * -Wrapper_Getname(Wrapper *w) { - return Char(w->_name); +static DOH * +Wrapper_nextkey(Wrapper *wo) { + WrapObj *w = (WrapObj *) ObjData(wo); + return Nextkey(w->attr); +} + +/* File methods. These simply operate on the code string */ + +static int +Wrapper_read(Wrapper *wo, void *buffer, int nbytes) { + WrapObj *w = (WrapObj *) ObjData(wo); + return Read(w->code,buffer,nbytes); +} + +static int +Wrapper_write(Wrapper *wo, void *buffer, int nbytes) { + WrapObj *w = (WrapObj *) ObjData(wo); + return Write(w->code,buffer,nbytes); +} + +static int +Wrapper_putc(Wrapper *wo, int ch) { + WrapObj *w = (WrapObj *) ObjData(wo); + return Putc(ch, w->code); +} + +static int +Wrapper_getc(Wrapper *wo) { + WrapObj *w = (WrapObj *) ObjData(wo); + return Getc(w->code); +} + +static int +Wrapper_ungetc(Wrapper *wo, int ch) { + WrapObj *w = (WrapObj *) ObjData(wo); + return Ungetc(ch, w->code); +} + +static int +Wrapper_seek(Wrapper *wo, long offset, int whence) { + WrapObj *w = (WrapObj *) ObjData(wo); + return Seek(w->code, offset, whence); +} + +static long +Wrapper_tell(Wrapper *wo) { + WrapObj *w = (WrapObj *) ObjData(wo); + return Tell(w->code); +} + +/* String method */ + +static int Wrapper_replace(DOH *wo, DOH *tok, DOH *rep, int flags) { + WrapObj *w = (WrapObj *) ObjData(wo); + return Replace(w->code, tok, rep, flags); } /* ----------------------------------------------------------------------------- - * Wrapper_Setname() + * type information * ----------------------------------------------------------------------------- */ -void -Wrapper_Setname(Wrapper *w, String_or_char *n) { - Delete(w->_name); - w->_name = NewString(n); +static DohHashMethods WrapperHashMethods = { + Wrapper_getattr, + Wrapper_setattr, + Wrapper_delattr, + Wrapper_firstkey, + Wrapper_nextkey, +}; + +static DohFileMethods WrapperFileMethods = { + Wrapper_read, + Wrapper_write, + Wrapper_putc, + Wrapper_getc, + Wrapper_ungetc, + Wrapper_seek, + Wrapper_tell, + 0, /* close */ +}; + +static DohStringMethods WrapperStringMethods = { + Wrapper_replace, + 0, +}; + +static DohObjInfo WrapperType = { + "Wrapper", /* objname */ + DelWrapper, /* doh_del */ + 0, /* doh_copy */ + 0, /* doh_clear */ + Wrapper_str, /* doh_str */ + 0, /* doh_data */ + 0, /* doh_dump */ + 0, /* doh_len */ + 0, /* doh_hash */ + 0, /* doh_cmp */ + 0, /* doh_setfile */ + 0, /* doh_getfile */ + 0, /* doh_setline */ + 0, /* doh_getline */ + &WrapperHashMethods, /* doh_mapping */ + 0, /* doh_sequence */ + &WrapperFileMethods, /* doh_file */ + &WrapperStringMethods, /* doh_string */ + 0, /* doh_positional */ + 0, +}; + +/* ----------------------------------------------------------------------------- + * NewWrapper() + * + * Create a new wrapper function object. + * ----------------------------------------------------------------------------- */ + +#define DOHTYPE_WRAPPER 0xa + +Wrapper * +NewWrapper() { + WrapObj *w; + static int init = 0; + if (!init) { + DohRegisterType(DOHTYPE_WRAPPER, &WrapperType); + init = 1; + } + w = (WrapObj *) DohMalloc(sizeof(WrapObj)); + w->localh = NewHash(); + w->code = NewString(""); + w->attr= NewHash(); + Setattr(w->attr,"locals",""); + Setattr(w->attr,"wrapcode", w->code); + return DohObjMalloc(DOHTYPE_WRAPPER, w); } - - -