Modified the WrapperFunction class. Fixed various bugs

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@555 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-07-10 16:46:18 +00:00
commit 64e2755215
18 changed files with 524 additions and 492 deletions

View file

@ -34,7 +34,11 @@ DohDelete(DOH *obj) {
DohBase *b = (DohBase *) obj; DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo; DohObjInfo *objinfo;
if (!DohCheck(b)) return; if (!obj) return;
if (!DohCheck(b)) {
fprintf(stderr,"DOH: Fatal error. Attempt to delete a non-doh object.\n");
abort();
}
if (b->flag_intern) return; if (b->flag_intern) return;
b->refcount--; b->refcount--;
if (b->refcount <= 0) { if (b->refcount <= 0) {

View file

@ -346,22 +346,22 @@ GUILE::close (void)
void void
GUILE::get_pointer (char *iname, int parm, DataType *t, GUILE::get_pointer (char *iname, int parm, DataType *t,
WrapperFunction &f, DOHString_or_char *proc_name, Wrapper *f, DOHString_or_char *proc_name,
int num_scheme_parm) int num_scheme_parm)
{ {
/* Pointers are smobs */ /* Pointers are smobs */
Printf(f.code, " if (SWIG_Guile_GetPtr_Str(s_%d,(void **) &_arg%d", parm, parm); Printf(f->code, " if (SWIG_Guile_GetPtr_Str(s_%d,(void **) &_arg%d", parm, parm);
if (t->type == T_VOID) if (t->type == T_VOID)
Printf(f.code, ", (char *) 0)) {\n"); Printf(f->code, ", (char *) 0)) {\n");
else else
Printv(f.code, ", \"", t->print_mangle(), "\")) {\n", 0); Printv(f->code, ", \"", t->print_mangle(), "\")) {\n", 0);
/* Raise exception */ /* Raise exception */
Printv(f.code, Printv(f->code,
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->code,"%d, s_%d);\n", num_scheme_parm, parm);
Printv(f.code, tab4, "}\n", 0); Printv(f->code, tab4, "}\n", 0);
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -405,10 +405,11 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
DOHString *proc_name = 0; DOHString *proc_name = 0;
char source[256], target[256], argnum[256], arg[256]; char source[256], target[256], argnum[256], arg[256];
char *tm; char *tm;
WrapperFunction f; Wrapper *f;
DOHString *cleanup; DOHString *cleanup;
DOHString *outarg; DOHString *outarg;
f = NewWrapper();
outarg = NewString(""); outarg = NewString("");
cleanup = NewString(""); cleanup = NewString("");
@ -422,7 +423,7 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
// Now write the wrapper function itself....this is pretty ugly // Now write the wrapper function itself....this is pretty ugly
Printv(f.def, "static SCM\n", wname," (", 0); Printv(f->def, "static SCM\n", wname," (", 0);
int i = 0; int i = 0;
int first_arg = 1; int first_arg = 1;
@ -431,17 +432,17 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
continue; continue;
if ((p->t->type != T_VOID) || (p->t->is_pointer)) { if ((p->t->type != T_VOID) || (p->t->is_pointer)) {
if (!first_arg) if (!first_arg)
Printf(f.def,", "); Printf(f->def,", ");
Printf(f.def,"SCM s_%d", i); Printf(f->def,"SCM s_%d", i);
first_arg = 0; first_arg = 0;
} }
} }
Printf(f.def, ")\n{\n"); Printf(f->def, ")\n{\n");
// Define the scheme name in C // Define the scheme name in C
Printv(f.def, "#define SCHEME_NAME \"", proc_name, "\"\n", 0); Printv(f->def, "#define SCHEME_NAME \"", proc_name, "\"\n", 0);
// Declare return variable and arguments // Declare return variable and arguments
@ -449,7 +450,7 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
int numargs = 0; int numargs = 0;
int numopt = 0; int numopt = 0;
f.add_local ((char*)"SCM", (char*)"gswig_result"); Wrapper_add_local (f,(char*)"SCM", (char*)"gswig_result", 0);
// Now write code to extract the parameters (this is super ugly) // Now write code to extract the parameters (this is super ugly)
@ -467,13 +468,13 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
// Handle parameter types. // Handle parameter types.
if (p.ignore) if (p.ignore)
Printv(f.code, "/* ", p.name, " ignored... */\n", 0); Printv(f->code, "/* ", p.name, " ignored... */\n", 0);
else { else {
++numargs; ++numargs;
if ((tm = typemap_lookup ((char*)"in", typemap_lang, if ((tm = typemap_lookup ((char*)"in", typemap_lang,
p.t, p.name, source, target, &f))) { p.t, p.name, source, target, f))) {
Printv(f.code,tm,"\n",0); Printv(f->code,tm,"\n",0);
mreplace (f.code, argnum, arg, proc_name); mreplace (f->code, argnum, arg, proc_name);
} }
else if (p.t->is_pointer) else if (p.t->is_pointer)
get_pointer (iname, i, p.t, f, proc_name, numargs); get_pointer (iname, i, p.t, f, proc_name, numargs);
@ -486,15 +487,15 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
// Check if there are any constraints. // Check if there are any constraints.
if ((tm = typemap_lookup ((char*)"check", typemap_lang, if ((tm = typemap_lookup ((char*)"check", typemap_lang,
p.t, p.name, source, target, &f))) { p.t, p.name, source, target, f))) {
Printv(f.code,tm,"\n",0); Printv(f->code,tm,"\n",0);
mreplace (f.code, argnum, arg, proc_name); mreplace (f->code, argnum, arg, proc_name);
} }
// Pass output arguments back to the caller. // Pass output arguments back to the caller.
if ((tm = typemap_lookup ((char*)"argout", typemap_lang, if ((tm = typemap_lookup ((char*)"argout", typemap_lang,
p.t, p.name, source, target, &f))) { p.t, p.name, source, target, f))) {
Printv(outarg,tm,"\n",0); Printv(outarg,tm,"\n",0);
mreplace (outarg, argnum, arg, proc_name); mreplace (outarg, argnum, arg, proc_name);
} }
@ -502,30 +503,30 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
// Free up any memory allocated for the arguments. // Free up any memory allocated for the arguments.
if ((tm = typemap_lookup ((char*)"freearg", typemap_lang, if ((tm = typemap_lookup ((char*)"freearg", typemap_lang,
p.t, p.name, source, target, &f))) { p.t, p.name, source, target, f))) {
Printv(cleanup, tm, "\n", 0); Printv(cleanup, tm, "\n", 0);
mreplace (cleanup, argnum, arg, proc_name); mreplace (cleanup, argnum, arg, proc_name);
} }
} }
// 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->code, tab4, "gh_defer_ints();\n", 0);
emit_func_call (name, d, l, f); emit_func_call (name, d, l, f);
Printv(f.code, tab4, "gh_allow_ints();\n", 0); Printv(f->code, 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 (d->type == T_VOID) if (d->type == T_VOID)
Printv(f.code, tab4, "gswig_result = GH_UNSPECIFIED;\n", 0); Printv(f->code, tab4, "gswig_result = GH_UNSPECIFIED;\n", 0);
else if ((tm = typemap_lookup ((char*)"out", typemap_lang, else if ((tm = typemap_lookup ((char*)"out", typemap_lang,
d, name, (char*)"_result", (char*)"gswig_result", &f))) { d, name, (char*)"_result", (char*)"gswig_result", f))) {
Printv(f.code,tm,"\n",0); Printv(f->code,tm,"\n",0);
mreplace (f.code, argnum, arg, proc_name); mreplace (f->code, argnum, arg, proc_name);
} }
else if (d->is_pointer) { else if (d->is_pointer) {
/* MK: I would like to use SWIG_Guile_MakePtr here to save one type /* MK: I would like to use SWIG_Guile_MakePtr here to save one type
look-up. */ look-up. */
Printv(f.code, tab4, Printv(f->code, tab4,
"gswig_result = SWIG_Guile_MakePtr_Str (", "gswig_result = SWIG_Guile_MakePtr_Str (",
"_result, ", "_result, ",
"\"", d->print_mangle(), "\", ", "\"", d->print_mangle(), "\", ",
@ -538,39 +539,39 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
} }
// Dump the argument output code // Dump the argument output code
Printv(f.code,outarg,0); Printv(f->code,outarg,0);
// Dump the argument cleanup code // Dump the argument cleanup code
Printv(f.code,cleanup,0); Printv(f->code,cleanup,0);
// Look for any remaining cleanup // Look for any remaining cleanup
if (NewObject) { if (NewObject) {
if ((tm = typemap_lookup ((char*)"newfree", typemap_lang, if ((tm = typemap_lookup ((char*)"newfree", typemap_lang,
d, iname, (char*)"_result", (char*)"", &f))) { d, iname, (char*)"_result", (char*)"", f))) {
Printv(f.code,tm,"\n",0); Printv(f->code,tm,"\n",0);
mreplace (f.code, argnum, arg, proc_name); mreplace (f->code, argnum, arg, proc_name);
} }
} }
// Free any memory allocated by the function being wrapped.. // Free any memory allocated by the function being wrapped..
if ((tm = typemap_lookup ((char*)"ret", typemap_lang, if ((tm = typemap_lookup ((char*)"ret", typemap_lang,
d, name, (char*)"_result", (char*)"", &f))) { d, name, (char*)"_result", (char*)"", f))) {
Printv(f.code,tm,"\n",0); Printv(f->code,tm,"\n",0);
mreplace (f.code, argnum, arg, proc_name); mreplace (f->code, argnum, arg, proc_name);
} }
// Wrap things up (in a manner of speaking) // Wrap things up (in a manner of speaking)
Printv(f.code, tab4, "return gswig_result;\n", 0); Printv(f->code, tab4, "return gswig_result;\n", 0);
// Undefine the scheme name // Undefine the scheme name
Printf(f.code, "#undef SCHEME_NAME\n"); Printf(f->code, "#undef SCHEME_NAME\n");
Printf(f.code, "}\n"); Printf(f->code, "}\n");
f.print (f_wrappers); Wrapper_print (f, f_wrappers);
if (numargs > 10) { if (numargs > 10) {
// Guile would complain: too many args // Guile would complain: too many args
@ -587,6 +588,7 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
Delete(proc_name); Delete(proc_name);
Delete(outarg); Delete(outarg);
Delete(cleanup); Delete(cleanup);
DelWrapper(f);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------

View file

@ -35,7 +35,7 @@ private:
GUILE_LSTYLE_HOBBIT // use (hobbit4d link) GUILE_LSTYLE_HOBBIT // use (hobbit4d link)
} linkage; } linkage;
void get_pointer(char *iname, int parm, DataType *t, void get_pointer(char *iname, int parm, DataType *t,
WrapperFunction &f, DOHString_or_char *proc_name, Wrapper *f, DOHString_or_char *proc_name,
int num_scheme_parm); int num_scheme_parm);
void usage_var(char *, DataType *, DOHString *usage); void usage_var(char *, DataType *, DOHString *usage);
void usage_func(char *, DataType *, ParmList *, DOHString *usage); void usage_func(char *, DataType *, ParmList *, DOHString *usage);

View file

@ -538,7 +538,7 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
javaParameterSignature = NewString(""); javaParameterSignature = NewString("");
// A new wrapper function object // A new wrapper function object
WrapperFunction f; Wrapper *f = NewWrapper();
if(!classdef_emitted) emit_classdef(); if(!classdef_emitted) emit_classdef();
@ -560,7 +560,7 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
} }
if(t->type != T_VOID || t->is_pointer) { if(t->type != T_VOID || t->is_pointer) {
f.add_local(jnirettype, (char*)"_jresult", (char*)"0"); Wrapper_add_local(f,jnirettype, (char*)"_jresult", (char*)"0");
} }
Printf(f_java, " %s ", method_modifiers); Printf(f_java, " %s ", method_modifiers);
@ -577,8 +577,8 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
Delete(member_name); Delete(member_name);
} }
if(!jnic) Printf(f.def,"extern \"C\"\n"); if(!jnic) Printf(f->def,"extern \"C\"\n");
Printv(f.def, "JNIEXPORT ", jnirettype, " JNICALL ", wname, "(JNIEnv *jenv, jclass jcls", 0); Printv(f->def, "JNIEXPORT ", jnirettype, " JNICALL ", wname, "(JNIEnv *jenv, jclass jcls", 0);
// Emit all of the local variables for holding arguments. // Emit all of the local variables for holding arguments.
int pcount = emit_args(t,l,f); int pcount = emit_args(t,l,f);
@ -621,24 +621,24 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
gencomma = 1; gencomma = 1;
// Add to Jni function header // Add to Jni function header
Printv(f.def, ", ", jnitype, " ", source, 0); Printv(f->def, ", ", jnitype, " ", source, 0);
// Get typemap for this argument // Get typemap for this argument
tm = typemap_lookup((char*)"in",typemap_lang,p->t,p->name,source,target,&f); tm = typemap_lookup((char*)"in",typemap_lang,p->t,p->name,source,target,f);
if (tm) { if (tm) {
Printf(f.code,"%s\n", tm); Printf(f->code,"%s\n", tm);
Replace(f.code,"$arg",source, DOH_REPLACE_ANY); Replace(f->code,"$arg",source, DOH_REPLACE_ANY);
} else { } else {
if(!p->t->is_pointer) if(!p->t->is_pointer)
Printv(f.code, tab4, target, " = ", p->t->print_cast(), source, ";\n", 0); Printv(f->code, tab4, target, " = ", p->t->print_cast(), source, ";\n", 0);
else if((p->t->type == T_VOID && p->t->is_pointer == 1) || else if((p->t->type == T_VOID && p->t->is_pointer == 1) ||
(p->t->type == T_USER && p->t->is_pointer == 1)) { (p->t->type == T_USER && p->t->is_pointer == 1)) {
p->t->is_pointer++; p->t->is_pointer++;
Printv(f.code, tab4, target, " = *", p->t->print_cast(), "&", source, ";\n", 0); Printv(f->code, tab4, target, " = *", p->t->print_cast(), "&", source, ";\n", 0);
p->t->is_pointer--; p->t->is_pointer--;
} else { } else {
if(p->t->type == T_CHAR && p->t->is_pointer == 1) { if(p->t->type == T_CHAR && p->t->is_pointer == 1) {
Printv(f.code, tab4, target, " = (", source, ") ? (char *)", JNICALL((char*)"GetStringUTFChars"), source, ", 0) : NULL;\n", 0); Printv(f->code, tab4, target, " = (", source, ") ? (char *)", JNICALL((char*)"GetStringUTFChars"), source, ", 0) : NULL;\n", 0);
} else { } else {
char *scalarType = SwigTcToJniScalarType(p->t); char *scalarType = SwigTcToJniScalarType(p->t);
char *cptrtype = p->t->print_type(); char *cptrtype = p->t->print_type();
@ -654,20 +654,20 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
DOHString *basic_jniptrtype = NewStringf("%s*",basic_jnitype); DOHString *basic_jniptrtype = NewStringf("%s*",basic_jnitype);
DOHString *source_length = NewStringf("%s%s)", JNICALL((char*)"GetArrayLength"), source); DOHString *source_length = NewStringf("%s%s)", JNICALL((char*)"GetArrayLength"), source);
target_copy = Swig_copy_string(f.new_local(Char(basic_jniptrtype), target, NULL)); target_copy = Swig_copy_string(Wrapper_new_local(f,Char(basic_jniptrtype), target, NULL));
target_length = Swig_copy_string(f.new_local((char*)"jsize", target, Char(source_length))); target_length = Swig_copy_string(Wrapper_new_local(f,(char*)"jsize", target, Char(source_length)));
if(local_i == NULL) local_i = Swig_copy_string(f.new_local((char*)"int", (char*)"i", NULL)); if(local_i == NULL) local_i = Swig_copy_string(Wrapper_new_local(f,(char*)"int", (char*)"i", NULL));
DOHString *scalarFunc = NewStringf("Get%sArrayElements",scalarType); DOHString *scalarFunc = NewStringf("Get%sArrayElements",scalarType);
Printv(f.code, tab4, target_copy, " = ", JNICALL(scalarFunc), source, ", 0);\n", 0); Printv(f->code, tab4, target_copy, " = ", JNICALL(scalarFunc), source, ", 0);\n", 0);
Printv(f.code, tab4, target, " = ", p->t->print_cast(), " malloc(", target_length, " * sizeof(", ctype, "));\n", 0); Printv(f->code, tab4, target, " = ", p->t->print_cast(), " malloc(", target_length, " * sizeof(", ctype, "));\n", 0);
Printv(f.code, tab4, "for(i=0; i<", target_length, "; i++)\n", 0); Printv(f->code, tab4, "for(i=0; i<", target_length, "; i++)\n", 0);
if(p->t->is_pointer > 1) { if(p->t->is_pointer > 1) {
Printv(f.code, tab8, target, "[i] = *", p->t->print_cast(), "&", target_copy, "[i];\n", 0); Printv(f->code, tab8, target, "[i] = *", p->t->print_cast(), "&", target_copy, "[i];\n", 0);
} else { } else {
p->t->is_pointer--; p->t->is_pointer--;
Printv(f.code, tab8, target, "[i] = ", p->t->print_cast(), target_copy, "[i];\n", 0); Printv(f->code, tab8, target, "[i] = ", p->t->print_cast(), target_copy, "[i];\n", 0);
p->t->is_pointer++; p->t->is_pointer++;
} }
Delete(scalarFunc); Delete(scalarFunc);
@ -680,8 +680,8 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
// Check to see if there was any sort of a constaint typemap // Check to see if there was any sort of a constaint typemap
if ((tm = typemap_lookup((char*)"check",typemap_lang,p->t,p->name,source,target))) { if ((tm = typemap_lookup((char*)"check",typemap_lang,p->t,p->name,source,target))) {
// Yep. Use it instead of the default // Yep. Use it instead of the default
Printf(f.code,"%s\n", tm); Printf(f->code,"%s\n", tm);
Replace(f.code,"$arg",source, DOH_REPLACE_ANY); Replace(f->code,"$arg",source, DOH_REPLACE_ANY);
} }
// Check if there was any cleanup code (save it for later) // Check if there was any cleanup code (save it for later)
@ -738,7 +738,7 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
Printf(body,")"); Printf(body,")");
Printf(f_shadow, "%s;\n }\n\n",body); Printf(f_shadow, "%s;\n }\n\n",body);
} }
Printf(f.def,") {"); Printf(f->def,") {");
// Now write code to make the function call // Now write code to make the function call
@ -749,27 +749,27 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
if((t->type != T_VOID || t->is_pointer) && !native_func) { if((t->type != T_VOID || t->is_pointer) && !native_func) {
if ((tm = typemap_lookup((char*)"out",typemap_lang,t,iname,(char*)"_result",(char*)"_jresult"))) { if ((tm = typemap_lookup((char*)"out",typemap_lang,t,iname,(char*)"_result",(char*)"_jresult"))) {
Printf(f.code,"%s\n", tm); Printf(f->code,"%s\n", tm);
} else { } else {
if(t->is_pointer == 0 && t->type == T_USER) { /* return by value */ if(t->is_pointer == 0 && t->type == T_USER) { /* return by value */
t->is_pointer=2; t->is_pointer=2;
Printv(f.code, tab4, "*", t->print_cast(), "&_jresult = _result;\n", 0); Printv(f->code, tab4, "*", t->print_cast(), "&_jresult = _result;\n", 0);
t->is_pointer=0; t->is_pointer=0;
} else if(t->is_pointer == 0 && t->type != T_USER) { } else if(t->is_pointer == 0 && t->type != T_USER) {
Printv(f.code, tab4, "_jresult = (", jnirettype, ") _result;\n", 0); Printv(f->code, tab4, "_jresult = (", jnirettype, ") _result;\n", 0);
} else if((t->type == T_VOID && t->is_pointer == 1) || } else if((t->type == T_VOID && t->is_pointer == 1) ||
(t->type == T_USER && t->is_pointer == 1)) { (t->type == T_USER && t->is_pointer == 1)) {
t->is_pointer++; t->is_pointer++;
Printv(f.code, tab4, "*", t->print_cast(), "&_jresult = _result;\n", 0); Printv(f->code, tab4, "*", t->print_cast(), "&_jresult = _result;\n", 0);
t->is_pointer--; t->is_pointer--;
} else { } else {
if(t->type == T_CHAR && t->is_pointer == 1) { if(t->type == T_CHAR && t->is_pointer == 1) {
Printv(f.code, tab4, "if(_result != NULL)\n", 0); Printv(f->code, tab4, "if(_result != NULL)\n", 0);
Printv(f.code, tab8, "_jresult = (jstring)", JNICALL((char*)"NewStringUTF"), "_result);\n", 0); Printv(f->code, tab8, "_jresult = (jstring)", JNICALL((char*)"NewStringUTF"), "_result);\n", 0);
} else { } else {
Printf(stderr,"%s : Line %d. Warning: no return typemap for datatype %s\n", input_file,line_number,t->print_type()); Printf(stderr,"%s : Line %d. Warning: no return typemap for datatype %s\n", input_file,line_number,t->print_type());
t->is_pointer++; t->is_pointer++;
Printv(f.code, tab4, "*", t->print_cast(), "&_jresult = _result;\n", 0); Printv(f->code, tab4, "*", t->print_cast(), "&_jresult = _result;\n", 0);
t->is_pointer--; t->is_pointer--;
} }
} }
@ -777,37 +777,37 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
} }
// Dump argument output code; // Dump argument output code;
Printv(f.code, outarg, 0); Printv(f->code, outarg, 0);
// Dump the argument cleanup code // Dump the argument cleanup code
Printv(f.code,cleanup, 0); Printv(f->code,cleanup, 0);
// Look for any remaining cleanup // Look for any remaining cleanup
if (NewObject) { if (NewObject) {
if ((tm = typemap_lookup((char*)"newfree",typemap_lang,t,iname,(char*)"_result",(char*)""))) { if ((tm = typemap_lookup((char*)"newfree",typemap_lang,t,iname,(char*)"_result",(char*)""))) {
Printf(f.code,"%s\n", tm); Printf(f->code,"%s\n", tm);
} }
} }
if((t->type != T_VOID || t->is_pointer) && !native_func) { if((t->type != T_VOID || t->is_pointer) && !native_func) {
if ((tm = typemap_lookup((char*)"ret",typemap_lang,t,iname,(char*)"_result",(char*)"_jresult", NULL))) { if ((tm = typemap_lookup((char*)"ret",typemap_lang,t,iname,(char*)"_result",(char*)"_jresult", NULL))) {
Printf(f.code,"%s\n", tm); Printf(f->code,"%s\n", tm);
} }
} }
// Wrap things up (in a manner of speaking) // Wrap things up (in a manner of speaking)
if(t->type != T_VOID || t->is_pointer) if(t->type != T_VOID || t->is_pointer)
Printv(f.code, tab4, "return _jresult;\n", 0); Printv(f->code, tab4, "return _jresult;\n", 0);
Printf(f.code, "}\n"); Printf(f->code, "}\n");
// Substitute the cleanup code (some exception handlers like to have this) // Substitute the cleanup code (some exception handlers like to have this)
Replace(f.code,"$cleanup",cleanup, DOH_REPLACE_ANY); Replace(f->code,"$cleanup",cleanup, DOH_REPLACE_ANY);
// Emit the function // Emit the function
if(!native_func) if(!native_func)
f.print(f_wrappers); Wrapper_print(f,f_wrappers);
// If registerNatives is active, store the table entry for this method // If registerNatives is active, store the table entry for this method
@ -819,6 +819,12 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
0); 0);
} }
Delete(cleanup);
Delete(outarg);
Delete(body);
Delete(javaParameterSignature);
DelWrapper(f);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------

View file

@ -246,10 +246,10 @@ MZSCHEME::close (void)
void void
MZSCHEME::get_pointer (DOHString_or_char *name, int parm, DataType *t, MZSCHEME::get_pointer (DOHString_or_char *name, int parm, DataType *t,
WrapperFunction &f) Wrapper *f)
{ {
Printf(f.code," if (!swig_get_c_pointer(argv[%d],\"%s\", (void **) &_arg%d))\n", parm, t->print_mangle(), parm); Printf(f->code," if (!swig_get_c_pointer(argv[%d],\"%s\", (void **) &_arg%d))\n", parm, t->print_mangle(), parm);
Printf(f.code," scheme_wrong_type(\"%s\", \"%s\", %d, argc, argv);\n", name, t->print_mangle(), parm); Printf(f->code," scheme_wrong_type(\"%s\", \"%s\", %d, argc, argv);\n", name, t->print_mangle(), parm);
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -292,7 +292,7 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
Parm *p; Parm *p;
char source[256], target[256], argnum[256], arg[256]; char source[256], target[256], argnum[256], arg[256];
char *tm; char *tm;
WrapperFunction f; Wrapper *f;
DOHString *cleanup = 0; DOHString *cleanup = 0;
DOHString *proc_name = 0; DOHString *proc_name = 0;
int need_len = 0; int need_len = 0;
@ -300,7 +300,7 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
DOHString *outarg = 0; DOHString *outarg = 0;
int argout_set = 0; int argout_set = 0;
f = NewWrapper();
outarg = NewString(""); outarg = NewString("");
cleanup = NewString(""); cleanup = NewString("");
@ -312,7 +312,7 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
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, Printv(f->def,
"static Scheme_Object *", wname, " (", "static Scheme_Object *", wname, " (",
"int argc, Scheme_Object **argv", "int argc, Scheme_Object **argv",
")\n{", ")\n{",
@ -328,9 +328,9 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
int numopt = 0; int numopt = 0;
// adds local variables : type name // adds local variables : type name
f.add_local ((char*)"char *", (char*)"_tempc"); Wrapper_add_local (f,(char*)"char *", (char*)"_tempc",0);
f.add_local ((char*)"int", (char*)"_len"); Wrapper_add_local (f,(char*)"int", (char*)"_len",0);
f.add_local ((char*)"Scheme_Object *", (char*)"swig_result"); Wrapper_add_local (f,(char*)"Scheme_Object *", (char*)"swig_result",0);
// Now write code to extract the parameters (this is super ugly) // Now write code to extract the parameters (this is super ugly)
@ -348,13 +348,13 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
// Handle parameter types. // Handle parameter types.
if (p.ignore) if (p.ignore)
Printv(f.code, "/* ", p.name, " ignored... */\n", 0); Printv(f->code, "/* ", p.name, " ignored... */\n", 0);
else { else {
++numargs; ++numargs;
if ((tm = typemap_lookup ((char*)"in", typemap_lang, if ((tm = typemap_lookup ((char*)"in", typemap_lang,
p.t, p.name, source, target, &f))) { p.t, p.name, source, target, f))) {
Printv(f.code, tm, "\n", 0); Printv(f->code, tm, "\n", 0);
mreplace (f.code, argnum, arg, proc_name); mreplace (f->code, argnum, arg, proc_name);
} }
// no typemap found // no typemap found
// assume it's a Scheme_Object containing the C pointer // assume it's a Scheme_Object containing the C pointer
@ -368,16 +368,16 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
// Check if there are any constraints. // Check if there are any constraints.
if ((tm = typemap_lookup ((char*)"check", typemap_lang, if ((tm = typemap_lookup ((char*)"check", typemap_lang,
p.t, p.name, source, target, &f))) { p.t, p.name, 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->code,tm,"\n", 0);
mreplace (f.code, argnum, arg, proc_name); mreplace (f->code, argnum, arg, proc_name);
} }
// Pass output arguments back to the caller. // Pass output arguments back to the caller.
if ((tm = typemap_lookup ((char*)"argout", typemap_lang, if ((tm = typemap_lookup ((char*)"argout", typemap_lang,
p.t, p.name, source, target, &f))) { p.t, p.name, source, target, f))) {
// Yep. Use it instead of the default // Yep. Use it instead of the default
Printv(outarg, tm, "\n", 0); Printv(outarg, tm, "\n", 0);
mreplace (outarg, argnum, arg, proc_name); mreplace (outarg, argnum, arg, proc_name);
@ -386,7 +386,7 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
// Free up any memory allocated for the arguments. // Free up any memory allocated for the arguments.
if ((tm = typemap_lookup ((char*)"freearg", typemap_lang, if ((tm = typemap_lookup ((char*)"freearg", typemap_lang,
p.t, p.name, source, target, &f))) { p.t, p.name, source, target, f))) {
// Yep. Use it instead of the default // Yep. Use it instead of the default
Printv(cleanup, tm, "\n", 0); Printv(cleanup, tm, "\n", 0);
mreplace (cleanup, argnum, arg, proc_name); mreplace (cleanup, argnum, arg, proc_name);
@ -401,18 +401,18 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
if (d->type == T_VOID) { if (d->type == T_VOID) {
if(!argout_set) if(!argout_set)
Printv(f.code, tab4, "swig_result = scheme_void;\n", 0); Printv(f->code, tab4, "swig_result = scheme_void;\n", 0);
} }
else if ((tm = typemap_lookup ((char*)"out", typemap_lang, else if ((tm = typemap_lookup ((char*)"out", typemap_lang,
d, name, (char*)"_result", (char*)"swig_result", &f))) { d, name, (char*)"_result", (char*)"swig_result", f))) {
Printv(f.code, tm, "\n", 0); Printv(f->code, tm, "\n", 0);
mreplace (f.code, argnum, arg, proc_name); mreplace (f->code, 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 (d->is_pointer) { else if (d->is_pointer) {
Printv(f.code, Printv(f->code,
tab4, tab4,
"swig_result = swig_make_c_pointer(", "swig_result = swig_make_c_pointer(",
"_result, \"", "_result, \"",
@ -425,50 +425,50 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
} }
// Dump the argument output code // Dump the argument output code
Printv(f.code, outarg,0); Printv(f->code, outarg,0);
// Dump the argument cleanup code // Dump the argument cleanup code
Printv(f.code, cleanup, 0); Printv(f->code, cleanup, 0);
// Look for any remaining cleanup // Look for any remaining cleanup
if (NewObject) { if (NewObject) {
if ((tm = typemap_lookup ((char*)"newfree", typemap_lang, if ((tm = typemap_lookup ((char*)"newfree", typemap_lang,
d, iname, (char*)"_result", (char*)"", &f))) { d, iname, (char*)"_result", (char*)"", f))) {
Printv(f.code,tm,"\n",0); Printv(f->code,tm,"\n",0);
mreplace (f.code, argnum, arg, proc_name); mreplace (f->code, argnum, arg, proc_name);
} }
} }
// Free any memory allocated by the function being wrapped.. // Free any memory allocated by the function being wrapped..
if ((tm = typemap_lookup ((char*)"ret", typemap_lang, if ((tm = typemap_lookup ((char*)"ret", typemap_lang,
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->code,tm,"\n",0);
mreplace (f.code, argnum, arg, proc_name); mreplace (f->code, argnum, arg, proc_name);
} }
// returning multiple values // returning multiple values
if(argout_set) { if(argout_set) {
if(d->type == T_VOID) { if(d->type == T_VOID) {
f.add_local((char*)"int", (char*)"_lenv", (char*)"0"); Wrapper_add_local(f,(char*)"int", (char*)"_lenv", (char*)"0");
f.add_local((char*)"Scheme_Object *", (char*)"_values[MAXVALUES]"); Wrapper_add_local(f,(char*)"Scheme_Object *", (char*)"_values[MAXVALUES]",0);
Printv(f.code, tab4, "swig_result = scheme_values(_lenv, _values);\n", 0); Printv(f->code, tab4, "swig_result = scheme_values(_lenv, _values);\n", 0);
} }
else { else {
f.add_local((char*)"int", (char*)"_lenv", (char*)"1"); Wrapper_add_local(f,(char*)"int", (char*)"_lenv", (char*)"1");
f.add_local((char*)"Scheme_Object *",(char*) "_values[MAXVALUES]"); Wrapper_add_local(f,(char*)"Scheme_Object *",(char*) "_values[MAXVALUES]",0);
Printv(f.code, tab4, "_values[0] = swig_result;\n", 0); Printv(f->code, tab4, "_values[0] = swig_result;\n", 0);
Printv(f.code, tab4, "swig_result = scheme_values(_lenv, _values);\n", 0); Printv(f->code, 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", "}\n", 0); Printv(f->code, tab4, "return swig_result;\n", "}\n", 0);
f.print (f_wrappers); Wrapper_print(f,f_wrappers);
// Now register the function // Now register the function
/* Printv(init_func_def, /* Printv(init_func_def,
@ -485,6 +485,7 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
Delete(proc_name); Delete(proc_name);
Delete(outarg); Delete(outarg);
Delete(cleanup); Delete(cleanup);
DelWrapper(f);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------

View file

@ -26,7 +26,7 @@
class MZSCHEME : public Language class MZSCHEME : public Language
{ {
private: private:
void get_pointer(DOHString_or_char *name, int parm, DataType *t, WrapperFunction &f); void get_pointer(DOHString_or_char *name, int parm, DataType *t, Wrapper *f);
void usage_var(char *, DataType *, DOHString *usage); void usage_var(char *, DataType *, DOHString *usage);
void usage_func(char *, DataType *, ParmList *, DOHString *usage); void usage_func(char *, DataType *, ParmList *, DOHString *usage);
void usage_returns(char *, DataType *, ParmList *, DOHString *usage); void usage_returns(char *, DataType *, ParmList *, DOHString *usage);

View file

@ -743,13 +743,14 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
int pcount,i,j; int pcount,i,j;
char *wname; char *wname;
char *usage = 0; char *usage = 0;
WrapperFunction f; Wrapper *f;
char source[256],target[256],temp[256], argnum[32]; char source[256],target[256],temp[256], argnum[32];
char *tm; char *tm;
DOHString *cleanup, *outarg; DOHString *cleanup, *outarg;
int numopt = 0; int numopt = 0;
int need_save, num_saved = 0; // Number of saved arguments. int need_save, num_saved = 0; // Number of saved arguments.
f = NewWrapper();
cleanup = NewString(""); cleanup = NewString("");
outarg = NewString(""); outarg = NewString("");
@ -759,19 +760,19 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
// Now write the wrapper function itself....this is pretty ugly // Now write the wrapper function itself....this is pretty ugly
Printv(f.def, "XS(", wname, ") {\n", 0); Printv(f->def, "XS(", wname, ") {\n", 0);
Printv(f.code, tab4, "cv = cv;\n", 0); Printv(f->code, tab4, "cv = cv;\n", 0);
pcount = emit_args(d, l, f); pcount = emit_args(d, l, f);
numopt = l->numopt(); numopt = l->numopt();
f.add_local((char*)"int",(char*)"argvi = 0"); Wrapper_add_local(f,(char*)"int",(char*)"argvi = 0",0);
// Check the number of arguments // Check the number of arguments
usage = usage_func(iname,d,l); usage = usage_func(iname,d,l);
Printf(f.code," if ((items < %d) || (items > %d)) \n", pcount-numopt, l->numarg()); Printf(f->code," if ((items < %d) || (items > %d)) \n", pcount-numopt, l->numarg());
Printf(f.code," croak(\"Usage: %s\");\n", usage); Printf(f->code," croak(\"Usage: %s\");\n", usage);
// Write code to extract parameters. // Write code to extract parameters.
// This section should be able to extract virtually any kind // This section should be able to extract virtually any kind
@ -793,13 +794,13 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
// If there are optional arguments, check for this // If there are optional arguments, check for this
if (j>= (pcount-numopt)) if (j>= (pcount-numopt))
Printf(f.code," if (items > %d) {\n", j); Printf(f->code," if (items > %d) {\n", j);
// See if there is a type-map // See if there is a type-map
if ((tm = typemap_lookup((char*)"in",(char*)"perl5",p->t,p->name,source,target,&f))) { if ((tm = typemap_lookup((char*)"in",(char*)"perl5",p->t,p->name,source,target,f))) {
Printf(f.code,"%s\n",tm); Printf(f->code,"%s\n",tm);
Replace(f.code,"$argnum",argnum,DOH_REPLACE_ANY); Replace(f->code,"$argnum",argnum,DOH_REPLACE_ANY);
Replace(f.code,"$arg",source,DOH_REPLACE_ANY); Replace(f->code,"$arg",source,DOH_REPLACE_ANY);
} else { } else {
if (!p->t->is_pointer) { if (!p->t->is_pointer) {
@ -822,19 +823,19 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
case T_USHORT: case T_USHORT:
case T_ULONG: case T_ULONG:
case T_UCHAR: case T_UCHAR:
Printf(f.code," _arg%d = %sSvIV(ST(%d));\n", i, p->t->print_cast(),j); Printf(f->code," _arg%d = %sSvIV(ST(%d));\n", i, p->t->print_cast(),j);
break; break;
case T_CHAR : case T_CHAR :
Printf(f.code," _arg%d = (char) *SvPV(ST(%d),PL_na);\n", i, j); Printf(f->code," _arg%d = (char) *SvPV(ST(%d),PL_na);\n", i, j);
break; break;
// Doubles // Doubles
case T_DOUBLE : case T_DOUBLE :
case T_FLOAT : case T_FLOAT :
Printf(f.code," _arg%d = %s SvNV(ST(%d));\n", i, p->t->print_cast(), j); Printf(f->code," _arg%d = %s SvNV(ST(%d));\n", i, p->t->print_cast(), j);
break; break;
// Void.. Do nothing. // Void.. Do nothing.
@ -859,15 +860,15 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
// since that is usually a string. // since that is usually a string.
if ((p->t->type == T_CHAR) && (p->t->is_pointer == 1)) { if ((p->t->type == T_CHAR) && (p->t->is_pointer == 1)) {
Printf(f.code," if (! SvOK((SV*) ST(%d))) { _arg%d = 0; }\n", j, i); Printf(f->code," if (! SvOK((SV*) ST(%d))) { _arg%d = 0; }\n", j, i);
Printf(f.code," else { _arg%d = (char *) SvPV(ST(%d),PL_na); }\n", i,j); Printf(f->code," else { _arg%d = (char *) SvPV(ST(%d),PL_na); }\n", i,j);
} else { } else {
// Have a generic pointer type here. Read it in as a swig // Have a generic pointer type here. Read it in as a swig
// typed pointer. // typed pointer.
sprintf(temp,"argument %d", i+1); sprintf(temp,"argument %d", i+1);
get_pointer(iname,temp,source,target, p->t, f.code, (char*)"XSRETURN(1)"); get_pointer(iname,temp,source,target, p->t, f->code, (char*)"XSRETURN(1)");
} }
} }
} }
@ -875,7 +876,7 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
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->code," } \n");
j++; j++;
} else { } else {
temp[0] = 0; temp[0] = 0;
@ -883,8 +884,8 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
// Check if there is any constraint code // Check if there is any constraint code
if ((tm = typemap_lookup((char*)"check",(char*)"perl5",p->t,p->name,source,target))) { if ((tm = typemap_lookup((char*)"check",(char*)"perl5",p->t,p->name,source,target))) {
Printf(f.code,"%s\n", tm); Printf(f->code,"%s\n", tm);
Replace(f.code,"$argnum",argnum, DOH_REPLACE_ANY); Replace(f->code,"$argnum",argnum, DOH_REPLACE_ANY);
} }
need_save = 0; need_save = 0;
@ -905,7 +906,7 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
// If we needed a saved variable, we need to emit to emit some code for that // If we needed 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) && (!p->ignore)) { if ((need_save) && (!p->ignore)) {
Printv(f.code, tab4, temp, " = ", source, ";\n", 0); Printv(f->code, tab4, temp, " = ", source, ";\n", 0);
num_saved++; num_saved++;
} }
p = l->get_next(); p = l->get_next();
@ -916,7 +917,7 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
if (num_saved) { if (num_saved) {
sprintf(temp,"_saved[%d]",num_saved); sprintf(temp,"_saved[%d]",num_saved);
f.add_local((char*)"SV *",temp); Wrapper_add_local(f,(char*)"SV *",temp,0);
} }
// Now write code to make the function call // Now write code to make the function call
@ -926,26 +927,26 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
// See if there was a typemap // See if there was a typemap
if ((tm = typemap_lookup((char*)"out",(char*)"perl5",d,iname,(char*)"_result",(char*)"ST(argvi)"))) { if ((tm = typemap_lookup((char*)"out",(char*)"perl5",d,iname,(char*)"_result",(char*)"ST(argvi)"))) {
// Yep. Use it instead of the default // Yep. Use it instead of the default
Printf(f.code, "%s\n", tm); Printf(f->code, "%s\n", tm);
} else if ((d->type != T_VOID) || (d->is_pointer)) { } else if ((d->type != T_VOID) || (d->is_pointer)) {
if (!d->is_pointer) { if (!d->is_pointer) {
// Function returns a "value" // Function returns a "value"
Printf(f.code," ST(argvi) = sv_newmortal();\n"); Printf(f->code," ST(argvi) = sv_newmortal();\n");
switch(d->type) { switch(d->type) {
case T_INT: case T_BOOL: case T_SINT: case T_UINT: case T_INT: case T_BOOL: case T_SINT: case T_UINT:
case T_SHORT: case T_SSHORT: case T_USHORT: case T_SHORT: case T_SSHORT: case T_USHORT:
case T_LONG : case T_SLONG : case T_ULONG: case T_LONG : case T_SLONG : 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->code," 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->code," sv_setnv(ST(argvi++), (double) _result);\n");
break; break;
case T_CHAR : case T_CHAR :
f.add_local((char*)"char", (char*)"_ctemp[2]"); Wrapper_add_local(f,(char*)"char", (char*)"_ctemp[2]",0);
Printv(f.code, Printv(f->code,
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",
@ -956,7 +957,7 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
case T_USER: case T_USER:
d->is_pointer++; d->is_pointer++;
Printv(f.code, Printv(f->code,
tab4, "sv_setref_pv(ST(argvi++),\"",(hidden ? realpackage : ""), (hidden ? "::" : ""), d->print_mangle(), tab4, "sv_setref_pv(ST(argvi++),\"",(hidden ? realpackage : ""), (hidden ? "::" : ""), d->print_mangle(),
"\", (void *) _result);\n", 0); "\", (void *) _result);\n", 0);
d->is_pointer--; d->is_pointer--;
@ -969,15 +970,15 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
} else { } else {
// Is a pointer return type // Is a pointer return type
Printf(f.code," ST(argvi) = sv_newmortal();\n"); Printf(f->code," ST(argvi) = sv_newmortal();\n");
if ((d->type == T_CHAR) && (d->is_pointer == 1)) { if ((d->type == T_CHAR) && (d->is_pointer == 1)) {
// Return a character string // Return a character string
Printf(f.code," sv_setpv((SV*)ST(argvi++),(char *) _result);\n"); Printf(f->code," sv_setpv((SV*)ST(argvi++),(char *) _result);\n");
} else { } else {
// Is an ordinary pointer type. // Is an ordinary pointer type.
Printv(f.code, tab4, "sv_setref_pv(ST(argvi++),\"", (hidden ? realpackage : ""), (hidden ? "::" : ""), d->print_mangle(), Printv(f->code, tab4, "sv_setref_pv(ST(argvi++),\"", (hidden ? realpackage : ""), (hidden ? "::" : ""), d->print_mangle(),
"\", (void *) _result);\n", 0); "\", (void *) _result);\n", 0);
} }
} }
@ -985,38 +986,38 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
// 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->code,outarg,0);
// If there was any cleanup, do that. // If there was any cleanup, do that.
Printv(f.code,cleanup,0); Printv(f->code,cleanup,0);
if (NewObject) { if (NewObject) {
if ((tm = typemap_lookup((char*)"newfree",(char*)"perl5",d,iname,(char*)"_result",(char*)""))) { if ((tm = typemap_lookup((char*)"newfree",(char*)"perl5",d,iname,(char*)"_result",(char*)""))) {
Printf(f.code,"%s\n",tm); Printf(f->code,"%s\n",tm);
} }
} }
if ((tm = typemap_lookup((char*)"ret",(char*)"perl5",d,iname,(char*)"_result",(char*)""))) { if ((tm = typemap_lookup((char*)"ret",(char*)"perl5",d,iname,(char*)"_result",(char*)""))) {
// Yep. Use it instead of the default // Yep. Use it instead of the default
Printf(f.code,"%s\n", tm); Printf(f->code,"%s\n", tm);
} }
// Wrap things up (in a manner of speaking) // Wrap things up (in a manner of speaking)
Printf(f.code," XSRETURN(argvi);\n}\n"); Printf(f->code," XSRETURN(argvi);\n}\n");
// Add the dXSARGS last // Add the dXSARGS last
f.add_local((char*)"dXSARGS",(char*)""); Wrapper_add_local(f,(char*)"dXSARGS",(char*)"",0);
// Substitute the cleanup code // Substitute the cleanup code
Replace(f.code,"$cleanup",cleanup,DOH_REPLACE_ANY); Replace(f->code,"$cleanup",cleanup,DOH_REPLACE_ANY);
Replace(f.code,"$name",iname,DOH_REPLACE_ANY); Replace(f->code,"$name",iname,DOH_REPLACE_ANY);
// Dump this function out // Dump this function out
f.print(f_wrappers); Wrapper_print(f,f_wrappers);
// Now register the function // Now register the function
@ -1133,6 +1134,9 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
} }
Delete(func); Delete(func);
} }
Delete(cleanup);
Delete(outarg);
DelWrapper(f);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -1145,11 +1149,14 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
{ {
char set_name[256]; char set_name[256];
char val_name[256]; char val_name[256];
WrapperFunction getf, setf; Wrapper *getf, *setf;
char *tm; char *tm;
sprintf(set_name,"_wrap_set_%s",iname); sprintf(set_name,"_wrap_set_%s",iname);
sprintf(val_name,"_wrap_val_%s",iname); sprintf(val_name,"_wrap_val_%s",iname);
getf = NewWrapper();
setf = NewWrapper();
// Create a new scalar that we will attach magic to // Create a new scalar that we will attach magic to
Printv(vinit, tab4, "sv = perl_get_sv(\"", package, "::", iname, "\",TRUE | 0x2);\n", 0); Printv(vinit, tab4, "sv = perl_get_sv(\"", package, "::", iname, "\",TRUE | 0x2);\n", 0);
@ -1157,17 +1164,17 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
// 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->def,"SWIGCLASS_STATIC int %s(SV* sv, MAGIC *mg) {\n", set_name);
Printv(setf.code, Printv(setf->code,
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 = typemap_lookup((char*)"varin",(char*)"perl5",t,(char*)"",(char*)"sv",name))) { if ((tm = typemap_lookup((char*)"varin",(char*)"perl5",t,(char*)"",(char*)"sv",name))) {
Printf(setf.code,"%s\n", tm); Printf(setf->code,"%s\n", tm);
} else if ((tm = typemap_lookup((char*)"in",(char*)"perl5",t,(char*)"",(char*)"sv",name))) { } else if ((tm = typemap_lookup((char*)"in",(char*)"perl5",t,(char*)"",(char*)"sv",name))) {
Printf(setf.code,"%s\n", tm); Printf(setf->code,"%s\n", tm);
} else { } else {
if (!t->is_pointer) { if (!t->is_pointer) {
@ -1178,14 +1185,14 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
case T_SHORT : case T_SSHORT : case T_USHORT: case T_SHORT : case T_SSHORT : case T_USHORT:
case T_LONG : case T_SLONG : case T_ULONG: case T_LONG : case T_SLONG : case T_ULONG:
case T_UCHAR: case T_SCHAR: case T_UCHAR: case T_SCHAR:
Printv(setf.code,tab4, name, " = ", t->print_cast(), " SvIV(sv);\n", 0); Printv(setf->code,tab4, name, " = ", t->print_cast(), " SvIV(sv);\n", 0);
break; break;
case T_DOUBLE : case T_DOUBLE :
case T_FLOAT : case T_FLOAT :
Printv(setf.code, tab4, name, " = ", t->print_cast(), " SvNV(sv);\n", 0); Printv(setf->code, tab4, name, " = ", t->print_cast(), " 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->code, tab4, name, " = (char) *SvPV(sv,PL_na);\n", 0);
break; break;
case T_USER: case T_USER:
@ -1194,9 +1201,9 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
// Get as a pointer value // Get as a pointer value
t->is_pointer++; t->is_pointer++;
setf.add_local((char*)"void",(char*)"*_temp"); Wrapper_add_local(setf,(char*)"void",(char*)"*_temp",0);
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->code, (char*)"return(1)");
Printv(setf.code, tab4, name, " = *(", t->print_cast(), " _temp);\n", 0); Printv(setf->code, tab4, name, " = *(", t->print_cast(), " _temp);\n", 0);
t->is_pointer--; t->is_pointer--;
break; break;
@ -1207,39 +1214,39 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
} else { } else {
// Have some sort of pointer type here, Process it differently // Have some sort of pointer type here, Process it differently
if ((t->type == T_CHAR) && (t->is_pointer == 1)) { if ((t->type == T_CHAR) && (t->is_pointer == 1)) {
setf.add_local((char*)"char",(char*)"*_a"); Wrapper_add_local(setf,(char*)"char",(char*)"*_a",0);
Printf(setf.code," _a = (char *) SvPV(sv,PL_na);\n"); Printf(setf->code," _a = (char *) SvPV(sv,PL_na);\n");
if (CPlusPlus) if (CPlusPlus)
Printv(setf.code, Printv(setf->code,
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->code,
tab4, "if (", name, ") free(", name, ");\n", tab4, "if (", name, ") free(", name, ");\n",
tab4, name, " = (char *) malloc(strlen(_a)+1);\n", tab4, name, " = (char *) malloc(strlen(_a)+1);\n",
0); 0);
Printv(setf.code,"strcpy(", name, ",_a);\n", 0); Printv(setf->code,"strcpy(", name, ",_a);\n", 0);
} else { } else {
// Set the value of a pointer // Set the value of a pointer
setf.add_local((char*)"void",(char*)"*_temp"); Wrapper_add_local(setf,(char*)"void",(char*)"*_temp",0);
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->code, (char*)"return(1)");
Printv(setf.code,tab4, name, " = ", t->print_cast(), " _temp;\n", 0); Printv(setf->code,tab4, name, " = ", t->print_cast(), " _temp;\n", 0);
} }
} }
} }
Printf(setf.code," return 1;\n}\n"); Printf(setf->code," return 1;\n}\n");
Replace(setf.code,"$name",iname, DOH_REPLACE_ANY); Replace(setf->code,"$name",iname, DOH_REPLACE_ANY);
setf.print(magic); Wrapper_print(setf,magic);
} }
// 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->def,"SWIGCLASS_STATIC int %s(SV *sv, MAGIC *mg) {\n", val_name);
Printv(getf.code, Printv(getf->code,
tab4, "MAGIC_PPERL\n", tab4, "MAGIC_PPERL\n",
tab4, "mg = mg;\n", tab4, "mg = mg;\n",
0); 0);
@ -1247,9 +1254,9 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
// Check for a typemap // Check for a typemap
if ((tm = typemap_lookup((char*)"varout",(char*)"perl5",t,(char*)"",name, (char*)"sv"))) { if ((tm = typemap_lookup((char*)"varout",(char*)"perl5",t,(char*)"",name, (char*)"sv"))) {
Printf(getf.code,"%s\n", tm); Printf(getf->code,"%s\n", tm);
} else if ((tm = typemap_lookup((char*)"out",(char*)"perl5",t,(char*)"",name,(char*)"sv"))) { } else if ((tm = typemap_lookup((char*)"out",(char*)"perl5",t,(char*)"",name,(char*)"sv"))) {
Printf(getf.code,"%s\n", tm); Printf(getf->code,"%s\n", tm);
} else { } else {
if (!t->is_pointer) { if (!t->is_pointer) {
switch(t->type) { switch(t->type) {
@ -1257,17 +1264,17 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
case T_SHORT : case T_SSHORT: case T_USHORT: case T_SHORT : case T_SSHORT: case T_USHORT:
case T_LONG : case T_SLONG : case T_ULONG: case T_LONG : case T_SLONG : 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->code,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->code, 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 :
getf.add_local((char*)"char",(char*)"_ptemp[2]"); Wrapper_add_local(getf,(char*)"char",(char*)"_ptemp[2]",0);
Printv(getf.code, Printv(getf->code,
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",
@ -1275,12 +1282,12 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
break; break;
case T_USER: case T_USER:
t->is_pointer++; t->is_pointer++;
Printv(getf.code, Printv(getf->code,
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);
getf.add_local((char*)"SV",(char*)"*rsv"); Wrapper_add_local(getf,(char*)"SV",(char*)"*rsv",0);
Printv(vinit, tab4, "sv_setref_pv(sv,\"", t->print_mangle(), "\",(void *) &", name, ");\n",0); Printv(vinit, tab4, "sv_setref_pv(sv,\"", t->print_mangle(), "\",(void *) &", name, ");\n",0);
t->is_pointer--; t->is_pointer--;
@ -1293,22 +1300,22 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
// Have some sort of arbitrary pointer type. Return it as a string // Have some sort of arbitrary pointer type. Return it as a string
if ((t->type == T_CHAR) && (t->is_pointer == 1)) if ((t->type == T_CHAR) && (t->is_pointer == 1))
Printv(getf.code, tab4, "sv_setpv((SV*) sv, ", name, ");\n", 0); Printv(getf->code, tab4, "sv_setpv((SV*) sv, ", name, ");\n", 0);
else { else {
Printv(getf.code, Printv(getf->code,
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);
getf.add_local((char*)"SV",(char*)"*rsv"); Wrapper_add_local(getf,(char*)"SV",(char*)"*rsv",0);
Printv(vinit, tab4, "sv_setref_pv(sv,\"", t->print_mangle(), "\",(void *) 1);\n",0); Printv(vinit, tab4, "sv_setref_pv(sv,\"", t->print_mangle(), "\",(void *) 1);\n",0);
} }
} }
} }
Printf(getf.code," return 1;\n}\n"); Printf(getf->code," return 1;\n}\n");
Replace(getf.code,"$name",iname, DOH_REPLACE_ANY); Replace(getf->code,"$name",iname, DOH_REPLACE_ANY);
getf.print(magic); Wrapper_print(getf,magic);
// Now add symbol to the PERL interpreter // Now add symbol to the PERL interpreter
if (Status & STAT_READONLY) { if (Status & STAT_READONLY) {
@ -1337,6 +1344,8 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
if (export_all) if (export_all)
Printf(exported,"$%s ", name); Printf(exported,"$%s ", name);
} }
DelWrapper(setf);
DelWrapper(getf);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------

View file

@ -496,7 +496,7 @@ void PYTHON::close_cmodule(void)
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// PYTHON::get_pointer(char *iname, char *srcname, char *src, char *target, // PYTHON::get_pointer(char *iname, char *srcname, char *src, char *target,
// DataType *t, WrapperFunction &f, char *ret) // DataType *t, DOHString *f, char *ret)
// //
// Emits code to get a pointer and do type checking. // Emits code to get a pointer and do type checking.
// iname = name of the function/method (used for error messages) // iname = name of the function/method (used for error messages)
@ -537,20 +537,20 @@ PYTHON::get_pointer(char *iname, char *srcname, char *src, char *dest,
// //
// Return the code to be used as a function header // Return the code to be used as a function header
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
void PYTHON::emit_function_header(WrapperFunction &emit_to, char *wname) void PYTHON::emit_function_header(Wrapper *emit_to, char *wname)
{ {
if (!use_kw) { if (!use_kw) {
Printv(emit_to.def, Printv(emit_to->def,
"static PyObject *", wname, "static PyObject *", wname,
"(PyObject *self, PyObject *args) {", "(PyObject *self, PyObject *args) {",
0); 0);
} else { } else {
Printv(emit_to.def, Printv(emit_to->def,
"static PyObject *", wname, "static PyObject *", wname,
"(PyObject *self, PyObject *args, PyObject *kwargs) {", "(PyObject *self, PyObject *args, PyObject *kwargs) {",
0); 0);
} }
Printf(emit_to.code," self = self;\n"); Printf(emit_to->code," self = self;\n");
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -562,7 +562,7 @@ void PYTHON::emit_function_header(WrapperFunction &emit_to, char *wname)
// //
// Returns the name of the variable to use as the self pointer // Returns the name of the variable to use as the self pointer
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
char *PYTHON::convert_self(WrapperFunction &) char *PYTHON::convert_self(Wrapper *f)
{ {
// Default behaviour is no translation // Default behaviour is no translation
return (char*)""; return (char*)"";
@ -619,7 +619,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
char wname[256], self_name[256], call_name[256]; char wname[256], self_name[256], call_name[256];
char source[64], target[64], temp[256], argnum[20]; char source[64], target[64], temp[256], argnum[20];
char *usage = 0; char *usage = 0;
WrapperFunction f; Wrapper *f;
DOHString *parse_args; DOHString *parse_args;
DOHString *arglist; DOHString *arglist;
DOHString *get_pointers; DOHString *get_pointers;
@ -631,6 +631,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
char *tm; char *tm;
int numopt = 0; int numopt = 0;
f = NewWrapper();
parse_args = NewString(""); parse_args = NewString("");
arglist = NewString(""); arglist = NewString("");
get_pointers = NewString(""); get_pointers = NewString("");
@ -652,7 +653,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
emit_function_header(f, wname); emit_function_header(f, wname);
f.add_local((char*)"PyObject *",(char*)"_resultobj"); Wrapper_add_local(f,(char*)"PyObject *",(char*)"_resultobj",0);
// Get the function usage string for later use // Get the function usage string for later use
@ -709,9 +710,9 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
// Look for input typemap // Look for input typemap
if ((tm = typemap_lookup((char*)"in",(char*)"python",p->t,p->name,source,target,&f))) { if ((tm = typemap_lookup((char*)"in",(char*)"python",p->t,p->name,source,target,f))) {
Putc('O',parse_args); Putc('O',parse_args);
f.add_local((char*)"PyObject *",source,(char*)"0"); Wrapper_add_local(f, (char*)"PyObject *",source,(char*)"0");
Printf(arglist,"&%s",source); Printf(arglist,"&%s",source);
if (i >= (pcount-numopt)) if (i >= (pcount-numopt))
Printv(get_pointers, tab4, "if (", source, ")\n", Printv(get_pointers, tab4, "if (", source, ")\n",
@ -764,9 +765,9 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
sprintf(tempb,"tempbool%d",i); sprintf(tempb,"tempbool%d",i);
Putc('i',parse_args); Putc('i',parse_args);
if (!p->defvalue) if (!p->defvalue)
f.add_local((char*)"int",tempb); Wrapper_add_local(f,(char*)"int",tempb,0);
else else
f.add_local((char*)"int",tempb,tempval); Wrapper_add_local(f,(char*)"int",tempb,tempval);
Printv(get_pointers, tab4, target, " = ", p->t->print_cast(), " ", tempb, ";\n", 0); Printv(get_pointers, tab4, target, " = ", p->t->print_cast(), " ", tempb, ";\n", 0);
Printf(arglist,"&%s",tempb); Printf(arglist,"&%s",tempb);
} }
@ -812,7 +813,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
sprintf(target,"_arg%d", i); sprintf(target,"_arg%d", i);
sprintf(temp,"argument %d",i+1); sprintf(temp,"argument %d",i+1);
f.add_local((char*)"PyObject *", source,(char*)"0"); Wrapper_add_local(f,(char*)"PyObject *", source,(char*)"0");
Printf(arglist,"&%s",source); Printf(arglist,"&%s",source);
get_pointer(iname, temp, source, target, p->t, get_pointers, (char*)"NULL"); get_pointer(iname, temp, source, target, p->t, get_pointers, (char*)"NULL");
} }
@ -843,7 +844,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
Printf(kwargs," NULL }"); Printf(kwargs," NULL }");
if (use_kw) { if (use_kw) {
Printv(f.locals,tab4, "char *_kwnames[] = ", kwargs, ";\n", 0); Printv(f->locals,tab4, "char *_kwnames[] = ", kwargs, ";\n", 0);
} }
Printf(parse_args,":%s\"", iname); Printf(parse_args,":%s\"", iname);
@ -855,7 +856,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
strcpy(self_name,convert_self(f)); strcpy(self_name,convert_self(f));
/* Now slap the whole first part of the wrapper function together */ /* Now slap the whole first part of the wrapper function together */
Printv(f.code, parse_args, get_pointers, check, 0); Printv(f->code, parse_args, get_pointers, check, 0);
// This function emits code to call the real function. Assuming you read // This function emits code to call the real function. Assuming you read
// the parameters in correctly, this will work. // the parameters in correctly, this will work.
@ -869,7 +870,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
if ((tm = typemap_lookup((char*)"out",(char*)"python",d,iname,(char*)"_result",(char*)"_resultobj"))) { if ((tm = typemap_lookup((char*)"out",(char*)"python",d,iname,(char*)"_result",(char*)"_resultobj"))) {
// Yep. Use it instead of the default // Yep. Use it instead of the default
Printf(f.code,"%s\n", tm); Printf(f->code,"%s\n", tm);
} else { } else {
if ((d->type != T_VOID) || (d->is_pointer)) { if ((d->type != T_VOID) || (d->is_pointer)) {
@ -884,38 +885,38 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
// Return an integer type // Return an integer type
case T_INT: case T_SINT: case T_UINT: case T_BOOL: case T_INT: case T_SINT: case T_UINT: case T_BOOL:
Printf(f.code," _resultobj = Py_BuildValue(\"i\",_result);\n"); Printf(f->code," _resultobj = Py_BuildValue(\"i\",_result);\n");
break; break;
case T_SHORT: case T_SSHORT: case T_USHORT: case T_SHORT: case T_SSHORT: case T_USHORT:
Printf(f.code," _resultobj = Py_BuildValue(\"h\",_result);\n"); Printf(f->code," _resultobj = Py_BuildValue(\"h\",_result);\n");
break; break;
case T_LONG : case T_SLONG : case T_ULONG: case T_LONG : case T_SLONG : case T_ULONG:
Printf(f.code," _resultobj = Py_BuildValue(\"l\",_result);\n"); Printf(f->code," _resultobj = Py_BuildValue(\"l\",_result);\n");
break; break;
case T_SCHAR: case T_UCHAR : case T_SCHAR: case T_UCHAR :
Printf(f.code," _resultobj = Py_BuildValue(\"b\",_result);\n"); Printf(f->code," _resultobj = Py_BuildValue(\"b\",_result);\n");
break; break;
// Return a floating point value // Return a floating point value
case T_DOUBLE : case T_DOUBLE :
Printf(f.code," _resultobj = Py_BuildValue(\"d\",_result);\n"); Printf(f->code," _resultobj = Py_BuildValue(\"d\",_result);\n");
break; break;
case T_FLOAT : case T_FLOAT :
Printf(f.code," _resultobj = Py_BuildValue(\"f\",_result);\n"); Printf(f->code," _resultobj = Py_BuildValue(\"f\",_result);\n");
break; break;
// Return a single ASCII value. Usually we need to convert // Return a single ASCII value. Usually we need to convert
// it to a NULL-terminate string and return that instead. // it to a NULL-terminate string and return that instead.
case T_CHAR : case T_CHAR :
Printf(f.code," _resultobj = Py_BuildValue(\"c\",_result);\n"); Printf(f->code," _resultobj = Py_BuildValue(\"c\",_result);\n");
break; break;
case T_USER : case T_USER :
d->is_pointer++; d->is_pointer++;
d->remember(); d->remember();
Printv(f.code,tab4, "_resultobj = SWIG_NewPointerObj((void *)_result, SWIGTYPE", d->print_mangle(), ");\n",0); Printv(f->code,tab4, "_resultobj = SWIG_NewPointerObj((void *)_result, SWIGTYPE", d->print_mangle(), ");\n",0);
d->is_pointer--; d->is_pointer--;
break; break;
default : default :
@ -931,36 +932,36 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
if ((d->type == T_CHAR) && (d->is_pointer == 1)) { if ((d->type == T_CHAR) && (d->is_pointer == 1)) {
// Return a character string // Return a character string
Printf(f.code," _resultobj = Py_BuildValue(\"s\", _result);\n"); Printf(f->code," _resultobj = Py_BuildValue(\"s\", _result);\n");
// If declared as a new object, free the result // If declared as a new object, free the result
} else { } else {
// Build a SWIG pointer. // Build a SWIG pointer.
d->remember(); d->remember();
Printv(f.code, tab4, "_resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE", d->print_mangle(), ");\n", 0); Printv(f->code, tab4, "_resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE", d->print_mangle(), ");\n", 0);
} }
} }
} else { } else {
Printf(f.code," Py_INCREF(Py_None);\n"); Printf(f->code," Py_INCREF(Py_None);\n");
Printf(f.code," _resultobj = Py_None;\n"); Printf(f->code," _resultobj = Py_None;\n");
} }
} }
// Check to see if there were any output arguments, if so we're going to // Check to see if there were any output arguments, if so we're going to
// create a Python list object out of the current result // create a Python list object out of the current result
Printv(f.code,outarg,0); Printv(f->code,outarg,0);
// If there was any other cleanup needed, do that // If there was any other cleanup needed, do that
Printv(f.code,cleanup,0); Printv(f->code,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 = typemap_lookup((char*)"newfree",(char*)"python",d,iname,(char*)"_result",(char*)""))) { if ((tm = typemap_lookup((char*)"newfree",(char*)"python",d,iname,(char*)"_result",(char*)""))) {
Printf(f.code,"%s\n",tm); Printf(f->code,"%s\n",tm);
} }
} }
@ -968,19 +969,19 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
if ((tm = typemap_lookup((char*)"ret",(char*)"python",d,iname,(char*)"_result",(char*)""))) { if ((tm = typemap_lookup((char*)"ret",(char*)"python",d,iname,(char*)"_result",(char*)""))) {
// Yep. Use it instead of the default // Yep. Use it instead of the default
Printf(f.code,"%s\n",tm); Printf(f->code,"%s\n",tm);
} }
Printf(f.code," return _resultobj;\n}\n"); Printf(f->code," return _resultobj;\n}\n");
// Substitute the cleanup code // Substitute the cleanup code
Replace(f.code,"$cleanup",cleanup, DOH_REPLACE_ANY); Replace(f->code,"$cleanup",cleanup, DOH_REPLACE_ANY);
// Substitute the function name // Substitute the function name
Replace(f.code,"$name",iname, DOH_REPLACE_ANY); Replace(f->code,"$name",iname, DOH_REPLACE_ANY);
// Dump the function out // Dump the function out
f.print(f_wrappers); Wrapper_print(f,f_wrappers);
// Now register the function with the interpreter. // Now register the function with the interpreter.
@ -1049,6 +1050,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
Delete(outarg); Delete(outarg);
Delete(check); Delete(check);
Delete(kwargs); Delete(kwargs);
DelWrapper(f);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -1070,7 +1072,10 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
static int have_globals = 0; static int have_globals = 0;
char *tm; char *tm;
WrapperFunction getf, setf; Wrapper *getf, *setf;
getf = NewWrapper();
setf = NewWrapper();
// If this is our first call, add the globals variable to the // If this is our first call, add the globals variable to the
// Python dictionary. // Python dictionary.
@ -1091,11 +1096,11 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
// 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->def,"static int %s_set(PyObject *val) {", wname);
if (!(Status & STAT_READONLY)) { if (!(Status & STAT_READONLY)) {
if ((tm = typemap_lookup((char*)"varin",(char*)"python",t,name,(char*)"val",name))) { if ((tm = typemap_lookup((char*)"varin",(char*)"python",t,name,(char*)"val",name))) {
Printf(setf.code,"%s\n",tm); Printf(setf->code,"%s\n",tm);
Replace(setf.code,"$name",iname, DOH_REPLACE_ANY); Replace(setf->code,"$name",iname, DOH_REPLACE_ANY);
} else { } else {
if ((t->type != T_VOID) || (t->is_pointer)) { if ((t->type != T_VOID) || (t->is_pointer)) {
if (!t->is_pointer) { if (!t->is_pointer) {
@ -1108,8 +1113,8 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
case T_SINT: case T_SSHORT: case T_SLONG: case T_SINT: case T_SSHORT: case T_SLONG:
case T_SCHAR: case T_UCHAR: case T_BOOL: case T_SCHAR: case T_UCHAR: case T_BOOL:
// Get an integer value // Get an integer value
setf.add_local(t->print_type(), (char*)"tval"); Wrapper_add_local(setf,t->print_type(), (char*)"tval",0);
Printv(setf.code, Printv(setf->code,
tab4, "tval = ", t->print_cast(), "PyInt_AsLong(val);\n", tab4, "tval = ", t->print_cast(), "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 '",
@ -1122,8 +1127,8 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
case T_FLOAT: case T_DOUBLE: case T_FLOAT: case T_DOUBLE:
// Get a floating point value // Get a floating point value
setf.add_local(t->print_type(), (char*)"tval"); Wrapper_add_local(setf,t->print_type(), (char*)"tval",0);
Printv(setf.code, Printv(setf->code,
tab4, "tval = ", t->print_cast(), "PyFloat_AsDouble(val);\n", tab4, "tval = ", t->print_cast(), "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 '",
@ -1137,8 +1142,8 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
// A single ascii character // A single ascii character
case T_CHAR: case T_CHAR:
setf.add_local((char*)"char *", (char*)"tval"); Wrapper_add_local(setf,(char*)"char *", (char*)"tval",0);
Printv(setf.code, Printv(setf->code,
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 '",
@ -1150,9 +1155,9 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
break; break;
case T_USER: case T_USER:
t->is_pointer++; t->is_pointer++;
setf.add_local(t->print_type(),(char*)"temp"); Wrapper_add_local(setf,t->print_type(),(char*)"temp",0);
get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf.code,(char*)"1"); get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf->code,(char*)"1");
Printv(setf.code, tab4, name, " = *temp;\n", 0); Printv(setf->code, tab4, name, " = *temp;\n", 0);
t->is_pointer--; t->is_pointer--;
break; break;
default: default:
@ -1163,8 +1168,8 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
// Parse a pointer value // Parse a pointer value
if ((t->type == T_CHAR) && (t->is_pointer == 1)) { if ((t->type == T_CHAR) && (t->is_pointer == 1)) {
setf.add_local((char*)"char *", (char*)"tval"); Wrapper_add_local(setf,(char*)"char *", (char*)"tval",0);
Printv(setf.code, Printv(setf->code,
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 '",
@ -1174,13 +1179,13 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
0); 0);
if (CPlusPlus) { if (CPlusPlus) {
Printv(setf.code, Printv(setf->code,
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->code,
tab4, "if (", name, ") free(", name, ");\n", tab4, "if (", name, ") free(", 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",
@ -1190,41 +1195,41 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
// Is a generic pointer value. // Is a generic pointer value.
setf.add_local(t->print_type(),(char*)"temp"); Wrapper_add_local(setf,t->print_type(),(char*)"temp",0);
get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf.code,(char*)"1"); get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf->code,(char*)"1");
Printv(setf.code,tab4, name, " = temp;\n", 0); Printv(setf->code,tab4, name, " = temp;\n", 0);
} }
} }
} }
} }
Printf(setf.code," return 0;\n"); Printf(setf->code," return 0;\n");
} else { } else {
// Is a readonly variable. Issue an error // Is a readonly variable. Issue an error
Printv(setf.code, Printv(setf->code,
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->code,"}\n");
// Dump out function for setting value // Dump out function for setting value
setf.print(f_wrappers); Wrapper_print(setf,f_wrappers);
// ---------------------------------------------------------------- // ----------------------------------------------------------------
// 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->def,"static PyObject *%s_get() {", wname);
getf.add_local((char*)"PyObject *",(char*)"pyobj"); Wrapper_add_local(getf,(char*)"PyObject *",(char*)"pyobj",0);
if ((tm = typemap_lookup((char*)"varout",(char*)"python",t,name,name,(char*)"pyobj"))) { if ((tm = typemap_lookup((char*)"varout",(char*)"python",t,name,name,(char*)"pyobj"))) {
Printf(getf.code,"%s\n",tm); Printf(getf->code,"%s\n",tm);
Replace(getf.code,"$name",iname, DOH_REPLACE_ANY); Replace(getf->code,"$name",iname, DOH_REPLACE_ANY);
} else if ((tm = typemap_lookup((char*)"out",(char*)"python",t,name,name,(char*)"pyobj"))) { } else if ((tm = typemap_lookup((char*)"out",(char*)"python",t,name,name,(char*)"pyobj"))) {
Printf(getf.code,"%s\n",tm); Printf(getf->code,"%s\n",tm);
Replace(getf.code,"$name",iname, DOH_REPLACE_ANY); Replace(getf->code,"$name",iname, DOH_REPLACE_ANY);
} else { } else {
if ((t->type != T_VOID) || (t->is_pointer)) { if ((t->type != T_VOID) || (t->is_pointer)) {
if (!t->is_pointer) { if (!t->is_pointer) {
@ -1235,14 +1240,14 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
case T_SHORT: case T_SSHORT: case T_USHORT: case T_SHORT: case T_SSHORT: case T_USHORT:
case T_LONG: case T_SLONG: case T_ULONG: case T_LONG: case T_SLONG: 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->code, 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->code, tab4, "pyobj = PyFloat_FromDouble((double) ", name, ");\n", 0);
break; break;
case T_CHAR: case T_CHAR:
getf.add_local((char*)"char",(char*)"ptemp[2]"); Wrapper_add_local(getf,(char*)"char",(char*)"ptemp[2]",0);
Printv(getf.code, Printv(getf->code,
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",
@ -1252,7 +1257,7 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
// Hack this into a pointer // Hack this into a pointer
t->is_pointer++; t->is_pointer++;
t->remember(); t->remember();
Printv(getf.code, Printv(getf->code,
tab4, "pyobj = SWIG_NewPointerObj((void *) &", name , tab4, "pyobj = SWIG_NewPointerObj((void *) &", name ,
", SWIGTYPE", t->print_mangle(), ");\n", ", SWIGTYPE", t->print_mangle(), ");\n",
0); 0);
@ -1266,14 +1271,14 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
// Is some sort of pointer value // Is some sort of pointer value
if ((t->type == T_CHAR) && (t->is_pointer == 1)) { if ((t->type == T_CHAR) && (t->is_pointer == 1)) {
Printv(getf.code, Printv(getf->code,
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",
0); 0);
} else { } else {
t->remember(); t->remember();
Printv(getf.code, Printv(getf->code,
tab4, "pyobj = SWIG_NewPointerObj((void *)", name, tab4, "pyobj = SWIG_NewPointerObj((void *)", name,
", SWIGTYPE", t->print_mangle(), ");\n", ", SWIGTYPE", t->print_mangle(), ");\n",
0); 0);
@ -1282,9 +1287,9 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
} }
} }
Printf(getf.code," return pyobj;\n}\n"); Printf(getf->code," return pyobj;\n}\n");
getf.print(f_wrappers); Wrapper_print(getf,f_wrappers);
// Now add this to the variable linking mechanism // Now add this to the variable linking mechanism
@ -1301,6 +1306,8 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
0); 0);
} }
} }
DelWrapper(setf);
DelWrapper(getf);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------

View file

@ -33,8 +33,8 @@ protected:
virtual void initialize_cmodule(); virtual void initialize_cmodule();
virtual void close_cmodule(); virtual void close_cmodule();
virtual void emit_function_header(WrapperFunction &emit_to, char *wname); virtual void emit_function_header(Wrapper *emit_to, char *wname);
virtual char *convert_self(WrapperFunction &f); virtual char *convert_self(Wrapper *f);
virtual char *make_funcname_wrapper(char *fnName); virtual char *make_funcname_wrapper(char *fnName);
void emitAddPragmas(DOHString *output, char* name, char* spacing); void emitAddPragmas(DOHString *output, char* name, char* spacing);

View file

@ -397,7 +397,7 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
char source[256], target[256]; char source[256], target[256];
char *tm; char *tm;
DOHString *cleanup, *outarg; DOHString *cleanup, *outarg;
WrapperFunction f; Wrapper *f;
int i; int i;
// Ruby needs no destructor wrapper // Ruby needs no destructor wrapper
@ -410,6 +410,7 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
cleanup = NewString(""); cleanup = NewString("");
outarg = NewString(""); outarg = NewString("");
f = NewWrapper();
switch (current) { switch (current) {
case MEMBER_FUNC: case MEMBER_FUNC:
@ -450,18 +451,18 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
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->def, "static VALUE\n", wname, "(", 0);
if (vararg) { if (vararg) {
Printv(f.def, "int argc, VALUE *argv, VALUE self",0); Printv(f->def, "int argc, VALUE *argv, VALUE self",0);
} else { } else {
Printv(f.def, "VALUE self", 0); Printv(f->def, "VALUE self", 0);
for (i = start; i < l->nparms; i++) { for (i = start; i < l->nparms; i++) {
if (!l->get(i)->ignore) { if (!l->get(i)->ignore) {
Printf(f.def,", VALUE varg%d", i); Printf(f->def,", VALUE varg%d", i);
} }
} }
} }
Printf(f.def,") {"); Printf(f->def,") {");
// Emit all of the local variables for holding arguments. // Emit all of the local variables for holding arguments.
if (vararg) { if (vararg) {
@ -469,11 +470,11 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
if (!l->get(i)->ignore) { if (!l->get(i)->ignore) {
char s[256]; char s[256];
sprintf(s,"varg%d",i); sprintf(s,"varg%d",i);
f.add_local((char*)"VALUE", s); Wrapper_add_local(f,(char*)"VALUE", s,0);
} }
} }
} }
f.add_local((char*)"VALUE", (char*)"vresult", (char*)"Qnil"); Wrapper_add_local(f,(char*)"VALUE", (char*)"vresult", (char*)"Qnil");
int pcount = emit_args(t,l,f); int pcount = emit_args(t,l,f);
#if 0 #if 0
@ -490,17 +491,17 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
<< (numarg-numoptreal) << numoptreal << "\") */" << br; << (numarg-numoptreal) << numoptreal << "\") */" << br;
temp << br; temp << br;
if (numignore != 0) Printf(stderr, temp); if (numignore != 0) Printf(stderr, temp);
f.code << temp; f->code << temp;
#endif #endif
// Emit count to check the number of arguments // Emit count to check the number of arguments
if (vararg) { if (vararg) {
Printf(f.code," rb_scan_args(argc, argv, \"%d%d\"", (numarg-numoptreal), numoptreal); Printf(f->code," rb_scan_args(argc, argv, \"%d%d\"", (numarg-numoptreal), numoptreal);
for (i = start; i < l->nparms; i++) { for (i = start; i < l->nparms; i++) {
if (!l->get(i)->ignore) { if (!l->get(i)->ignore) {
Printf(f.code,", &varg%d", i); Printf(f->code,", &varg%d", i);
} }
} }
Printf(f.code,");\n"); Printf(f->code,");\n");
} }
// Now walk the function parameter list and generate code // Now walk the function parameter list and generate code
@ -522,24 +523,24 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
if (!p.ignore) { if (!p.ignore) {
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->code," if (argc > %d) {\n", j - start);
tab = (char*)tab8; tab = (char*)tab8;
} }
// Get typemap for this argument // Get typemap for this argument
tm = ruby_typemap_lookup((char*)"in",p.t,p.name,source,target,&f); tm = ruby_typemap_lookup((char*)"in",p.t,p.name,source,target,f);
if (tm) { if (tm) {
DOHString *s = NewString(tm); DOHString *s = NewString(tm);
indent(s,tab); indent(s,tab);
Printv(f.code, s, "\n", 0); Printv(f->code, s, "\n", 0);
Replace(f.code, "$arg", source, DOH_REPLACE_ANY); Replace(f->code, "$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, p.t->print_type()); input_file,line_number, p.t->print_type());
} }
if (j >= (pcount-numopt)) if (j >= (pcount-numopt))
Printv(f.code, tab4, "} \n"); Printv(f->code, tab4, "} \n");
j++; j++;
} }
@ -548,8 +549,8 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
if (tm) { if (tm) {
DOHString *s = NewString(tm); DOHString *s = NewString(tm);
indent(s); indent(s);
Printv(f.code, s, "\n", 0); Printv(f->code, s, "\n", 0);
Replace(f.code, "$arg", source, DOH_REPLACE_ANY); Replace(f->code, "$arg", source, DOH_REPLACE_ANY);
Delete(s); Delete(s);
} }
@ -579,13 +580,13 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
// Return value if necessary // Return value if necessary
if ((t->type != T_VOID) || (t->is_pointer)) { if ((t->type != T_VOID) || (t->is_pointer)) {
if (predicate) { if (predicate) {
Printv(f.code, tab4, "vresult = (_result ? Qtrue : Qfalse);\n", 0); Printv(f->code, 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) {
DOHString *s = NewString(tm); DOHString *s = NewString(tm);
indent(s); indent(s);
Printv(f.code, s, "\n", 0); Printv(f->code, s, "\n", 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",
@ -595,10 +596,10 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
} }
// Dump argument output code; // Dump argument output code;
Printv(f.code,outarg,0); Printv(f->code,outarg,0);
// Dump the argument cleanup code // Dump the argument cleanup code
Printv(f.code,cleanup,0); Printv(f->code,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) {
@ -606,14 +607,14 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
if (tm) { if (tm) {
DOHString *s = NewString(tm); DOHString *s = NewString(tm);
indent(s); indent(s);
Printv(f.code,s,"\n", 0); Printv(f->code,s,"\n", 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->code, tab4, "DATA_PTR(self) = 0;\n", 0);
} }
// Special processing on return value. // Special processing on return value.
@ -621,22 +622,23 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
if (tm) { if (tm) {
DOHString *s = NewString(tm); DOHString *s = NewString(tm);
indent(s); indent(s);
Printv(f.code,s,"\n", 0); Printv(f->code,s,"\n", 0);
} }
// Wrap things up (in a manner of speaking) // Wrap things up (in a manner of speaking)
Printv(f.code, tab4, "return vresult;\n}\n", 0); Printv(f->code, tab4, "return vresult;\n}\n", 0);
// Substitute the cleanup code // Substitute the cleanup code
Replace(f.code,"$cleanup",cleanup, DOH_REPLACE_ANY); Replace(f->code,"$cleanup",cleanup, DOH_REPLACE_ANY);
// Emit the function // Emit the function
f.print(f_wrappers); Wrapper_print(f,f_wrappers);
// 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);
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -651,9 +653,12 @@ void RUBY::link_variable(char *name, char *iname, DataType *t) {
char *tm; char *tm;
DOHString *getfname, *setfname; DOHString *getfname, *setfname;
WrapperFunction getf, setf; Wrapper *getf, *setf;
int mod_attr = 0; int mod_attr = 0;
getf = NewWrapper();
setf = NewWrapper();
// module attribute? // module attribute?
if (current == STATIC_VAR || !toplevel) if (current == STATIC_VAR || !toplevel)
mod_attr = 1; mod_attr = 1;
@ -661,31 +666,31 @@ void RUBY::link_variable(char *name, char *iname, DataType *t) {
// 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->def, "static VALUE\n", getfname, "(", 0);
if (mod_attr) Printf(getf.def, "VALUE self"); if (mod_attr) Printf(getf->def, "VALUE self");
Printf(getf.def, ") {"); Printf(getf->def, ") {");
getf.add_local((char*)"VALUE", (char*)"_val"); Wrapper_add_local(getf,(char*)"VALUE", (char*)"_val",0);
tm = ruby_typemap_lookup((char*)"varout",t,name,name,(char*)"_val"); tm = ruby_typemap_lookup((char*)"varout",t,name,name,(char*)"_val");
if (!tm) if (!tm)
tm = ruby_typemap_lookup((char*)"out",t,name,name,(char*)"_val"); tm = ruby_typemap_lookup((char*)"out",t,name,name,(char*)"_val");
if (tm) { if (tm) {
DOHString *s = NewString(tm); DOHString *s = NewString(tm);
indent(s); indent(s);
Printv(getf.code,s,"\n", 0); Printv(getf->code,s,"\n", 0);
Delete(s); Delete(s);
} else if (!t->is_pointer && t->type == T_USER) { } else if (!t->is_pointer && t->type == T_USER) {
// Hack this into a pointer // Hack this into a pointer
t->is_pointer++; t->is_pointer++;
t->remember(); t->remember();
Printv(getf.code, tab4, "_val = SWIG_NewPointerObj((void *)&", name, Printv(getf->code, tab4, "_val = SWIG_NewPointerObj((void *)&", name,
", \"", t->print_mangle(), "\");\n", 0); ", \"", t->print_mangle(), "\");\n", 0);
t->is_pointer--; t->is_pointer--;
} 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,t->print_type()); input_file,line_number,t->print_type());
} }
Printv(getf.code, tab4, "return _val;\n}\n", 0); Printv(getf->code, tab4, "return _val;\n}\n", 0);
getf.print(f_wrappers); Wrapper_print(getf,f_wrappers);
if (Status & STAT_READONLY) { if (Status & STAT_READONLY) {
setfname = NewString("NULL"); setfname = NewString("NULL");
@ -694,34 +699,34 @@ void RUBY::link_variable(char *name, char *iname, DataType *t) {
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? */
if (mod_attr) if (mod_attr)
Printv(setf.def, "static VALUE\n", setfname, "(VALUE self, ", 0); Printv(setf->def, "static VALUE\n", setfname, "(VALUE self, ", 0);
else else
Printv(setf.def, "static void\n", setfname, "(", 0); Printv(setf->def, "static void\n", setfname, "(", 0);
Printf(setf.def, "VALUE _val) {"); Printf(setf->def, "VALUE _val) {");
tm = ruby_typemap_lookup((char*)"varin",t,name,(char*)"_val",name); tm = ruby_typemap_lookup((char*)"varin",t,name,(char*)"_val",name);
if (!tm) if (!tm)
tm = ruby_typemap_lookup((char*)"in",t,name,(char*)"_val",name); tm = ruby_typemap_lookup((char*)"in",t,name,(char*)"_val",name);
if (tm) { if (tm) {
DOHString *s = NewString(tm); DOHString *s = NewString(tm);
indent(s); indent(s);
Printv(setf.code,s,"\n",0); Printv(setf->code,s,"\n",0);
Delete(s); Delete(s);
} else if (!t->is_pointer && t->type == T_USER) { } else if (!t->is_pointer && t->type == T_USER) {
t->is_pointer++; t->is_pointer++;
setf.add_local(t->print_type(), (char*)"temp"); Wrapper_add_local(setf,t->print_type(), (char*)"temp",0);
Printv(setf.code, tab4, "temp = (", t->print_type(), ")", Printv(setf->code, tab4, "temp = (", t->print_type(), ")",
"SWIG_ConvertPtr(_val, \"", t->print_mangle(), "\");\n", "SWIG_ConvertPtr(_val, \"", t->print_mangle(), "\");\n",
0); 0);
Printv(setf.code, tab4, name, " = *temp;\n",0); Printv(setf->code, tab4, name, " = *temp;\n",0);
t->is_pointer--; t->is_pointer--;
} 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,t->print_type()); input_file,line_number,t->print_type());
} }
if (mod_attr) if (mod_attr)
Printv(setf.code, tab4, "return _val;\n",0); Printv(setf->code, tab4, "return _val;\n",0);
Printf(setf.code,"}\n"); Printf(setf->code,"}\n");
setf.print(f_wrappers); Wrapper_print(setf,f_wrappers);
} }
// define accessor method // define accessor method
@ -775,6 +780,8 @@ void RUBY::link_variable(char *name, char *iname, DataType *t) {
} }
Delete(getfname); Delete(getfname);
Delete(setfname); Delete(setfname);
DelWrapper(setf);
DelWrapper(getf);
} }
@ -851,7 +858,7 @@ void RUBY::declare_const(char *name, char *iname, DataType *type, char *value) {
// target = a string containing the target value // target = a string containing the target value
// f = a wrapper function object (optional) // f = a wrapper function object (optional)
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
char *RUBY::ruby_typemap_lookup(char *op, DataType *type, char *pname, char *source, char *target, WrapperFunction *f) { char *RUBY::ruby_typemap_lookup(char *op, DataType *type, char *pname, char *source, char *target, Wrapper *f) {
static DOHString *s = 0; static DOHString *s = 0;
char *tm; char *tm;
DOHString *target_replace = NewString(target); DOHString *target_replace = NewString(target);

View file

@ -82,7 +82,7 @@ class RUBY : public Language {
private: private:
virtual char *make_wrapper_name(char *cname); virtual char *make_wrapper_name(char *cname);
virtual char *validate_const_name(char *name); virtual char *validate_const_name(char *name);
virtual char *ruby_typemap_lookup(char *, DataType *, char *, char *, char *, WrapperFunction * = 0); virtual char *ruby_typemap_lookup(char *, DataType *, char *, char *, char *, Wrapper * = 0);
virtual int to_VALUE(DataType *, char *, DOHString *, int = 0); virtual int to_VALUE(DataType *, char *, DOHString *, int = 0);
virtual int from_VALUE(DataType *, char *, DOHString *); virtual int from_VALUE(DataType *, char *, DOHString *);
public: public:

View file

@ -470,11 +470,11 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
char source[64]; char source[64];
char target[64]; char target[64];
char argnum[32]; char argnum[32];
WrapperFunction f; Wrapper *f;
DOHString *incode, *cleanup, *outarg, *argstr, *args; DOHString *incode, *cleanup, *outarg, *argstr, *args;
int numopt= 0; int numopt= 0;
f = NewWrapper();
incode = NewString(""); incode = NewString("");
cleanup = NewString(""); cleanup = NewString("");
outarg = NewString(""); outarg = NewString("");
@ -487,7 +487,7 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
// Now write the wrapper function itself....this is pretty ugly // Now write the wrapper function itself....this is pretty ugly
Printv(f.def, Printv(f->def,
"static int ", wname, "(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {", "static int ", wname, "(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {",
0); 0);
@ -520,7 +520,7 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
if (j == (pcount-numopt)) if (j == (pcount-numopt))
Putc('|',argstr); Putc('|',argstr);
if ((tm = typemap_lookup((char*)"in",(char*)"tcl8",p->t,p->name,source,target,&f))) { if ((tm = typemap_lookup((char*)"in",(char*)"tcl8",p->t,p->name,source,target,f))) {
Putc('o',argstr); Putc('o',argstr);
Printf(args,",0"); Printf(args,",0");
@ -548,7 +548,7 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
{ {
char tb[32]; char tb[32];
sprintf(tb,"tempb%d",i); sprintf(tb,"tempb%d",i);
f.add_local((char*)"int",tb); Wrapper_add_local(f,(char*)"int",tb,0);
Printf(args,",&%s",tb); Printf(args,",&%s",tb);
Printv(incode, tab4, target, " = (bool) ", tb, ";\n", 0); Printv(incode, tab4, target, " = (bool) ", tb, ";\n", 0);
} }
@ -646,11 +646,11 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
p = l->get_next(); // Get next parameter and continue p = l->get_next(); // Get next parameter and continue
} }
Printf(argstr,":%s\"",usage); Printf(argstr,":%s\"",usage);
Printv(f.code, Printv(f->code,
tab4, "if (SWIG_GetArgs(interp, objc, objv,", argstr, args, ") == TCL_ERROR) return TCL_ERROR;\n", tab4, "if (SWIG_GetArgs(interp, objc, objv,", argstr, args, ") == TCL_ERROR) return TCL_ERROR;\n",
0); 0);
Printv(f.code,incode,0); Printv(f->code,incode,0);
// Now write code to make the function call // Now write code to make the function call
@ -660,7 +660,7 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
if ((tm = typemap_lookup((char*)"out",(char*)"tcl8",d,name,(char*)"_result",(char*)"tcl_result"))) { if ((tm = typemap_lookup((char*)"out",(char*)"tcl8",d,name,(char*)"_result",(char*)"tcl_result"))) {
// Yep. Use it instead of the default // Yep. Use it instead of the default
Printf(f.code,"%s\n", tm); Printf(f->code,"%s\n", tm);
} else if ((d->type != T_VOID) || (d->is_pointer)) { } else if ((d->type != T_VOID) || (d->is_pointer)) {
if (!d->is_pointer) { if (!d->is_pointer) {
@ -680,18 +680,18 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
case T_USHORT: case T_USHORT:
case T_ULONG: case T_ULONG:
case T_UCHAR: case T_UCHAR:
Printv(f.code, tab4, "Tcl_SetObjResult(interp,Tcl_NewIntObj((long) _result));\n",0); Printv(f->code, tab4, "Tcl_SetObjResult(interp,Tcl_NewIntObj((long) _result));\n",0);
break; break;
// Is a single character. Assume we return it as a string // Is a single character. Assume we return it as a string
case T_CHAR : case T_CHAR :
Printv(f.code, tab4, "Tcl_SetObjResult(interp,Tcl_NewStringObj(&_result,1));\n",0); Printv(f->code, tab4, "Tcl_SetObjResult(interp,Tcl_NewStringObj(&_result,1));\n",0);
break; break;
// Floating point number // Floating point number
case T_DOUBLE : case T_DOUBLE :
case T_FLOAT : case T_FLOAT :
Printv(f.code, tab4, "Tcl_SetObjResult(interp,Tcl_NewDoubleObj((double) _result));\n",0); Printv(f->code, tab4, "Tcl_SetObjResult(interp,Tcl_NewDoubleObj((double) _result));\n",0);
break; break;
// User defined type // User defined type
@ -702,7 +702,7 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
d->is_pointer++; d->is_pointer++;
d->remember(); d->remember();
Printv(f.code, tab4, "Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) _result,SWIGTYPE", Printv(f->code, tab4, "Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) _result,SWIGTYPE",
d->print_mangle(), "));\n", 0); d->print_mangle(), "));\n", 0);
d->is_pointer--; d->is_pointer--;
@ -720,10 +720,10 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
if ((d->type == T_CHAR) && (d->is_pointer == 1)) { if ((d->type == T_CHAR) && (d->is_pointer == 1)) {
// Return a character string // Return a character string
Printv(f.code, tab4, "Tcl_SetObjResult(interp,Tcl_NewStringObj(_result,-1));\n",0); Printv(f->code, tab4, "Tcl_SetObjResult(interp,Tcl_NewStringObj(_result,-1));\n",0);
} else { } else {
d->remember(); d->remember();
Printv(f.code, tab4, "Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) _result,SWIGTYPE", Printv(f->code, tab4, "Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) _result,SWIGTYPE",
d->print_mangle(), "));\n", d->print_mangle(), "));\n",
0); 0);
} }
@ -731,32 +731,32 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
} }
// Dump output argument code // Dump output argument code
Printv(f.code,outarg,0); Printv(f->code,outarg,0);
// Dump the argument cleanup code // Dump the argument cleanup code
Printv(f.code,cleanup,0); Printv(f->code,cleanup,0);
// Look for any remaining cleanup // Look for any remaining cleanup
if (NewObject) { if (NewObject) {
if ((tm = typemap_lookup((char*)"newfree",(char*)"tcl8",d,iname,(char*)"_result",(char*)""))) { if ((tm = typemap_lookup((char*)"newfree",(char*)"tcl8",d,iname,(char*)"_result",(char*)""))) {
Printf(f.code,"%s\n", tm); Printf(f->code,"%s\n", tm);
} }
} }
if ((tm = typemap_lookup((char*)"ret",(char*)"tcl8",d,name,(char*)"_result",(char*)""))) { if ((tm = typemap_lookup((char*)"ret",(char*)"tcl8",d,name,(char*)"_result",(char*)""))) {
// Yep. Use it instead of the default // Yep. Use it instead of the default
Printf(f.code,"%s\n", tm); Printf(f->code,"%s\n", tm);
} }
Printv(f.code,tab4, "return TCL_OK;\n}", 0); Printv(f->code,tab4, "return TCL_OK;\n}", 0);
// Substitute the cleanup code // Substitute the cleanup code
Replace(f.code,"$cleanup",cleanup,DOH_REPLACE_ANY); Replace(f->code,"$cleanup",cleanup,DOH_REPLACE_ANY);
Replace(f.code,"$name", iname, DOH_REPLACE_ANY); Replace(f->code,"$name", iname, DOH_REPLACE_ANY);
// Dump out the function // Dump out the function
f.print(f_wrappers); Wrapper_print(f,f_wrappers);
// Now register the function with Tcl // Now register the function with Tcl
@ -767,7 +767,7 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
Delete(outarg); Delete(outarg);
Delete(argstr); Delete(argstr);
Delete(args); Delete(args);
DelWrapper(f);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -792,21 +792,22 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
// Dump a collection of set/get functions suitable for variable tracing // Dump a collection of set/get functions suitable for variable tracing
if (!Getattr(setget,t->print_type())) { if (!Getattr(setget,t->print_type())) {
Setattr(setget,t->print_type(),"1"); Setattr(setget,t->print_type(),"1");
WrapperFunction get; Wrapper *get, *set;
WrapperFunction set; get = NewWrapper();
Printv(set.def, "static char *_swig_", t->print_mangle(), "_set(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {",0); set = NewWrapper();
Printv(set->def, "static char *_swig_", t->print_mangle(), "_set(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {",0);
Printv(get.def, "static char *_swig_", t->print_mangle(), "_get(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {",0); Printv(get->def, "static char *_swig_", t->print_mangle(), "_get(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {",0);
t->is_pointer++; t->is_pointer++;
get.add_local(t->print_type(),(char*)"addr"); Wrapper_add_local(get,t->print_type(),(char*)"addr",0);
set.add_local(t->print_type(),(char*)"addr"); Wrapper_add_local(set,t->print_type(),(char*)"addr",0);
Printv(set.code, tab4, "addr = ", t->print_cast(), " clientData;\n", 0); Printv(set->code, tab4, "addr = ", t->print_cast(), " clientData;\n", 0);
Printv(get.code, tab4, "addr = ", t->print_cast(), " clientData;\n", 0); Printv(get->code, tab4, "addr = ", t->print_cast(), " clientData;\n", 0);
t->is_pointer--; t->is_pointer--;
set.add_local((char*)"char *",(char*)"value"); Wrapper_add_local(set,(char*)"char *",(char*)"value",0);
get.add_local((char*)"Tcl_Obj *",(char*)"value"); Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0);
Printv(set.code, tab4, "value = Tcl_GetVar2(interp, name1, name2, flags);\n", Printv(set->code, tab4, "value = Tcl_GetVar2(interp, name1, name2, flags);\n",
tab4, "if (!value) return NULL;\n", 0); tab4, "if (!value) return NULL;\n", 0);
if (!t->is_pointer) { if (!t->is_pointer) {
@ -821,24 +822,24 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
case T_UCHAR: case T_UCHAR:
case T_SCHAR: case T_SCHAR:
case T_BOOL: case T_BOOL:
Printv(set.code, tab4, "*(addr) = ", t->print_cast(), "atol(value);\n", 0); Printv(set->code, tab4, "*(addr) = ", t->print_cast(), "atol(value);\n", 0);
break; break;
case T_UINT: case T_UINT:
case T_ULONG: case T_ULONG:
Printv(set.code, tab4, "*(addr) = ", t->print_cast(), "strtoul(value,0,0);\n",0); Printv(set->code, tab4, "*(addr) = ", t->print_cast(), "strtoul(value,0,0);\n",0);
break; break;
case T_FLOAT: case T_FLOAT:
case T_DOUBLE: case T_DOUBLE:
Printv(set.code, tab4, "*(addr) = ", t->print_cast(), "atof(value);\n",0); Printv(set->code, tab4, "*(addr) = ", t->print_cast(), "atof(value);\n",0);
break; break;
case T_CHAR: /* Single character. */ case T_CHAR: /* Single character. */
Printv(set.code, tab4, "*(addr) = *value;\n",0); Printv(set->code, tab4, "*(addr) = *value;\n",0);
break; break;
case T_USER: case T_USER:
// User defined type. We return it as a pointer // User defined type. We return it as a pointer
t->is_pointer++; t->is_pointer++;
t->remember(); t->remember();
Printv(set.code, tab4, "{\n", Printv(set->code, tab4, "{\n",
tab8, "void *ptr;\n", tab8, "void *ptr;\n",
tab8, "if (SWIG_ConvertPtrFromString(interp,value,&ptr,SWIGTYPE", t->print_mangle(), ") != TCL_OK) {\n", tab8, "if (SWIG_ConvertPtrFromString(interp,value,&ptr,SWIGTYPE", t->print_mangle(), ") != TCL_OK) {\n",
tab8, tab4, "return \"Type Error\";\n", tab8, tab4, "return \"Type Error\";\n",
@ -855,14 +856,14 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
} }
} else { } else {
if ((t->is_pointer == 1) && (t->type == T_CHAR)) { if ((t->is_pointer == 1) && (t->type == T_CHAR)) {
Printv(set.code, tab4, "if (*addr) free(*addr);\n", Printv(set->code, tab4, "if (*addr) free(*addr);\n",
tab4, "*addr = (char *) malloc(strlen(value)+1);\n", tab4, "*addr = (char *) malloc(strlen(value)+1);\n",
tab4, "strcpy(*addr,value);\n", tab4, "strcpy(*addr,value);\n",
0); 0);
} else { } else {
// User defined type. We return it as a pointer // User defined type. We return it as a pointer
t->remember(); t->remember();
Printv(set.code, tab4, "{\n", Printv(set->code, tab4, "{\n",
tab8, "void *ptr;\n", tab8, "void *ptr;\n",
tab8, "if (SWIG_ConvertPtrFromString(interp,value,&ptr,SWIGTYPE", t->print_mangle(), ") != TCL_OK) {\n", tab8, "if (SWIG_ConvertPtrFromString(interp,value,&ptr,SWIGTYPE", t->print_mangle(), ") != TCL_OK) {\n",
tab8, tab4, "return \"Type Error\";\n", tab8, tab4, "return \"Type Error\";\n",
@ -874,7 +875,7 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
/* A Pointer */ /* A Pointer */
} }
} }
Printv(set.code, tab4, "return NULL;\n", "}\n",0); Printv(set->code, tab4, "return NULL;\n", "}\n",0);
if (!t->is_pointer) { if (!t->is_pointer) {
switch(t->type) { switch(t->type) {
@ -890,8 +891,8 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
case T_UCHAR: case T_UCHAR:
case T_SCHAR: case T_SCHAR:
case T_BOOL: case T_BOOL:
get.add_local((char*)"Tcl_Obj *",(char*)"value"); Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0);
Printv(get.code, Printv(get->code,
tab4, "value = Tcl_NewIntObj((int) *addr);\n", tab4, "value = Tcl_NewIntObj((int) *addr);\n",
tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
tab4, "Tcl_DecrRefCount(value);\n", tab4, "Tcl_DecrRefCount(value);\n",
@ -899,8 +900,8 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
break; break;
case T_FLOAT: case T_FLOAT:
case T_DOUBLE: case T_DOUBLE:
get.add_local((char*)"Tcl_Obj *",(char*)"value"); Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0);
Printv(get.code, Printv(get->code,
tab4, "value = Tcl_NewDoubleObj((double) *addr);\n", tab4, "value = Tcl_NewDoubleObj((double) *addr);\n",
tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
tab4, "Tcl_DecrRefCount(value);\n", tab4, "Tcl_DecrRefCount(value);\n",
@ -908,17 +909,17 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
break; break;
case T_CHAR: case T_CHAR:
get.add_local((char*)"char",(char*)"temp[4]"); Wrapper_add_local(get,(char*)"char",(char*)"temp[4]",0);
Printv(get.code,tab4, "temp[0] = *addr; temp[1] = 0;\n", Printv(get->code,tab4, "temp[0] = *addr; temp[1] = 0;\n",
tab4, "Tcl_SetVar2(interp,name1,name2,temp,flags);\n", tab4, "Tcl_SetVar2(interp,name1,name2,temp,flags);\n",
0); 0);
break; break;
case T_USER: case T_USER:
get.add_local((char*)"Tcl_Obj *",(char*)"value"); Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0);
t->is_pointer++; t->is_pointer++;
t->remember(); t->remember();
Printv(get.code, tab4, "value = SWIG_NewPointerObj(addr, SWIGTYPE", t->print_mangle(), ");\n", Printv(get->code, tab4, "value = SWIG_NewPointerObj(addr, SWIGTYPE", t->print_mangle(), ");\n",
tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
tab4, "Tcl_DecrRefCount(value);\n",0); tab4, "Tcl_DecrRefCount(value);\n",0);
t->is_pointer--; t->is_pointer--;
@ -929,11 +930,11 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
} }
} else { } else {
if ((t->is_pointer == 1) && (t->type == T_CHAR)) { if ((t->is_pointer == 1) && (t->type == T_CHAR)) {
Printv(get.code, tab4, "Tcl_SetVar2(interp,name1,name2,*addr, flags);\n",0); Printv(get->code, tab4, "Tcl_SetVar2(interp,name1,name2,*addr, flags);\n",0);
} else { } else {
get.add_local((char*)"Tcl_Obj *",(char*)"value"); Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0);
t->remember(); t->remember();
Printv(get.code, Printv(get->code,
tab4, "value = SWIG_NewPointerObj(*addr, SWIGTYPE", t->print_mangle(), ");\n", tab4, "value = SWIG_NewPointerObj(*addr, SWIGTYPE", t->print_mangle(), ");\n",
tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n", tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
tab4, "Tcl_DecrRefCount(value);\n", tab4, "Tcl_DecrRefCount(value);\n",
@ -941,20 +942,23 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
} }
} }
Printv(get.code, tab4, "return NULL;\n", "}\n",0); Printv(get->code, tab4, "return NULL;\n", "}\n",0);
get.print(f_wrappers); Wrapper_print(get,f_wrappers);
set.print(f_wrappers); Wrapper_print(set,f_wrappers);
DelWrapper(get);
DelWrapper(set);
} }
Printv(var_info, tab4,"{ SWIG_prefix \"", iname, "\", (void *) &", name, ", _swig_", t->print_mangle(), "_get,", 0); Printv(var_info, tab4,"{ SWIG_prefix \"", iname, "\", (void *) &", name, ", _swig_", t->print_mangle(), "_get,", 0);
if (Status & STAT_READONLY) { if (Status & STAT_READONLY) {
static int readonly = 0; static int readonly = 0;
if (!readonly) { if (!readonly) {
WrapperFunction ro; Wrapper *ro = NewWrapper();
Printf(ro.def, "static char *_swig_readonly(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {"); Printf(ro->def, "static char *_swig_readonly(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {");
Printv(ro.code, tab4, "return \"Variable is read-only\";\n", "}\n", 0); Printv(ro->code, tab4, "return \"Variable is read-only\";\n", "}\n", 0);
ro.print(f_wrappers); Wrapper_print(ro,f_wrappers);
readonly = 1; readonly = 1;
DelWrapper(ro);
} }
Printf(var_info, "_swig_readonly},\n"); Printf(var_info, "_swig_readonly},\n");
} else { } else {

View file

@ -240,7 +240,8 @@ public:
int oldnewobject = NewObject; int oldnewobject = NewObject;
AddMethods = new_method; AddMethods = new_method;
NewObject = new_object; NewObject = new_object;
CCode = code; Clear(CCode);
Append(CCode,code);
if (is_static) { if (is_static) {
cplus_static_func(name, iname, ret_type, parms); cplus_static_func(name, iname, ret_type, parms);
} else { } else {
@ -248,7 +249,7 @@ public:
} }
AddMethods = oldaddmethods; AddMethods = oldaddmethods;
NewObject = oldnewobject; NewObject = oldnewobject;
CCode = ""; Clear(CCode);
} }
} }
void emit() { void emit() {
@ -423,10 +424,11 @@ public:
if (!is_static) { if (!is_static) {
int oldaddmethods = AddMethods; int oldaddmethods = AddMethods;
AddMethods = new_method; AddMethods = new_method;
CCode = code; Clear(CCode);
Append(CCode,code);
cplus_variable(name,iname,type); cplus_variable(name,iname,type);
AddMethods = oldaddmethods; AddMethods = oldaddmethods;
CCode = ""; Clear(CCode);
} else { } else {
cplus_static_var(name,iname,type); cplus_static_var(name,iname,type);
} }
@ -632,7 +634,7 @@ public:
if (!generate_default) return; if (!generate_default) return;
// Try to generate a constructor if not available. // Try to generate a constructor if not available.
CCode = ""; Clear(CCode);
AddMethods = 0; AddMethods = 0;
if ((!have_constructor) && (1)) { if ((!have_constructor) && (1)) {
ParmList *l; ParmList *l;

View file

@ -175,7 +175,7 @@ char *emit_local(int i) {
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// int emit_args(char *d, DataType *rt, ParmList *l, WrapperFunction &f) // int emit_args(char *d, DataType *rt, ParmList *l, Wrapper *f)
// //
// Creates a list of variable declarations for both the return value // Creates a list of variable declarations for both the return value
// and function parameters. // and function parameters.
@ -186,7 +186,7 @@ char *emit_local(int i) {
// Returns the number of parameters associated with a function. // Returns the number of parameters associated with a function.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
int emit_args(DataType *rt, ParmList *l, WrapperFunction &f) { int emit_args(DataType *rt, ParmList *l, Wrapper *f) {
Parm *p; Parm *p;
int i; int i;
@ -199,13 +199,12 @@ int emit_args(DataType *rt, ParmList *l, WrapperFunction &f) {
// Special case for return by "value" // Special case for return by "value"
rt->is_pointer++; rt->is_pointer++;
f.add_local(rt->print_type(), (char*)"_result"); Wrapper_add_local(f, rt->print_type(), (char*)"_result",0);
rt->is_pointer--; rt->is_pointer--;
} else { } else {
// Normal return value // Normal return value
Wrapper_add_local(f,rt->print_type(), (char*)"_result",0);
f.add_local(rt->print_type(), (char*)"_result");
} }
} }
@ -221,28 +220,28 @@ int emit_args(DataType *rt, ParmList *l, WrapperFunction &f) {
((p->t->type == T_USER) && (p->call_type == CALL_REFERENCE) && (p->defvalue))) { ((p->t->type == T_USER) && (p->call_type == CALL_REFERENCE) && (p->defvalue))) {
char deftmp[1024]; char deftmp[1024];
sprintf(deftmp,"(%s) &%s", p->t->print_type(), p->defvalue); sprintf(deftmp,"(%s) &%s", p->t->print_type(), p->defvalue);
f.add_local(p->t->print_type(),temp,deftmp); Wrapper_add_local(f,p->t->print_type(),temp,deftmp);
} else { } else {
char deftmp[1024]; char deftmp[1024];
if (p->defvalue) { if (p->defvalue) {
sprintf(deftmp,"(%s) %s", p->t->print_type(), p->defvalue); sprintf(deftmp,"(%s) %s", p->t->print_type(), p->defvalue);
f.add_local(p->t->print_type(), temp, deftmp); Wrapper_add_local(f,p->t->print_type(), temp, deftmp);
} else { } else {
f.add_local(p->t->print_type(), temp, 0); Wrapper_add_local(f,p->t->print_type(), temp, 0);
} }
tm = typemap_lookup((char*)"arginit", typemap_lang, p->t,p->name,(char*)"",temp,&f); tm = typemap_lookup((char*)"arginit", typemap_lang, p->t,p->name,(char*)"",temp,f);
if (tm) { if (tm) {
Printv(f.code,tm,"\n",0); Printv(f->code,tm,"\n",0);
} }
} }
// Check for ignore or default typemaps // Check for ignore or default typemaps
tm = typemap_lookup((char*)"default",typemap_lang,p->t,p->name,(char*)"",temp,&f); tm = typemap_lookup((char*)"default",typemap_lang,p->t,p->name,(char*)"",temp,f);
if (tm) if (tm)
Printv(f.code,tm,"\n",0); Printv(f->code,tm,"\n",0);
tm = typemap_lookup((char*)"ignore",typemap_lang,p->t,p->name,(char*)"",temp,&f); tm = typemap_lookup((char*)"ignore",typemap_lang,p->t,p->name,(char*)"",temp,f);
if (tm) { if (tm) {
Printv(f.code,tm,"\n",0); Printv(f->code,tm,"\n",0);
p->ignore = 1; p->ignore = 1;
} }
tm = typemap_check((char*)"build",typemap_lang,p->t,p->name); tm = typemap_check((char*)"build",typemap_lang,p->t,p->name);
@ -260,7 +259,7 @@ int emit_args(DataType *rt, ParmList *l, WrapperFunction &f) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// int emit_func_call(char *decl, DataType *t, ParmList *l, WrapperFunction &f) // int emit_func_call(char *decl, DataType *t, ParmList *l, Wrapper*f)
// //
// Emits code for a function call (new version). // Emits code for a function call (new version).
// //
@ -271,7 +270,7 @@ int emit_args(DataType *rt, ParmList *l, WrapperFunction &f) {
// handling block. // handling block.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void emit_func_call(char *decl, DataType *t, ParmList *l, WrapperFunction &f) { void emit_func_call(char *decl, DataType *t, ParmList *l, Wrapper *f) {
int i; int i;
Parm *p; Parm *p;
@ -353,14 +352,14 @@ void emit_func_call(char *decl, DataType *t, ParmList *l, WrapperFunction &f) {
Printv(exc,tm); Printv(exc,tm);
Replace(exc,"$function",fcall,DOH_REPLACE_ANY); Replace(exc,"$function",fcall,DOH_REPLACE_ANY);
Replace(exc,"$name",decl,DOH_REPLACE_ANY); Replace(exc,"$name",decl,DOH_REPLACE_ANY);
Printv(f.code,exc,0); Printv(f->code,exc,0);
} else if ((tm = fragment_lookup((char*)"except",typemap_lang, t->id))) { } else if ((tm = fragment_lookup((char*)"except",typemap_lang, t->id))) {
Printv(exc,tm); Printv(exc,tm);
Replace(exc,"$function",fcall,DOH_REPLACE_ANY); Replace(exc,"$function",fcall,DOH_REPLACE_ANY);
Replace(exc,"$name",decl,DOH_REPLACE_ANY); Replace(exc,"$name",decl,DOH_REPLACE_ANY);
Printv(f.code,exc,0); Printv(f->code,exc,0);
} else { } else {
Printv(f.code,fcall,0); Printv(f->code,fcall,0);
} }
Delete(fcall); Delete(fcall);
Delete(exc); Delete(exc);

View file

@ -825,6 +825,7 @@ statement : INCLUDE STRING LBRACE {
DOH *s = NewString($2); DOH *s = NewString($2);
Setline(s,start_line); Setline(s,start_line);
Setfile(s,input_file); Setfile(s,input_file);
Seek(s,0,SEEK_SET);
cpps = Preprocessor_parse(s); cpps = Preprocessor_parse(s);
start_inline(Char(cpps), start_line); start_inline(Char(cpps), start_line);
Delete(s); Delete(s);
@ -2691,13 +2692,13 @@ cpp_tail : SEMI { }
; ;
cpp_end : cpp_const SEMI { cpp_end : cpp_const SEMI {
CCode = ""; Clear(CCode);
} }
| cpp_const LBRACE { skip_brace(); } | cpp_const LBRACE { skip_brace(); }
; ;
cpp_vend : cpp_const SEMI { CCode = ""; } cpp_vend : cpp_const SEMI { Clear(CCode); }
| cpp_const EQUAL definetype SEMI { CCode = ""; } | cpp_const EQUAL definetype SEMI { Clear(CCode); }
| cpp_const LBRACE { skip_brace(); } | cpp_const LBRACE { skip_brace(); }
; ;
@ -2831,7 +2832,7 @@ cpp_const : CONST {}
/* Constructor initializer */ /* Constructor initializer */
ctor_end : cpp_const ctor_initializer SEMI { ctor_end : cpp_const ctor_initializer SEMI {
CCode = ""; Clear(CCode);
} }
| cpp_const ctor_initializer LBRACE { skip_brace(); } | cpp_const ctor_initializer LBRACE { skip_brace(); }
; ;
@ -3112,7 +3113,7 @@ objc_method : MINUS objc_ret_type ID objc_args objc_end {
} }
; ;
objc_end : SEMI { CCode = ""; } objc_end : SEMI { Clear(CCode); }
| LBRACE { skip_brace(); } | LBRACE { skip_brace(); }
; ;

View file

@ -413,27 +413,27 @@ extern "C" {
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// Class for Creating Wrapper Functions // Structure for Creating Wrapper Functions
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
class WrapperFunction { typedef struct Wrapper {
private:
void *h; void *h;
void *localh; void *localh;
public: void *def;
WrapperFunction();
~WrapperFunction();
void *def; /* Migration code */
void *locals; void *locals;
void *code; void *code;
void print(void *f); } Wrapper;
void add_local(char *type, char *name, char *defvalue = 0);
char *new_local(char *type, char *name, char *defvalue = 0);
static void del_type(void *obj);
};
extern int emit_args(DataType *, ParmList *, WrapperFunction &f); extern Wrapper *NewWrapper();
extern void emit_func_call(char *, DataType *, ParmList *, WrapperFunction &f); extern void DelWrapper(Wrapper *w);
extern void Wrapper_print(Wrapper *w, void *f);
extern void Wrapper_add_local(Wrapper *w, char *type, char *name, char *defvalue = 0);
extern char *Wrapper_new_local(Wrapper *w, char *type, char *name, char *defvalue = 0);
// Misc
extern int emit_args(DataType *, ParmList *, Wrapper *f);
extern void emit_func_call(char *, DataType *, ParmList *, Wrapper *f);
extern void SWIG_exit(int); extern void SWIG_exit(int);
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -444,7 +444,7 @@ extern void typemap_register(char *op, char *lang, DataType *type, char *pnam
extern void typemap_register(char *op, char *lang, char *type, char *pname, char *code,ParmList *l = 0); extern void typemap_register(char *op, char *lang, char *type, char *pname, char *code,ParmList *l = 0);
extern void typemap_register_default(char *op, char *lang, int type, int ptr, char *arraystr, char *code, ParmList *l = 0); extern void typemap_register_default(char *op, char *lang, int type, int ptr, char *arraystr, char *code, ParmList *l = 0);
extern char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *source, char *target, extern char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *source, char *target,
WrapperFunction *f = 0); Wrapper *f = 0);
extern void typemap_clear(char *op, char *lang, DataType *type, char *pname); extern void typemap_clear(char *op, char *lang, DataType *type, char *pname);
extern void typemap_copy(char *op, char *lang, DataType *stype, char *sname, DataType *ttype, char *tname); extern void typemap_copy(char *op, char *lang, DataType *stype, char *sname, DataType *ttype, char *tname);
extern char *typemap_check(char *op, char *lang, DataType *type, char *pname); extern char *typemap_check(char *op, char *lang, DataType *type, char *pname);
@ -461,9 +461,3 @@ extern char *fragment_lookup(char *op, char *lang, int age);
extern void fragment_clear(char *op, char *lang); extern void fragment_clear(char *op, char *lang);
extern void emit_ptr_equivalence(WrapperFunction &);

View file

@ -470,7 +470,7 @@ TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname,
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// static typemap_locals(Datatype *t, char *pname, String &s, ParmList *l, WrapperFunction &f) // static typemap_locals(Datatype *t, char *pname, String &s, ParmList *l, Wrapper *f)
// //
// Takes a string, a parameter list and a wrapper function argument and // Takes a string, a parameter list and a wrapper function argument and
// starts creating local variables. // starts creating local variables.
@ -478,7 +478,7 @@ TypeMap *typemap_search_array(char *op, char *lang, DataType *type, char *pname,
// Substitutes locals in the string with actual values used. // Substitutes locals in the string with actual values used.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
static void typemap_locals(DataType *t, char *pname, DOHString *s, ParmList *l, WrapperFunction &f) { static void typemap_locals(DataType *t, char *pname, DOHString *s, ParmList *l, Wrapper *f) {
Parm *p; Parm *p;
char *new_name; char *new_name;
@ -516,12 +516,12 @@ static void typemap_locals(DataType *t, char *pname, DOHString *s, ParmList *l,
char temp_ip1 = tt->implicit_ptr; char temp_ip1 = tt->implicit_ptr;
tt->is_pointer = 0; tt->is_pointer = 0;
tt->implicit_ptr = 0; tt->implicit_ptr = 0;
new_name = f.new_local(tt->print_type(),Char(str)); new_name = Wrapper_new_local(f,tt->print_type(),Char(str));
tt->is_pointer = temp_ip; tt->is_pointer = temp_ip;
tt->implicit_ptr = temp_ip1; tt->implicit_ptr = temp_ip1;
} }
else else
new_name = f.new_local(tt->print_full(),Char(str)); new_name = Wrapper_new_local(f,tt->print_full(),Char(str));
if (tt->arraystr) tt->is_pointer++; if (tt->arraystr) tt->is_pointer++;
// Substitute // Substitute
@ -537,7 +537,7 @@ static void typemap_locals(DataType *t, char *pname, DOHString *s, ParmList *l,
char temp[10]; char temp[10];
for (int i = 0; i < t->array_dimensions(); i++) { for (int i = 0; i < t->array_dimensions(); i++) {
sprintf(temp,"$dim%d",i); sprintf(temp,"$dim%d",i);
Replace(f.locals,temp,t->get_dimension(i), DOH_REPLACE_ANY); Replace(f->locals,temp,t->get_dimension(i), DOH_REPLACE_ANY);
} }
} }
@ -581,7 +581,7 @@ static DataType *realtype; // This is a gross hack
static char *realname = 0; // Real parameter name static char *realname = 0; // Real parameter name
char *typemap_lookup_internal(char *op, char *lang, DataType *type, char *pname, char *source, char *typemap_lookup_internal(char *op, char *lang, DataType *type, char *pname, char *source,
char *target, WrapperFunction *f) { char *target, Wrapper *f) {
static DOHString *str = 0; static DOHString *str = 0;
char *key = 0; char *key = 0;
TypeMap *tm = 0; TypeMap *tm = 0;
@ -641,7 +641,7 @@ char *typemap_lookup_internal(char *op, char *lang, DataType *type, char *pname,
// If there were locals and a wrapper function, replace // If there were locals and a wrapper function, replace
if ((tm->args) && f) { if ((tm->args) && f) {
typemap_locals(realtype, pname, str,tm->args,*f); typemap_locals(realtype, pname, str,tm->args,f);
} }
// If there were locals and no wrapper function, print a warning // If there were locals and no wrapper function, print a warning
@ -661,7 +661,7 @@ char *typemap_lookup_internal(char *op, char *lang, DataType *type, char *pname,
// ---------------------------------------------------------- // ----------------------------------------------------------
char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *source, char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *source,
char *target, WrapperFunction *f) { char *target, Wrapper *f) {
TmMethod *m; TmMethod *m;
char temp[512]; char temp[512];
char *result; char *result;

View file

@ -33,17 +33,23 @@ extern "C" {
#include "doh.h" #include "doh.h"
} }
WrapperFunction::WrapperFunction() { Wrapper *NewWrapper() {
h = NewHash(); Wrapper *w = (Wrapper *) malloc(sizeof(Wrapper));
localh = NewHash(); w->h = NewHash();
def = NewString(""); w->localh = NewHash();
locals = NewString(""); w->def = NewString("");
code = NewString(""); w->locals = NewString("");
w->code = NewString("");
return w;
} }
WrapperFunction::~WrapperFunction() { void DelWrapper(Wrapper *w) {
Delete(h); Delete(w->h);
Delete(localh); Delete(w->localh);
Delete(w->def);
Delete(w->locals);
Delete(w->code);
free(w);
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -68,20 +74,20 @@ static char *isolate_type_name(char *tname) {
// Print out a wrapper function. // Print out a wrapper function.
// ------------------------------------------------------------------- // -------------------------------------------------------------------
void WrapperFunction::print(DOHFile *f) { void Wrapper_print(Wrapper *w, DOHFile *f) {
DOHString *s; DOHString *s;
DOH *key; DOH *key;
key = Firstkey(localh); key = Firstkey(w->localh);
while (key) { while (key) {
s = Getattr(localh,key); s = Getattr(w->localh,key);
Delitem(s,DOH_END); Delitem(s,DOH_END);
Printv(locals,tab4,s,";\n",0); Printv(w->locals,tab4,s,";\n",0);
key = Nextkey(localh); key = Nextkey(w->localh);
} }
Printf(f,"%s\n",def); Printf(f,"%s\n",w->def);
Printf(f,"%s",locals); Printf(f,"%s",w->locals);
Printf(f,"%s\n",code); Printf(f,"%s\n",w->code);
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -90,12 +96,11 @@ void WrapperFunction::print(DOHFile *f) {
// Maintains a hash table to prevent double adding. // Maintains a hash table to prevent double adding.
// ------------------------------------------------------------------- // -------------------------------------------------------------------
void WrapperFunction::add_local(char *type, char *name, char *defarg) { void Wrapper_add_local(Wrapper *w, char *type, char *name, char *defarg) {
char *stored_type; char *stored_type;
char *new_type; char new_type[256];
char temp[256],*c,*t; char temp[256],*c,*t;
new_type = new char[strlen(type)+1];
strcpy(new_type,type); strcpy(new_type,type);
// Figure out what the name of this variable is // Figure out what the name of this variable is
@ -107,24 +112,24 @@ void WrapperFunction::add_local(char *type, char *name, char *defarg) {
c++; c++;
} }
*t = 0; *t = 0;
if (Getattr(h,temp)) { if (Getattr(w->h,temp)) {
// Check to see if a type mismatch has occurred // Check to see if a type mismatch has occurred
stored_type = GetChar(h,temp); stored_type = GetChar(w->h,temp);
if (strcmp(type,stored_type) != 0) if (strcmp(type,stored_type) != 0)
fprintf(stderr,"Error. Type %s conflicts with previously declared type of %s\n", fprintf(stderr,"Error. Type %s conflicts with previously declared type of %s\n",
type, stored_type); type, stored_type);
return; return;
} else { } else {
SetChar(h,temp,new_type); SetChar(w->h,temp,new_type);
} }
// See if any wrappers have been generated with this type // See if any wrappers have been generated with this type
char *tname = isolate_type_name(type); char *tname = isolate_type_name(type);
DOHString *lstr = Getattr(localh,tname); DOHString *lstr = Getattr(w->localh,tname);
if (!lstr) { if (!lstr) {
lstr = NewStringf("%s ", tname); lstr = NewStringf("%s ", tname);
Setattr(localh,tname,lstr); Setattr(w->localh,tname,lstr);
} }
// Successful, write some wrapper code // Successful, write some wrapper code
@ -138,28 +143,29 @@ void WrapperFunction::add_local(char *type, char *name, char *defarg) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// char *WrapperFunction::new_local(char *type, char *name, char *defarg) { // Wrapper_new_local()
// //
// A safe way to add a new local variable. type and name are used as // A safe way to add a new local variable. type and name are used as
// a starting point, but a new local variable will be created if these // a starting point, but a new local variable will be created if these
// are already in use. // are already in use.
// ------------------------------------------------------------------- // -------------------------------------------------------------------
char *WrapperFunction::new_local(char *type, char *name, char *defarg) { char *Wrapper_new_local(Wrapper *w, char *type, char *name, char *defarg) {
char *new_type; char new_type[256];
static DOHString *new_name = 0; static DOHString *new_name = 0;
char *c; char *c;
new_type = new char[strlen(type)+1]; strcpy(new_type,type);
if (!new_name) new_name = NewString(""); if (!new_name) new_name = NewString("");
strcpy(new_type,type);
strcpy(new_type,type);
Clear(new_name); Clear(new_name);
c = name; c = name;
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++) for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
Putc(*c,new_name); Putc(*c,new_name);
// Try to add a new local variable // Try to add a new local variable
if (Getattr(h,new_name)) { if (Getattr(w->h,new_name)) {
// Local variable already exists, try to generate a new name // Local variable already exists, try to generate a new name
int i = 0; int i = 0;
Clear(new_name); Clear(new_name);
@ -170,7 +176,7 @@ char *WrapperFunction::new_local(char *type, char *name, char *defarg) {
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++) for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
Putc(*c,new_name); Putc(*c,new_name);
Printf(new_name,"%d",i); Printf(new_name,"%d",i);
while (Getattr(h,new_name)) { while (Getattr(w->h,new_name)) {
i++; i++;
c = name; c = name;
Clear(new_name); Clear(new_name);
@ -178,16 +184,16 @@ char *WrapperFunction::new_local(char *type, char *name, char *defarg) {
Putc(*c,new_name); Putc(*c,new_name);
Printf(new_name,"%d",i); Printf(new_name,"%d",i);
} }
Setattr(h,new_name,new_type); Setattr(w->h,new_name,new_type);
} else { } else {
Setattr(h,new_name,new_type); Setattr(w->h,new_name,new_type);
} }
Printf(new_name,"%s",c); Printf(new_name,"%s",c);
// Successful, write some wrapper code // Successful, write some wrapper code
if (!defarg) if (!defarg)
Printv(locals,tab4,type, " ", new_name, ";\n"); Printv(w->locals,tab4,type, " ", new_name, ";\n");
else else
Printv(locals,tab4,type, " ", new_name, " = ", defarg, ";\n"); Printv(w->locals,tab4,type, " ", new_name, " = ", defarg, ";\n");
// Need to strip off the array symbols now // Need to strip off the array symbols now
@ -197,13 +203,3 @@ char *WrapperFunction::new_local(char *type, char *name, char *defarg) {
*c = 0; *c = 0;
return Char(new_name); return Char(new_name);
} }
// ------------------------------------------------------------------
// static WrapperFunction::del_type(void *obj)
//
// Callback function used when cleaning up the hash table.
// ------------------------------------------------------------------
void WrapperFunction::del_type(void *obj) {
delete (char *) obj;
}