Make abstract_access test work and clean functionWrapper in scilab.cxx
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@12401 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c48e483fca
commit
f961981748
3 changed files with 183 additions and 144 deletions
|
|
@ -13,4 +13,4 @@ catch
|
||||||
swigtesterror();
|
swigtesterror();
|
||||||
end
|
end
|
||||||
|
|
||||||
exec("swigtest.start", -1);
|
exec("swigtest.quit", -1);
|
||||||
|
|
|
||||||
|
|
@ -580,7 +580,7 @@
|
||||||
iVarOut++;
|
iVarOut++;
|
||||||
%enddef
|
%enddef
|
||||||
%define SCILAB_OUT_SCALAR_WITHCAST(CASTTYPE, SCIAPIFUNCTION)
|
%define SCILAB_OUT_SCALAR_WITHCAST(CASTTYPE, SCIAPIFUNCTION)
|
||||||
CASTTYPE temp = (CASTTYPE) $result;
|
CASTTYPE temp = (CASTTYPE) $1;
|
||||||
iRowsOut = 1;
|
iRowsOut = 1;
|
||||||
iColsOut = 1;
|
iColsOut = 1;
|
||||||
|
|
||||||
|
|
@ -590,10 +590,6 @@
|
||||||
printError(&sciErr, 0);
|
printError(&sciErr, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LhsVar(iOutNum) = iVarOut;
|
|
||||||
iOutNum++;
|
|
||||||
iVarOut++;
|
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
/* Basic C types */
|
/* Basic C types */
|
||||||
|
|
|
||||||
|
|
@ -176,8 +176,8 @@ public:
|
||||||
|
|
||||||
/* A new wrapper function object */
|
/* A new wrapper function object */
|
||||||
Wrapper *f = NewWrapper();
|
Wrapper *f = NewWrapper();
|
||||||
Parm *p;
|
Parm *parm;
|
||||||
String *tm;
|
String *typemap;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
/* Determine whether the function is overloaded or not */
|
/* Determine whether the function is overloaded or not */
|
||||||
|
|
@ -189,82 +189,96 @@ public:
|
||||||
String *iname = Getattr(n, "sym:name");
|
String *iname = Getattr(n, "sym:name");
|
||||||
String *wname = Swig_name_wrapper(iname);
|
String *wname = Swig_name_wrapper(iname);
|
||||||
String *overname = Copy(wname);
|
String *overname = Copy(wname);
|
||||||
SwigType *d = Getattr(n, "type");
|
SwigType *nodeType = Getattr(n, "type");
|
||||||
ParmList *l = Getattr(n, "parms");
|
ParmList *parmList = Getattr(n, "parms");
|
||||||
|
|
||||||
if (!overloaded && !addSymbol(iname, n))
|
if (!overloaded && !addSymbol(iname, n))
|
||||||
return SWIG_ERROR;
|
{
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (overloaded)
|
if (overloaded)
|
||||||
Append(overname, Getattr(n, "sym:overname"));
|
{
|
||||||
|
Append(overname, Getattr(n, "sym:overname"));
|
||||||
|
}
|
||||||
|
|
||||||
Printv(f->def, "int ", overname, " (char *fname, unsigned long fname_len) {\n", NIL);
|
Printv(f->def, "int ", overname, " (char *fname, unsigned long fname_len) {\n", NIL);
|
||||||
|
|
||||||
/* Emit all of the local variables for holding arguments */
|
/* Emit all of the local variables for holding arguments */
|
||||||
emit_parameter_variables(l, f);
|
emit_parameter_variables(parmList, f);
|
||||||
|
|
||||||
/* Attach typemaps to the parameter list */
|
/* Attach typemaps to the parameter list */
|
||||||
emit_attach_parmmaps(l, f);
|
emit_attach_parmmaps(parmList, f);
|
||||||
Setattr(n, "wrap:parms", l);
|
Setattr(n, "wrap:parms", parmList);
|
||||||
|
|
||||||
/* Get number of required and total arguments */
|
/* Get number of required and total arguments */
|
||||||
int num_arguments = emit_num_arguments(l);
|
int num_arguments = emit_num_arguments(parmList);
|
||||||
int num_required = emit_num_required(l);
|
int num_required = emit_num_required(parmList);
|
||||||
|
|
||||||
/* The number of the output */
|
/* The number of the output */
|
||||||
int out_required = 0;
|
int out_required = 0;
|
||||||
|
|
||||||
/* Walk the function parameter list and generate code to get arguments */
|
/* Walk the function parameter list and generate code to get arguments */
|
||||||
for (j = 0, p = l; j < num_arguments; ++j) {
|
for (j = 0, parm = parmList; j < num_arguments; ++j)
|
||||||
while (checkAttribute(p, "tmap:in:numinputs", "0")) {
|
{
|
||||||
p = Getattr(p, "tmap:in:next");
|
while (checkAttribute(parm, "tmap:in:numinputs", "0"))
|
||||||
}
|
{
|
||||||
|
parm = Getattr(parm, "tmap:in:next");
|
||||||
SwigType *pt = Getattr(p, "type");
|
|
||||||
if ( Equal(SwigType_base(pt), "long long") || Equal(SwigType_base(pt), "unsigned long long")) {
|
|
||||||
Printv(f->code, " #ifdef __SCILAB_INT64__\n", NIL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get typemap for this argument */
|
|
||||||
String *tm = Getattr(p, "tmap:in");
|
|
||||||
|
|
||||||
if (tm) {
|
|
||||||
if (!tm || checkAttribute(p, "tmap:in:numinputs", "0")) {
|
|
||||||
p = nextSibling(p);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char source[64];
|
SwigType *parmType = Getattr(parm, "type");
|
||||||
sprintf(source, "%d", j + 1);
|
if ( Equal(SwigType_base(parmType), "long long") || Equal(SwigType_base(parmType), "unsigned long long"))
|
||||||
Setattr(p, "emit:input", source);
|
{
|
||||||
Replaceall(tm, "$input", Getattr(p, "emit:input"));
|
Printv(f->code, " #ifdef __SCILAB_INT64__\n", NIL);
|
||||||
|
|
||||||
if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) {
|
|
||||||
Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
|
|
||||||
} else {
|
|
||||||
Replaceall(tm, "$disown", "0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String *getargs = NewString("");
|
/* Get typemap for this argument */
|
||||||
|
String *parmTypemap = Getattr(parm, "tmap:in");
|
||||||
|
|
||||||
/* The parameter is variable */
|
if (parmTypemap) {
|
||||||
if (j >= num_required) {
|
if (!parmTypemap || checkAttribute(parm, "tmap:in:numinputs", "0")) {
|
||||||
Printf(getargs, "if (Rhs > %d) {\n%s\n}", j, tm);
|
parm = nextSibling(parm);
|
||||||
} else {
|
continue;
|
||||||
Printv(getargs, tm, NIL);
|
}
|
||||||
|
|
||||||
|
char source[64];
|
||||||
|
sprintf(source, "%d", j + 1);
|
||||||
|
Setattr(parm, "emit:input", source);
|
||||||
|
Replaceall(parmTypemap, "$input", Getattr(parm, "emit:input"));
|
||||||
|
|
||||||
|
if (Getattr(parm, "wrap:disown") || (Getattr(parm, "tmap:in:disown")))
|
||||||
|
{
|
||||||
|
Replaceall(parmTypemap, "$disown", "SWIG_POINTER_DISOWN");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Replaceall(parmTypemap, "$disown", "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
String *getargs = NewString("");
|
||||||
|
|
||||||
|
/* The parameter is variable */
|
||||||
|
if (j >= num_required) {
|
||||||
|
Printf(getargs, "if (Rhs > %d) {\n%s\n}", j, parmTypemap);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Printv(getargs, parmTypemap, NIL);
|
||||||
|
}
|
||||||
|
Printv(f->code, getargs, "\n", NIL);
|
||||||
|
if ( Equal(SwigType_base(parmType), "long long") || Equal(SwigType_base(parmType), "unsigned long long"))
|
||||||
|
{
|
||||||
|
Printv(f->code, "#endif\n", NIL);
|
||||||
|
}
|
||||||
|
Delete(getargs);
|
||||||
|
parm = Getattr(parm, "tmap:in:next");
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
Printv(f->code, getargs, "\n", NIL);
|
else
|
||||||
if ( Equal(SwigType_base(pt), "long long") || Equal(SwigType_base(pt), "unsigned long long")) {
|
{
|
||||||
Printv(f->code, "#endif\n", NIL);
|
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(parmType, 0));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
Delete(getargs);
|
|
||||||
p = Getattr(p, "tmap:in:next");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Setattr(n, "wrap:name", overname);
|
Setattr(n, "wrap:name", overname);
|
||||||
|
|
@ -274,74 +288,95 @@ public:
|
||||||
String *actioncode = emit_action(n);
|
String *actioncode = emit_action(n);
|
||||||
|
|
||||||
/* Insert the return variable */
|
/* Insert the return variable */
|
||||||
emit_return_variable(n, d, f);
|
emit_return_variable(n, nodeType, f);
|
||||||
|
|
||||||
Wrapper_add_local(f, "_outv", "int _outv");
|
Wrapper_add_local(f, "_outv", "int _outv");
|
||||||
|
|
||||||
if ((tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode))) {
|
if ((typemap = Swig_typemap_lookup_out("out", n, "result", f, actioncode)))
|
||||||
Replaceall(tm, "$source", "result");
|
{
|
||||||
Replaceall(tm, "$target", "_outv");
|
Replaceall(typemap, "$source", "result");
|
||||||
Replaceall(tm, "$result", "_outv");
|
Replaceall(typemap, "$target", "result");
|
||||||
|
Replaceall(typemap, "$result", "_outv");
|
||||||
|
|
||||||
if (GetFlag(n, "feature:new"))
|
if (GetFlag(n, "feature:new"))
|
||||||
Replaceall(tm, "$owner", "1");
|
{
|
||||||
|
Replaceall(typemap, "$owner", "1");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Replaceall(tm, "$owner", "0");
|
{
|
||||||
|
Replaceall(typemap, "$owner", "0");
|
||||||
|
}
|
||||||
|
|
||||||
/* There are more than one output */
|
/* There are more than one output */
|
||||||
if (out_required > 0) {
|
if (out_required > 0)
|
||||||
|
{
|
||||||
Printf(f->code, "LhsVar(iOutNum) = iVarOut;\n");
|
Printf(f->code, "LhsVar(iOutNum) = iVarOut;\n");
|
||||||
Printf(f->code, "iOutNum ++;\niVarOut ++;\n");
|
Printf(f->code, "iOutNum ++;\niVarOut ++;\n");
|
||||||
}
|
}
|
||||||
Printf(f->code, "%s\n", tm);
|
Printf(f->code, "%s\n", typemap);
|
||||||
if ((strlen(Char(tm)) != 0) && (out_required <= 0)) {
|
if ((strlen(Char(typemap)) != 0) && (out_required <= 0))
|
||||||
|
{
|
||||||
Printf(f->code, "LhsVar(iOutNum) = iVarOut;\n");
|
Printf(f->code, "LhsVar(iOutNum) = iVarOut;\n");
|
||||||
Printf(f->code, "iOutNum ++;\niVarOut ++;\n");
|
Printf(f->code, "iOutNum ++;\niVarOut ++;\n");
|
||||||
out_required ++;
|
out_required ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), iname);
|
{
|
||||||
|
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(nodeType, 0), iname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert argument output code */
|
/* Insert argument output code */
|
||||||
String *outarg = NewString("");
|
String *outarg = NewString("");
|
||||||
for (p = l; p;) {
|
for (parm = parmList; parm != NULL;)
|
||||||
if ((tm = Getattr(p, "tmap:argout"))) {
|
{
|
||||||
//if (out_required > 0) {
|
if ((typemap = Getattr(parm, "tmap:argout")))
|
||||||
// Printf(f->code, "LhsVar(iOutNum) = iVarOut;\n");
|
{
|
||||||
// Printf(f->code,"iOutNum ++;\niVarOut ++;\n");
|
//if (out_required > 0) {
|
||||||
//}
|
// Printf(f->code, "LhsVar(iOutNum) = iVarOut;\n");
|
||||||
Printv(outarg, tm, "\n", NIL);
|
// Printf(f->code,"iOutNum ++;\niVarOut ++;\n");
|
||||||
p = Getattr(p, "tmap:argout:next");
|
//}
|
||||||
out_required ++;
|
Printv(outarg, typemap, "\n", NIL);
|
||||||
} else {
|
parm = Getattr(parm, "tmap:argout:next");
|
||||||
p = nextSibling(p);
|
out_required ++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parm = nextSibling(parm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Printv(f->code, outarg, NIL);
|
Printv(f->code, outarg, NIL);
|
||||||
|
|
||||||
/* Insert constraint checking code */
|
/* Insert constraint checking code */
|
||||||
for (p = l; p;) {
|
for (parm = parmList; parm != NULL;)
|
||||||
if ((tm = Getattr(p, "tmap:check"))) {
|
{
|
||||||
Printv(f->code, tm, "\n", NIL);
|
if ((typemap = Getattr(parm, "tmap:check")))
|
||||||
p = Getattr(p, "tmap:check:next");
|
{
|
||||||
} else {
|
Printv(f->code, typemap, "\n", NIL);
|
||||||
p = nextSibling(p);
|
parm = Getattr(parm, "tmap:check:next");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parm = nextSibling(parm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert cleanup code */
|
/* Insert cleanup code */
|
||||||
String *cleanup = NewString("");
|
String *cleanup = NewString("");
|
||||||
for (p = l; p;) {
|
for (parm = parmList; parm != NULL ;)
|
||||||
if ((tm = Getattr(p, "tmap:freearg"))) {
|
{
|
||||||
if (tm && (Len(tm) != 0)) {
|
if ((typemap = Getattr(parm, "tmap:freearg")))
|
||||||
Printv(cleanup, tm, "\n", NIL);
|
{
|
||||||
|
if (typemap && (Len(typemap) != 0))
|
||||||
|
{
|
||||||
|
Printv(cleanup, typemap, "\n", NIL);
|
||||||
|
}
|
||||||
|
parm = Getattr(parm, "tmap:freearg:next");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parm = nextSibling(parm);
|
||||||
}
|
}
|
||||||
p = Getattr(p, "tmap:freearg:next");
|
|
||||||
} else {
|
|
||||||
p = nextSibling(p);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Output cleanup code */
|
/* Output cleanup code */
|
||||||
|
|
@ -350,11 +385,14 @@ public:
|
||||||
|
|
||||||
/* Insert the code checking for the number of input and output */
|
/* Insert the code checking for the number of input and output */
|
||||||
int flag;
|
int flag;
|
||||||
if (out_required == 0) {
|
if (out_required == 0)
|
||||||
out_required = 1;
|
{
|
||||||
flag = 0;
|
out_required = 1;
|
||||||
} else {
|
flag = 0;
|
||||||
flag = 1;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
flag = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -366,7 +404,9 @@ public:
|
||||||
|
|
||||||
/* Insert the order of output parameters*/
|
/* Insert the order of output parameters*/
|
||||||
if (flag)
|
if (flag)
|
||||||
Printf(f->def, "\nint iOutNum = 1;\nint iVarOut = Rhs + 1;");
|
{
|
||||||
|
Printf(f->def, "\nint iOutNum = 1;\nint iVarOut = Rhs + 1;");
|
||||||
|
}
|
||||||
|
|
||||||
/* Insert the argument counter */
|
/* Insert the argument counter */
|
||||||
//Printf(f->def, "\nint scilabArgNumber=0;");
|
//Printf(f->def, "\nint scilabArgNumber=0;");
|
||||||
|
|
@ -382,19 +422,22 @@ public:
|
||||||
Wrapper_print(f, f_wrappers);
|
Wrapper_print(f, f_wrappers);
|
||||||
DelWrapper(f);
|
DelWrapper(f);
|
||||||
|
|
||||||
if (last_overload) {
|
if (last_overload)
|
||||||
if (++ function_count % 10 == 0) {
|
{
|
||||||
Printf(f_builder_code, "];\n\ntable = [table;");
|
if (++ function_count % 10 == 0)
|
||||||
}
|
{
|
||||||
Printf(f_builder_code, "\"%s\",\"%s\";", iname, wname);
|
Printf(f_builder_code, "];\n\ntable = [table;");
|
||||||
dispatchFunction(n);
|
}
|
||||||
|
Printf(f_builder_code, "\"%s\",\"%s\";", iname, wname);
|
||||||
|
dispatchFunction(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!overloaded) {
|
if (!overloaded)
|
||||||
if (++ function_count % 10 == 0) {
|
{
|
||||||
Printf(f_builder_code, "];\n\ntable = [table;");
|
if (++ function_count % 10 == 0) {
|
||||||
}
|
Printf(f_builder_code, "];\n\ntable = [table;");
|
||||||
Printf(f_builder_code, "\"%s\",\"%s\";", iname, wname);
|
}
|
||||||
|
Printf(f_builder_code, "\"%s\",\"%s\";", iname, wname);
|
||||||
}
|
}
|
||||||
Delete(overname);
|
Delete(overname);
|
||||||
Delete(wname);
|
Delete(wname);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue