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