Move argument number checking after variables declaration

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@12699 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Vincent Couvert 2011-05-20 09:00:11 +00:00
commit 2343534f55

View file

@ -248,6 +248,9 @@ public:
int minInputArguments = emit_num_required(functionParamsList); int minInputArguments = emit_num_required(functionParamsList);
int minOutputArguments = 0; int minOutputArguments = 0;
int maxOutputArguments = 0; int maxOutputArguments = 0;
/* Insert calls to CheckRhs and CheckLhs */
Printf(wrapper->code, "CheckRhs($mininputarguments, $maxinputarguments);\n");
Printf(wrapper->code, "CheckLhs($minoutputarguments, $maxoutputarguments);\n");
for (paramIndex = 0, param = functionParamsList; paramIndex < maxInputArguments; ++paramIndex) { for (paramIndex = 0, param = functionParamsList; paramIndex < maxInputArguments; ++paramIndex) {
@ -310,7 +313,7 @@ public:
Replaceall(functionReturnTypemap, "$owner", "0"); Replaceall(functionReturnTypemap, "$owner", "0");
} }
Printf(wrapper->code, "\n%s\n", functionReturnTypemap); //TODO: is first \n needed Printf(wrapper->code, "%s\n", functionReturnTypemap);
/* If the typemap is not empty, the function return one more argument than the typemaps gives */ /* If the typemap is not empty, the function return one more argument than the typemaps gives */
if (Len(functionReturnTypemap) > 0) { if (Len(functionReturnTypemap) > 0) {
@ -350,17 +353,22 @@ public:
/* TODO */ /* TODO */
/* Final substititions if applicable */ /* Final substititions if applicable */
/* TODO */ Replaceall(wrapper->code, "$symname", functionName);
/* Insert the code checking the number of input */ /* Set CheckLhs and CheckRhs input arguments */
Printf(wrapper->def, "\nCheckRhs(%d, %d);", minInputArguments, maxInputArguments); /* In Scilab there is always one output even if not defined */
// In Scilab there is always one output even if not defined
if (minOutputArguments == 0) { if (minOutputArguments == 0) {
maxOutputArguments = 1; maxOutputArguments = 1;
} }
Printf(wrapper->def, "\nCheckLhs(%d, %d);", minOutputArguments, maxOutputArguments); char argnumber[64] = {};
sprintf(argnumber, "%d", minInputArguments);
Replaceall(wrapper->code, "$symname", functionName); Replaceall(wrapper->code, "$mininputarguments", argnumber);
sprintf(argnumber, "%d", maxInputArguments);
Replaceall(wrapper->code, "$maxinputarguments", argnumber);
sprintf(argnumber, "%d", minOutputArguments);
Replaceall(wrapper->code, "$minoutputarguments", argnumber);
sprintf(argnumber, "%d", maxOutputArguments);
Replaceall(wrapper->code, "$maxoutputarguments", argnumber);
/* Dump the function out */ /* Dump the function out */
Wrapper_print(wrapper, wrappersSection); Wrapper_print(wrapper, wrappersSection);