Commit caa4c93b authored by David Gobbi's avatar David Gobbi
Browse files

Add missing parameter types to docstrings.

Enum parameter types were missing from the python docstrings.  Also,
the PythonName utility function fits better in vtkWrapText.h.
parent d0d6e833
......@@ -307,7 +307,7 @@ static void vtkWrapPython_ExportVTKClass(
const char *supername;
/* mangle the classname if necessary */
vtkWrapPython_PythonicName(data->Name, classname);
vtkWrapText_PythonName(data->Name, classname);
/* for vtkObjectBase objects: export New method for use by subclasses */
fprintf(fp,
......@@ -319,7 +319,7 @@ static void vtkWrapPython_ExportVTKClass(
supername = vtkWrapPython_GetSuperClass(data, hinfo);
if (supername)
{
vtkWrapPython_PythonicName(supername, classname);
vtkWrapText_PythonName(supername, classname);
fprintf(fp,
"#ifndef DECLARED_Py%s_ClassNew\n"
"extern \"C\" { PyObject *Py%s_ClassNew(); }\n"
......@@ -401,7 +401,7 @@ static void vtkWrapPython_GenerateObjectNew(
name = vtkWrapPython_GetSuperClass(data, hinfo);
if (name)
{
vtkWrapPython_PythonicName(name, superclassname);
vtkWrapText_PythonName(name, superclassname);
fprintf(fp,
" pytype->tp_base = (PyTypeObject *)Py%s_ClassNew();\n\n",
superclassname);
......
......@@ -18,6 +18,7 @@
#include "vtkWrapPythonTemplate.h"
#include "vtkWrap.h"
#include "vtkWrapText.h"
#include <stdio.h>
#include <stdlib.h>
......@@ -273,7 +274,7 @@ void vtkWrapPython_GetSingleArgument(
}
else if (vtkWrap_IsVTKObject(arg))
{
vtkWrapPython_PythonicName(arg->Class, pythonname);
vtkWrapText_PythonName(arg->Class, pythonname);
if (strcmp(arg->Class, pythonname) != 0)
{
/* use typeid() for templated names */
......@@ -289,14 +290,14 @@ void vtkWrapPython_GetSingleArgument(
else if (vtkWrap_IsSpecialObject(arg) &&
!vtkWrap_IsNonConstRef(arg))
{
vtkWrapPython_PythonicName(arg->Class, pythonname);
vtkWrapText_PythonName(arg->Class, pythonname);
fprintf(fp, "%sGetSpecialObject(%stemp%d, pobj%d, \"%s\")",
prefix, argname, i, i, pythonname);
}
else if (vtkWrap_IsSpecialObject(arg) &&
vtkWrap_IsNonConstRef(arg))
{
vtkWrapPython_PythonicName(arg->Class, pythonname);
vtkWrapText_PythonName(arg->Class, pythonname);
fprintf(fp, "%sGetSpecialObject(%stemp%d, \"%s\")",
prefix, argname, i, pythonname);
}
......@@ -467,7 +468,7 @@ void vtkWrapPython_ReturnValue(
else if (vtkWrap_IsSpecialObject(val) &&
vtkWrap_IsRef(val))
{
vtkWrapPython_PythonicName(val->Class, pythonname);
vtkWrapText_PythonName(val->Class, pythonname);
fprintf(fp,
" result = %sBuildSpecialObject(tempr, \"%s\");\n",
prefix, pythonname);
......@@ -475,7 +476,7 @@ void vtkWrapPython_ReturnValue(
else if (vtkWrap_IsSpecialObject(val) &&
!vtkWrap_IsRef(val))
{
vtkWrapPython_PythonicName(val->Class, pythonname);
vtkWrapText_PythonName(val->Class, pythonname);
fprintf(fp,
" result = %sBuildSpecialObject(&tempr, \"%s\");\n",
prefix, pythonname);
......
......@@ -81,6 +81,7 @@
#include "vtkWrapPythonTemplate.h"
#include "vtkWrap.h"
#include "vtkWrapText.h"
/* required for VTK_USE_64BIT_IDS */
#include "vtkConfigure.h"
......@@ -246,27 +247,27 @@ static char *vtkWrapPython_ArgCheckString(
else if (arg->IsEnum)
{
c = 'E';
vtkWrapPython_PythonicName(arg->Class, classname);
vtkWrapText_PythonName(arg->Class, classname);
}
else if (vtkWrap_IsPythonObject(arg))
{
c = 'O';
vtkWrapPython_PythonicName(arg->Class, classname);
vtkWrapText_PythonName(arg->Class, classname);
}
else if (vtkWrap_IsVTKObject(arg))
{
c = 'V';
vtkWrapPython_PythonicName(arg->Class, classname);
vtkWrapText_PythonName(arg->Class, classname);
}
else if (vtkWrap_IsSpecialObject(arg))
{
c = 'W';
vtkWrapPython_PythonicName(arg->Class, classname);
vtkWrapText_PythonName(arg->Class, classname);
}
else if (vtkWrap_IsQtEnum(arg) || vtkWrap_IsQtObject(arg))
{
c = 'Q';
vtkWrapPython_PythonicName(arg->Class, classname);
vtkWrapText_PythonName(arg->Class, classname);
}
else if (vtkWrap_IsFunction(arg))
{
......
......@@ -18,8 +18,8 @@
#include "vtkWrapPythonMethod.h"
#include "vtkWrapPythonType.h"
#include "vtkWrapText.h"
#include "vtkParseExtras.h"
#include "vtkParseMangle.h"
/* required for VTK_LEGACY_REMOVE */
#include "vtkConfigure.h"
......@@ -30,77 +30,6 @@
#include <ctype.h>
/* -------------------------------------------------------------------- */
/* convert C++ templated types to valid python ids by mangling */
void vtkWrapPython_PythonicName(const char *name, char *pname)
{
size_t j = 0;
size_t i;
size_t l;
char *cp;
int scoped = 0;
/* look for first char that is not alphanumeric or underscore */
l = vtkParse_IdentifierLength(name);
if (name[l] != '\0')
{
/* get the mangled name */
vtkParse_MangledTypeName(name, pname);
/* put dots after namespaces */
i = 0;
cp = pname;
while (*cp == 'N')
{
scoped++;
cp++;
while (*cp >= '0' && *cp <= '9')
{
i = i*10 + (*cp++ - '0');
}
i += j;
while (j < i)
{
pname[j++] = *cp++;
}
pname[j++] = '.';
}
/* remove mangling from first identifier and add an underscore */
i = 0;
while (*cp >= '0' && *cp <= '9')
{
i = i*10 + (*cp++ - '0');
}
i += j;
while (j < i)
{
pname[j++] = *cp++;
}
pname[j++] = '_';
while (*cp != '\0')
{
pname[j++] = *cp++;
}
pname[j] = '\0';
}
else
{
strcpy(pname, name);
}
/* remove the "_E" that is added to mangled scoped names */
if (scoped)
{
j = strlen(pname);
if (j > 2 && pname[j-2] == '_' && pname[j-1] == 'E')
{
pname[j-2] = '\0';
}
}
}
/* -------------------------------------------------------------------- */
/* convert a C++ templated type to pythonic dict form */
size_t vtkWrapPython_PyTemplateName(const char *name, char *pname)
......@@ -424,7 +353,7 @@ int vtkWrapPython_WrapTemplatedClass(
sdata = (ClassInfo *)malloc(sizeof(ClassInfo));
vtkParse_CopyClass(sdata, data);
vtkParse_InstantiateClassTemplate(sdata, file_info->Strings, nargs, args);
vtkWrapPython_PythonicName(instantiations[k], classname);
vtkWrapText_PythonName(instantiations[k], classname);
vtkWrapPython_WrapOneClass(
fp, modulename, classname, sdata, file_info, hinfo, is_vtkobject);
......@@ -468,7 +397,7 @@ int vtkWrapPython_WrapTemplatedClass(
for (k = 0; k < ninstantiations; k++)
{
vtkWrapPython_PythonicName(instantiations[k], classname);
vtkWrapText_PythonName(instantiations[k], classname);
entry = vtkParseHierarchy_FindEntry(hinfo, instantiations[k]);
if (vtkParseHierarchy_IsTypeOfTemplated(
......
......@@ -27,7 +27,4 @@ size_t vtkWrapPython_PyTemplateName(const char *name, char *pname);
int vtkWrapPython_WrapTemplatedClass(
FILE *fp, ClassInfo *data, FileInfo *file_info, HierarchyInfo *hinfo);
/* if name has template args, mangle and prefix with "T" */
void vtkWrapPython_PythonicName(const char *name, char *pname);
#endif /* VTK_WRAP_PYTHON_TEMPLATE_H */
......@@ -22,6 +22,7 @@
#include "vtkWrapPythonTemplate.h"
#include "vtkWrap.h"
#include "vtkWrapText.h"
#include "vtkParseExtras.h"
#include <stdio.h>
......@@ -647,7 +648,7 @@ void vtkWrapPython_GenerateSpecialType(
if (has_superclass)
{
name = vtkWrapPython_GetSuperClass(data, hinfo);
vtkWrapPython_PythonicName(name, supername);
vtkWrapText_PythonName(name, supername);
}
/* generate all constructor methods */
......
......@@ -15,6 +15,10 @@
#include "vtkWrapText.h"
#include "vtkWrap.h"
#include "vtkParseExtras.h"
#include "vtkParseMangle.h"
#include <string.h>
#include <ctype.h>
#include <stdio.h>
......@@ -890,7 +894,7 @@ const char *vtkWrapText_PythonSignature(
static void vtkWrapText_PythonTypeSignature(
struct vtkWPString *result, const char *braces[2], ValueInfo *arg)
{
char text[32];
char text[256];
const char *dimension;
const char *classname = "";
......@@ -898,10 +902,6 @@ static void vtkWrapText_PythonTypeSignature(
{
classname = "void";
}
else if (vtkWrap_IsObject(arg))
{
classname = arg->Class;
}
else if (vtkWrap_IsFunction(arg))
{
classname = "function";
......@@ -930,6 +930,11 @@ static void vtkWrapText_PythonTypeSignature(
{
classname = "int";
}
else
{
vtkWrapText_PythonName(arg->Class, text);
classname = text;
}
if ((vtkWrap_IsArray(arg) && arg->CountHint) ||
vtkWrap_IsPODPointer(arg))
......@@ -984,3 +989,73 @@ static void vtkWrapText_PythonArraySignature(
}
vtkWPString_Append(result, braces[1]);
}
/* convert C++ identifier to a valid python identifier by mangling */
void vtkWrapText_PythonName(const char *name, char *pname)
{
size_t j = 0;
size_t i;
size_t l;
char *cp;
int scoped = 0;
/* look for first char that is not alphanumeric or underscore */
l = vtkParse_IdentifierLength(name);
if (name[l] != '\0')
{
/* get the mangled name */
vtkParse_MangledTypeName(name, pname);
/* put dots after namespaces */
i = 0;
cp = pname;
while (*cp == 'N')
{
scoped++;
cp++;
while (*cp >= '0' && *cp <= '9')
{
i = i*10 + (*cp++ - '0');
}
i += j;
while (j < i)
{
pname[j++] = *cp++;
}
pname[j++] = '.';
}
/* remove mangling from first identifier and add an underscore */
i = 0;
while (*cp >= '0' && *cp <= '9')
{
i = i*10 + (*cp++ - '0');
}
i += j;
while (j < i)
{
pname[j++] = *cp++;
}
pname[j++] = '_';
while (*cp != '\0')
{
pname[j++] = *cp++;
}
pname[j] = '\0';
}
else
{
strcpy(pname, name);
}
/* remove the "_E" that is added to mangled scoped names */
if (scoped)
{
j = strlen(pname);
if (j > 2 && pname[j-2] == '_' && pname[j-1] == 'E')
{
pname[j-2] = '\0';
}
}
}
......@@ -54,6 +54,15 @@ const char *vtkWrapText_FormatSignature(
*/
const char *vtkWrapText_PythonSignature(FunctionInfo *currentFunction);
/**
* Convert a C++ identifier into an identifier that can be used from Python.
* The "::" namespace separators are converted to ".", and template args
* are mangled and prefix with "T" according to the ia64 ABI. The output
* parameter "pname" must be large enough to accept the result. If it is
* as long as the input name, that is sufficient. */
void vtkWrapText_PythonName(const char *name, char *pname);
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment