Commit 88693d29 authored by David Gobbi's avatar David Gobbi

Allow wrappers to properly support "using" methods.

A using declaration allows a class to easily re-declare all superclass
method signatures for a particular method.  This kind of re-declaration
is necessary to avoid shadowing superclass methods that the class does
not override.  This patch allows the wrappers to recognize using
declarations.
parent 1424cab4
......@@ -17,6 +17,7 @@ set(VTK_PARSE_SOURCES
vtkParseMain.c
vtkParseExtras.c
vtkParseMangle.c
vtkParseMerge.c
vtkParseString.c
vtkParseHierarchy.c
vtkParsePreprocess.c
......
This diff is collapsed.
......@@ -29,6 +29,16 @@
#include "vtkParseData.h"
#include <stddef.h>
/* Flags for selecting what info to print for declarations */
#define VTK_PARSE_NAMES 0x00000010
#define VTK_PARSE_VALUES 0x00000020
#define VTK_PARSE_RETURN_VALUE 0x00000040
#define VTK_PARSE_PARAMETER_LIST 0x00000080
#define VTK_PARSE_SPECIFIERS 0x00FF0000
#define VTK_PARSE_TRAILERS 0x0F000000
#define VTK_PARSE_TEMPLATES 0xF0000000
#define VTK_PARSE_EVERYTHING 0xFFFFFFFF
#ifdef __cplusplus
extern "C" {
#endif
......@@ -83,12 +93,55 @@ size_t vtkParse_ValueInfoFromString(
ValueInfo *val, StringCache *cache, const char *text);
/**
* Generate a declaration string from a ValueInfo struct. If the
* "nf" arg is set, the returned string must be freed.
* Only simple text strings are supported, e.g. "const T **".
* The variable or typedef name, if present, is ignored.
* Generate a C++ declaration string from a ValueInfo struct.
*
* The resulting string can represent a parameter declaration, a variable
* or type declaration, or a function return value. To use this function,
* you should call it twice: first, call it with "text" set to NULL, and
* it will return a lower bound on the length of the string that will be
* produced. Next, allocate at least length+1 bytes for the string, and
* and call it again with "text" set to the allocated string. The number
* of bytes written to the string (not including the terminating null) will
* be returned.
*
* The flags provide a mask that controls what information will be included,
* for example VTK_PARSE_CONST|VTK_PARSE_VOLATILE is needed to include the
* 'const' or 'volatile' qualifiers. Use VTK_PARSE_EVERYTHING to generate
* the entire declaration for a variable or parameter.
*/
size_t vtkParse_ValueInfoToString(
ValueInfo *data, char *text, unsigned int flags);
/**
* Generate a C++ function signature from a FunctionInfo struct.
*
* See vtkParse_ValueInfoToString() for basic usage. The flags can be set
* to VTK_PARSE_RETURN_VALUE to print only the return value for the function,
* or VTK_PARSE_PARAMETER_LIST to print only the parameter list.
*/
size_t vtkParse_FunctionInfoToString(
FunctionInfo *func, char *text, unsigned int flags);
/**
* Generate a C++ template declaration from a TemplateInfo struct.
*
* See vtkParse_ValueInfoToString() for basic usage.
*/
size_t vtkParse_TemplateInfoToString(
TemplateInfo *func, char *text, unsigned int flags);
/**
* Compare two C++ functions to see if they have the same signature.
*
* The following are the possible return values. Any non-zero return value
* means that the parameters match. If the 2nd bit is also set, then the
* function return value also matches. If the 3rd bit is set, then the
* parameters match and both methods are members of the same class, and
* the constness of the functions match. This means that the signatures
* are not identical unless the return value is 7 or higher (.
*/
const char *vtkParse_ValueInfoToString(ValueInfo *val, int *nf);
int vtkParse_CompareFunctionSignature(
const FunctionInfo *func1, const FunctionInfo *func2);
/**
* Expand a typedef within a variable, parameter, or typedef declaration.
......
......@@ -19,6 +19,7 @@
#include "vtkParse.h"
#include "vtkParseMain.h"
#include "vtkParseHierarchy.h"
#include "vtkWrap.h"
HierarchyInfo *hierarchyInfo = NULL;
StringCache *stringCache = NULL;
......@@ -861,6 +862,11 @@ int main(int argc, char *argv[])
if (options->HierarchyFileName)
{
hierarchyInfo = vtkParseHierarchy_ReadFile(options->HierarchyFileName);
if (hierarchyInfo)
{
/* resolve using declarations within the header files */
vtkWrap_ApplyUsingDeclarations(data, file_info, hierarchyInfo);
}
}
fprintf(fp,"// java wrapper for %s object\n//\n",data->Name);
......
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkParseMerge.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.
=========================================================================*/
/*-------------------------------------------------------------------------
Copyright (c) 2010,2015 David Gobbi
Contributed to the VisualizationToolkit by the author in March 2015
under the terms of the Visualization Toolkit 2015 copyright.
-------------------------------------------------------------------------*/
/**
This file contains utility functions for merging together the
methods for a class with those inherited from all superclasses.
*/
#ifndef VTK_PARSE_MERGE_H
#define VTK_PARSE_MERGE_H
#include "vtkParseData.h"
#include "vtkParseHierarchy.h"
/**
* This struct is meant to supplement ClassInfo, it gives information
* about which class (or classes) each method was inherited from
*/
typedef struct _MergeInfo
{
int NumberOfClasses; /* number of classes in geneology */
const char **ClassNames; /* class name */
int NumberOfFunctions; /* must match FunctionInfo */
int *NumberOfOverrides; /* n classes that define this function */
int **OverrideClasses; /* class for the override */
} MergeInfo;
#ifdef __cplusplus
extern "C" {
#endif
/**
* Merge all inherited methods into the ClassInfo.
* This will find and parse the header files for all the superclasses,
* and recursively add all inherited superclass methods into one ClassInfo.
* The returned MergeInfo object provides information about which class
* each inherited method was inherited from.
*/
MergeInfo *vtkParseMerge_MergeSuperClasses(
FileInfo *finfo, NamespaceInfo *data, ClassInfo *classInfo);
/**
* Free the MergeInfo object.
*/
void vtkParseMerge_FreeMergeInfo(MergeInfo *info);
/**
* Recursive suproutine to inherit methods from "classname".
* The class named by "classname" should be a superclass of the ClassInfo.
* If the MergeInfo is not provided (if it is NULL), then the only methods
* that are brought into the class are ones that are explicitly named
* by using declarations. The hintfile can also be NULL, if there is
* no hints file.
*/
void vtkParseMerge_MergeHelper(
FileInfo *finfo, const NamespaceInfo *data, const HierarchyInfo *hinfo,
const char *classname, FILE *hintfile, MergeInfo *info, ClassInfo *merge);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
......@@ -16,6 +16,7 @@
#include "vtkWrap.h"
#include "vtkParseData.h"
#include "vtkParseExtras.h"
#include "vtkParseMerge.h"
#include "vtkParseString.h"
#include <stdlib.h>
#include <string.h>
......@@ -844,6 +845,34 @@ void vtkWrap_ExpandTypedefs(
}
}
/* -------------------------------------------------------------------- */
/* Merge superclass methods according to using declarations */
void vtkWrap_ApplyUsingDeclarations(
ClassInfo *data, FileInfo *finfo, HierarchyInfo *hinfo)
{
int i, n;
/* first, check if there are any declarations to apply */
n = data->NumberOfUsings;
for (i = 0; i < n; i++)
{
if (data->Usings[i] && data->Usings[i]->Name)
{
break;
}
}
/* if using declarations found, read superclass headers */
if (i < n)
{
n = data->NumberOfSuperClasses;
for (i = 0; i < n; i++)
{
vtkParseMerge_MergeHelper(
finfo, finfo->Contents, hinfo, data->SuperClasses[i],
NULL, NULL, data);
}
}
}
/* -------------------------------------------------------------------- */
/* get the type name */
......
......@@ -163,6 +163,15 @@ int vtkWrap_HasPublicCopyConstructor(ClassInfo *data);
void vtkWrap_ExpandTypedefs(
ClassInfo *data, FileInfo *finfo, HierarchyInfo *hinfo);
/**
* Apply any using declarations that appear in the class.
* If any using declarations appear in the class that refer to superclass
* methods, the superclass header file will be parsed and the used methods
* will be brought into the class.
*/
void vtkWrap_ApplyUsingDeclarations(
ClassInfo *data, FileInfo *finfo, HierarchyInfo *hinfo);
/**
* Apply any hints about array sizes, e.g. hint that the
* GetNumberOfComponents() method gives the tuple size.
......
......@@ -1282,6 +1282,11 @@ int main(int argc, char *argv[])
if (options->HierarchyFileName)
{
hierarchyInfo = vtkParseHierarchy_ReadFile(options->HierarchyFileName);
if (hierarchyInfo)
{
/* resolve using declarations within the header files */
vtkWrap_ApplyUsingDeclarations(data, file_info, hierarchyInfo);
}
}
fprintf(fp,"// java wrapper for %s object\n//\n",data->Name);
......
......@@ -471,6 +471,10 @@ int main(int argc, char *argv[])
/* use the hierarchy file to expand typedefs */
if (hinfo)
{
for (i = 0; i < contents->NumberOfClasses; i++)
{
vtkWrap_ApplyUsingDeclarations(contents->Classes[i], file_info, hinfo);
}
for (i = 0; i < contents->NumberOfClasses; i++)
{
vtkWrap_ExpandTypedefs(contents->Classes[i], file_info, hinfo);
......
......@@ -1127,6 +1127,11 @@ int main(int argc, char *argv[])
if (options->HierarchyFileName)
{
hierarchyInfo = vtkParseHierarchy_ReadFile(options->HierarchyFileName);
if (hierarchyInfo)
{
/* resolve using declarations within the header files */
vtkWrap_ApplyUsingDeclarations(data, file_info, hierarchyInfo);
}
}
fprintf(fp,"// tcl wrapper for %s object\n//\n",data->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