Commit 79307d76 authored by David Gobbi's avatar David Gobbi Committed by Marcus D. Hanwell
Browse files

ENH: Add a --special option to vtkParse, change calling convention

The old calling convention for vtkParse still works, but the new
convention is as follows:

vtkWrapPython [options] input_file output_file\n"
options:
  --concrete      concrete class (default)
  --abstract      abstract class
  --vtkobject     vtkObjectBase-derived class (default)
  --special       non-vtkObjectBase class
  --hints <file>  hints file
parent 7da8adeb
......@@ -31,62 +31,70 @@ MACRO(VTK_WRAP_PYTHON3 TARGET SRC_LIST_NAME SOURCES)
SET(VTK_WRAP_PYTHON_CUSTOM_NAME ${TARGET})
SET(VTK_WRAP_PYTHON_CUSTOM_LIST)
ENDIF(VTK_WRAP_PYTHON_NEED_CUSTOM_TARGETS)
# start writing the input file for the init file
SET(VTK_WRAPPER_INIT_DATA "${TARGET}")
# For each class
FOREACH(FILE ${SOURCES})
# should we wrap the file?
GET_SOURCE_FILE_PROPERTY(TMP_WRAP_EXCLUDE ${FILE} WRAP_EXCLUDE)
GET_SOURCE_FILE_PROPERTY(TMP_WRAP_SPECIAL ${FILE} WRAP_SPECIAL)
# if we should wrap it
IF (TMP_WRAP_SPECIAL OR NOT TMP_WRAP_EXCLUDE)
# what is the filename without the extension
GET_FILENAME_COMPONENT(TMP_FILENAME ${FILE} NAME_WE)
# the input file might be full path so handle that
GET_FILENAME_COMPONENT(TMP_FILEPATH ${FILE} PATH)
# compute the input filename
IF (TMP_FILEPATH)
SET(TMP_INPUT ${TMP_FILEPATH}/${TMP_FILENAME}.h)
SET(TMP_INPUT ${TMP_FILEPATH}/${TMP_FILENAME}.h)
ELSE (TMP_FILEPATH)
SET(TMP_INPUT ${CMAKE_CURRENT_SOURCE_DIR}/${TMP_FILENAME}.h)
ENDIF (TMP_FILEPATH)
# is it abstract?
GET_SOURCE_FILE_PROPERTY(TMP_ABSTRACT ${FILE} ABSTRACT)
IF (TMP_ABSTRACT)
SET(TMP_CONCRETE 0)
SET(TMP_CONCRETE "--abstract")
ELSE (TMP_ABSTRACT)
SET(TMP_CONCRETE 1)
SET(TMP_CONCRETE "--concrete")
ENDIF (TMP_ABSTRACT)
# is it special?
IF (TMP_WRAP_SPECIAL)
SET(TMP_SPECIAL "--special")
ELSE (TMP_WRAP_SPECIAL)
SET(TMP_SPECIAL "--vtkobject")
ENDIF (TMP_WRAP_SPECIAL)
# add the info to the init file
SET(VTK_WRAPPER_INIT_DATA
"${VTK_WRAPPER_INIT_DATA}\n${TMP_FILENAME}")
# new source file is namePython.cxx, add to resulting list
SET(${SRC_LIST_NAME} ${${SRC_LIST_NAME}}
SET(${SRC_LIST_NAME} ${${SRC_LIST_NAME}}
${TMP_FILENAME}Python.cxx)
# add custom command to output
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TMP_FILENAME}Python.cxx
DEPENDS ${VTK_WRAP_PYTHON_EXE} ${VTK_WRAP_HINTS} ${TMP_INPUT}
COMMAND ${VTK_WRAP_PYTHON_EXE}
ARGS
"${quote}${TMP_INPUT}${quote}"
"${quote}${VTK_WRAP_HINTS}${quote}"
${TMP_CONCRETE}
ARGS
${TMP_CONCRETE}
${TMP_SPECIAL}
"--hints" "${quote}${VTK_WRAP_HINTS}${quote}"
"${quote}${TMP_INPUT}${quote}"
"${quote}${CMAKE_CURRENT_BINARY_DIR}/${TMP_FILENAME}Python.cxx${quote}"
COMMENT "Python Wrapping - generating ${TMP_FILENAME}Python.cxx"
${verbatim}
)
# Add this output to a custom target if needed.
IF(VTK_WRAP_PYTHON_NEED_CUSTOM_TARGETS)
SET(VTK_WRAP_PYTHON_CUSTOM_LIST ${VTK_WRAP_PYTHON_CUSTOM_LIST}
......@@ -102,30 +110,30 @@ MACRO(VTK_WRAP_PYTHON3 TARGET SRC_LIST_NAME SOURCES)
ENDIF(VTK_WRAP_PYTHON_NEED_CUSTOM_TARGETS)
ENDIF (TMP_WRAP_SPECIAL OR NOT TMP_WRAP_EXCLUDE)
ENDFOREACH(FILE)
# finish the data file for the init file
# finish the data file for the init file
CONFIGURE_FILE(
${VTK_CMAKE_DIR}/vtkWrapperInit.data.in
${VTK_CMAKE_DIR}/vtkWrapperInit.data.in
${CMAKE_CURRENT_BINARY_DIR}/${TARGET}Init.data
COPY_ONLY
IMMEDIATE
)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}Init.cxx
DEPENDS ${VTK_WRAP_PYTHON_INIT_EXE}
${CMAKE_CURRENT_BINARY_DIR}/${TARGET}Init.data
COMMAND ${VTK_WRAP_PYTHON_INIT_EXE}
ARGS
ARGS
"${quote}${CMAKE_CURRENT_BINARY_DIR}/${TARGET}Init.data${quote}"
"${quote}${CMAKE_CURRENT_BINARY_DIR}/${TARGET}Init.cxx${quote}"
COMMENT "Python Wrapping - generating ${TARGET}Init.cxx"
${verbatim}
)
# Create the Init File
SET(${SRC_LIST_NAME} ${${SRC_LIST_NAME}} ${TARGET}Init.cxx)
ENDMACRO(VTK_WRAP_PYTHON3)
IF(VTK_WRAP_PYTHON_FIND_LIBS)
......
......@@ -43,6 +43,7 @@
int HasDelete;
int IsAbstract;
int IsConcrete;
int IsVTKObject;
char *ClassName;
char *FileName;
char *OutputFileName;
......
This diff is collapsed.
......@@ -117,6 +117,7 @@ FileInfo data;
FunctionInfo throwAwayFunction;
FunctionInfo *currentFunction;
char *hintFileName;
FILE *fhint;
char temps[2048];
int in_public;
......@@ -1960,34 +1961,86 @@ void outputGetVectorMacro(
extern void vtkParseOutput(FILE *,FileInfo *);
int main(int argc,char *argv[])
int check_options(int argc, char *argv[])
{
int i;
data.IsConcrete = 1;
data.IsVTKObject = 1;
hintFileName = 0;
for (i = 1; i < argc && argv[i][0] == '-'; i++)
{
if (strcmp(argv[i], "--concrete") == 0)
{
data.IsConcrete = 1;
}
else if (strcmp(argv[i], "--abstract") == 0)
{
data.IsConcrete = 0;
}
else if (strcmp(argv[i], "--vtkobject") == 0)
{
data.IsVTKObject = 1;
}
else if (strcmp(argv[i], "--special") == 0)
{
data.IsVTKObject = 0;
}
else if (strcmp(argv[i], "--hints") == 0)
{
i++;
if (i >= argc || argv[i][0] == '-')
{
return -1;
}
hintFileName = argv[i];
}
}
return i;
}
int main(int argc, char *argv[])
{
int i, j;
int argi;
int has_options = 0;
FILE *fin;
int ret;
FILE *fout;
if (argc < 4 || argc > 5)
argi = check_options(argc, argv);
if (argi > 1 && argc - argi == 2)
{
fprintf(stderr,
"Usage: %s input_file <hint_file> is_concrete output_file\n",argv[0]);
exit(1);
has_options = 1;
}
if (!(fin = fopen(argv[1],"r")))
else if (argi < 0 || argc < 4 || argc > 5)
{
fprintf(stderr,"Error opening input file %s\n",argv[1]);
fprintf(stderr,
"Usage: %s [options] input_file output_file\n"
" --concrete concrete class (default)\n"
" --abstract abstract class\n"
" --vtkobject vtkObjectBase-derived class (default)\n"
" --special non-vtkObjectBase class\n"
" --hints <file> hints file\n",
argv[0]);
exit(1);
}
fhint = 0;
data.FileName = argv[1];
data.FileName = argv[argi++];
data.NameComment = NULL;
data.Description = NULL;
data.Caveats = NULL;
data.SeeAlso = NULL;
CommentState = 0;
if (!(fin = fopen(data.FileName, "r")))
{
fprintf(stderr,"Error opening input file %s\n", data.FileName);
exit(1);
}
/* The class name should be the file name */
i = strlen(data.FileName);
j = i;
......@@ -2013,18 +2066,19 @@ int main(int argc,char *argv[])
currentFunction = &throwAwayFunction;
if (argc == 5)
if (!has_options)
{
if (!(fhint = fopen(argv[2],"r")))
if (argc == 5)
{
fprintf(stderr,"Error opening hint file %s\n",argv[2]);
exit(1);
hintFileName = argv[argi++];
}
data.IsConcrete = atoi(argv[3]);
data.IsConcrete = atoi(argv[argi++]);
}
else
if (!(fhint = fopen(hintFileName, "r")))
{
data.IsConcrete = atoi(argv[2]);
fprintf(stderr, "Error opening hint file %s\n", hintFileName);
exit(1);
}
yyin = fin;
......@@ -2033,29 +2087,22 @@ int main(int argc,char *argv[])
if (ret)
{
fprintf(stdout,
"*** SYNTAX ERROR found in parsing the header file %s before line %d ***\n",
argv[1], yylineno);
"*** SYNTAX ERROR found in parsing the header file %s "
"before line %d ***\n",
data.FileName, yylineno);
return ret;
}
if (argc == 5)
{
fout = fopen(argv[4],"w");
data.OutputFileName = argv[4];
}
else
{
fout = fopen(argv[3],"w");
data.OutputFileName = argv[3];
}
data.OutputFileName = argv[argi++];
fout = fopen(data.OutputFileName, "w");
if (!fout)
{
fprintf(stderr,"Error opening output file %s\n",argv[3]);
fprintf(stderr, "Error opening output file %s\n", data.OutputFileName);
exit(1);
}
vtkParseOutput(fout,&data);
fclose (fout);
vtkParseOutput(fout, &data);
fclose(fout);
return 0;
}
......
......@@ -3223,11 +3223,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
data->ClassName);
/* is this isn't a vtkObjectBase-derived object, then it is special */
if (strcmp(data->ClassName,"vtkObjectBase") != 0 &&
data->NumberOfSuperClasses == 0)
{
is_vtkobject = 0;
}
is_vtkobject = data->IsVTKObject;
/* add sstream header for special objects and vtkObjectBase*/
if (strcmp(data->ClassName, "vtkObjectBase") == 0 ||
......@@ -3258,14 +3254,11 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
}
/* prototype for the docstring function */
if (data->NumberOfSuperClasses || !data->IsAbstract)
{
fprintf(fp,
"\n"
"static const char **%sDoc();\n"
"\n",
data->ClassName);
}
fprintf(fp,
"\n"
"static const char **%sDoc();\n"
"\n",
data->ClassName);
/* check for New() function */
for (i = 0; i < data->NumberOfFunctions; i++)
......
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