Commit 1bb3de05 authored by David Gobbi's avatar David Gobbi

Allow enum types to be used as method parameters.

Previously, any method that accepted enum types as arguments would
not be wrapped.  This change allows those methods to be wrapped by
using a static_cast to convert the wrapper languages "integer" type
to the required enum type.

Change-Id: Ifa3105f2f70cdaba413e047f244cf871a30afc3d
parent 627baeb3
......@@ -1014,3 +1014,40 @@ const char *vtkParseHierarchy_ExpandTypedefsInName(
return name;
}
/* -------------------------------------------------------------------- */
const char *vtkParseHierarchy_QualifiedEnumName(
HierarchyInfo *hinfo, ClassInfo *data, StringCache *cache,
const char *name)
{
// check to see if this is an enum defined in the class
if (data)
{
int j;
for (j = 0; j < data->NumberOfEnums; j++)
{
EnumInfo *info = data->Enums[j];
if (name && info->Name && strcmp(name, info->Name) == 0)
{
char *scoped_name;
size_t scoped_len = strlen(data->Name) + strlen(info->Name) + 2;
scoped_name = vtkParse_NewString(cache, scoped_len);
sprintf(scoped_name, "%s::%s", data->Name, info->Name);
return scoped_name;
}
}
}
// check the hierarchy information for the enum type
if (hinfo)
{
HierarchyEntry *entry;
entry = vtkParseHierarchy_FindEntry(hinfo, name);
if (entry && entry->IsEnum)
{
return name;
}
}
return NULL;
}
......@@ -152,6 +152,15 @@ int vtkParseHierarchy_ExpandTypedefsInValue(
const char *vtkParseHierarchy_ExpandTypedefsInName(
const HierarchyInfo *info, const char *text, const char *scope);
/**
* Check whether the named type is an enum type that appears either in
* the HierarchyInfo or within the ClassInfo. If the enum type is found,
* its qualified name is returned, otherwise NULL is returned.
*/
const char *vtkParseHierarchy_QualifiedEnumName(
HierarchyInfo *hinfo, ClassInfo *data, StringCache *cache,
const char *name);
#ifdef __cplusplus
} /* extern "C" */
#endif
......
......@@ -21,6 +21,7 @@
#include "vtkParseHierarchy.h"
HierarchyInfo *hierarchyInfo = NULL;
StringCache *stringCache = NULL;
int numberOfWrappedFunctions = 0;
FunctionInfo *wrappedFunctions[1000];
extern FunctionInfo *currentFunction;
......@@ -65,7 +66,7 @@ void output_temp(FILE *fp,int i)
case VTK_PARSE_VOID: fprintf(fp,"void "); break;
case VTK_PARSE_CHAR: fprintf(fp,"char "); break;
case VTK_PARSE_OBJECT: fprintf(fp,"%s ",currentFunction->ArgClasses[i]); break;
case VTK_PARSE_UNKNOWN: return;
case VTK_PARSE_UNKNOWN: fprintf(fp,"int "); break;
}
}
......@@ -111,6 +112,7 @@ void return_result(FILE *fp)
case VTK_PARSE_UNSIGNED_ID_TYPE:
case VTK_PARSE_UNSIGNED_LONG_LONG:
case VTK_PARSE_UNSIGNED___INT64:
case VTK_PARSE_UNKNOWN:
fprintf(fp,"int ");
break;
case VTK_PARSE_BOOL:
......@@ -189,6 +191,7 @@ void return_result_native(FILE *fp)
case VTK_PARSE_UNSIGNED_ID_TYPE:
case VTK_PARSE_UNSIGNED_LONG_LONG:
case VTK_PARSE_UNSIGNED___INT64:
case VTK_PARSE_UNKNOWN:
fprintf(fp,"int ");
break;
case VTK_PARSE_BOOL:
......@@ -467,7 +470,7 @@ int checkFunctionSignature(ClassInfo *data)
VTK_PARSE_ID_TYPE, VTK_PARSE_UNSIGNED_ID_TYPE,
VTK_PARSE_LONG_LONG, VTK_PARSE_UNSIGNED_LONG_LONG,
VTK_PARSE___INT64, VTK_PARSE_UNSIGNED___INT64,
VTK_PARSE_OBJECT, VTK_PARSE_STRING,
VTK_PARSE_OBJECT, VTK_PARSE_STRING, VTK_PARSE_UNKNOWN,
0
};
......@@ -533,6 +536,25 @@ int checkFunctionSignature(ClassInfo *data)
args_ok = 0;
}
if (baseType == VTK_PARSE_UNKNOWN)
{
const char *qualified_name = 0;
if ((aType & VTK_PARSE_INDIRECT) == 0)
{
qualified_name = vtkParseHierarchy_QualifiedEnumName(
hierarchyInfo, data, stringCache,
currentFunction->ArgClasses[i]);
}
if (qualified_name)
{
currentFunction->ArgClasses[i] = qualified_name;
}
else
{
args_ok = 0;
}
}
if (baseType == VTK_PARSE_OBJECT)
{
if ((aType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER)
......@@ -570,6 +592,25 @@ int checkFunctionSignature(ClassInfo *data)
args_ok = 0;
}
if (baseType == VTK_PARSE_UNKNOWN)
{
const char *qualified_name = 0;
if ((rType & VTK_PARSE_INDIRECT) == 0)
{
qualified_name = vtkParseHierarchy_QualifiedEnumName(
hierarchyInfo, data, stringCache,
currentFunction->ReturnClass);
}
if (qualified_name)
{
currentFunction->ReturnClass = qualified_name;
}
else
{
args_ok = 0;
}
}
if (baseType == VTK_PARSE_OBJECT)
{
if ((rType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER)
......@@ -794,6 +835,9 @@ int main(int argc, char *argv[])
/* get command-line args and parse the header file */
file_info = vtkParse_Main(argc, argv);
/* some utility functions require the string cache */
stringCache = file_info->Strings;
/* get the command-line options */
options = vtkParse_GetCommandLineOptions();
......
......@@ -21,6 +21,7 @@
#include "vtkParseHierarchy.h"
HierarchyInfo *hierarchyInfo = NULL;
StringCache *stringCache = NULL;
int numberOfWrappedFunctions = 0;
FunctionInfo *wrappedFunctions[1000];
extern FunctionInfo *currentFunction;
......@@ -89,7 +90,7 @@ void output_proto_vars(FILE *fp, int i)
case VTK_PARSE_VOID: fprintf(fp,"void "); break;
case VTK_PARSE_CHAR: fprintf(fp,"jchar "); break;
case VTK_PARSE_OBJECT: fprintf(fp,"jobject "); break;
case VTK_PARSE_UNKNOWN: return;
case VTK_PARSE_UNKNOWN: fprintf(fp,"jint "); break;
}
fprintf(fp,"id%i",i);
......@@ -211,6 +212,7 @@ void return_result(FILE *fp)
case VTK_PARSE_UNSIGNED_ID_TYPE:
case VTK_PARSE_UNSIGNED_LONG_LONG:
case VTK_PARSE_UNSIGNED___INT64:
case VTK_PARSE_UNKNOWN:
fprintf(fp,"jint ");
break;
case VTK_PARSE_BOOL:
......@@ -293,7 +295,7 @@ void output_temp(FILE *fp, int i, unsigned int aType, const char *Id,
case VTK_PARSE_BOOL: fprintf(fp,"bool "); break;
case VTK_PARSE_OBJECT: fprintf(fp,"%s ",Id); break;
case VTK_PARSE_STRING: fprintf(fp,"%s ",Id); break;
case VTK_PARSE_UNKNOWN: return;
case VTK_PARSE_UNKNOWN: fprintf(fp,"%s ",Id); break;
}
switch (aType & VTK_PARSE_INDIRECT)
......@@ -394,6 +396,10 @@ void get_args(FILE *fp, int i)
fprintf(fp," temp%i[%i] = ((jint *)tempArray%i)[%i];\n",i,j,i,j);
}
break;
case VTK_PARSE_UNKNOWN:
fprintf(fp," temp%i = static_cast<%s>(id%i);\n",
i,currentFunction->ArgClasses[i],i);
break;
case VTK_PARSE_VOID:
case VTK_PARSE_OBJECT:
case VTK_PARSE_OBJECT_REF: break;
......@@ -801,7 +807,7 @@ int checkFunctionSignature(ClassInfo *data)
VTK_PARSE_ID_TYPE, VTK_PARSE_UNSIGNED_ID_TYPE,
VTK_PARSE_LONG_LONG, VTK_PARSE_UNSIGNED_LONG_LONG,
VTK_PARSE___INT64, VTK_PARSE_UNSIGNED___INT64,
VTK_PARSE_OBJECT, VTK_PARSE_STRING,
VTK_PARSE_OBJECT, VTK_PARSE_STRING, VTK_PARSE_UNKNOWN,
0
};
......@@ -867,6 +873,25 @@ int checkFunctionSignature(ClassInfo *data)
args_ok = 0;
}
if (baseType == VTK_PARSE_UNKNOWN)
{
const char *qualified_name = 0;
if ((aType & VTK_PARSE_INDIRECT) == 0)
{
qualified_name = vtkParseHierarchy_QualifiedEnumName(
hierarchyInfo, data, stringCache,
currentFunction->ArgClasses[i]);
}
if (qualified_name)
{
currentFunction->ArgClasses[i] = qualified_name;
}
else
{
args_ok = 0;
}
}
if (baseType == VTK_PARSE_OBJECT)
{
if ((aType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER)
......@@ -904,6 +929,25 @@ int checkFunctionSignature(ClassInfo *data)
args_ok = 0;
}
if (baseType == VTK_PARSE_UNKNOWN)
{
const char *qualified_name = 0;
if ((rType & VTK_PARSE_INDIRECT) == 0)
{
qualified_name = vtkParseHierarchy_QualifiedEnumName(
hierarchyInfo, data, stringCache,
currentFunction->ReturnClass);
}
if (qualified_name)
{
currentFunction->ReturnClass = qualified_name;
}
else
{
args_ok = 0;
}
}
if (baseType == VTK_PARSE_OBJECT)
{
if ((rType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER)
......@@ -1211,6 +1255,9 @@ int main(int argc, char *argv[])
/* get command-line args and parse the header file */
file_info = vtkParse_Main(argc, argv);
/* some utility functions require the string cache */
stringCache = file_info->Strings;
/* get the command-line options */
options = vtkParse_GetCommandLineOptions();
......
......@@ -23,6 +23,7 @@
#include "vtkConfigure.h"
HierarchyInfo *hierarchyInfo = NULL;
StringCache *stringCache = NULL;
int numberOfWrappedFunctions = 0;
FunctionInfo *wrappedFunctions[1000];
extern FunctionInfo *currentFunction;
......@@ -155,7 +156,7 @@ void output_temp(FILE *fp, int i, unsigned int aType,
case VTK_PARSE_SIGNED_CHAR: fprintf(fp,"signed char "); break;
case VTK_PARSE_BOOL: fprintf(fp,"bool "); break;
case VTK_PARSE_STRING: fprintf(fp,"%s ",Id); break;
case VTK_PARSE_UNKNOWN: return;
case VTK_PARSE_UNKNOWN: fprintf(fp,"%s ",Id); break;
}
/* handle array arguments */
......@@ -467,6 +468,12 @@ void return_result(FILE *fp)
MAX_ARGS);
fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
break;
case VTK_PARSE_UNKNOWN:
fprintf(fp," char tempResult[1024];\n");
fprintf(fp," sprintf(tempResult,\"%%i\",static_cast<int>(temp%i));\n",
MAX_ARGS);
fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
break;
case VTK_PARSE_STRING:
fprintf(fp," Tcl_SetResult(interp, const_cast<char *>(temp%i.c_str()), TCL_VOLATILE);\n",MAX_ARGS);
break;
......@@ -596,6 +603,12 @@ void get_args(FILE *fp, int i)
start_arg);
fprintf(fp," temp%i = static_cast<unsigned long long>(tempi);\n",i);
break;
case VTK_PARSE_UNKNOWN:
fprintf(fp," if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
start_arg);
fprintf(fp," temp%i = static_cast<%s>(tempi);\n",i,
currentFunction->ArgClasses[i]);
break;
case VTK_PARSE_STRING:
case VTK_PARSE_STRING_REF:
fprintf(fp," temp%i = argv[%i];\n",i,start_arg);
......@@ -632,6 +645,7 @@ void get_args(FILE *fp, int i)
case VTK_PARSE_LONG_LONG:
case VTK_PARSE___INT64:
case VTK_PARSE_SIGNED_CHAR:
case VTK_PARSE_UNKNOWN:
fprintf(fp," if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
start_arg);
fprintf(fp," temp%i[%i] = tempi;\n",i,j);
......@@ -716,7 +730,7 @@ int checkFunctionSignature(ClassInfo *data)
#ifdef VTK_TYPE_USE___INT64
VTK_PARSE___INT64, VTK_PARSE_UNSIGNED___INT64,
#endif
VTK_PARSE_OBJECT, VTK_PARSE_STRING,
VTK_PARSE_OBJECT, VTK_PARSE_STRING, VTK_PARSE_UNKNOWN,
0
};
......@@ -760,6 +774,25 @@ int checkFunctionSignature(ClassInfo *data)
args_ok = 0;
}
if (baseType == VTK_PARSE_UNKNOWN)
{
const char *qualified_name = 0;
if ((argType & VTK_PARSE_INDIRECT) == 0)
{
qualified_name = vtkParseHierarchy_QualifiedEnumName(
hierarchyInfo, data, stringCache,
currentFunction->ArgClasses[i]);
}
if (qualified_name)
{
currentFunction->ArgClasses[i] = qualified_name;
}
else
{
args_ok = 0;
}
}
if (baseType == VTK_PARSE_STRING &&
(argType & VTK_PARSE_INDIRECT) != 0 &&
(argType & VTK_PARSE_INDIRECT) != VTK_PARSE_REF)
......@@ -825,6 +858,25 @@ int checkFunctionSignature(ClassInfo *data)
args_ok = 0;
}
if (baseType == VTK_PARSE_UNKNOWN)
{
const char *qualified_name = 0;
if ((returnType & VTK_PARSE_INDIRECT) == 0)
{
qualified_name = vtkParseHierarchy_QualifiedEnumName(
hierarchyInfo, data, stringCache,
currentFunction->ReturnClass);
}
if (qualified_name)
{
currentFunction->ReturnClass = qualified_name;
}
else
{
args_ok = 0;
}
}
if (baseType == VTK_PARSE_STRING &&
(returnType & VTK_PARSE_INDIRECT) != 0 &&
(returnType & VTK_PARSE_INDIRECT) != VTK_PARSE_REF)
......@@ -1048,6 +1100,9 @@ int main(int argc, char *argv[])
/* get command-line args and parse the header file */
file_info = vtkParse_Main(argc, argv);
/* some utility functions require the string cache */
stringCache = file_info->Strings;
/* get the command-line options */
options = vtkParse_GetCommandLineOptions();
......
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