static char *vtkWrapPython_FormatString(FunctionInfo *currentFunction) { static char result[2048]; /* max literal string length */ size_t currPos = 0; ValueInfo *arg; unsigned int argtype; int i; int totalArgs, requiredArgs; totalArgs = vtkWrap_CountWrappedParameters(currentFunction); requiredArgs = vtkWrap_CountRequiredArguments(currentFunction); for (i = 0; i < totalArgs; i++) { arg = currentFunction->Parameters[i]; argtype = (arg->Type & VTK_PARSE_UNQUALIFIED_TYPE); if (i == requiredArgs) { /* make all following arguments optional */ result[currPos++] = '|'; } /* add the format char to the string */ result[currPos++] = vtkWrapPython_FormatChar(argtype); if (((argtype & VTK_PARSE_INDIRECT) == VTK_PARSE_POINTER || (argtype & VTK_PARSE_INDIRECT) == VTK_PARSE_ARRAY) && argtype != VTK_PARSE_OBJECT_PTR && argtype != VTK_PARSE_QOBJECT_PTR) { /* back up and replace the char */ --currPos; if (argtype == VTK_PARSE_CHAR_PTR) { /* string with "None" equivalent to "NULL" */ result[currPos++] = 'z'; } else if (argtype == VTK_PARSE_VOID_PTR) { /* buffer type, None not allowed to avoid passing NULL pointer */ result[currPos++] = 's'; result[currPos++] = '#'; } else { result[currPos++] = 'O'; } } } result[currPos++] = '\0'; return result; }
/* Write the code to convert the arguments with vtkPythonArgs */ static void vtkWrapPython_GetAllParameters( FILE *fp, ClassInfo *data, FunctionInfo *currentFunction) { ValueInfo *arg; int requiredArgs, totalArgs; int i; totalArgs = vtkWrap_CountWrappedParameters(currentFunction); requiredArgs = vtkWrap_CountRequiredArguments(currentFunction); if (requiredArgs == totalArgs) { fprintf(fp, "ap.CheckArgCount(%d)", totalArgs); } else { fprintf(fp, "ap.CheckArgCount(%d, %d)", requiredArgs, totalArgs); } for (i = 0; i < totalArgs; i++) { arg = currentFunction->Parameters[i]; fprintf(fp, " &&\n" " "); if (i >= requiredArgs) { fprintf(fp, "(ap.NoArgsLeft() || "); } vtkWrapPython_GetSingleArgument(fp, data, i, arg, 0); if (i >= requiredArgs) { fprintf(fp, ")"); } if (vtkWrap_IsFunction(arg)) { break; } } }
void vtkWrapPython_OverloadMethodDef( FILE *fp, const char *classname, ClassInfo *data, int *overloadMap, FunctionInfo **wrappedFunctions, int numberOfWrappedFunctions, int fnum, int numberOfOccurrences, int is_vtkobject, int all_legacy) { char occSuffix[8]; int occ, occCounter; FunctionInfo *theOccurrence; FunctionInfo *theFunc; int totalArgs, requiredArgs; int i; int putInTable; theFunc = wrappedFunctions[fnum]; if (all_legacy) { fprintf(fp, "#if !defined(VTK_LEGACY_REMOVE)\n"); } fprintf(fp, "static PyMethodDef Py%s_%s_Methods[] = {\n", classname, theFunc->Name); occCounter = 0; for (occ = fnum; occ < numberOfWrappedFunctions; occ++) { theOccurrence = wrappedFunctions[occ]; if (theOccurrence->Name == 0 || strcmp(theOccurrence->Name, theFunc->Name) != 0) { continue; } occCounter++; totalArgs = vtkWrap_CountWrappedParameters(theOccurrence); requiredArgs = vtkWrap_CountRequiredArguments(theOccurrence); putInTable = 0; /* all conversion constructors must go into the table */ if (vtkWrap_IsConstructor(data, theOccurrence) && requiredArgs <= 1 && totalArgs >= 1 && !theOccurrence->IsExplicit) { putInTable = 1; } /* all methods that overlap with others must go in the table */ for (i = requiredArgs; i <= totalArgs; i++) { if (overloadMap[i] == -1) { putInTable = 1; } } if (!putInTable) { continue; } if (theOccurrence->IsLegacy && !all_legacy) { fprintf(fp, "#if !defined(VTK_LEGACY_REMOVE)\n"); } /* method suffix to distinguish between signatures */ occSuffix[0] = '\0'; if (numberOfOccurrences > 1) { sprintf(occSuffix, "_s%d", occCounter); } fprintf(fp, " {NULL, Py%s_%s%s, METH_VARARGS%s,\n" " (char*)\"%s\"},\n", classname, wrappedFunctions[occ]->Name, occSuffix, theOccurrence->IsStatic ? " | METH_STATIC" : "", vtkWrapPython_ArgCheckString( (is_vtkobject && !theOccurrence->IsStatic), wrappedFunctions[occ])); if (theOccurrence->IsLegacy && !all_legacy) { fprintf(fp, "#endif\n"); } } fprintf(fp, " {NULL, NULL, 0, NULL}\n" "};\n"); if (all_legacy) { fprintf(fp, "#endif\n"); } fprintf(fp, "\n"); }
int *vtkWrapPython_ArgCountToOverloadMap( FunctionInfo **wrappedFunctions, int numberOfWrappedFunctions, int fnum, int is_vtkobject, int *nmax, int *overlap) { static int overloadMap[512]; int totalArgs, requiredArgs; int occ, occCounter; FunctionInfo *theOccurrence; FunctionInfo *theFunc; int mixed_static, any_static; int i; *nmax = 0; *overlap = 0; theFunc = wrappedFunctions[fnum]; any_static = 0; mixed_static = 0; for (i = fnum; i < numberOfWrappedFunctions; i++) { if (wrappedFunctions[i]->Name && strcmp(wrappedFunctions[i]->Name, theFunc->Name) == 0) { if (wrappedFunctions[i]->IsStatic) { any_static = 1; } else if (any_static) { mixed_static = 1; } } } for (i = 0; i < 100; i++) { overloadMap[i] = 0; } occCounter = 0; for (occ = fnum; occ < numberOfWrappedFunctions; occ++) { theOccurrence = wrappedFunctions[occ]; if (theOccurrence->Name == 0 || strcmp(theOccurrence->Name, theFunc->Name) != 0) { continue; } occCounter++; totalArgs = vtkWrap_CountWrappedParameters(theOccurrence); requiredArgs = vtkWrap_CountRequiredArguments(theOccurrence); /* vtkobject calls might have an extra "self" arg in front */ if (mixed_static && is_vtkobject && !theOccurrence->IsStatic) { totalArgs++; } if (totalArgs > *nmax) { *nmax = totalArgs; } for (i = requiredArgs; i <= totalArgs && i < 100; i++) { if (overloadMap[i] == 0) { overloadMap[i] = occCounter; } else { overloadMap[i] = -1; *overlap = 1; } } } return overloadMap; }
/* Write the code to convert the arguments with vtkPythonArgs */ static void vtkWrapPython_GetAllParameters( FILE *fp, ClassInfo *data, FunctionInfo *currentFunction) { ValueInfo *arg; int requiredArgs, totalArgs; int i; totalArgs = vtkWrap_CountWrappedParameters(currentFunction); requiredArgs = vtkWrap_CountRequiredArguments(currentFunction); if (requiredArgs == totalArgs) { fprintf(fp, "ap.CheckArgCount(%d)", totalArgs); } else { fprintf(fp, "ap.CheckArgCount(%d, %d)", requiredArgs, totalArgs); } for (i = 0; i < totalArgs; i++) { arg = currentFunction->Parameters[i]; fprintf(fp, " &&\n" " "); if (i >= requiredArgs) { fprintf(fp, "(ap.NoArgsLeft() || "); } vtkWrapPython_GetSingleArgument(fp, data, i, arg, 0); if (i >= requiredArgs) { fprintf(fp, ")"); } if (vtkWrap_IsFunction(arg)) { break; } } /* loop again, check sizes against any size hints */ for (i = 0; i < totalArgs; i++) { arg = currentFunction->Parameters[i]; if (arg->CountHint && !vtkWrap_IsRef(arg)) { fprintf(fp, " &&\n" " ap.CheckSizeHint(%d, size%d, ", i, i); /* write out the code that gives the size */ vtkWrapPython_SubstituteCode(fp, data, currentFunction, arg->CountHint); fprintf(fp, ")"); } if (vtkWrap_IsFunction(arg)) { break; } } }