Commit 2de7b282 authored by David Gobbi's avatar David Gobbi
Browse files

Add VTK_SIZEHINT for the wrappers.

VTK_SIZEHINT(a, n) hints that the parameter "a" has a size "n".
If only one argument is given, VTK_SIZEHINT(n), then the hint is
for the size of the return value.
parent d2ff5027
......@@ -30,10 +30,13 @@
#define VTK_ZEROCOPY [[vtk::zerocopy]]
// Set preconditions for a function
#define VTK_EXPECTS(x) [[vtk::expects(x)]]
// Set size hint for parameter or return value
#define VTK_SIZEHINT(...) [[vtk::sizehint(__VA_ARGS__)]]
#else
#define VTK_NEWINSTANCE
#define VTK_ZEROCOPY
#define VTK_EXPECTS(x)
#define VTK_SIZEHINT(...)
#endif
#endif
......
......@@ -188,4 +188,5 @@ PREDEFINED = "vtkSetMacro(name,type)= \
"VTK_DELETE=delete" \
"VTK_NEWINSTANCE=" \
"VTK_ZEROCOPY=" \
"VTK_EXPECTS(x)="
"VTK_EXPECTS(x)=" \
"VTK_SIZEHINT(...)="
......@@ -11842,6 +11842,60 @@ void handle_attribute(const char *att, int pack)
&currentFunction->NumberOfPreconds,
vtkstrndup(args, la));
}
else if (l == 13 && strncmp(att, "vtk::sizehint", l) == 0 &&
args && role == VTK_PARSE_ATTRIB_FUNC)
{
/* first arg is parameter name, unless return value hint */
ValueInfo *arg = currentFunction->ReturnValue;
size_t n = vtkParse_SkipId(args);
preproc_int_t count;
int is_unsigned;
int i;
l = n;
while (args[n] == ' ') { n++; }
if (l > 0 && args[n] == ',')
{
do { n++; } while (args[n] == ' ');
/* find the named parameter */
for (i = 0; i < currentFunction->NumberOfParameters; i++)
{
arg = currentFunction->Parameters[i];
if (arg->Name && strlen(arg->Name) == l &&
strncmp(arg->Name, args, l) == 0)
{
break;
}
}
if (i == currentFunction->NumberOfParameters)
{
print_parser_error("unrecognized parameter name", args, l);
exit(1);
}
/* advance args to second attribute arg */
args += n;
la -= n;
}
/* set the size hint */
arg->CountHint = vtkstrndup(args, la);
/* see if hint is an integer */
if (VTK_PARSE_OK == vtkParsePreprocess_EvaluateExpression(
preprocessor, arg->CountHint, &count, &is_unsigned))
{
if (count > 0 && count < 127)
{
arg->CountHint = NULL;
arg->Count = (int)count;
#ifndef VTK_PARSE_LEGACY_REMOVE
if (arg == currentFunction->ReturnValue)
{
currentFunction->HaveHint = 1;
currentFunction->HintSize = arg->Count;
}
#endif
}
}
}
else
{
print_parser_error("attribute cannot be used here", att, l);
......
......@@ -4737,6 +4737,60 @@ void handle_attribute(const char *att, int pack)
&currentFunction->NumberOfPreconds,
vtkstrndup(args, la));
}
else if (l == 13 && strncmp(att, "vtk::sizehint", l) == 0 &&
args && role == VTK_PARSE_ATTRIB_FUNC)
{
/* first arg is parameter name, unless return value hint */
ValueInfo *arg = currentFunction->ReturnValue;
size_t n = vtkParse_SkipId(args);
preproc_int_t count;
int is_unsigned;
int i;
l = n;
while (args[n] == ' ') { n++; }
if (l > 0 && args[n] == ',')
{
do { n++; } while (args[n] == ' ');
/* find the named parameter */
for (i = 0; i < currentFunction->NumberOfParameters; i++)
{
arg = currentFunction->Parameters[i];
if (arg->Name && strlen(arg->Name) == l &&
strncmp(arg->Name, args, l) == 0)
{
break;
}
}
if (i == currentFunction->NumberOfParameters)
{
print_parser_error("unrecognized parameter name", args, l);
exit(1);
}
/* advance args to second attribute arg */
args += n;
la -= n;
}
/* set the size hint */
arg->CountHint = vtkstrndup(args, la);
/* see if hint is an integer */
if (VTK_PARSE_OK == vtkParsePreprocess_EvaluateExpression(
preprocessor, arg->CountHint, &count, &is_unsigned))
{
if (count > 0 && count < 127)
{
arg->CountHint = NULL;
arg->Count = (int)count;
#ifndef VTK_PARSE_LEGACY_REMOVE
if (arg == currentFunction->ReturnValue)
{
currentFunction->HaveHint = 1;
currentFunction->HintSize = arg->Count;
}
#endif
}
}
}
else
{
print_parser_error("attribute cannot be used here", att, l);
......
......@@ -211,6 +211,8 @@ void vtkParseMerge_FreeMergeInfo(MergeInfo *info)
static void merge_function(
FileInfo *finfo, FunctionInfo *merge, const FunctionInfo *func)
{
int i, j;
/* virtuality is inherited */
if (func->IsVirtual)
{
......@@ -220,7 +222,6 @@ static void merge_function(
/* contracts are inherited */
if (merge->NumberOfPreconds == 0)
{
int i, j;
for (i = 0; i < func->NumberOfPreconds; i++)
{
StringTokenizer t;
......@@ -287,6 +288,41 @@ static void merge_function(
}
}
/* hints are inherited */
j = func->NumberOfParameters;
for (i = -1; i < j; i++)
{
ValueInfo *arg = merge->ReturnValue;
ValueInfo *arg2 = func->ReturnValue;
if (i >= 0)
{
arg = merge->Parameters[i];
arg2 = func->Parameters[i];
}
if (arg && arg2)
{
if (arg2->CountHint && !arg->CountHint)
{
arg->CountHint = arg2->CountHint;
}
else if (arg2->Count && !arg->Count)
{
arg->Count = arg2->Count;
}
/* attribute flags */
arg->Type |= (arg2->Type & VTK_PARSE_ATTRIBUTES);
}
}
#ifndef VTK_PARSE_LEGACY_REMOVE
if (func->HaveHint && !merge->HaveHint)
{
merge->HaveHint = func->HaveHint;
merge->HintSize = func->HintSize;
}
#endif
/* comments are inherited */
if (func->Comment && !merge->Comment)
{
merge->Comment = func->Comment;
......
......@@ -1118,7 +1118,7 @@ void vtkWrap_DeclareVariable(
!vtkWrap_IsPODPointer(val) &&
!(vtkWrap_IsArray(val) && val->Value))
{
if (val->NumberOfDimensions == 1 && val->Count > 0)
if (val->NumberOfDimensions <= 1 && val->Count > 0)
{
fprintf(fp, "[%d]", val->Count);
}
......
......@@ -402,8 +402,14 @@ static void vtkWrapPython_GetAllParameters(
if (arg->CountHint)
{
fprintf(fp, " &&\n"
" ap.CheckSizeHint(%d, size%d, op->%s)",
i, i, arg->CountHint);
" ap.CheckSizeHint(%d, size%d, ",
i, i);
/* write out the code that gives the size */
vtkWrapPython_SubstituteCode(fp, data, currentFunction,
arg->CountHint);
fprintf(fp, ")");
}
if (vtkWrap_IsFunction(arg))
......@@ -1262,8 +1268,10 @@ void vtkWrapPython_GenerateOneMethod(
if (theOccurrence->ReturnValue && theOccurrence->ReturnValue->CountHint)
{
fprintf(fp,
" int sizer = op->%s;\n",
theOccurrence->ReturnValue->CountHint);
" int sizer = ");
vtkWrapPython_SubstituteCode(fp, data, theOccurrence,
theOccurrence->ReturnValue->CountHint);
fprintf(fp, ";\n");
}
/* save a copy of all non-const array arguments */
......
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