Commit a73ab651 authored by David Gobbi's avatar David Gobbi

Refactor vtkWrapPython into smaller source files.

Because several thousands lines of code is too much for one file.

Change-Id: Ib3af0f2153fddc3f593fd90913bb3408944062f6
parent 75c1a33e
......@@ -71,7 +71,16 @@ if(NOT CMAKE_CROSSCOMPILING)
vtk_compile_tools_target(vtkWrapTcl)
vtk_compile_tools_target(vtkWrapTclInit)
add_executable(vtkWrapPython vtkWrapPython.c)
add_executable(vtkWrapPython
vtkWrapPython.c
vtkWrapPythonClass.c
vtkWrapPythonConstant.c
vtkWrapPythonMethod.c
vtkWrapPythonMethodDef.c
vtkWrapPythonOverload.c
vtkWrapPythonTemplate.c
vtkWrapPythonType.c
)
target_link_libraries(vtkWrapPython vtkWrappingTools)
add_executable(vtkWrapPythonInit vtkWrapPythonInit.c)
vtk_compile_tools_target(vtkWrapPython)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkWrapPythonClass.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef VTK_WRAP_PYTHON_CLASS_H
#define VTK_WRAP_PYTHON_CLASS_H
#include "vtkParse.h"
#include "vtkParseData.h"
#include "vtkParseHierarchy.h"
/* Wrap one class, returns zero if not wrappable */
int vtkWrapPython_WrapOneClass(
FILE *fp, const char *classname, ClassInfo *data,
FileInfo *file_info, HierarchyInfo *hinfo, int is_vtkobject);
/* get the true superclass */
const char *vtkWrapPython_GetSuperClass(
ClassInfo *data, HierarchyInfo *hinfo);
/* check whether the superclass of the specified class is wrapped */
int vtkWrapPython_HasWrappedSuperClass(
HierarchyInfo *hinfo, const char *classname, int *is_external);
/* generate the class docstring and write it to "fp" */
void vtkWrapPython_ClassDoc(
FILE *fp, FileInfo *file_info, ClassInfo *data, HierarchyInfo *hinfo,
int is_vtkobject);
#endif /* VTK_WRAP_PYTHON_CLASS_H */
/*=========================================================================
Program: Visualization Toolkit
Module: vtkWrapPythonConstant.c
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkWrapPythonConstant.h"
/* for VTK_TYPE_USE_LONG_LONG vs VTK_TYPE_USE___INT64 */
#include "vtkConfigure.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/* -------------------------------------------------------------------- */
/* This method adds constants defined in the file to the module */
void vtkWrapPython_AddConstant(
FILE *fp, const char *indent, const char *dictvar, const char *objvar,
ValueInfo *val)
{
unsigned int valtype;
const char *valstring;
int objcreated = 0;
valtype = (val->Type & VTK_PARSE_UNQUALIFIED_TYPE);
valstring = val->Value;
if (valtype == 0 && (valstring == NULL || valstring[0] == '\0'))
{
valtype = VTK_PARSE_VOID;
}
else if (strcmp(valstring, "NULL") == 0)
{
valtype = VTK_PARSE_VOID;
}
if (valtype == 0 || val->Name == NULL)
{
return;
}
switch (valtype)
{
case VTK_PARSE_VOID:
fprintf(fp,
"%sPy_INCREF(Py_None);\n"
"%s%s = Py_None;\n",
indent, indent, objvar);
objcreated = 1;
break;
case VTK_PARSE_CHAR_PTR:
fprintf(fp,
"%s%s = PyString_FromString((char *)(%s));\n",
indent, objvar, valstring);
objcreated = 1;
break;
case VTK_PARSE_FLOAT:
case VTK_PARSE_DOUBLE:
fprintf(fp,
"%s%s = PyFloat_FromDouble(%s);\n",
indent, objvar, valstring);
objcreated = 1;
break;
case VTK_PARSE_LONG:
case VTK_PARSE_INT:
case VTK_PARSE_SHORT:
case VTK_PARSE_UNSIGNED_SHORT:
case VTK_PARSE_CHAR:
case VTK_PARSE_SIGNED_CHAR:
case VTK_PARSE_UNSIGNED_CHAR:
fprintf(fp,
"%s%s = PyInt_FromLong(%s);\n",
indent, objvar, valstring);
objcreated = 1;
break;
case VTK_PARSE_UNSIGNED_INT:
fprintf(fp,
"#if VTK_SIZEOF_INT < VTK_SIZEOF_LONG\n"
"%s%s = PyInt_FromLong(%s);\n"
"#else\n"
"%s%s = PyLong_FromUnsignedLong(%s);\n"
"#endif\n",
indent, objvar, valstring, indent, objvar, valstring);
objcreated = 1;
break;
case VTK_PARSE_UNSIGNED_LONG:
fprintf(fp,
"%s%s = PyLong_FromUnsignedLong(%s);\n",
indent, objvar, valstring);
objcreated = 1;
break;
#ifndef VTK_PYTHON_NO_LONG_LONG
#ifdef VTK_TYPE_USE___INT64
case VTK_PARSE___INT64:
fprintf(fp,
"%s%s = PyLong_FromLongLong(%s);\n",
indent, objvar, valstring);
objcreated = 1;
break;
case VTK_PARSE_UNSIGNED___INT64:
fprintf(fp,
"%s%s = PyLong_FromUnsignedLongLong(%s);\n",
indent, objvar, valstring);
objcreated = 1;
break;
#endif
#ifdef VTK_TYPE_USE_LONG_LONG
case VTK_PARSE_LONG_LONG:
fprintf(fp,
"%s%s = PyLong_FromLongLong(%s);\n",
indent, objvar, valstring);
objcreated = 1;
break;
case VTK_PARSE_UNSIGNED_LONG_LONG:
fprintf(fp,
"%s%s = PyLong_FromUnsignedLongLong(%s);\n",
indent, objvar, valstring);
objcreated = 1;
break;
#endif
#endif
case VTK_PARSE_BOOL:
fprintf(fp,
"#if PY_VERSION_HEX >= 0x02030000\n"
"%s%s = PyBool_FromLong((long)(%s));\n"
"#else\n"
"%s%s = PyInt_FromLong((long)(%s));\n"
"#endif\n",
indent, objvar, valstring, indent, objvar, valstring);
objcreated = 1;
break;
}
if (objcreated)
{
fprintf(fp,
"%sif (%s)\n"
"%s {\n"
"%s PyDict_SetItemString(%s, (char *)\"%s\", %s);\n"
"%s Py_DECREF(%s);\n"
"%s }\n",
indent, objvar, indent, indent, dictvar, val->Name, objvar,
indent, objvar, indent);
}
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkWrapPythonConstant.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef VTK_WRAP_PYTHON_CONSTANT_H
#define VTK_WRAP_PYTHON_CONSTANT_H
#include "vtkParse.h"
#include "vtkParseData.h"
#include "vtkParseHierarchy.h"
/* Generate code that add a constant value to a python dict */
void vtkWrapPython_AddConstant(
FILE *fp, const char *indent, const char *dictvar, const char *objvar,
ValueInfo *val);
#endif /* VTK_WRAP_PYTHON_CONSTANT_H */
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkWrapPythonMethod.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef VTK_WRAP_PYTHON_METHOD_H
#define VTK_WRAP_PYTHON_METHOD_H
#include "vtkParse.h"
#include "vtkParseData.h"
#include "vtkParseHierarchy.h"
/* print out the code for one method, including all of its overloads */
void vtkWrapPython_GenerateOneMethod(
FILE *fp, const char *classname, ClassInfo *data, HierarchyInfo *hinfo,
FunctionInfo *wrappedFunctions[], int numberOfWrappedFunctions, int fnum,
int is_vtkobject, int do_constructors);
/* declare all variables needed by the wrapper method */
void vtkWrapPython_DeclareVariables(
FILE *fp, FunctionInfo *theFunc);
/* Write the code to convert an argument with vtkPythonArgs */
void vtkWrapPython_GetSingleArgument(
FILE *fp, int i, ValueInfo *arg, int call_static);
/* print the code to build python return value from a method */
void vtkWrapPython_ReturnValue(
FILE *fp, ValueInfo *val, int static_call);
#endif /* VTK_WRAP_PYTHON_METHOD_H */
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkWrapPythonMethodDef.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef VTK_WRAP_PYTHON_METHODDEF_H
#define VTK_WRAP_PYTHON_METHODDEF_H
#include "vtkParse.h"
#include "vtkParseData.h"
#include "vtkParseHierarchy.h"
/* check whether a method is wrappable */
int vtkWrapPython_MethodCheck(
FunctionInfo *currentFunction, HierarchyInfo *hinfo);
/* print out all methods and the method table */
void vtkWrapPython_GenerateMethods(
FILE *fp, const char *classname, ClassInfo *data,
FileInfo *finfo, HierarchyInfo *hinfo,
int is_vtkobject, int do_constructors);
#endif /* VTK_WRAP_PYTHON_METHODDEF_H */
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkWrapPythonOverload.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef VTK_WRAP_PYTHON_OVERLOAD_H
#define VTK_WRAP_PYTHON_OVERLOAD_H
#include "vtkParse.h"
#include "vtkParseData.h"
#include "vtkParseHierarchy.h"
/* output the method table for all overloads of a particular method */
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);
/* a master method to choose which overload to call */
void vtkWrapPython_OverloadMasterMethod(
FILE *fp, const char *classname, int *overloadMap, int maxArgs,
FunctionInfo **wrappedFunctions, int numberOfWrappedFunctions, int fnum,
int is_vtkobject, int all_legacy);
/* generate an int array that maps arg counts to overloads */
int *vtkWrapPython_ArgCountToOverloadMap(
FunctionInfo **wrappedFunctions, int numberOfWrappedFunctions,
int fnum, int is_vtkobject, int *nmax, int *overlap);
#endif /* VTK_WRAP_PYTHON_OVERLOAD_H */
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkWrapPythonTemplate.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef VTK_WRAP_PYTHON_TEMPLATE_H
#define VTK_WRAP_PYTHON_TEMPLATE_H
#include "vtkParse.h"
#include "vtkParseData.h"
#include "vtkParseHierarchy.h"
/* if name has template args, convert to pythonic dict format */
size_t vtkWrapPython_PyTemplateName(const char *name, char *pname);
/* wrap a templated class */
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 */
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkWrapPythonType.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef VTK_WRAP_PYTHON_TYPE_H
#define VTK_WRAP_PYTHON_TYPE_H
#include "vtkParse.h"
#include "vtkParseData.h"
#include "vtkParseHierarchy.h"
/* check whether a non-vtkObjectBase class is wrappable */
int vtkWrapPython_IsSpecialTypeWrappable(ClassInfo *data);
/* write out a python type object */
void vtkWrapPython_GenerateSpecialType(
FILE *fp, const char *classname, ClassInfo *data,
FileInfo *finfo, HierarchyInfo *hinfo);
#endif /* VTK_WRAP_PYTHON_TYPE_H */
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