add overload_extend and overload_extendc testcases

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11548 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Baozeng Ding 2009-08-13 15:55:19 +00:00
commit 39f1193f87
4 changed files with 204 additions and 8 deletions

View file

@ -0,0 +1,9 @@
exec loader.sce
x = new_Foo();
if Foo_test(x) <> 0 then pause, end
if Foo_test(x, 1) <> 1 then pause, end
if Foo_test(x, 2, 3) <> 5 then pause, end
if Foo_test(x, "Hello, swig!") <> 2 then pause, end
exit

View file

@ -0,0 +1,11 @@
exec loader.sce
x = new_Foo();
if Foo_test(x, 1) <> 1 then pause, end
if Foo_test(x, "Hello swig!") <> 2 then pause, end
if Foo_test(x, 2, 3) <> 3 then pause, end
if Foo_test(x, x) <> 30 then pause, end
if Foo_test(x, x, 4) <> 24 then pause, end
if Foo_test(x, x, 4, 5) <> 9 then pause, end
exit

View file

@ -84,8 +84,11 @@
if (getVarType(piAddrVar) != sci_strings || iRows != 1 || iCols != 1 || isVarComplex(piAddrVar)) {
Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, $argnum);
}
getMatrixOfString(piAddrVar, &iRows, &iCols,&_piLength, &_pstStrings);
getMatrixOfString(piAddrVar, &iRows, &iCols, &_piLength, NULL);
_pstStrings = (char *)malloc(sizeof(char) * _piLength + 1);
getMatrixOfString(piAddrVar, &iRows, &iCols, &_piLength, &_pstStrings);
$1 = strdup(_pstStrings);
free(_pstStrings);
}
%typemap(in) signed char [ANY] (int iRows, int iCols) {
@ -407,10 +410,6 @@
LhsVar(iOutNum) = iVarOut;
}
%typemap(freearg, noblock=1) char * {
if ($1) free($1);
}
%typemap(out) enum SWIGTYPE (int iRowsOut, int iColsOut) {
int temp;
temp = (int)($result);
@ -480,7 +479,7 @@
Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, $argnum);
}
getMatrixOfString(piAddrVar, &iRows, &iCols, &_piLength, NULL);
_pstStrings = (char *)malloc(sizeof(char) * _piLength);
_pstStrings = (char *)malloc(sizeof(char) * _piLength + 1);
getMatrixOfString(piAddrVar, &iRows, &iCols, &_piLength, &_pstStrings);
$1 = strdup(_pstStrings);
free(_pstStrings);
@ -782,6 +781,7 @@
LhsVar(iOutNum) = iVarOut;
}
/* pointer to basic C types */
%typemap(varout,noblock=1) signed char *,
short *,
unsigned char *,
@ -796,6 +796,7 @@
LhsVar(iOutNum) = iVarOut;
}
/* Arrays */
%typemap(varout,noblock=1) char [ANY] {
char **pstData = NULL;
pstData = (char **)malloc(sizeof(char *));
@ -855,12 +856,14 @@
LhsVar(iOutNum) = iVarOut;
}
/* Enums */
%typemap(varout,noblock=1) enum SWIGTYPE {
int temp = $result;
createMatrixOfInteger32(iVarOut, iRowsOut, iColsOut, &temp);
LhsVar(iOutNum) = iVarOut;
}
/* Other types */
%typemap(varout,noblock=1) SWIGTYPE * {
createPointer(iVarOut, (void *)$result);
LhsVar(iOutNum) = iVarOut;
@ -870,7 +873,133 @@
createPointer(iVarOut, (void *)&$result);
LhsVar(iOutNum) = iVarOut;
}
/* ------------------------------------------------------------
* --- Typecheck typemaps ---
* ------------------------------------------------------------ */
/* Basic C types */
%typecheck(SWIG_TYPECHECK_CHAR) char {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_strings) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_INT8) signed char {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_UINT8) unsigned char {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_INT16) short {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_UINT16) unsigned short {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_INT32) int,
long {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_UINT32) unsigned int,
unsigned long {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_DOUBLE) double {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_FLOAT) float {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_STRING) char * {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_strings) ? 1 : 0;
}
/* Arrays */
%typecheck(SWIG_TYPECHECK_CHAR_ARRAY) char [ANY] {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_strings) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_INT8_ARRAY) signed char [ANY] {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_INT16_ARRAY) unsigned char [ANY],
short [ANY] {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_INT32_ARRAY) unsigned short [ANY],
int [ANY],
long [ANY] {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_INT64_ARRAY) unsigned int [ANY],
unsigned long [ANY] {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY) double [ANY]{
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_FLOAT_ARRAY) float [ANY]{
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_matrix) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_STRING_ARRAY) char ** {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_strings) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE * {
int *piAddrVar;
getVarAddressFromPosition($argnum, &piAddrVar);
$1 = (getVarType(piAddrVar) == sci_lufact_pointer) ? 1 : 0;
}
/* ------------------------------------------------------------
* size_t mapped as int
* ------------------------------------------------------------ */

View file

@ -30,6 +30,7 @@ private:
public:
SCILAB():
f_builder_code(NewString("")) {
allow_overloading();
}
@ -154,7 +155,7 @@ public:
// int destructor = (!Cmp(nodeType, "destructor"));
String *storage = Getattr(n, "storage");
bool overloaded = !!Getattr(n, "sym:overloaded");
//bool last_overload = overloaded && !Getattr(n, "sym:nextSibling");
bool last_overload = overloaded && !Getattr(n, "sym:nextSibling");
String *iname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(iname);
String *overname = Copy(wname);
@ -263,6 +264,16 @@ public:
}
Printv(f->code, outarg, NIL);
/* Insert constraint checking code */
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:check"))) {
Printv(f->code, tm, "\n", NIL);
p = Getattr(p, "tmap:check:next");
} else {
p = nextSibling(p);
}
}
/* Insert cleanup code */
String *cleanup = NewString("");
for (p = l; p;) {
@ -304,6 +315,10 @@ public:
/* Dump the wrapper function */
Wrapper_print(f, f_wrappers);
DelWrapper(f);
if (last_overload)
dispatchFunction(n);
Printf(f_builder_code, "\"%s\",\"%s\";", iname, wname);
Delete(overname);
@ -312,7 +327,39 @@ public:
return SWIG_OK;
}
/* -----------------------------------------------------------------------
* dispatchFunctionWrapper()
* ----------------------------------------------------------------------- */
void dispatchFunction(Node *n) {
Wrapper *f = NewWrapper();
String *iname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(iname);
int maxargs;
String *dispatch = Swig_overload_dispatch(n, "return %s(fname, fname_len);", &maxargs);
String *tmp = NewString("");
Printv(f->def, "int ", wname, " (char *fname,unsigned long fname_len) {\n", NIL);
Wrapper_add_local(f, "argc", "int argc = Rhs;");
//Printf(tmp, "octave_value_ref argv[%d]={", maxargs);
//for (int j = 0; j < maxargs; ++j)
//Printf(tmp, "%soctave_value_ref(args,%d)", j ? "," : " ", j);
//Printf(tmp, "}");
//Wrapper_add_local(f, "argv", tmp);
Printv(f->code, dispatch, "\n", NIL);
Printf(f->code, "error(\"No matching function for overload\");\n", iname);
Printf(f->code, "return 0;\n");
Printv(f->code, "}\n", NIL);
Wrapper_print(f, f_wrappers);
Delete(tmp);
DelWrapper(f);
Delete(dispatch);
Delete(wname);
}
/* -----------------------------------------------------------------------
* variableWrapper()
* ----------------------------------------------------------------------- */