Commit 59b38c86 authored by Ben Boeckel's avatar Ben Boeckel

wrapping: find superclasses that are templates

Template names are not valid C identifiers, so add a way to make them
valid.

Based on a patch from Debian.

Change-Id: Icb58d18f079ea6cc77af1ff68e401a072d5108fe
parent 5a49848a
......@@ -1092,3 +1092,34 @@ void vtkWrap_DeclareVariableSize(
name, idx, val->Dimensions[0]);
}
}
char *vtkWrap_SafeSuperclassName(const char *name)
{
int template_class = 0;
int size = strlen(name);
char *safe_name = malloc(size + 1);
int i;
memcpy(safe_name, name, size + 1);
for (i = 0; i < size; ++i)
{
char c = name[i];
if (c == '<' || c == '>')
{
safe_name[i] = '_';
template_class = 1;
}
if (c == ',' || c == ' ')
{
safe_name[i] = '_';
}
}
if (!template_class)
{
free(safe_name);
return NULL;
}
return safe_name;
}
......@@ -249,6 +249,12 @@ void vtkWrap_DeclareVariable(
void vtkWrap_DeclareVariableSize(
FILE *fp, ValueInfo *v, const char *name, int idx);
/**
* Makes a superclass name into a valid identifier. Returns NULL if the given
* name is valid as-is.
*/
char *vtkWrap_SafeSuperclassName(const char *name);
#ifdef __cplusplus
}
......
......@@ -19,6 +19,7 @@
#include "vtkParse.h"
#include "vtkParseMain.h"
#include "vtkParseHierarchy.h"
#include "vtkWrap.h"
HierarchyInfo *hierarchyInfo = NULL;
StringCache *stringCache = NULL;
......@@ -1298,8 +1299,20 @@ int main(int argc, char *argv[])
for (i = 0; i < data->NumberOfSuperClasses; i++)
{
char *safe_name = vtkWrap_SafeSuperclassName(data->SuperClasses[i]);
const char *safe_superclass = safe_name ? safe_name : data->SuperClasses[i];
/* if a template class is detected add a typedef */
if (safe_name)
{
fprintf(fp,"typedef %s %s;\n",
data->SuperClasses[i], safe_name);
}
fprintf(fp,"extern \"C\" JNIEXPORT void* %s_Typecast(void *op,char *dType);\n",
data->SuperClasses[i]);
safe_superclass);
free(safe_name);
}
fprintf(fp,"\nextern \"C\" JNIEXPORT void* %s_Typecast(void *me,char *dType)\n{\n",data->Name);
......@@ -1311,9 +1324,14 @@ int main(int argc, char *argv[])
/* check our superclasses */
for (i = 0; i < data->NumberOfSuperClasses; i++)
{
char *safe_name = vtkWrap_SafeSuperclassName(data->SuperClasses[i]);
const char *safe_superclass = safe_name ? safe_name : data->SuperClasses[i];
fprintf(fp," if ((res= %s_Typecast(me,dType)) != NULL)",
data->SuperClasses[i]);
safe_superclass);
fprintf(fp," { return res; }\n");
free(safe_name);
}
fprintf(fp," return NULL;\n");
fprintf(fp,"}\n\n");
......
......@@ -21,6 +21,7 @@
#include "vtkParseMain.h"
#include "vtkParseHierarchy.h"
#include "vtkConfigure.h"
#include "vtkWrap.h"
HierarchyInfo *hierarchyInfo = NULL;
StringCache *stringCache = NULL;
......@@ -1170,7 +1171,20 @@ int main(int argc, char *argv[])
for (i = 0; i < data->NumberOfSuperClasses; i++)
{
fprintf(fp,"int %sCppCommand(%s *op, Tcl_Interp *interp,\n int argc, char *argv[]);\n",data->SuperClasses[i],data->SuperClasses[i]);
char *safe_name = vtkWrap_SafeSuperclassName(data->SuperClasses[i]);
const char *safe_superclass = safe_name ? safe_name : data->SuperClasses[i];
/* if a template class is detected add a typedef */
if (safe_name)
{
fprintf(fp,"typedef %s %s;\n",
data->SuperClasses[i], safe_name);
}
fprintf(fp,"int %sCppCommand(%s *op, Tcl_Interp *interp,\n int argc, char *argv[]);\n",
safe_superclass, safe_superclass);
free(safe_name);
}
fprintf(fp,"int VTKTCL_EXPORT %sCppCommand(%s *op, Tcl_Interp *interp,\n int argc, char *argv[]);\n",data->Name,data->Name);
fprintf(fp,"\nint %sCommand(ClientData cd, Tcl_Interp *interp,\n int argc, char *argv[])\n{\n",data->Name);
......@@ -1211,9 +1225,14 @@ int main(int argc, char *argv[])
/* check our superclasses */
for (i = 0; i < data->NumberOfSuperClasses; i++)
{
char *safe_name = vtkWrap_SafeSuperclassName(data->SuperClasses[i]);
const char *safe_superclass = safe_name ? safe_name : data->SuperClasses[i];
fprintf(fp," if (%sCppCommand(static_cast<%s *>(op),interp,argc,argv) == TCL_OK)\n {\n",
data->SuperClasses[i],data->SuperClasses[i]);
safe_superclass, data->SuperClasses[i]);
fprintf(fp," return TCL_OK;\n }\n");
free(safe_name);
}
fprintf(fp," }\n return TCL_ERROR;\n }\n\n");
......@@ -1246,8 +1265,13 @@ int main(int argc, char *argv[])
/* recurse up the tree */
for (i = 0; i < data->NumberOfSuperClasses; i++)
{
char *safe_name = vtkWrap_SafeSuperclassName(data->SuperClasses[i]);
const char *safe_superclass = safe_name ? safe_name : data->SuperClasses[i];
fprintf(fp," %sCppCommand(op,interp,argc,argv);\n",
data->SuperClasses[i]);
safe_superclass);
free(safe_name);
}
/* now list our methods */
fprintf(fp," Tcl_AppendResult(interp,\"Methods from %s:\\n\",NULL);\n",data->Name);
......@@ -1311,11 +1335,16 @@ int main(int argc, char *argv[])
/* recurse up the tree */
for (i = 0; i < data->NumberOfSuperClasses; i++)
{
char *safe_name = vtkWrap_SafeSuperclassName(data->SuperClasses[i]);
const char *safe_superclass = safe_name ? safe_name : data->SuperClasses[i];
fprintf(fp," %sCppCommand(op,interp,argc,argv);\n",
data->SuperClasses[i]);
safe_superclass);
/* append the result to our string */
fprintf(fp," Tcl_DStringGetResult ( interp, &dStringParent );\n" );
fprintf(fp," Tcl_DStringAppend ( &dString, Tcl_DStringValue ( &dStringParent ), -1 );\n" );
free(safe_name);
}
for (k = 0; k < numberOfWrappedFunctions; k++)
{
......@@ -1345,9 +1374,14 @@ int main(int argc, char *argv[])
/* recurse up the tree */
for (i = 0; i < data->NumberOfSuperClasses; i++)
{
char *safe_name = vtkWrap_SafeSuperclassName(data->SuperClasses[i]);
const char *safe_superclass = safe_name ? safe_name : data->SuperClasses[i];
fprintf(fp," SuperClassStatus = %sCppCommand(op,interp,argc,argv);\n",
data->SuperClasses[i]);
safe_superclass);
fprintf(fp," if ( SuperClassStatus == TCL_OK ) { return TCL_OK; }\n" );
free(safe_name);
}
/* Now we handle it ourselves */
for (k = 0; k < numberOfWrappedFunctions; k++)
......@@ -1484,9 +1518,14 @@ int main(int argc, char *argv[])
/* try superclasses */
for (i = 0; i < data->NumberOfSuperClasses; i++)
{
char *safe_name = vtkWrap_SafeSuperclassName(data->SuperClasses[i]);
const char *safe_superclass = safe_name ? safe_name : data->SuperClasses[i];
fprintf(fp,"\n if (%sCppCommand(static_cast<%s *>(op),interp,argc,argv) == TCL_OK)\n",
data->SuperClasses[i], data->SuperClasses[i]);
safe_superclass, data->SuperClasses[i]);
fprintf(fp," {\n return TCL_OK;\n }\n");
free(safe_name);
}
......
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