Major reworking of the Wrapper object. It is now a DOH object.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@948 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-11-22 23:14:01 +00:00
commit a543ad49f7
14 changed files with 717 additions and 653 deletions

View file

@ -549,3 +549,4 @@ NewHash() {
h->line = 0; h->line = 0;
return DohObjMalloc(DOHTYPE_HASH,h); return DohObjMalloc(DOHTYPE_HASH,h);
} }

View file

@ -363,18 +363,18 @@ get_pointer (char *iname, int parm, SwigType *t,
{ {
SwigType_remember(t); SwigType_remember(t);
/* Pointers are smobs */ /* 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) if (SwigType_type(t) == T_VOID)
Printf(f->code, ", NULL)) {\n"); Printf(f, ", NULL)) {\n");
else else
Printv(f->code, ", SWIGTYPE", SwigType_manglestr(t), ")) {\n", 0); Printv(f, ", SWIGTYPE", SwigType_manglestr(t), ")) {\n", 0);
/* Raise exception */ /* Raise exception */
Printv(f->code, Printv(f,
tab8, tab8,
"scm_wrong_type_arg(\"",proc_name, "\", ", "scm_wrong_type_arg(\"",proc_name, "\", ",
0); 0);
Printf(f->code,"%d, s_%d);\n", num_scheme_parm, parm); Printf(f,"%d, s_%d);\n", num_scheme_parm, parm);
Printv(f->code, tab4, "}\n", 0); Printv(f, tab4, "}\n", 0);
} }
/* Return true iff T is a pointer type */ /* Return true iff T is a pointer type */
@ -497,7 +497,7 @@ GUILE::function (DOH *node) {
proc_name = NewString(iname); proc_name = NewString(iname);
Replace(proc_name,"_", "-", DOH_REPLACE_ANY); 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); emit_args (node, f);
/* Declare return variable */ /* Declare return variable */
@ -510,9 +510,22 @@ GUILE::function (DOH *node) {
/* Open prototype and signature */ /* Open prototype and signature */
Printv(f->def, "static SCM\n", wname," (", 0); /* <DB> The function prototype must be produced first */
Printv(signature, "(", proc_name, 0);
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(signature, "(", proc_name, 0);
/* Now write code to extract the parameters */ /* Now write code to extract the parameters */
for (p = l, i = 0; p; p=Getnext(p), i++) { for (p = l, i = 0; p; p=Getnext(p), i++) {
@ -528,16 +541,14 @@ GUILE::function (DOH *node) {
// Handle parameter types. // Handle parameter types.
if (Getignore(p)) if (Getignore(p))
Printv(f->code, "/* ", pn, " ignored... */\n", 0); Printv(f, "/* ", pn, " ignored... */\n", 0);
else { else {
if (numargs!=0) Printf(f->def,", ");
Printf(f->def,"SCM s_%d", i);
if (opt_p) { if (opt_p) {
numopt++; numopt++;
Printf(f->code," if (s_%d != GH_NOT_PASSED) {\n", i); Printf(f," if (s_%d != GH_NOT_PASSED) {\n", i);
} }
++numargs; ++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)) { source, target, numargs, proc_name, f, 0)) {
/* nothing to do */ /* nothing to do */
} }
@ -554,12 +565,12 @@ GUILE::function (DOH *node) {
numargs, proc_name, f); numargs, proc_name, f);
} }
if (opt_p) if (opt_p)
Printf(f->code," }\n"); Printf(f," }\n");
} }
/* Check if there are any constraints. */ /* 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); source, target, numargs, proc_name, f, 0);
/* Pass output arguments back to the caller. */ /* Pass output arguments back to the caller. */
@ -591,27 +602,23 @@ GUILE::function (DOH *node) {
/* Close prototype and signature */ /* Close prototype and signature */
Printv(signature, ")\n", 0); 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 // 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); 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. // 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", (char*)"result", (char*)"gswig_result",
0, proc_name, f, 0)) { 0, proc_name, f, 0)) {
/* nothing */ /* nothing */
} }
else if (is_a_pointer(d)) { else if (is_a_pointer(d)) {
SwigType_remember(d); SwigType_remember(d);
Printv(f->code, tab4, Printv(f, tab4,
"gswig_result = SWIG_Guile_MakePtr (", "gswig_result = SWIG_Guile_MakePtr (",
"result, ", "result, ",
"SWIGTYPE", SwigType_manglestr(d), "SWIGTYPE", SwigType_manglestr(d),
@ -623,33 +630,33 @@ GUILE::function (DOH *node) {
} }
// Dump the argument output code // Dump the argument output code
Printv(f->code,outarg,0); Printv(f,outarg,0);
// Dump the argument cleanup code // Dump the argument cleanup code
Printv(f->code,cleanup,0); Printv(f,cleanup,0);
// Look for any remaining cleanup // Look for any remaining cleanup
if (NewObject) { 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); (char*)"result", (char*)"", 0, proc_name, f, 0);
} }
// Free any memory allocated by the function being wrapped.. // 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); (char*)"result", (char*)"", 0, proc_name, f, 0);
// Wrap things up (in a manner of speaking) // 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 // Undefine the scheme name
Printf(f->code, "#undef FUNC_NAME\n"); Printf(f, "#undef FUNC_NAME\n");
Printf(f->code, "}\n"); Printf(f, "}\n");
Wrapper_print (f, f_wrappers); Printf(f_wrappers,"%s", f);
if (numargs > 10) { if (numargs > 10) {
int i; int i;
@ -722,7 +729,7 @@ GUILE::function (DOH *node) {
Delete(signature); Delete(signature);
Delete(returns); Delete(returns);
Delete(tmp); Delete(tmp);
DelWrapper(f); Delete(f);
delete[] wname; delete[] wname;
} }
@ -888,7 +895,7 @@ GUILE::variable (DOH *node)
input_file, line_number, SwigType_str(t,0)); input_file, line_number, SwigType_str(t,0));
} }
Delete(proc_name); Delete(proc_name);
DelWrapper(f); Delete(f);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -965,7 +972,7 @@ GUILE::constant(DOH *node)
} }
Delete(proc_name); Delete(proc_name);
Delete(rvalue); Delete(rvalue);
DelWrapper(f); Delete(f);
} }
void GUILE::cpp_variable(DOH *node) void GUILE::cpp_variable(DOH *node)

View file

@ -234,9 +234,9 @@ MZSCHEME::get_pointer (String *name, int parm, SwigType *t, Wrapper *f)
{ {
char p[256]; char p[256];
sprintf(p, "%d", parm); 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); "\", (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); "\", \"", SwigType_manglestr(t), "\", ", p, ", argc, argv);\n",0);
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -302,9 +302,10 @@ MZSCHEME::function(DOH *node)
Replace(proc_name, "_", "-", DOH_REPLACE_ANY); Replace(proc_name, "_", "-", DOH_REPLACE_ANY);
// writing the function wrapper function // writing the function wrapper function
Printv(f->def, "static Scheme_Object *", wname, " (", 0); Printv(f, "static Scheme_Object *", wname, " (", 0);
Printv(f->def, "int argc, Scheme_Object **argv", 0); Printv(f, "int argc, Scheme_Object **argv", 0);
Printv(f->def, ")\n{", 0); Printv(f, ")\n{\n", 0);
Printf(f, "$locals\n");
// Declare return variable and arguments // Declare return variable and arguments
// number of parameters // number of parameters
@ -336,13 +337,13 @@ MZSCHEME::function(DOH *node)
// Handle parameter types. // Handle parameter types.
if (Getignore(p)) if (Getignore(p))
Printv(f->code, "/* ", Char(Getname(p)), " ignored... */\n", 0); Printv(f, "/* ", Char(Getname(p)), " ignored... */\n", 0);
else { else {
++numargs; ++numargs;
if ((tm = Swig_typemap_lookup ((char*)"in", if ((tm = Swig_typemap_lookup ((char*)"in",
Gettype(p), Getname(p), source, target, f))) { Gettype(p), Getname(p), source, target, f))) {
Printv(f->code, tm, "\n", 0); Printv(f, tm, "\n", 0);
mreplace (f->code, argnum, arg, proc_name); mreplace (f, argnum, arg, proc_name);
} }
// no typemap found // no typemap found
// check if typedef and resolve // check if typedef and resolve
@ -363,8 +364,8 @@ MZSCHEME::function(DOH *node)
if ((tm = Swig_typemap_lookup ((char*)"check", if ((tm = Swig_typemap_lookup ((char*)"check",
Gettype(p), Getname(p), source, target, f))) { Gettype(p), Getname(p), source, target, f))) {
// Yep. Use it instead of the default // Yep. Use it instead of the default
Printv(f->code, tm, "\n", 0); Printv(f, tm, "\n", 0);
mreplace (f->code, argnum, arg, proc_name); mreplace (f, argnum, arg, proc_name);
} }
// Pass output arguments back to the caller. // Pass output arguments back to the caller.
@ -395,18 +396,18 @@ MZSCHEME::function(DOH *node)
if (SwigType_type(d) == T_VOID) { if (SwigType_type(d) == T_VOID) {
if(!argout_set) 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", else if ((tm = Swig_typemap_lookup ((char*)"out",
d, name, (char*)"result", (char*)"swig_result", f))) { d, name, (char*)"result", (char*)"swig_result", f))) {
Printv(f->code, tm, "\n",0); Printv(f, tm, "\n",0);
mreplace (f->code, argnum, arg, proc_name); mreplace (f, argnum, arg, proc_name);
} }
// no typemap found and not void then create a Scheme_Object holding // no typemap found and not void then create a Scheme_Object holding
// the C pointer and return it // the C pointer and return it
else if (SwigType_ispointer(d)) { else if (SwigType_ispointer(d)) {
Printv(f->code, tab4, Printv(f, tab4,
"swig_result = swig_make_c_pointer(", "swig_result = swig_make_c_pointer(",
"result, \"", "result, \"",
SwigType_manglestr(d), SwigType_manglestr(d),
@ -417,18 +418,18 @@ MZSCHEME::function(DOH *node)
} }
// Dump the argument output code // Dump the argument output code
Printv(f->code, Char(outarg),0); Printv(f, Char(outarg),0);
// Dump the argument cleanup code // Dump the argument cleanup code
Printv(f->code, Char(cleanup),0); Printv(f, Char(cleanup),0);
// Look for any remaining cleanup // Look for any remaining cleanup
if (NewObject) { if (NewObject) {
if ((tm = Swig_typemap_lookup ((char*)"newfree", if ((tm = Swig_typemap_lookup ((char*)"newfree",
d, iname, (char*)"result", (char*)"", f))) { d, iname, (char*)"result", (char*)"", f))) {
Printv(f->code, tm, "\n",0); Printv(f, tm, "\n",0);
mreplace (f->code, argnum, arg, proc_name); mreplace (f, argnum, arg, proc_name);
} }
} }
@ -437,8 +438,8 @@ MZSCHEME::function(DOH *node)
if ((tm = Swig_typemap_lookup ((char*)"ret", if ((tm = Swig_typemap_lookup ((char*)"ret",
d, name, (char*)"result", (char*)"", f))) { d, name, (char*)"result", (char*)"", f))) {
// Yep. Use it instead of the default // Yep. Use it instead of the default
Printv(f->code, tm, "\n",0); Printv(f, tm, "\n",0);
mreplace (f->code, argnum, arg, proc_name); mreplace (f, argnum, arg, proc_name);
} }
// returning multiple values // returning multiple values
@ -446,22 +447,22 @@ MZSCHEME::function(DOH *node)
if(SwigType_type(d) == T_VOID) { if(SwigType_type(d) == T_VOID) {
Wrapper_add_local(f, "_lenv", "int _lenv = 0"); Wrapper_add_local(f, "_lenv", "int _lenv = 0");
Wrapper_add_local(f, "values", "Scheme_Object *values[MAXVALUES]"); 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 { else {
Wrapper_add_local(f, "_lenv", "int _lenv = 1"); Wrapper_add_local(f, "_lenv", "int _lenv = 1");
Wrapper_add_local(f, "values", "Scheme_Object *values[MAXVALUES]"); Wrapper_add_local(f, "values", "Scheme_Object *values[MAXVALUES]");
Printv(f->code, tab4, "_values[0] = swig_result;\n",0); Printv(f, tab4, "_values[0] = swig_result;\n",0);
Printv(f->code, tab4, "swig_result = scheme_values(_lenv, _values);\n",0); Printv(f, tab4, "swig_result = scheme_values(_lenv, _values);\n",0);
} }
} }
// Wrap things up (in a manner of speaking) // Wrap things up (in a manner of speaking)
Printv(f->code, tab4, "return swig_result;\n",0); Printv(f, tab4, "return swig_result;\n",0);
Printv(f->code, "}\n",0); Printv(f, "}\n",0);
Wrapper_print(f, f_wrappers); Printf(f_wrappers,"%s", f);
// Now register the function // Now register the function
char temp[256]; char temp[256];
@ -479,7 +480,7 @@ MZSCHEME::function(DOH *node)
Delete(outarg); Delete(outarg);
Delete(cleanup); Delete(cleanup);
Delete(build); Delete(build);
DelWrapper(f); Delete(f);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------

View file

@ -521,7 +521,8 @@ PERL5::function(DOH *node)
cleanup = NewString(""); cleanup = NewString("");
outarg = 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); pcount = emit_args(node, f);
numopt = check_numopt(l); numopt = check_numopt(l);
@ -530,8 +531,8 @@ PERL5::function(DOH *node)
/* Check the number of arguments */ /* Check the number of arguments */
Printf(f->code," if ((items < %d) || (items > %d)) \n", pcount-numopt, ParmList_numarg(l)); Printf(f," 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," croak(\"Usage: %s\");\n", usage_func(iname,d,l));
/* Write code to extract parameters. */ /* Write code to extract parameters. */
i = 0; i = 0;
@ -549,12 +550,12 @@ PERL5::function(DOH *node)
if (!Getignore(p)) { if (!Getignore(p)) {
/* Check for optional argument */ /* Check for optional argument */
if (j>= (pcount-numopt)) 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))) { if ((tm = Swig_typemap_lookup((char*)"in",pt,pn,source,target,f))) {
Printf(f->code,"%s\n",tm); Printf(f,"%s\n",tm);
Replace(f->code,"$argnum",argnum,DOH_REPLACE_ANY); Replace(f,"$argnum",argnum,DOH_REPLACE_ANY);
Replace(f->code,"$arg",source,DOH_REPLACE_ANY); Replace(f,"$arg",source,DOH_REPLACE_ANY);
} else { } else {
switch(SwigType_type(pt)) { switch(SwigType_type(pt)) {
case T_BOOL: case T_BOOL:
@ -566,16 +567,16 @@ PERL5::function(DOH *node)
case T_USHORT: case T_USHORT:
case T_ULONG: case T_ULONG:
case T_UCHAR: 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; break;
case T_CHAR : 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; break;
case T_DOUBLE : case T_DOUBLE :
case T_FLOAT : 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; break;
case T_VOID : case T_VOID :
@ -584,18 +585,18 @@ PERL5::function(DOH *node)
case T_USER: case T_USER:
SwigType_add_pointer(pt); SwigType_add_pointer(pt);
sprintf(temp,"argument %d", i+1); 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); SwigType_del_pointer(pt);
break; break;
case T_STRING: case T_STRING:
Printf(f->code," if (! SvOK((SV*) ST(%d))) { %s = 0; }\n", j, target); Printf(f," 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," else { %s = (char *) SvPV(ST(%d),PL_na); }\n", target,j);
break; break;
case T_POINTER: case T_ARRAY: case T_REFERENCE: case T_POINTER: case T_ARRAY: case T_REFERENCE:
sprintf(temp,"argument %d", i+1); 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; break;
default : default :
@ -606,7 +607,7 @@ PERL5::function(DOH *node)
/* The source is going to be an array of saved values. */ /* The source is going to be an array of saved values. */
sprintf(temp,"_saved[%d]",num_saved); sprintf(temp,"_saved[%d]",num_saved);
if (j>= (pcount-numopt)) if (j>= (pcount-numopt))
Printf(f->code," } \n"); Printf(f," } \n");
j++; j++;
} else { } else {
temp[0] = 0; temp[0] = 0;
@ -614,8 +615,8 @@ PERL5::function(DOH *node)
/* Check if there is any constraint code */ /* Check if there is any constraint code */
if ((tm = Swig_typemap_lookup((char*)"check",pt,pn,source,target,0))) { if ((tm = Swig_typemap_lookup((char*)"check",pt,pn,source,target,0))) {
Printf(f->code,"%s\n", tm); Printf(f,"%s\n", tm);
Replace(f->code,"$argnum",argnum, DOH_REPLACE_ANY); Replace(f,"$argnum",argnum, DOH_REPLACE_ANY);
} }
need_save = 0; 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 /* 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) */ This only applies if the argument actually existed (not ignore) */
if ((need_save) && (!Getignore(p))) { if ((need_save) && (!Getignore(p))) {
Printv(f->code, tab4, temp, " = ", source, ";\n", 0); Printv(f, tab4, temp, " = ", source, ";\n", 0);
num_saved++; num_saved++;
} }
i++; i++;
@ -653,24 +654,24 @@ PERL5::function(DOH *node)
emit_func_call(node,f); emit_func_call(node,f);
if ((tm = Swig_typemap_lookup((char*)"out",d,iname,(char*)"result",(char*)"ST(argvi)",0))) { 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 { } else {
if (SwigType_type(d) != T_VOID) { 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)) { switch (SwigType_type(d)) {
case T_INT: case T_BOOL: case T_UINT: case T_INT: case T_BOOL: case T_UINT:
case T_SHORT: case T_USHORT: case T_SHORT: case T_USHORT:
case T_LONG : case T_ULONG: case T_LONG : case T_ULONG:
case T_SCHAR: case T_UCHAR : 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; break;
case T_DOUBLE : case T_DOUBLE :
case T_FLOAT : case T_FLOAT :
Printf(f->code," sv_setnv(ST(argvi++), (double) result);\n"); Printf(f," sv_setnv(ST(argvi++), (double) result);\n");
break; break;
case T_CHAR : case T_CHAR :
Wrapper_add_local(f,"_ctemp", "char ctemp[2]"); Wrapper_add_local(f,"_ctemp", "char ctemp[2]");
Printv(f->code, Printv(f,
tab4, "ctemp[0] = result;\n", tab4, "ctemp[0] = result;\n",
tab4, "ctemp[1] = 0;\n", tab4, "ctemp[1] = 0;\n",
tab4, "sv_setpv((SV*)ST(argvi++),ctemp);\n", tab4, "sv_setpv((SV*)ST(argvi++),ctemp);\n",
@ -680,18 +681,18 @@ PERL5::function(DOH *node)
case T_USER: case T_USER:
SwigType_add_pointer(d); SwigType_add_pointer(d);
SwigType_remember(d); SwigType_remember(d);
Printv(f->code, Printv(f,
tab4, "SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE", SwigType_manglestr(d),");\n", 0); tab4, "SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE", SwigType_manglestr(d),");\n", 0);
SwigType_del_pointer(d); SwigType_del_pointer(d);
break; break;
case T_STRING: 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; break;
case T_POINTER: case T_ARRAY: case T_REFERENCE: case T_POINTER: case T_ARRAY: case T_REFERENCE:
SwigType_remember(d); 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; break;
default : default :
@ -703,35 +704,35 @@ PERL5::function(DOH *node)
/* If there were any output args, take care of them. */ /* 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. */ /* If there was any cleanup, do that. */
Printv(f->code,cleanup,0); Printv(f,cleanup,0);
if (NewObject) { if (NewObject) {
if ((tm = Swig_typemap_lookup((char*)"newfree",d,iname,(char*)"result",(char*)"",0))) { 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))) { 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 */ /* Add the dXSARGS last */
Wrapper_add_local(f,"dXSARGS","dXSARGS"); Wrapper_add_local(f,"dXSARGS","dXSARGS");
/* Substitute the cleanup code */ /* Substitute the cleanup code */
Replace(f->code,"$cleanup",cleanup,DOH_REPLACE_ANY); Replace(f,"$cleanup",cleanup,DOH_REPLACE_ANY);
Replace(f->code,"$name",iname,DOH_REPLACE_ANY); Replace(f,"$name",iname,DOH_REPLACE_ANY);
/* Dump the wrapper function */ /* Dump the wrapper function */
Wrapper_print(f,f_wrappers); Printf(f_wrappers,"%s", f);
/* Now register the function */ /* Now register the function */
@ -844,7 +845,7 @@ PERL5::function(DOH *node)
} }
Delete(cleanup); Delete(cleanup);
Delete(outarg); Delete(outarg);
DelWrapper(f); Delete(f);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -878,57 +879,58 @@ void PERL5::variable(DOH *node) {
/* Create a Perl function for setting the variable value */ /* Create a Perl function for setting the variable value */
if (!(Status & STAT_READONLY)) { if (!(Status & STAT_READONLY)) {
Printf(setf->def,"SWIGCLASS_STATIC int %s(SV* sv, MAGIC *mg) {\n", set_name); Printf(setf,"SWIGCLASS_STATIC int %s(SV* sv, MAGIC *mg) {\n", set_name);
Printv(setf->code, Printf(setf,"$locals\n");
Printv(setf,
tab4, "MAGIC_PPERL\n", tab4, "MAGIC_PPERL\n",
tab4, "mg = mg;\n", tab4, "mg = mg;\n",
0); 0);
/* Check for a few typemaps */ /* Check for a few typemaps */
if ((tm = Swig_typemap_lookup((char*)"varin",t,(char*)"",(char*)"sv",name,0))) { 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))) { } 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 { } else {
switch(SwigType_type(t)) { switch(SwigType_type(t)) {
case T_INT : case T_BOOL: case T_UINT: case T_INT : case T_BOOL: case T_UINT:
case T_SHORT : case T_USHORT: case T_SHORT : case T_USHORT:
case T_LONG : case T_ULONG: case T_LONG : case T_ULONG:
case T_UCHAR: case T_SCHAR: 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; break;
case T_DOUBLE : case T_DOUBLE :
case T_FLOAT : 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; break;
case T_CHAR : 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; break;
case T_USER: case T_USER:
SwigType_add_pointer(t); SwigType_add_pointer(t);
Wrapper_add_local(setf,"_temp", "void *_temp"); Wrapper_add_local(setf,"_temp", "void *_temp");
get_pointer(iname,(char*)"value",(char*)"sv",(char*)"_temp", t, setf->code, (char*)"return(1)"); get_pointer(iname,(char*)"value",(char*)"sv",(char*)"_temp", t, setf, (char*)"return(1)");
Printv(setf->code, tab4, name, " = *((", SwigType_str(t,0), ") _temp);\n", 0); Printv(setf, tab4, name, " = *((", SwigType_str(t,0), ") _temp);\n", 0);
SwigType_del_pointer(t); SwigType_del_pointer(t);
break; break;
case T_STRING: case T_STRING:
Wrapper_add_local(setf,"_a","char *_a"); 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) if (CPlusPlus)
Printv(setf->code, Printv(setf,
tab4, "if (", name, ") delete [] ", name, ";\n", tab4, "if (", name, ") delete [] ", name, ";\n",
tab4, name, " = new char[strlen(_a)+1];\n", tab4, name, " = new char[strlen(_a)+1];\n",
0); 0);
else else
Printv(setf->code, Printv(setf,
tab4, "if (", name, ") free((char*)", name, ");\n", tab4, "if (", name, ") free((char*)", name, ");\n",
tab4, name, " = (char *) malloc(strlen(_a)+1);\n", tab4, name, " = (char *) malloc(strlen(_a)+1);\n",
0); 0);
Printv(setf->code,"strcpy((char*)", name, ",_a);\n", 0); Printv(setf,"strcpy((char*)", name, ",_a);\n", 0);
break; break;
case T_ARRAY: case T_ARRAY:
@ -939,7 +941,7 @@ void PERL5::variable(DOH *node) {
if (SwigType_type(ta) == T_CHAR) { if (SwigType_type(ta) == T_CHAR) {
String *dim = SwigType_array_getdim(aop,0); String *dim = SwigType_array_getdim(aop,0);
if (dim && Len(dim)) { 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; setable = 1;
} else { } else {
setable = 0; setable = 0;
@ -954,8 +956,8 @@ void PERL5::variable(DOH *node) {
case T_POINTER: case T_REFERENCE: case T_POINTER: case T_REFERENCE:
Wrapper_add_local(setf,"_temp","void *_temp"); Wrapper_add_local(setf,"_temp","void *_temp");
get_pointer(iname,(char*)"value",(char*)"sv",(char*)"_temp", t, setf->code, (char*)"return(1)"); get_pointer(iname,(char*)"value",(char*)"sv",(char*)"_temp", t, setf, (char*)"return(1)");
Printv(setf->code,tab4, name, " = (", SwigType_str(t,0), ") _temp;\n", 0); Printv(setf,tab4, name, " = (", SwigType_str(t,0), ") _temp;\n", 0);
break; break;
default : default :
@ -963,24 +965,25 @@ void PERL5::variable(DOH *node) {
return; return;
} }
} }
Printf(setf->code," return 1;\n}\n"); Printf(setf," return 1;\n}\n");
Replace(setf->code,"$name",iname, DOH_REPLACE_ANY); Replace(setf,"$name",iname, DOH_REPLACE_ANY);
Wrapper_print(setf,magic); Printf(magic,"%s", setf);
} }
/* Now write a function to evaluate the variable */ /* Now write a function to evaluate the variable */
Printf(getf->def,"SWIGCLASS_STATIC int %s(SV *sv, MAGIC *mg) {\n", val_name); Printf(getf,"SWIGCLASS_STATIC int %s(SV *sv, MAGIC *mg) {\n", val_name);
Printv(getf->code, Printf(getf,"$locals\n");
Printv(getf,
tab4, "MAGIC_PPERL\n", tab4, "MAGIC_PPERL\n",
tab4, "mg = mg;\n", tab4, "mg = mg;\n",
0); 0);
if ((tm = Swig_typemap_lookup((char*)"varout",t,(char*)"",name, (char*)"sv",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))) { } 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 { } else {
switch(SwigType_type(t)) { switch(SwigType_type(t)) {
@ -988,17 +991,17 @@ void PERL5::variable(DOH *node) {
case T_SHORT : case T_USHORT: case T_SHORT : case T_USHORT:
case T_LONG : case T_ULONG: case T_LONG : case T_ULONG:
case T_UCHAR: case T_SCHAR: 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); Printv(vinit, tab4, "sv_setiv(sv,(IV)", name, ");\n",0);
break; break;
case T_DOUBLE : case T_DOUBLE :
case T_FLOAT : 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); Printv(vinit, tab4, "sv_setnv(sv,(double)", name, ");\n",0);
break; break;
case T_CHAR : case T_CHAR :
Wrapper_add_local(getf,"_ptemp","char _ptemp[2]"); Wrapper_add_local(getf,"_ptemp","char _ptemp[2]");
Printv(getf->code, Printv(getf,
tab4, "_ptemp[0] = ", name, ";\n", tab4, "_ptemp[0] = ", name, ";\n",
tab4, "_ptemp[1] = 0;\n", tab4, "_ptemp[1] = 0;\n",
tab4, "sv_setpv((SV*) sv, _ptemp);\n", tab4, "sv_setpv((SV*) sv, _ptemp);\n",
@ -1006,7 +1009,7 @@ void PERL5::variable(DOH *node) {
break; break;
case T_USER: case T_USER:
SwigType_add_pointer(t); SwigType_add_pointer(t);
Printv(getf->code, Printv(getf,
tab4, "rsv = SvRV(sv);\n", tab4, "rsv = SvRV(sv);\n",
tab4, "sv_setiv(rsv,(IV) &", name, ");\n", tab4, "sv_setiv(rsv,(IV) &", name, ");\n",
0); 0);
@ -1018,7 +1021,7 @@ void PERL5::variable(DOH *node) {
break; break;
case T_STRING: 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; break;
case T_ARRAY: case T_ARRAY:
@ -1027,7 +1030,7 @@ void PERL5::variable(DOH *node) {
SwigType *ta = Copy(t); SwigType *ta = Copy(t);
aop = SwigType_pop(ta); aop = SwigType_pop(ta);
if (SwigType_type(ta) == T_CHAR) { 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(ta);
Delete(aop); Delete(aop);
break; break;
@ -1037,7 +1040,7 @@ void PERL5::variable(DOH *node) {
} }
/* No break here is intentional */ /* No break here is intentional */
case T_POINTER: case T_REFERENCE: case T_POINTER: case T_REFERENCE:
Printv(getf->code, Printv(getf,
tab4, "rsv = SvRV(sv);\n", tab4, "rsv = SvRV(sv);\n",
tab4, "sv_setiv(rsv,(IV) ", name, ");\n", tab4, "sv_setiv(rsv,(IV) ", name, ");\n",
0); 0);
@ -1050,10 +1053,10 @@ void PERL5::variable(DOH *node) {
break; break;
} }
} }
Printf(getf->code," return 1;\n}\n"); Printf(getf," return 1;\n}\n");
Replace(getf->code,"$name",iname, DOH_REPLACE_ANY); Replace(getf,"$name",iname, DOH_REPLACE_ANY);
Wrapper_print(getf,magic); Printf(magic,"%s", getf);
/* Now add symbol to the PERL interpreter */ /* Now add symbol to the PERL interpreter */
if ((Status & STAT_READONLY) || (!setable)) { if ((Status & STAT_READONLY) || (!setable)) {
@ -1082,8 +1085,8 @@ void PERL5::variable(DOH *node) {
if (export_all) if (export_all)
Printf(exported,"$%s ", name); Printf(exported,"$%s ", name);
} }
DelWrapper(setf); Delete(setf);
DelWrapper(getf); Delete(getf);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------

View file

@ -361,17 +361,17 @@ PYTHON::function(DOH *node) {
strcpy(wname,Char(Swig_name_wrapper(iname))); strcpy(wname,Char(Swig_name_wrapper(iname)));
if (!use_kw) { if (!use_kw) {
Printv(f->def, Printv(f,
"static PyObject *", wname, "static PyObject *", wname,
"(PyObject *self, PyObject *args) {", "(PyObject *self, PyObject *args) {",
0); 0);
} else { } else {
Printv(f->def, Printv(f,
"static PyObject *", wname, "static PyObject *", wname,
"(PyObject *self, PyObject *args, PyObject *kwargs) {", "(PyObject *self, PyObject *args, PyObject *kwargs) {",
0); 0);
} }
Printf(f,"$locals\n");
Wrapper_add_local(f,"resultobj", "PyObject *resultobj"); Wrapper_add_local(f,"resultobj", "PyObject *resultobj");
/* Get the function usage string for later use */ /* Get the function usage string for later use */
@ -538,7 +538,8 @@ PYTHON::function(DOH *node) {
Printf(kwargs," NULL }"); Printf(kwargs," NULL }");
if (use_kw) { 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); Printf(parse_args,":%s\"", iname);
@ -547,45 +548,45 @@ PYTHON::function(DOH *node) {
0); 0);
/* Now slap the whole first part of the wrapper function together */ /* Now slap the whole first part of the wrapper function together */
Printv(f->code, parse_args, get_pointers, check, 0); Printv(f, parse_args, get_pointers, check, 0);
/* Emit the function call */ /* Emit the function call */
emit_func_call(node,f); emit_func_call(node,f);
/* Return the function value */ /* Return the function value */
if ((tm = Swig_typemap_lookup((char*)"out",d,iname,(char*)"result",(char*)"resultobj",0))) { 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 { } else {
switch(SwigType_type(d)) { switch(SwigType_type(d)) {
case T_INT: case T_UINT: case T_BOOL: case T_INT: case T_UINT: case T_BOOL:
case T_SHORT: case T_USHORT: case T_SHORT: case T_USHORT:
case T_LONG : case T_ULONG: case T_LONG : case T_ULONG:
case T_SCHAR: case T_UCHAR : case T_SCHAR: case T_UCHAR :
Printf(f->code," resultobj = PyInt_FromLong((long)result);\n"); Printf(f," resultobj = PyInt_FromLong((long)result);\n");
break; break;
case T_DOUBLE : case T_DOUBLE :
case T_FLOAT : case T_FLOAT :
Printf(f->code," resultobj = PyFloat_FromDouble(result);\n"); Printf(f," resultobj = PyFloat_FromDouble(result);\n");
break; break;
case T_CHAR : case T_CHAR :
Printf(f->code," resultobj = Py_BuildValue(\"c\",result);\n"); Printf(f," resultobj = Py_BuildValue(\"c\",result);\n");
break; break;
case T_USER : case T_USER :
SwigType_add_pointer(d); SwigType_add_pointer(d);
SwigType_remember(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); SwigType_del_pointer(d);
break; break;
case T_STRING: case T_STRING:
Printf(f->code," resultobj = Py_BuildValue(\"s\",result);\n"); Printf(f," resultobj = Py_BuildValue(\"s\",result);\n");
break; break;
case T_POINTER: case T_ARRAY: case T_REFERENCE: case T_POINTER: case T_ARRAY: case T_REFERENCE:
SwigType_remember(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);
break; break;
case T_VOID: case T_VOID:
Printf(f->code," Py_INCREF(Py_None);\n"); Printf(f," Py_INCREF(Py_None);\n");
Printf(f->code," resultobj = Py_None;\n"); Printf(f," resultobj = Py_None;\n");
break; break;
default : 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); 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 */ /* Output argument output code */
Printv(f->code,outarg,0); Printv(f,outarg,0);
/* Output cleanup code */ /* Output cleanup code */
Printv(f->code,cleanup,0); Printv(f,cleanup,0);
/* Look to see if there is any newfree cleanup code */ /* Look to see if there is any newfree cleanup code */
if (NewObject) { if (NewObject) {
if ((tm = Swig_typemap_lookup((char*)"newfree",d,iname,(char*)"result",(char*)"",0))) { 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 */ /* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup((char*)"ret",d,iname,(char*)"result",(char*)"",0))) { 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 */ /* Substitute the cleanup code */
Replace(f->code,"$cleanup",cleanup, DOH_REPLACE_ANY); Replace(f,"$cleanup",cleanup, DOH_REPLACE_ANY);
/* Substitute the function name */ /* Substitute the function name */
Replace(f->code,"$name",iname, DOH_REPLACE_ANY); Replace(f,"$name",iname, DOH_REPLACE_ANY);
/* Dump the function out */ /* Dump the function out */
Wrapper_print(f,f_wrappers); Printf(f_wrappers,"%s",f);
/* Now register the function with the interpreter. */ /* Now register the function with the interpreter. */
add_method(iname, wname, use_kw); add_method(iname, wname, use_kw);
@ -674,7 +675,7 @@ PYTHON::function(DOH *node) {
Delete(outarg); Delete(outarg);
Delete(check); Delete(check);
Delete(kwargs); Delete(kwargs);
DelWrapper(f); Delete(f);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -711,11 +712,12 @@ PYTHON::variable(DOH *node) {
/* Create a function for setting the value of the variable */ /* 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 (!(Status & STAT_READONLY)) {
if ((tm = Swig_typemap_lookup((char*)"varin",t,name,(char*)"val",name,0))) { if ((tm = Swig_typemap_lookup((char*)"varin",t,name,(char*)"val",name,0))) {
Printf(setf->code,"%s\n",tm); Printf(setf,"%s\n",tm);
Replace(setf->code,"$name",iname, DOH_REPLACE_ANY); Replace(setf,"$name",iname, DOH_REPLACE_ANY);
} else { } else {
switch(SwigType_type(t)) { switch(SwigType_type(t)) {
@ -723,7 +725,7 @@ PYTHON::variable(DOH *node) {
case T_UINT: case T_USHORT: case T_ULONG: case T_UINT: case T_USHORT: case T_ULONG:
case T_SCHAR: case T_UCHAR: case T_BOOL: case T_SCHAR: case T_UCHAR: case T_BOOL:
Wrapper_add_localv(setf,"tval",SwigType_lstr(t,0),"tval",0); 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, "tval = (", SwigType_lstr(t,0), ") PyInt_AsLong(val);\n",
tab4, "if (PyErr_Occurred()) {\n", tab4, "if (PyErr_Occurred()) {\n",
tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '", tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '",
@ -736,7 +738,7 @@ PYTHON::variable(DOH *node) {
case T_FLOAT: case T_DOUBLE: case T_FLOAT: case T_DOUBLE:
Wrapper_add_localv(setf,"tval",SwigType_lstr(t,0), "tval",0); 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, "tval = (", SwigType_lstr(t,0), ") PyFloat_AsDouble(val);\n",
tab4, "if (PyErr_Occurred()) {\n", tab4, "if (PyErr_Occurred()) {\n",
tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '", tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '",
@ -749,7 +751,7 @@ PYTHON::variable(DOH *node) {
case T_CHAR: case T_CHAR:
Wrapper_add_local(setf,"tval","char * tval"); Wrapper_add_local(setf,"tval","char * tval");
Printv(setf->code, Printv(setf,
tab4, "tval = (char *) PyString_AsString(val);\n", tab4, "tval = (char *) PyString_AsString(val);\n",
tab4, "if (PyErr_Occurred()) {\n", tab4, "if (PyErr_Occurred()) {\n",
tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '", tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '",
@ -763,14 +765,14 @@ PYTHON::variable(DOH *node) {
case T_USER: case T_USER:
SwigType_add_pointer(t); SwigType_add_pointer(t);
Wrapper_add_localv(setf,"temp",SwigType_lstr(t,0),"temp",0); Wrapper_add_localv(setf,"temp",SwigType_lstr(t,0),"temp",0);
get_pointer((char*)"val",(char*)"temp",t,setf->code,(char*)"1"); get_pointer((char*)"val",(char*)"temp",t,setf,(char*)"1");
Printv(setf->code, tab4, name, " = *temp;\n", 0); Printv(setf, tab4, name, " = *temp;\n", 0);
SwigType_del_pointer(t); SwigType_del_pointer(t);
break; break;
case T_STRING: case T_STRING:
Wrapper_add_local(setf,"tval","char * tval"); Wrapper_add_local(setf,"tval","char * tval");
Printv(setf->code, Printv(setf,
tab4, "tval = (char *) PyString_AsString(val);\n", tab4, "tval = (char *) PyString_AsString(val);\n",
tab4, "if (PyErr_Occurred()) {\n", tab4, "if (PyErr_Occurred()) {\n",
tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '", tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '",
@ -780,13 +782,13 @@ PYTHON::variable(DOH *node) {
0); 0);
if (CPlusPlus) { if (CPlusPlus) {
Printv(setf->code, Printv(setf,
tab4, "if (", name, ") delete [] ", name, ";\n", tab4, "if (", name, ") delete [] ", name, ";\n",
tab4, name, " = new char[strlen(tval)+1];\n", tab4, name, " = new char[strlen(tval)+1];\n",
tab4, "strcpy((char *)", name, ",tval);\n", tab4, "strcpy((char *)", name, ",tval);\n",
0); 0);
} else { } else {
Printv(setf->code, Printv(setf,
tab4, "if (", name, ") free((char*)", name, ");\n", tab4, "if (", name, ") free((char*)", name, ");\n",
tab4, name, " = (char *) malloc(strlen(tval)+1);\n", tab4, name, " = (char *) malloc(strlen(tval)+1);\n",
tab4, "strcpy((char *)", name, ",tval);\n", tab4, "strcpy((char *)", name, ",tval);\n",
@ -803,12 +805,12 @@ PYTHON::variable(DOH *node) {
if (SwigType_type(ta) == T_CHAR) { if (SwigType_type(ta) == T_CHAR) {
String *dim = SwigType_array_getdim(aop,0); String *dim = SwigType_array_getdim(aop,0);
if (dim && Len(dim)) { 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; setable = 1;
} }
} }
if (!setable) { if (!setable) {
Printv(setf->code, Printv(setf,
tab4, "PyErr_SetString(PyExc_TypeError,\"Variable ", iname, tab4, "PyErr_SetString(PyExc_TypeError,\"Variable ", iname,
" is read-only.\");\n", " is read-only.\");\n",
tab4, "return 1;\n", tab4, "return 1;\n",
@ -821,50 +823,51 @@ PYTHON::variable(DOH *node) {
case T_POINTER: case T_REFERENCE: case T_POINTER: case T_REFERENCE:
Wrapper_add_localv(setf,"temp", SwigType_lstr(t,0), "temp",0); Wrapper_add_localv(setf,"temp", SwigType_lstr(t,0), "temp",0);
get_pointer((char*)"val",(char*)"temp",t,setf->code,(char*)"1"); get_pointer((char*)"val",(char*)"temp",t,setf,(char*)"1");
Printv(setf->code,tab4, name, " = temp;\n", 0); Printv(setf,tab4, name, " = temp;\n", 0);
break; break;
default: default:
Printf(stderr,"%s : Line %d. Unable to link with type %s.\n", input_file, line_number, SwigType_str(t,0)); Printf(stderr,"%s : Line %d. Unable to link with type %s.\n", input_file, line_number, SwigType_str(t,0));
} }
} }
Printf(setf->code," return 0;\n"); Printf(setf," return 0;\n");
} else { } else {
/* Is a readonly variable. Issue an error */ /* Is a readonly variable. Issue an error */
Printv(setf->code, Printv(setf,
tab4, "PyErr_SetString(PyExc_TypeError,\"Variable ", iname, tab4, "PyErr_SetString(PyExc_TypeError,\"Variable ", iname,
" is read-only.\");\n", " is read-only.\");\n",
tab4, "return 1;\n", tab4, "return 1;\n",
0); 0);
} }
Printf(setf->code,"}\n"); Printf(setf,"}\n");
Wrapper_print(setf,f_wrappers); Printf(f_wrappers,"%s", setf);
/* Create a function for getting the value of a variable */ /* 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"); Wrapper_add_local(getf,"pyobj", "PyObject *pyobj");
if ((tm = Swig_typemap_lookup((char*)"varout",t,name,name,(char*)"pyobj",0))) { if ((tm = Swig_typemap_lookup((char*)"varout",t,name,name,(char*)"pyobj",0))) {
Printf(getf->code,"%s\n",tm); Printf(getf,"%s\n",tm);
Replace(getf->code,"$name",iname, DOH_REPLACE_ANY); Replace(getf,"$name",iname, DOH_REPLACE_ANY);
} else if ((tm = Swig_typemap_lookup((char*)"out",t,name,name,(char*)"pyobj",0))) { } else if ((tm = Swig_typemap_lookup((char*)"out",t,name,name,(char*)"pyobj",0))) {
Printf(getf->code,"%s\n",tm); Printf(getf,"%s\n",tm);
Replace(getf->code,"$name",iname, DOH_REPLACE_ANY); Replace(getf,"$name",iname, DOH_REPLACE_ANY);
} else { } else {
switch(SwigType_type(t)) { switch(SwigType_type(t)) {
case T_INT: case T_UINT: case T_INT: case T_UINT:
case T_SHORT: case T_USHORT: case T_SHORT: case T_USHORT:
case T_LONG: case T_ULONG: case T_LONG: case T_ULONG:
case T_SCHAR: case T_UCHAR: case T_BOOL: 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; break;
case T_FLOAT: case T_DOUBLE: 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; break;
case T_CHAR: case T_CHAR:
Wrapper_add_local(getf,"ptemp","char ptemp[2]"); Wrapper_add_local(getf,"ptemp","char ptemp[2]");
Printv(getf->code, Printv(getf,
tab4, "ptemp[0] = ", name, ";\n", tab4, "ptemp[0] = ", name, ";\n",
tab4, "ptemp[1] = 0;\n", tab4, "ptemp[1] = 0;\n",
tab4, "pyobj = PyString_FromString(ptemp);\n", tab4, "pyobj = PyString_FromString(ptemp);\n",
@ -873,14 +876,14 @@ PYTHON::variable(DOH *node) {
case T_USER: case T_USER:
SwigType_add_pointer(t); SwigType_add_pointer(t);
SwigType_remember(t); SwigType_remember(t);
Printv(getf->code, Printv(getf,
tab4, "pyobj = SWIG_NewPointerObj((void *) &", name , tab4, "pyobj = SWIG_NewPointerObj((void *) &", name ,
", SWIGTYPE", SwigType_manglestr(t), ");\n", ", SWIGTYPE", SwigType_manglestr(t), ");\n",
0); 0);
SwigType_del_pointer(t); SwigType_del_pointer(t);
break; break;
case T_STRING: case T_STRING:
Printv(getf->code, Printv(getf,
tab4, "if (", name, ")\n", tab4, "if (", name, ")\n",
tab8, "pyobj = PyString_FromString(", name, ");\n", tab8, "pyobj = PyString_FromString(", name, ");\n",
tab4, "else pyobj = PyString_FromString(\"(NULL)\");\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: case T_POINTER: case T_ARRAY: case T_REFERENCE:
SwigType_remember(t); SwigType_remember(t);
Printv(getf->code, Printv(getf,
tab4, "pyobj = SWIG_NewPointerObj((void *)", name, tab4, "pyobj = SWIG_NewPointerObj((void *)", name,
", SWIGTYPE", SwigType_manglestr(t), ");\n", ", SWIGTYPE", SwigType_manglestr(t), ");\n",
0); 0);
@ -901,8 +904,8 @@ PYTHON::variable(DOH *node) {
} }
} }
Printf(getf->code," return pyobj;\n}\n"); Printf(getf," return pyobj;\n}\n");
Wrapper_print(getf,f_wrappers); Printf(f_wrappers,"%s", getf);
/* Now add this to the variable linking mechanism */ /* Now add this to the variable linking mechanism */
@ -917,8 +920,8 @@ PYTHON::variable(DOH *node) {
0); 0);
} }
} }
DelWrapper(setf); Delete(setf);
DelWrapper(getf); Delete(getf);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------

View file

@ -449,7 +449,7 @@ void RUBY::function(DOH *node) {
if (current == DESTRUCTOR) { if (current == DESTRUCTOR) {
Wrapper *dummy = NewWrapper(); Wrapper *dummy = NewWrapper();
emit_func_call(node,dummy); emit_func_call(node,dummy);
DelWrapper(dummy); Delete(dummy);
return; return;
} }
@ -502,20 +502,21 @@ void RUBY::function(DOH *node) {
int vararg = (numoptreal != 0); int vararg = (numoptreal != 0);
/* Now write the wrapper function itself */ /* Now write the wrapper function itself */
Printv(f->def, "static VALUE\n", wname, "(", 0); Printv(f, "static VALUE\n", wname, "(", 0);
if (vararg) { if (vararg) {
Printv(f->def, "int argc, VALUE *argv, VALUE self",0); Printv(f, "int argc, VALUE *argv, VALUE self",0);
} else { } else {
Printv(f->def, "VALUE self", 0); Printv(f, "VALUE self", 0);
p = l; p = l;
for (i = 0; i < start; i++) p = Getnext(p); for (i = 0; i < start; i++) p = Getnext(p);
for (i = start; p; i++, p = Getnext(p)) { for (i = start; p; i++, p = Getnext(p)) {
if (!Getignore(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. */ /* Emit all of the local variables for holding arguments. */
if (vararg) { if (vararg) {
@ -538,14 +539,14 @@ void RUBY::function(DOH *node) {
for (i = start; p; i++, p = Getnext(p)) { for (i = start; p; i++, p = Getnext(p)) {
if (!Getignore(p)) numscan++; 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 (p = l, i = 0; i < start; i++) p = Getnext(p);
for (i = start; p; i++, p = Getnext(p)) { for (i = start; p; i++, p = Getnext(p)) {
if (!Getignore(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 */ /* Now walk the function parameter list and generate code */
@ -569,7 +570,7 @@ void RUBY::function(DOH *node) {
if (!Getignore(p)) { if (!Getignore(p)) {
char *tab = (char*)tab4; char *tab = (char*)tab4;
if (j >= (pcount-numopt)) { /* Check if parsing an optional argument */ 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; tab = (char*)tab8;
} }
@ -577,15 +578,15 @@ void RUBY::function(DOH *node) {
tm = ruby_typemap_lookup((char*)"in",pt,pn,source,target,f); tm = ruby_typemap_lookup((char*)"in",pt,pn,source,target,f);
if (tm) { if (tm) {
String *s = NewString(tm); String *s = NewString(tm);
Printv(f->code, s, 0); Printv(f, s, 0);
Replace(f->code, "$arg", source, DOH_REPLACE_ANY); Replace(f, "$arg", source, DOH_REPLACE_ANY);
Delete(s); Delete(s);
} else { } else {
Printf(stderr,"%s : Line %d. No typemapping for datatype %s\n", Printf(stderr,"%s : Line %d. No typemapping for datatype %s\n",
input_file,line_number, SwigType_str(pt,0)); input_file,line_number, SwigType_str(pt,0));
} }
if (j >= (pcount-numopt)) if (j >= (pcount-numopt))
Printv(f->code, tab4, "} \n", 0); Printv(f, tab4, "} \n", 0);
j++; j++;
} }
@ -593,8 +594,8 @@ void RUBY::function(DOH *node) {
tm = ruby_typemap_lookup((char*)"check",pt,pn,source,target); tm = ruby_typemap_lookup((char*)"check",pt,pn,source,target);
if (tm) { if (tm) {
String *s = NewString(tm); String *s = NewString(tm);
Printv(f->code, s, 0); Printv(f, s, 0);
Replace(f->code, "$arg", source, DOH_REPLACE_ANY); Replace(f, "$arg", source, DOH_REPLACE_ANY);
Delete(s); Delete(s);
} }
@ -625,12 +626,12 @@ void RUBY::function(DOH *node) {
if (SwigType_type(t) != T_VOID) { if (SwigType_type(t) != T_VOID) {
need_result = 1; need_result = 1;
if (predicate) { if (predicate) {
Printv(f->code, tab4, "vresult = (result ? Qtrue : Qfalse);\n", 0); Printv(f, tab4, "vresult = (result ? Qtrue : Qfalse);\n", 0);
} else { } else {
tm = ruby_typemap_lookup((char*)"out",t,name,(char*)"result",(char*)"vresult"); tm = ruby_typemap_lookup((char*)"out",t,name,(char*)"result",(char*)"vresult");
if (tm) { if (tm) {
String *s = NewString(tm); String *s = NewString(tm);
Printv(f->code, s, 0); Printv(f, s, 0);
Delete(s); Delete(s);
} else { } else {
Printf(stderr,"%s : Line %d. No return typemap for datatype %s\n", 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; */ /* Dump argument output code; */
Printv(f->code,outarg,0); Printv(f,outarg,0);
/* Dump the argument cleanup code */ /* Dump the argument cleanup code */
Printv(f->code,cleanup,0); Printv(f,cleanup,0);
/* Look for any remaining cleanup. This processes the %new directive */ /* Look for any remaining cleanup. This processes the %new directive */
if (NewObject) { if (NewObject) {
tm = ruby_typemap_lookup((char*)"newfree",t,name,(char*)"result",(char*)""); tm = ruby_typemap_lookup((char*)"newfree",t,name,(char*)"result",(char*)"");
if (tm) { if (tm) {
String *s = NewString(tm); String *s = NewString(tm);
Printv(f->code,s, 0); Printv(f,s, 0);
Delete(s); Delete(s);
} }
} }
/* free pragma */ /* free pragma */
if (current == MEMBER_FUNC && Getattr(klass->freemethods, mname)) { 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. */ /* Special processing on return value. */
tm = ruby_typemap_lookup((char*)"ret",t,name,(char*)"result",(char*)""); tm = ruby_typemap_lookup((char*)"ret",t,name,(char*)"result",(char*)"");
if (tm) { if (tm) {
String *s = NewString(tm); String *s = NewString(tm);
Printv(f->code,s, 0); Printv(f,s, 0);
} }
/* Wrap things up (in a manner of speaking) */ /* Wrap things up (in a manner of speaking) */
if (need_result) { if (need_result) {
Wrapper_add_local(f,"vresult","VALUE vresult = Qnil"); 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 { } else {
Printv(f->code, tab4, "return Qnil;\n}\n", 0); Printv(f, tab4, "return Qnil;\n}\n", 0);
} }
/* Substitute the cleanup code */ /* Substitute the cleanup code */
Replace(f->code,"$cleanup",cleanup, DOH_REPLACE_ANY); Replace(f,"$cleanup",cleanup, DOH_REPLACE_ANY);
/* Emit the function */ /* Emit the function */
Wrapper_print(f,f_wrappers); Printf(f_wrappers,"%s", f);
/* Now register the function with the language */ /* Now register the function with the language */
create_command(name, iname, (vararg ? -1 : numarg)); create_command(name, iname, (vararg ? -1 : numarg));
Delete(cleanup); Delete(cleanup);
Delete(outarg); Delete(outarg);
DelWrapper(f); Delete(f);
} }
/* --------------------------------------------------------------------- /* ---------------------------------------------------------------------
@ -713,9 +714,10 @@ void RUBY::variable(DOH *node) {
/* create getter */ /* create getter */
getfname = NewString(Swig_name_get(name)); getfname = NewString(Swig_name_get(name));
Replace(getfname,"::", "_", DOH_REPLACE_ANY); /* FIXME: Swig_name_get bug? */ Replace(getfname,"::", "_", DOH_REPLACE_ANY); /* FIXME: Swig_name_get bug? */
Printv(getf->def, "static VALUE\n", getfname, "(", 0); Printv(getf, "static VALUE\n", getfname, "(", 0);
Printf(getf->def, "VALUE self"); Printf(getf, "VALUE self");
Printf(getf->def, ") {"); Printf(getf, ") {\n");
Printf(getf, "$locals\n");
Wrapper_add_local(getf,"_val","VALUE _val"); Wrapper_add_local(getf,"_val","VALUE _val");
if (SwigType_type(t) == T_USER) { 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"); tm = ruby_typemap_lookup((char*)"out",t,name,source,(char*)"_val");
if (tm) { if (tm) {
String *s = NewString(tm); String *s = NewString(tm);
Printv(getf->code,s, 0); Printv(getf,s, 0);
Delete(s); Delete(s);
} else { } else {
Printf(stderr,"%s: Line %d. Unable to link with variable type %s\n", Printf(stderr,"%s: Line %d. Unable to link with variable type %s\n",
input_file,line_number,SwigType_str(t,0)); input_file,line_number,SwigType_str(t,0));
} }
Printv(getf->code, tab4, "return _val;\n}\n", 0); Printv(getf, tab4, "return _val;\n}\n", 0);
Wrapper_print(getf,f_wrappers); Printf(f_wrappers,"%s", getf);
if (Status & STAT_READONLY) { if (Status & STAT_READONLY) {
setfname = NewString("NULL"); setfname = NewString("NULL");
@ -749,8 +751,9 @@ void RUBY::variable(DOH *node) {
setfname = NewString(Swig_name_set(name)); setfname = NewString(Swig_name_set(name));
Replace(setfname,"::", "_", DOH_REPLACE_ANY); /* FIXME: Swig_name_get bug? */ Replace(setfname,"::", "_", DOH_REPLACE_ANY); /* FIXME: Swig_name_get bug? */
Printv(setf->def, "static VALUE\n", setfname, "(VALUE self, ", 0); Printv(setf, "static VALUE\n", setfname, "(VALUE self, ", 0);
Printf(setf->def, "VALUE _val) {"); Printf(setf, "VALUE _val) {\n");
Printf(setf, "$locals\n");
if (SwigType_type(t) == T_USER) { if (SwigType_type(t) == T_USER) {
SwigType_add_pointer(t); SwigType_add_pointer(t);
@ -766,18 +769,18 @@ void RUBY::variable(DOH *node) {
tm = ruby_typemap_lookup((char*)"in",t,name,(char*)"_val",target); tm = ruby_typemap_lookup((char*)"in",t,name,(char*)"_val",target);
if (tm) { if (tm) {
String *s = NewString(tm); String *s = NewString(tm);
Printv(setf->code,s,0); Printv(setf,s,0);
Delete(s); Delete(s);
} else { } else {
Printf(stderr,"%s: Line %d. Unable to link with variable type %s\n", Printf(stderr,"%s: Line %d. Unable to link with variable type %s\n",
input_file,line_number,SwigType_str(t,0)); input_file,line_number,SwigType_str(t,0));
} }
if (SwigType_type(t) == T_USER) { 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); Printv(setf, tab4, "return _val;\n",0);
Printf(setf->code,"}\n"); Printf(setf,"}\n");
Wrapper_print(setf,f_wrappers); Printf(f_wrappers,"%s", setf);
} }
/* define accessor method */ /* define accessor method */
@ -823,8 +826,8 @@ void RUBY::variable(DOH *node) {
} }
Delete(getfname); Delete(getfname);
Delete(setfname); Delete(setfname);
DelWrapper(setf); Delete(setf);
DelWrapper(getf); Delete(getf);
} }

View file

@ -287,9 +287,10 @@ TCL8::function(DOH *node) {
args = NewString(""); args = NewString("");
f = NewWrapper(); f = NewWrapper();
Printv(f->def, Printv(f,
"static int\n ", Swig_name_wrapper(iname), "(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {", "static int\n ", Swig_name_wrapper(iname), "(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {\n",
0); 0);
Printf(f,"$locals\n");
/* Print out variables for storing arguments. */ /* Print out variables for storing arguments. */
pcount = emit_args(node, f); pcount = emit_args(node, f);
@ -433,18 +434,18 @@ TCL8::function(DOH *node) {
} }
Printf(argstr,":%s\"",usage_string(iname,d,l)); 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", "if (SWIG_GetArgs(interp, objc, objv,", argstr, args, ") == TCL_ERROR) return TCL_ERROR;\n",
0); 0);
Printv(f->code,incode,0); Printv(f,incode,0);
/* Now write code to make the function call */ /* Now write code to make the function call */
emit_func_call(node,f); emit_func_call(node,f);
/* Return value if necessary */ /* Return value if necessary */
if ((tm = Swig_typemap_lookup((char*)"out",d,name,(char*)"result",(char*)"tcl_result",0))) { 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 { } else {
switch(SwigType_type(d)) { switch(SwigType_type(d)) {
case T_BOOL: case T_BOOL:
@ -456,17 +457,17 @@ TCL8::function(DOH *node) {
case T_USHORT: case T_USHORT:
case T_ULONG: case T_ULONG:
case T_UCHAR: 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; break;
/* Is a single character. We return it as a string */ /* Is a single character. We return it as a string */
case T_CHAR : 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; break;
case T_DOUBLE : case T_DOUBLE :
case T_FLOAT : 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; break;
case T_USER : case T_USER :
@ -475,18 +476,18 @@ TCL8::function(DOH *node) {
Probably dangerous, but safe programming is for wimps. */ Probably dangerous, but safe programming is for wimps. */
SwigType_add_pointer(d); SwigType_add_pointer(d);
SwigType_remember(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_manglestr(d), "));\n", 0);
SwigType_del_pointer(d); SwigType_del_pointer(d);
break; break;
case T_STRING: 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; break;
case T_POINTER: case T_REFERENCE: case T_ARRAY: case T_POINTER: case T_REFERENCE: case T_ARRAY:
SwigType_remember(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", SwigType_manglestr(d), "));\n",
0); 0);
break; break;
@ -502,29 +503,29 @@ TCL8::function(DOH *node) {
} }
/* Dump output argument code */ /* Dump output argument code */
Printv(f->code,outarg,0); Printv(f,outarg,0);
/* Dump the argument cleanup code */ /* Dump the argument cleanup code */
Printv(f->code,cleanup,0); Printv(f,cleanup,0);
/* Look for any remaining cleanup */ /* Look for any remaining cleanup */
if (NewObject) { if (NewObject) {
if ((tm = Swig_typemap_lookup((char*)"newfree",d,iname,(char*)"result",(char*)"",0))) { 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))) { 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 */ /* Substitute the cleanup code */
Replace(f->code,"$cleanup",cleanup,DOH_REPLACE_ANY); Replace(f,"$cleanup",cleanup,DOH_REPLACE_ANY);
Replace(f->code,"$name", iname, DOH_REPLACE_ANY); Replace(f,"$name", iname, DOH_REPLACE_ANY);
/* Dump out the function */ /* Dump out the function */
Wrapper_print(f,f_wrappers); Printf(f_wrappers,"%s",f);
/* Register the function with Tcl */ /* Register the function with Tcl */
Printv(cmd_info, tab4, "{ SWIG_prefix \"", iname, "\", ", Swig_name_wrapper(iname), ", NULL},\n", 0); 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(outarg);
Delete(argstr); Delete(argstr);
Delete(args); Delete(args);
DelWrapper(f); Delete(f);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -584,23 +585,25 @@ TCL8::variable(DOH *node) {
getname = NewStringf("swig_%s_get", Swig_string_mangle(t)); getname = NewStringf("swig_%s_get", Swig_string_mangle(t));
get = NewWrapper(); get = NewWrapper();
set = 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); SwigType *lt = Swig_clocal_type(t);
if ((tc != T_USER) && (!isarray)) if ((tc != T_USER) && (!isarray))
SwigType_add_pointer(lt); SwigType_add_pointer(lt);
Wrapper_add_localv(get,"addr",SwigType_lstr(lt,"addr"),0); Wrapper_add_localv(get,"addr",SwigType_lstr(lt,"addr"),0);
Wrapper_add_localv(set,"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(set, "addr = (", SwigType_lstr(lt,0), ") clientData;\n", 0);
Printv(get->code, "addr = (", SwigType_lstr(lt,0), ") clientData;\n", 0); Printv(get, "addr = (", SwigType_lstr(lt,0), ") clientData;\n", 0);
if ((tc != T_USER) && (!isarray)) if ((tc != T_USER) && (!isarray))
SwigType_del_pointer(lt); SwigType_del_pointer(lt);
Delete(lt); Delete(lt);
Wrapper_add_local(set, "value", "char *value"); Wrapper_add_local(set, "value", "char *value");
Wrapper_add_local(get, "value", "Tcl_Obj *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); "if (!value) return NULL;\n", 0);
switch(tc) { switch(tc) {
@ -611,9 +614,9 @@ TCL8::variable(DOH *node) {
case T_UCHAR: case T_UCHAR:
case T_SCHAR: case T_SCHAR:
case T_BOOL: 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"); Wrapper_add_local(get,"value","Tcl_Obj *value");
Printv(get->code, Printv(get,
"value = Tcl_NewIntObj((int) *addr);\n", "value = Tcl_NewIntObj((int) *addr);\n",
"Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
"Tcl_DecrRefCount(value);\n", "Tcl_DecrRefCount(value);\n",
@ -622,9 +625,9 @@ TCL8::variable(DOH *node) {
case T_UINT: case T_UINT:
case T_ULONG: 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"); Wrapper_add_local(get,"value","Tcl_Obj *value");
Printv(get->code, Printv(get,
"value = Tcl_NewIntObj((int) *addr);\n", "value = Tcl_NewIntObj((int) *addr);\n",
"Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
"Tcl_DecrRefCount(value);\n", "Tcl_DecrRefCount(value);\n",
@ -633,9 +636,9 @@ TCL8::variable(DOH *node) {
case T_FLOAT: case T_FLOAT:
case T_DOUBLE: 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"); Wrapper_add_local(get,"value","Tcl_Obj *value");
Printv(get->code, Printv(get,
"value = Tcl_NewDoubleObj((double) *addr);\n", "value = Tcl_NewDoubleObj((double) *addr);\n",
"Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
"Tcl_DecrRefCount(value);\n", "Tcl_DecrRefCount(value);\n",
@ -643,9 +646,9 @@ TCL8::variable(DOH *node) {
break; break;
case T_CHAR: case T_CHAR:
Printv(set->code, "*(addr) = *value;\n",0); Printv(set, "*(addr) = *value;\n",0);
Wrapper_add_local(get,"temp", "char temp[2]"); 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", "Tcl_SetVar2(interp,name1,name2,temp,flags);\n",
0); 0);
break; break;
@ -654,7 +657,7 @@ TCL8::variable(DOH *node) {
/* User defined type. We return it as a pointer */ /* User defined type. We return it as a pointer */
SwigType_add_pointer(t); SwigType_add_pointer(t);
SwigType_remember(t); SwigType_remember(t);
Printv(set->code, "{\n", Printv(set, "{\n",
"void *ptr;\n", "void *ptr;\n",
"if (SWIG_ConvertPtrFromString(interp,value,&ptr,SWIGTYPE", SwigType_manglestr(t), ") != TCL_OK) {\n", "if (SWIG_ConvertPtrFromString(interp,value,&ptr,SWIGTYPE", SwigType_manglestr(t), ") != TCL_OK) {\n",
"return \"Type Error\";\n", "return \"Type Error\";\n",
@ -667,7 +670,7 @@ TCL8::variable(DOH *node) {
Wrapper_add_local(get,"value", "Tcl_Obj *value"); Wrapper_add_local(get,"value", "Tcl_Obj *value");
SwigType_add_pointer(t); SwigType_add_pointer(t);
SwigType_remember(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_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
"Tcl_DecrRefCount(value);\n",0); "Tcl_DecrRefCount(value);\n",0);
SwigType_del_pointer(t); SwigType_del_pointer(t);
@ -675,11 +678,11 @@ TCL8::variable(DOH *node) {
break; break;
case T_STRING: 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", "*addr = (char *) malloc(strlen(value)+1);\n",
"strcpy(*addr,value);\n", "strcpy(*addr,value);\n",
0); 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; break;
case T_ARRAY: case T_ARRAY:
@ -693,16 +696,16 @@ TCL8::variable(DOH *node) {
if (SwigType_type(ta) == T_CHAR) { if (SwigType_type(ta) == T_CHAR) {
String *dim = SwigType_array_getdim(aop,0); String *dim = SwigType_array_getdim(aop,0);
if (dim && Len(dim)) { if (dim && Len(dim)) {
Printf(set->code, "strncpy(addr,value,%s);\n", dim); Printf(set, "strncpy(addr,value,%s);\n", dim);
setable = 1; setable = 1;
readonly = Status & STAT_READONLY; 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 { } else {
Printf(stderr,"%s:%d: Array variable '%s' will be read-only.\n", input_file, line_number, name); 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"); Wrapper_add_local(get,"value","Tcl_Obj *value");
SwigType_remember(t); SwigType_remember(t);
Printv(get->code, Printv(get,
"value = SWIG_NewPointerObj(addr, SWIGTYPE", SwigType_manglestr(t), ");\n", "value = SWIG_NewPointerObj(addr, SWIGTYPE", SwigType_manglestr(t), ");\n",
"Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
"Tcl_DecrRefCount(value);\n", "Tcl_DecrRefCount(value);\n",
@ -715,7 +718,7 @@ TCL8::variable(DOH *node) {
case T_POINTER: case T_REFERENCE: case T_POINTER: case T_REFERENCE:
SwigType_remember(t); SwigType_remember(t);
Printv(set->code, "{\n", Printv(set, "{\n",
"void *ptr;\n", "void *ptr;\n",
"if (SWIG_ConvertPtrFromString(interp,value,&ptr,SWIGTYPE", SwigType_manglestr(t), ") != TCL_OK) {\n", "if (SWIG_ConvertPtrFromString(interp,value,&ptr,SWIGTYPE", SwigType_manglestr(t), ") != TCL_OK) {\n",
"return \"Type Error\";\n", "return \"Type Error\";\n",
@ -725,7 +728,7 @@ TCL8::variable(DOH *node) {
0); 0);
Wrapper_add_local(get,"value","Tcl_Obj *value"); Wrapper_add_local(get,"value","Tcl_Obj *value");
Printv(get->code, Printv(get,
"value = SWIG_NewPointerObj(*addr, SWIGTYPE", SwigType_manglestr(t), ");\n", "value = SWIG_NewPointerObj(*addr, SWIGTYPE", SwigType_manglestr(t), ");\n",
"Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
"Tcl_DecrRefCount(value);\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)); Printf(stderr,"TCL8::link_variable. Unknown type %s!\n", SwigType_str(t,0));
break; break;
} }
Printv(set->code, "return NULL;\n", "}\n",0); Printv(set, "return NULL;\n", "}\n",0);
Printv(get->code, "return NULL;\n", "}\n",0); Printv(get, "return NULL;\n", "}\n",0);
Wrapper_print(get,f_wrappers); Printf(f_wrappers,"%s",get);
Setattr(getf,Copy(t),getname); Setattr(getf,Copy(t),getname);
if (setable) { if (setable) {
Wrapper_print(set,f_wrappers); Printf(f_wrappers,"%s",set);
Setattr(setf,Copy(t),setname); Setattr(setf,Copy(t),setname);
} }
DelWrapper(get); Delete(get);
DelWrapper(set); Delete(set);
} }
Printv(var_info, tab4,"{ SWIG_prefix \"", iname, "\", (void *) ", isarray ? "" : "&", name, ",", getname, ",", 0); Printv(var_info, tab4,"{ SWIG_prefix \"", iname, "\", (void *) ", isarray ? "" : "&", name, ",", getname, ",", 0);
@ -756,11 +759,12 @@ TCL8::variable(DOH *node) {
static int readonlywrap = 0; static int readonlywrap = 0;
if (!readonlywrap) { if (!readonlywrap) {
Wrapper *ro = NewWrapper(); Wrapper *ro = NewWrapper();
Printf(ro->def, "static char *swig_readonly(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {"); Printf(ro, "static char *swig_readonly(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {\n");
Printv(ro->code, "return \"Variable is read-only\";\n", "}\n", 0); Printf(ro,"$locals\n");
Wrapper_print(ro,f_wrappers); Printv(ro, "return \"Variable is read-only\";\n", "}\n", 0);
Printf(f_wrappers,"%s",ro);
readonlywrap = 1; readonlywrap = 1;
DelWrapper(ro); Delete(ro);
} }
Printf(var_info, "swig_readonly},\n"); Printf(var_info, "swig_readonly},\n");
} else { } else {

View file

@ -189,7 +189,6 @@ public:
char *base; // Base class where this was defined char *base; // Base class where this was defined
int inherited; // Was this member inherited? int inherited; // Was this member inherited?
CPP_member *next; // Next member (for building linked lists) CPP_member *next; // Next member (for building linked lists)
int id; // type id when created
String *signature; String *signature;
CPP_member() { CPP_member() {
@ -231,7 +230,6 @@ public:
line = line_number; line = line_number;
file = input_file; file = input_file;
signature = NewStringf("%s(%s)", n, ParmList_str(l)); signature = NewStringf("%s(%s)", n, ParmList_str(l));
id = cpp_id;
if (AddMethods) { if (AddMethods) {
if (strlen(Char(CCode))) if (strlen(Char(CCode)))
code = Swig_copy_string(Char(CCode)); code = Swig_copy_string(Char(CCode));
@ -317,7 +315,6 @@ public:
next = 0; next = 0;
line = line_number; line = line_number;
file = input_file; file = input_file;
id = 0;
if (AddMethods) { if (AddMethods) {
if (strlen(Char(CCode))) if (strlen(Char(CCode)))
code = Swig_copy_string(Char(CCode)); code = Swig_copy_string(Char(CCode));
@ -369,7 +366,6 @@ public:
inherited = 0; inherited = 0;
line = line_number; line = line_number;
file = input_file; file = input_file;
id = 0;
if (AddMethods) { if (AddMethods) {
if (strlen(Char(CCode))) if (strlen(Char(CCode)))
code = Swig_copy_string(Char(CCode)); code = Swig_copy_string(Char(CCode));
@ -425,11 +421,6 @@ public:
new_method = AddMethods; new_method = AddMethods;
line = line_number; line = line_number;
file = input_file; file = input_file;
if (Inherit_mode) {
id = cpp_id;
} else {
id = 0;
}
code = 0; code = 0;
inherited = 0; inherited = 0;
} }
@ -513,10 +504,6 @@ public:
next = 0; next = 0;
line = line_number; line = line_number;
file = input_file; file = input_file;
if (Inherit_mode)
id = cpp_id;
else
id = 0;
code = 0; code = 0;
inherited = 0; inherited = 0;
} }
@ -652,7 +639,6 @@ public:
m = members; m = members;
while (m) { while (m) {
inherit_base_class = m->base; inherit_base_class = m->base;
cpp_id = m->id;
m->inherit(mode); m->inherit(mode);
m = m->next; m = m->next;
} }
@ -668,7 +654,6 @@ public:
abstract = is_abstract; abstract = is_abstract;
/* Printf(stdout,"class %s. Abstract = %d\n", classname, is_abstract); */ /* Printf(stdout,"class %s. Abstract = %d\n", classname, is_abstract); */
while (m) { while (m) {
cpp_id = m->id;
m->emit(); m->emit();
m = m->next; m = m->next;
} }
@ -1580,7 +1565,7 @@ void cplus_emit_member_func(char *classname, char *classtype, char *classrename,
bc = classname; 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(key,"%s+%s", Swig_name_member(bc,mrename), ParmList_protostr(l));
/* Printf(stdout,"virtual = %d, bc = %s, mkey = %s\n", IsVirtual, bc, key); */ /* 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 (!prev_wrap) {
if (mode && ccode) { if (mode && ccode) {
/* Produce an actual C wrapper */ /* Produce an actual C wrapper */
Wrapper_print(w,f_wrappers); Printf(f_wrappers,"%s",w);
} else if (!mode) { } else if (!mode) {
/* Nah. Just produce a string that does the work for us */ /* 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)); Setattr(w,"scriptname",iname);
DelWrapper(w); lang->function(w);
Delete(w);
} else { } else {
lang->create_command(prev_wrap, iname); 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); new_create_function(cname,iname, type, l);
} else { } else {
Wrapper *w = Swig_cfunction_wrapper(cname, type, l, ccode); Wrapper *w = Swig_cfunction_wrapper(cname, type, l, ccode);
Wrapper_print(w,f_wrappers); Printf(f_wrappers,"%s", w);
new_create_function(cname,iname, Wrapper_Gettype(w), Wrapper_Getparms(w)); Setattr(w,"scriptname",iname);
DelWrapper(w); lang->function(w);
Delete(w);
} }
} }
} else { } else {
@ -1770,19 +1757,20 @@ void cplus_emit_destructor(char *classname, char *classtype, char *classrename,
} else { } else {
w = Swig_cdestructor_wrapper(fclassname, ccode); w = Swig_cdestructor_wrapper(fclassname, ccode);
} }
Setattr(w,"scriptname",iname);
if (mode && ccode) { if (mode && ccode) {
Wrapper_print(w,f_wrappers); Printf(f_wrappers,"%s",w);
new_create_function(Wrapper_Getname(w),iname,Wrapper_Gettype(w), Wrapper_Getparms(w)); lang->function(w);
} else if (mode) { } else if (mode) {
new_create_function(Wrapper_Getname(w),iname,Wrapper_Gettype(w), Wrapper_Getparms(w)); lang->function(w);
} else { } else {
if (CPlusPlus) if (CPlusPlus)
emit_set_action(Swig_cppdestructor_call()); emit_set_action(Swig_cppdestructor_call());
else else
emit_set_action(Swig_cdestructor_call()); 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 { } else {
w = Swig_cconstructor_wrapper(fclassname, l, ccode); w = Swig_cconstructor_wrapper(fclassname, l, ccode);
} }
Setattr(w,"scriptname",iname);
if (!mode) { if (!mode) {
if (CPlusPlus) { if (CPlusPlus) {
emit_set_action(Swig_cppconstructor_call(fclassname, l)); emit_set_action(Swig_cppconstructor_call(fclassname, l));
@ -1837,11 +1825,11 @@ void cplus_emit_constructor(char *classname, char *classtype, char *classrename,
} }
} else { } else {
if (ccode) { 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)); lang->function(w);
DelWrapper(w); Delete(w);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -1922,20 +1910,20 @@ void cplus_emit_variable_get(char *classname, char *classtype, char *classrename
sprintf(fclassname,"%s%s", classtype, classname); sprintf(fclassname,"%s%s", classtype, classname);
w = Swig_cmemberget_wrapper(fclassname,mname,type,ccode); w = Swig_cmemberget_wrapper(fclassname,mname,type,ccode);
Setattr(w,"scriptname",iname);
// Only generate code if already existing wrapper doesn't exist // Only generate code if already existing wrapper doesn't exist
if (!prev_wrap) { if (!prev_wrap) {
if ((mode) && (ccode)) { if ((mode) && (ccode)) {
Wrapper_print(w,f_wrappers); Printf(f_wrappers,"%s", w);
} else if (!mode) { } else if (!mode) {
emit_set_action(Swig_cmemberget_call(mname, type)); 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 { } else {
// Already wrapped this function. Just patch it up // Already wrapped this function. Just patch it up
lang->create_command(prev_wrap,iname); 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); sprintf(fclassname,"%s%s",classtype,classname);
w = Swig_cmemberset_wrapper(fclassname,mname,type,ccode); w = Swig_cmemberset_wrapper(fclassname,mname,type,ccode);
Setattr(w,"scriptname",iname);
// Only generate code if already existing wrapper doesn't exist // Only generate code if already existing wrapper doesn't exist
if (!prev_wrap) { if (!prev_wrap) {
if ((mode) && (ccode)) { if ((mode) && (ccode)) {
Wrapper_print(w,f_wrappers); Printf(f_wrappers,"%s",w);
} else if (!mode) { } else if (!mode) {
/* Check for a member in typemap here */ /* Check for a member in typemap here */
String *target = NewStringf("%s->%s", Swig_cparm_name(0,0),mname); 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); emit_set_action(tm);
Delete(target); Delete(target);
} }
new_create_function(Wrapper_Getname(w),iname, Wrapper_Gettype(w), Wrapper_Getparms(w)); lang->function(w);
} else { } else {
lang->create_command(prev_wrap,iname); lang->create_command(prev_wrap,iname);
} }
DelWrapper(w); Delete(w);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View file

@ -74,16 +74,16 @@ int emit_args(DOH *node, Wrapper *f) {
tm = Swig_typemap_lookup((char*)"arginit",pt,pname,(char*)"",lname,f); tm = Swig_typemap_lookup((char*)"arginit",pt,pname,(char*)"",lname,f);
if (tm) { if (tm) {
Printv(f->code,tm,"\n",0); Printv(f,tm,"\n",0);
} }
/* Check for ignore or default typemaps */ /* Check for ignore or default typemaps */
tm = Swig_typemap_lookup((char*)"default",pt,pname,(char*)"",lname,f); tm = Swig_typemap_lookup((char*)"default",pt,pname,(char*)"",lname,f);
if (tm) { if (tm) {
Printv(f->code,tm,"\n",0); Printv(f,tm,"\n",0);
} }
tm = Swig_typemap_lookup((char*)"ignore",pt,pname,(char*)"",lname,f); tm = Swig_typemap_lookup((char*)"ignore",pt,pname,(char*)"",lname,f);
if (tm) { if (tm) {
Printv(f->code,tm,"\n",0); Printv(f,tm,"\n",0);
Setignore(p,1); Setignore(p,1);
} }
i++; i++;
@ -122,13 +122,13 @@ void emit_func_call(DOH *node, Wrapper *f) {
l = Getattr(node,"parms"); l = Getattr(node,"parms");
if ((tm = Swig_typemap_lookup((char*)"except",t,decl,(char*)"result",(char*)"",0))) { if ((tm = Swig_typemap_lookup((char*)"except",t,decl,(char*)"result",(char*)"",0))) {
Printv(f->code,tm,0); Printv(f,tm,0);
Replace(f->code,"$name",decl,DOH_REPLACE_ANY); Replace(f,"$name",decl,DOH_REPLACE_ANY);
} else if ((tm = Swig_except_lookup())) { } else if ((tm = Swig_except_lookup())) {
Printv(f->code,tm,0); Printv(f,tm,0);
Replace(f->code,"$name",decl,DOH_REPLACE_ANY); Replace(f,"$name",decl,DOH_REPLACE_ANY);
} else { } else {
Printv(f->code,"$function",0); Printv(f,"$function",0);
} }
if (!fcall) fcall = NewString(Swig_cfunction_call(decl,l)); if (!fcall) fcall = NewString(Swig_cfunction_call(decl,l));
@ -200,21 +200,21 @@ void emit_set_get(DOH *node) {
code = c_str; code = c_str;
} }
w = Swig_cvarset_wrapper(name, t, code); w = Swig_cvarset_wrapper(name, t, code);
Wrapper_print(w,f_header); Printf(f_header,"%s", w);
new_iname = Swig_name_set(iname); new_iname = Swig_name_set(iname);
DohIncref(new_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); Delete(new_iname);
DelWrapper(w); Delete(w);
} }
w = Swig_cvarget_wrapper(name,t,0); w = Swig_cvarget_wrapper(name,t,0);
Wrapper_print(w,f_header); Printf(f_header,"%s", w);
new_iname = Swig_name_get(iname); new_iname = Swig_name_get(iname);
DohIncref(new_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); Delete(new_iname);
DelWrapper(w); Delete(w);
} }
/* ------------------------------------------------------------------ /* ------------------------------------------------------------------

View file

@ -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")); 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 String *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 String *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 *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() * Language::cpp_open_class()
@ -53,24 +55,32 @@ void Language::cpp_open_class(char *classname, char *classrename, char *ctype, i
/* Copy the class name */ /* Copy the class name */
if (ClassName) free(ClassName); if (ClassName) Delete(ClassName);
ClassName = Swig_copy_string(classname); ClassName = NewString(classname);
/* Copy the class renaming */ /* Copy the class renaming */
if (ClassRename) free(ClassRename); if (ClassRename) Delete(ClassRename);
if (classrename) { if (classrename) {
ClassRename = Swig_copy_string(classrename); ClassRename = NewString(classrename);
} else { } else {
ClassRename = 0; /* No renaming */ ClassRename = 0; /* No renaming */
} }
/* Make the class type*/ /* Make the class type*/
if (ClassType) free(ClassType); if (ClassType) Delete(ClassType);
ClassType = (char *) malloc(strlen(ctype)+2); if (strip) ClassType = NewString("");
if (strip) ClassType[0] = 0; else ClassType = NewStringf("%s ", ctype);
else sprintf(ClassType,"%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) { void Language::cpp_memberfunction(DOH *node) {
char *name, *iname; String *name;
SwigType *t; String *iname;
ParmList *l; String *ccode;
char new_name[256]; String *script_name;
char *prefix; SwigType *type;
ParmList *parms;
Wrapper *w;
name = GetChar(node,"name"); name = Getattr(node,"name");
iname = GetChar(node,"scriptname"); iname = Getattr(node,"scriptname");
t = Getattr(node,"type"); type = Getattr(node,"type");
l = Getattr(node,"parms"); parms = Getattr(node,"parms");
ccode = Getattr(node,"ccode");
/* Generate the C wrapper function name and interpreter name of this function*/ /* 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 */ /* Create the actual function name */
if (iname) { script_name = Swig_name_member(ClassPrefix, iname ? iname : name);
strcpy(new_name, Char(Swig_name_member(prefix,iname)));
} else {
strcpy(new_name, Char(Swig_name_member(prefix,name)));
}
/* Now do a symbol table lookup on it : */ /* Now do a symbol table lookup on it : */
if (add_symbol(Char(script_name))) {
if (add_symbol(new_name)) {
Printf(stderr,"%s : Line %d. Function %s (member %s) multiply defined (2nd definition ignored).\n", Printf(stderr,"%s : Line %d. Function %s (member %s) multiply defined (2nd definition ignored).\n",
input_file, line_number, iname, name); input_file, line_number, iname, name);
return; 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) { void Language::cpp_constructor(DOH *node) {
char *name, *iname; char *name, *iname;
ParmList *l; ParmList *l;
char *prefix, *cname; char *cname;
name = GetChar(node,"name"); name = GetChar(node,"name");
iname = GetChar(node,"scriptname"); iname = GetChar(node,"scriptname");
l = Getattr(node,"parms"); 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", Printf(stderr,"%s : Line %d. Function %s must have a return type.\n",
input_file, line_number, name); input_file, line_number, name);
return; return;
} }
/* Set the prefix */ cname = Char(Swig_name_construct(iname ? iname : ClassPrefix));
if (ClassRename)
prefix = ClassRename;
else
prefix = ClassName;
if (iname)
cname = Char(Swig_name_construct(iname));
else
cname = Char(Swig_name_construct(prefix));
/* Add this function to the SWIG symbol table */ /* Add this function to the SWIG symbol table */
if (add_symbol(cname)) { if (add_symbol(cname)) {
Printf(stderr,"%s : Line %d. Constructor %s multiply defined (2nd definition ignored).\n", Printf(stderr,"%s : Line %d. Constructor %s multiply defined (2nd definition ignored).\n",
input_file, line_number, cname); input_file, line_number, cname);
@ -165,8 +167,7 @@ void Language::cpp_constructor(DOH *node) {
} }
/* Call our default method */ /* Call our default method */
cplus_emit_constructor(Char(ClassName), Char(ClassType), Char(ClassRename), name, iname, l, AddMethods);
cplus_emit_constructor(ClassName, ClassType, ClassRename, name, iname, l, AddMethods);
} }
@ -180,10 +181,7 @@ void Language::cpp_destructor(DOH *node) {
name = GetChar(node,"name"); name = GetChar(node,"name");
iname = GetChar(node,"scriptname"); iname = GetChar(node,"scriptname");
if (ClassRename) cname = Char(Swig_name_destroy(ClassRename ? ClassRename : ClassName));
cname = Char(Swig_name_destroy(ClassRename));
else
cname = Char(Swig_name_destroy(ClassName));
/* Add this function to the SWIG symbol table */ /* Add this function to the SWIG symbol table */
@ -196,7 +194,7 @@ void Language::cpp_destructor(DOH *node) {
/* Call our default method */ /* 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,7 +231,7 @@ void Language::cpp_inherit(char **baseclass, int mode) {
void Language::cpp_variable(DOH *node) { void Language::cpp_variable(DOH *node) {
char *name, *iname; char *name, *iname;
SwigType *t; SwigType *t;
char *prefix, *cname; char *cname;
name = GetChar(node,"name"); name = GetChar(node,"name");
iname = GetChar(node,"scriptname"); iname = GetChar(node,"scriptname");
@ -241,33 +239,21 @@ void Language::cpp_variable(DOH *node) {
/* Set the class prefix */ /* Set the class prefix */
if (ClassRename) { cname = Char(Swig_name_get(Swig_name_member(ClassPrefix, iname ? iname : name)));
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)));
/* Check the symbol table */ /* Check the symbol table */
if (add_symbol(cname)) { if (add_symbol(cname)) {
Printf(stderr,"%s : Line %d. Variable %s multiply defined (2nd definition ignored).\n", input_file, line_number, cname); Printf(stderr,"%s : Line %d. Variable %s multiply defined (2nd definition ignored).\n", input_file, line_number, cname);
return; return;
} }
/* Create a function to set the value of the variable */ /* Create a function to set the value of the variable */
if (!(Status & STAT_READONLY)) { 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 */ /* Create a function to get the value of a variable */
cplus_emit_variable_get(Char(ClassName),Char(ClassType), Char(ClassRename), name, iname, t, AddMethods);
cplus_emit_variable_get(ClassName,ClassType, ClassRename, name, iname, t, AddMethods);
} }
@ -279,8 +265,6 @@ void Language::cpp_staticfunction(DOH *node) {
char *name, *iname; char *name, *iname;
SwigType *t; SwigType *t;
ParmList *l; ParmList *l;
char *prefix;
char *mname;
char *cname; char *cname;
name = GetChar(node,"name"); name = GetChar(node,"name");
@ -288,21 +272,9 @@ void Language::cpp_staticfunction(DOH *node) {
t = Getattr(node,"type"); t = Getattr(node,"type");
l = Getattr(node,"parms"); l = Getattr(node,"parms");
/* Set the classname prefix */
if (ClassRename)
prefix = ClassRename;
else
prefix = ClassName;
/* Set the member function name */ /* Set the member function name */
if (iname) cname = Char(Swig_name_member(ClassPrefix,iname ? iname : name));
mname = iname;
else
mname = name;
cname = Char(Swig_name_member(prefix,mname));
/* Now do a symbol table lookup on it : */ /* Now do a symbol table lookup on it : */
@ -315,8 +287,7 @@ void Language::cpp_staticfunction(DOH *node) {
input_file, line_number, cname); input_file, line_number, cname);
return; 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 *cname;
char mname[256]; char mname[256];
char *new_value; String *new_value;
char *prefix;
name = GetChar(node,"name"); name = GetChar(node,"name");
iname = GetChar(node,"scriptname"); iname = GetChar(node,"scriptname");
value = GetChar(node,"value"); value = GetChar(node,"value");
type = Getattr(node,"type"); type = Getattr(node,"type");
/* Set the classname prefix */
if (ClassRename) {
prefix = ClassRename;
} else {
prefix = ClassName;
}
/* Set the constant name */ /* Set the constant name */
if (iname) cname = Char(Swig_name_member(ClassPrefix, iname ? iname : name));
cname = Char(Swig_name_member(prefix,iname));
else
cname = Char(Swig_name_member(prefix,name));
/* Now do a symbol table lookup on it : */ /* Now do a symbol table lookup on it : */
if (add_symbol(cname)) { if (add_symbol(cname)) {
Printf(stderr,"%s : Line %d. Constant %s (member %s) multiply defined (2nd definition ignored).\n", Printf(stderr,"%s : Line %d. Constant %s (member %s) multiply defined (2nd definition ignored).\n",
input_file, line_number, cname, name); input_file, line_number, cname, name);
@ -362,15 +320,13 @@ void Language::cpp_constant(DOH *node)
} }
/* Form correct C++ name */ /* Form correct C++ name */
sprintf(mname,"%s::%s",ClassName,name); sprintf(mname,"%s::%s",ClassName,name);
/* Declare a constant */ /* Declare a constant */
if (!value) { if (!value) {
new_value = (char *) malloc(strlen(ClassName)+strlen(name)+3); new_value = NewStringf("%s::%s", ClassName, name);
sprintf(new_value,"%s::%s",ClassName,name);
} else { } else {
new_value = value; new_value = NewString(value);
} }
Hash *n; Hash *n;
n = NewHash(); n = NewHash();
@ -380,10 +336,7 @@ void Language::cpp_constant(DOH *node)
Setattr(n,"value",new_value); Setattr(n,"value",new_value);
lang->constant(n); lang->constant(n);
Delete(n); Delete(n);
Delete(new_value);
if (!value) {
free(new_value);
}
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -395,29 +348,16 @@ void Language::cpp_staticvariable(DOH *node) {
SwigType *t; SwigType *t;
char *cname; char *cname;
char mname[256]; char mname[256];
char *prefix;
name = GetChar(node,"name"); name = GetChar(node,"name");
iname = GetChar(node,"scriptname"); iname = GetChar(node,"scriptname");
t = Getattr(node,"type"); t = Getattr(node,"type");
/* Set the classname prefix */
if (ClassRename) {
prefix = ClassRename;
} else {
prefix = ClassName;
}
/* Create the variable name */ /* Create the variable name */
if (iname) cname = Char(Swig_name_member(ClassPrefix, iname ? iname : name));
cname = Char(Swig_name_member(prefix,iname));
else
cname = Char(Swig_name_member(prefix,name));
/* Now do a symbol table lookup on it : */ /* Now do a symbol table lookup on it : */
if (add_symbol(cname)) { if (add_symbol(cname)) {
Printf(stderr,"%s : Line %d. Variable %s (member %s) multiply defined (2nd definition ignored).\n", Printf(stderr,"%s : Line %d. Variable %s (member %s) multiply defined (2nd definition ignored).\n",
input_file, line_number, cname, name); input_file, line_number, cname, name);
@ -425,7 +365,6 @@ void Language::cpp_staticvariable(DOH *node) {
} }
/* Form correct C++ name */ /* Form correct C++ name */
sprintf(mname,"%s::%s",ClassName,name); sprintf(mname,"%s::%s",ClassName,name);
/* Link with this variable */ /* Link with this variable */

View file

@ -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)); Printf(fcall,"%s = (%s) &_result_ref;\n", name, SwigType_lstr(t,0));
} }
if (Replace(w->code,"$function",fcall, DOH_REPLACE_ANY) == 0) { if (Replace(w,"$function",fcall, DOH_REPLACE_ANY) == 0) {
Printv(w->code, fcall, 0); Printv(w, fcall, 0);
} }
Delete(fcall); Delete(fcall);
} }
@ -278,8 +278,8 @@ void Swig_cppresult(Wrapper *w, SwigType *t, String_or_char *name, String_or_cha
break; break;
} }
if (Replace(w->code,"$function",fcall, DOH_REPLACE_ANY) == 0) { if (Replace(w,"$function",fcall, DOH_REPLACE_ANY) == 0) {
Printv(w->code, fcall, 0); Printv(w, fcall, 0);
} }
Delete(fcall); Delete(fcall);
} }
@ -519,18 +519,19 @@ Swig_cfunction_wrapper(String_or_char *funcname,
w = NewWrapper(); w = NewWrapper();
/* Set the name of the function */ /* Set the name of the function */
Wrapper_Setname(w,funcname); Setname(w,funcname);
l = CopyParmList(parms); l = CopyParmList(parms);
fix_parm_names(l); 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) { if (code) {
Printv(w->code, code, "\n", 0); Printv(w, code, "\n", 0);
} }
Printf(w->code,"}\n"); Printf(w,"}\n");
Wrapper_Settype(w,rtype); Setattr(w,"type",rtype);
Wrapper_Setparms(w,l); Setattr(w,"parms",l);
Delete(l); Delete(l);
return w; return w;
} }
@ -557,7 +558,7 @@ Swig_cmethod_wrapper(String_or_char *classname,
w = NewWrapper(); w = NewWrapper();
/* Set the name of the function */ /* Set the name of the function */
Wrapper_Setname(w,Swig_name_member(classname, methodname)); Setname(w,Swig_name_member(classname, methodname));
l = CopyParmList(parms); l = CopyParmList(parms);
t = NewString(classname); t = NewString(classname);
@ -569,30 +570,31 @@ Swig_cmethod_wrapper(String_or_char *classname,
l = p; l = p;
fix_parm_names(l); 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) { if (!code) {
/* No code supplied. Write a function manually */ /* No code supplied. Write a function manually */
if (SwigType_type(rtype) != T_VOID) { 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); p = Getnext(l);
while (p) { while (p) {
Printf(w->code,"%s", Getname(p)); Printf(w,"%s", Getname(p));
p = Getnext(p); p = Getnext(p);
if (p) if (p)
Printf(w->code,","); Printf(w,",");
} }
Printf(w->code,");\n"); Printf(w,");\n");
Printf(w->code,"}\n"); Printf(w,"}\n");
} else { } else {
Printv(w->code, code, "\n", 0); Printv(w, code, "\n", 0);
Printf(w->code,"}\n"); Printf(w,"}\n");
} }
Wrapper_Settype(w,rtype); Setattr(w,"type",rtype);
Wrapper_Setparms(w,l); Setattr(w,"parms",l);
Delete(l); Delete(l);
return w; return w;
} }
@ -616,7 +618,7 @@ Swig_cconstructor_wrapper(String_or_char *classname,
w = NewWrapper(); w = NewWrapper();
/* Set the name of the function */ /* Set the name of the function */
Wrapper_Setname(w,Swig_name_construct(classname)); Setname(w,Swig_name_construct(classname));
l = CopyParmList(parms); l = CopyParmList(parms);
t = NewString(classname); t = NewString(classname);
@ -625,17 +627,18 @@ Swig_cconstructor_wrapper(String_or_char *classname,
/* Patch up the argument names */ /* Patch up the argument names */
fix_parm_names(l); 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) { if (!code) {
/* No code supplied. Write a function manually */ /* 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 { } else {
Printv(w->code, code, "\n", 0); Printv(w, code, "\n", 0);
} }
Printf(w->code,"}\n"); Printf(w,"}\n");
Wrapper_Settype(w,t); Setattr(w,"type",t);
Wrapper_Setparms(w,l); Setattr(w,"parms",l);
Delete(l); Delete(l);
Delete(t); Delete(t);
return w; return w;
@ -660,7 +663,7 @@ Swig_cppconstructor_wrapper(String_or_char *classname,
w = NewWrapper(); w = NewWrapper();
/* Set the name of the function */ /* Set the name of the function */
Wrapper_Setname(w,Swig_name_construct(classname)); Setname(w,Swig_name_construct(classname));
l = CopyParmList(parms); l = CopyParmList(parms);
t = NewString(classname); t = NewString(classname);
@ -669,29 +672,30 @@ Swig_cppconstructor_wrapper(String_or_char *classname,
/* Patch up the argument names */ /* Patch up the argument names */
fix_parm_names(l); 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) { if (!code) {
/* No code supplied. Write a function manually */ /* 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; p = l;
if (p) { if (p) {
Printf(w->code,"("); Printf(w,"(");
while (p) { while (p) {
Printf(w->code,"%s", Getname(p)); Printf(w,"%s", Getname(p));
p = Getnext(p); p = Getnext(p);
if (p) if (p)
Printf(w->code,","); Printf(w,",");
} }
Printf(w->code,")"); Printf(w,")");
} }
Printf(w->code,";\n"); Printf(w,";\n");
} else { } else {
Printv(w->code, code, "\n", 0); Printv(w, code, "\n", 0);
} }
Printf(w->code,"}\n"); Printf(w,"}\n");
Wrapper_Settype(w,t); Setattr(w,"type",t);
Wrapper_Setparms(w,l); Setattr(w,"parms",l);
Delete(l); Delete(l);
Delete(t); Delete(t);
return w; return w;
@ -716,7 +720,7 @@ Swig_cdestructor_wrapper(String_or_char *classname,
w = NewWrapper(); w = NewWrapper();
/* Set the name of the function */ /* Set the name of the function */
Wrapper_Setname(w,Swig_name_destroy(classname)); Setname(w, Swig_name_destroy(classname));
t = NewString(classname); t = NewString(classname);
SwigType_add_pointer(t); SwigType_add_pointer(t);
@ -726,17 +730,18 @@ Swig_cdestructor_wrapper(String_or_char *classname,
t = NewString("void"); 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) { if (!code) {
/* No code supplied. Write a function manually */ /* No code supplied. Write a function manually */
Printf(w->code,"free((char *) self);\n"); Printf(w,"free((char *) self);\n");
} else { } else {
Printv(w->code, code, "\n", 0); Printv(w, code, "\n", 0);
} }
Printf(w->code,"}\n"); Printf(w,"}\n");
Wrapper_Settype(w,t); Setattr(w,"type",t);
Wrapper_Setparms(w,l); Setattr(w,"parms",l);
Delete(l); Delete(l);
Delete(t); Delete(t);
return w; return w;
@ -761,7 +766,7 @@ Swig_cppdestructor_wrapper(String_or_char *classname,
w = NewWrapper(); w = NewWrapper();
/* Set the name of the function */ /* Set the name of the function */
Wrapper_Setname(w,Swig_name_destroy(classname)); Setname(w, Swig_name_destroy(classname));
t = NewString(classname); t = NewString(classname);
SwigType_add_pointer(t); SwigType_add_pointer(t);
@ -772,17 +777,18 @@ Swig_cppdestructor_wrapper(String_or_char *classname,
t = NewString("void"); 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) { if (!code) {
/* No code supplied. Write a function manually */ /* No code supplied. Write a function manually */
Printf(w->code,"delete self;\n"); Printf(w,"delete self;\n");
} else { } else {
Printv(w->code, code, "\n", 0); Printv(w, code, "\n", 0);
} }
Printf(w->code,"}\n"); Printf(w,"}\n");
Wrapper_Settype(w,t); Setattr(w,"type",t);
Wrapper_Setparms(w,l); Setattr(w,"parms",l);
Delete(l); Delete(l);
Delete(t); Delete(t);
return w; return w;
@ -809,7 +815,7 @@ Swig_cmemberset_wrapper(String_or_char *classname,
w = NewWrapper(); w = NewWrapper();
/* Set the name of the function */ /* 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); t = NewString(classname);
SwigType_add_pointer(t); SwigType_add_pointer(t);
@ -821,20 +827,20 @@ Swig_cmemberset_wrapper(String_or_char *classname,
p = NewParm(lt,"value"); p = NewParm(lt,"value");
Setnext(l,p); Setnext(l,p);
/* Printf(w->def,"%s %s(%s) {", SwigType_str(lt,0), Wrapper_Getname(w), ParmList_str(l)); */ Printf(w,"void %s(%s) {\n", Getname(w), ParmList_str(l));
Printf(w->def,"void %s(%s) {", Wrapper_Getname(w), ParmList_str(l)); Printf(w,"$locals\n");
if (!code) { if (!code) {
/* No code supplied. Write a function manually */ /* No code supplied. Write a function manually */
Printf(w->code,"self->%s = %s;\n", membername, Swig_clocal_deref(lt,"value")); Printf(w,"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,"return %s self->%s;\n", Swig_clocal_assign(lt,""), membername);
} else { } 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,lt); */
Wrapper_Settype(w,"void"); Setattr(w,"type","void");
Wrapper_Setparms(w,l); Setattr(w,"parms", l);
Delete(l); Delete(l);
Delete(lt); Delete(lt);
return w; return w;
@ -862,7 +868,7 @@ Swig_cmemberget_wrapper(String_or_char *classname,
w = NewWrapper(); w = NewWrapper();
/* Set the name of the function */ /* 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); t = NewString(classname);
SwigType_add_pointer(t); SwigType_add_pointer(t);
@ -871,17 +877,18 @@ Swig_cmemberget_wrapper(String_or_char *classname,
Delete(t); Delete(t);
lt = Swig_clocal_type(type); 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) { if (!code) {
/* No code supplied. Write a function manually */ /* 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 { } else {
Printv(w->code, code, "\n", 0); Printv(w, code, "\n", 0);
} }
Printf(w->code,"}\n"); Printf(w,"}\n");
Wrapper_Settype(w,lt); Setattr(w,"type",lt);
Wrapper_Setparms(w,l); Setattr(w,"parms",l);
Delete(l); Delete(l);
Delete(lt); Delete(lt);
return w; return w;
@ -906,28 +913,29 @@ Swig_cvarset_wrapper(String_or_char *varname,
w = NewWrapper(); w = NewWrapper();
/* Set the name of the function */ /* Set the name of the function */
Wrapper_Setname(w,Swig_name_set(varname)); Setname(w,Swig_name_set(varname));
lt = Swig_clocal_type(type); lt = Swig_clocal_type(type);
p = NewParm(lt,"value"); p = NewParm(lt,"value");
l = p; 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) { if (!code) {
/* No code supplied. Write a function manually */ /* No code supplied. Write a function manually */
Printf(w->code,"%s = %s;\n", varname, Swig_clocal_deref(lt,"value")); Printf(w,"%s = %s;\n", varname, Swig_clocal_deref(lt,"value"));
Printf(w->code,"return %s;\n", Swig_clocal_assign(lt,varname)); Printf(w,"return %s;\n", Swig_clocal_assign(lt,varname));
} else { } else {
Printv(w->code, code, "\n", 0); Printv(w, code, "\n", 0);
Replace(w->code,"$target",varname, DOH_REPLACE_ANY); Replace(w,"$target",varname, DOH_REPLACE_ANY);
Replace(w->code,"$source","value", DOH_REPLACE_ANY); Replace(w,"$source","value", DOH_REPLACE_ANY);
Replace(w->code,"$ltype", SwigType_str(lt,""), DOH_REPLACE_ANY); Replace(w,"$ltype", SwigType_str(lt,""), DOH_REPLACE_ANY);
Replace(w->code,"$rtype", SwigType_str(type,""), DOH_REPLACE_ANY); Replace(w,"$rtype", SwigType_str(type,""), DOH_REPLACE_ANY);
} }
Printf(w->code,"}\n"); Printf(w,"}\n");
Wrapper_Settype(w,lt); Setattr(w,"type",lt);
Wrapper_Setparms(w,l); Setattr(w,"parms",l);
Delete(l); Delete(l);
Delete(lt); Delete(lt);
return w; return w;
@ -951,21 +959,22 @@ Swig_cvarget_wrapper(String_or_char *varname,
w = NewWrapper(); w = NewWrapper();
/* Set the name of the function */ /* Set the name of the function */
Wrapper_Setname(w, Swig_name_get(varname)); Setname(w,Swig_name_get(varname));
lt = Swig_clocal_type(type); 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) { if (!code) {
/* No code supplied. Write a function manually */ /* 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 { } else {
Printv(w->code, code, "\n", 0); Printv(w, code, "\n", 0);
} }
Printf(w->code,"}\n"); Printf(w,"}\n");
Wrapper_Settype(w,lt); Setattr(w,"type",lt);
Wrapper_Setparms(w,l); Setattr(w,"parms",l);
Delete(l); Delete(l);
Delete(lt); Delete(lt);
return w; return w;

View file

@ -263,31 +263,15 @@ extern void Swig_dump_rules();
/* -- Wrapper function Object */ /* -- Wrapper function Object */
typedef struct { typedef DOH Wrapper;
SwigType *_type;
ParmList *_parms;
String *_name;
Hash *localh;
String *def;
String *locals;
String *code;
} Wrapper;
extern Wrapper *NewWrapper(); extern Wrapper *NewWrapper();
extern void DelWrapper(Wrapper *w);
extern void Wrapper_pretty_print(String *str, File *f); 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_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_add_localv(Wrapper *w, const String_or_char *name, ...);
extern int Wrapper_check_local(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_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 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 --- */ /* --- Naming functions --- */

View file

@ -429,7 +429,7 @@ char *Swig_typemap_lookup(char *op, SwigType *type, String_or_char *pname, Strin
DOHString *dim = SwigType_array_getdim(type,i); DOHString *dim = SwigType_array_getdim(type,i);
sprintf(temp,"$dim%d",i); sprintf(temp,"$dim%d",i);
if (f) 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); Replace(s,temp,dim,DOH_REPLACE_ANY);
} }
} }

View file

@ -19,42 +19,25 @@ static char cvsroot[] = "$Header$";
#include "swig.h" #include "swig.h"
#include <ctype.h> #include <ctype.h>
/* ----------------------------------------------------------------------------- #include "dohobj.h"
* NewWrapper()
*
* Create a new wrapper function object.
* ----------------------------------------------------------------------------- */
Wrapper * typedef struct {
NewWrapper() { Hash *attr; /* Attributes */
Wrapper *w; Hash *localh; /* Hash of local variable names */
w = (Wrapper *) malloc(sizeof(Wrapper)); String *code; /* Code string */
w->localh = NewHash(); } WrapObj;
w->locals = NewString("");
w->code = NewString("");
w->def = NewString("");
w->_type = 0;
w->_parms = 0;
w->_name = 0;
return w;
}
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* DelWrapper() * DelWrapper()
*
* Delete a wrapper function object.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void static void
DelWrapper(Wrapper *w) { DelWrapper(DOH *wo) {
WrapObj *w = (WrapObj *) ObjData(wo);
Delete(w->localh); Delete(w->localh);
Delete(w->locals);
Delete(w->code); Delete(w->code);
Delete(w->def); Delete(w->attr);
Delete(w->_type); DohFree(w);
Delete(w->_parms);
Delete(w->_name);
free(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 static String *
Wrapper_print(Wrapper *w, File *f) { Wrapper_str(DOH *wo) {
String *str; 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); * Wrapper_dump()
Printf(str,"%s\n", w->locals); *
Printf(str,"%s\n", w->code); * Serialize on out
Wrapper_pretty_print(str,f); * ----------------------------------------------------------------------------- */
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 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 */ /* See if the local has already been declared */
if (Getattr(w->localh,name)) { if (Getattr(w->localh,name)) {
return -1; return -1;
} }
Setattr(w->localh,name,decl); Setattr(w->localh,name,decl);
Printf(w->locals,"%s;\n", decl); Printf(Getattr(w->attr,"locals"),"%s;\n", decl);
return 0; return 0;
} }
@ -182,11 +183,12 @@ Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int int
Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) { Wrapper_add_localv(Wrapper *wo, const String_or_char *name, ...) {
va_list ap; va_list ap;
int ret; int ret;
String *decl; String *decl;
DOH *obj; DOH *obj;
WrapObj *w = (WrapObj *) ObjData(wo);
decl = NewString(""); decl = NewString("");
va_start(ap,name); va_start(ap,name);
@ -198,7 +200,7 @@ Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) {
} }
va_end(ap); va_end(ap);
ret = Wrapper_add_local(w,name,decl); ret = Wrapper_add_local(wo,name,decl);
Delete(decl); Delete(decl);
return ret; return ret;
} }
@ -210,7 +212,8 @@ Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) {
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int 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)) { if (Getattr(w->localh,name)) {
return 1; return 1;
} }
@ -225,12 +228,12 @@ Wrapper_check_local(Wrapper *w, const String_or_char *name) {
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
char * 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; int i;
char *ret;
String *nname = NewString(name); String *nname = NewString(name);
String *ndecl = NewString(decl); String *ndecl = NewString(decl);
char *ret; WrapObj *w = (WrapObj *) ObjData(wo);
i = 0; i = 0;
while (Wrapper_check_local(w,nname)) { 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); Replace(ndecl, name, nname, DOH_REPLACE_ID);
Setattr(w->localh,nname,ndecl); Setattr(w->localh,nname,ndecl);
Printf(w->locals,"%s;\n", ndecl); Printf(Getattr(w->attr,"locals"),"%s;\n", ndecl);
ret = Char(nname); ret = Char(nname);
Delete(nname); Delete(nname);
Delete(ndecl); Delete(ndecl);
@ -257,11 +260,12 @@ Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
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; va_list ap;
char *ret; char *ret;
String *decl; String *decl;
DOH *obj; DOH *obj;
WrapObj *w = (WrapObj *) ObjData(wo);
decl = NewString(""); decl = NewString("");
va_start(ap,name); va_start(ap,name);
@ -273,71 +277,188 @@ Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...) {
} }
va_end(ap); va_end(ap);
ret = Wrapper_new_local(w,name,decl); ret = Wrapper_new_local(wo,name,decl);
Delete(decl); Delete(decl);
return ret; return ret;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Wrapper_Gettype() * Wrapper_Getattr()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
SwigType * static DOH *
Wrapper_Gettype(Wrapper *w) { Wrapper_getattr(Wrapper *wo, DOH *k) {
return w->_type; WrapObj *w = (WrapObj *) ObjData(wo);
return Getattr(w->attr,k);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Wrapper_Settype() * Wrapper_Delattr()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void static int
Wrapper_Settype(Wrapper *w, SwigType *t) { Wrapper_delattr(Wrapper *wo, DOH *k) {
Delete(w->_type); WrapObj *w = (WrapObj *) ObjData(wo);
w->_type = NewString(t); Delattr(w->attr,k);
return 0;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Wrapper_Getparms() * Wrapper_Setattr()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
ParmList * static int
Wrapper_Getparms(Wrapper *w) { Wrapper_setattr(Wrapper *wo, DOH *k, DOH *obj) {
return w->_parms; WrapObj *w = (WrapObj *) ObjData(wo);
return Setattr(w->attr,k,obj);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Wrapper_Setparms() * Wrapper_firstkey()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void static DOH *
Wrapper_Setparms(Wrapper *w, ParmList *l) { Wrapper_firstkey(Wrapper *wo) {
Delete(w->_parms); WrapObj *w = (WrapObj *) ObjData(wo);
w->_parms = l; return Firstkey(w->attr);
DohIncref(l);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Wrapper_Getname() * Wrapper_firstkey()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
char * static DOH *
Wrapper_Getname(Wrapper *w) { Wrapper_nextkey(Wrapper *wo) {
return Char(w->_name); 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 static DohHashMethods WrapperHashMethods = {
Wrapper_Setname(Wrapper *w, String_or_char *n) { Wrapper_getattr,
Delete(w->_name); Wrapper_setattr,
w->_name = NewString(n); 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);
} }