Commit 29b6e700 authored by Brad King's avatar Brad King
Browse files

ENH: Added compile-time options VTK_LEGACY_REMOVE and VTK_LEGACY_SILENT along...

ENH: Added compile-time options VTK_LEGACY_REMOVE and VTK_LEGACY_SILENT along with VTK_LEGACY macro.  This provides a new deprecation mechanism with more user control over whether deprecated code is available and whether using it produces warnings.  Wrappers now also take the deprecation mechanism into account.
parent 3ebd3859
......@@ -46,6 +46,12 @@ INSTALL_FILES(/lib/vtk .cmake VTKBuildSettings)
OPTION(BUILD_SHARED_LIBS "Build VTK with shared libraries." OFF)
SET(VTK_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
#-----------------------------------------------------------------------------
# Provide compatibility options.
OPTION(VTK_LEGACY_REMOVE "Remove all legacy code completely." OFF)
OPTION(VTK_LEGACY_SILENT "Silence all legacy code messages." OFF)
MARK_AS_ADVANCED(VTK_LEGACY_REMOVE VTK_LEGACY_SILENT)
#-----------------------------------------------------------------------------
# Determine the set of VTK kits that should be built.
OPTION(VTK_USE_RENDERING "Build the vtkRendering kit. Needed for displaying data." ON)
......
......@@ -664,10 +664,8 @@ virtual double *Get##name() \
#define vtkTemplateMacro10(func,a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
vtkTemplateMacro(func(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10))
// Use to mark methods legacy. Make sure the correct date is used to
// keep track of when a method was made legacy, and so that it can be
// eliminated at the right time.
#ifndef VTK_LEAN_AND_MEAN
// Old-style legacy code marker macro.
#if !defined(VTK_LEGACY_REMOVE) && !defined(VTK_LEAN_AND_MEAN)
#define VTK_LEGACY_METHOD(oldMethod,versionStringMadeLegacy) \
vtkErrorMacro(<< #oldMethod \
<< " was obsoleted for version " << #versionStringMadeLegacy \
......@@ -676,6 +674,53 @@ virtual double *Get##name() \
#define VTK_LEGACY_METHOD(oldMethod,versionStringMadeLegacy)
#endif
//----------------------------------------------------------------------------
// Setup legacy code policy.
// Define VTK_LEGACY macro to mark legacy methods where they are
// declared in their class. Example usage:
//
// // @deprecated Replaced by MyOtherMethod() as of VTK 5.0.
// VTK_LEGACY(void MyMethod());
#if defined(VTK_LEGACY_REMOVE)
// Remove legacy methods completely.
# define VTK_LEGACY(method)
#elif defined(VTK_LEGACY_SILENT)
// Provide legacy methods with no warnings.
# define VTK_LEGACY(method) method
#else
// Setup compile-time warnings for uses of deprecated methods if
// possible on this compiler.
# if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
# define VTK_LEGACY(method) __attribute__((deprecated)) method
# elif defined(_MSC_VER) && _MSC_VER >= 1300
# define VTK_LEGACY(method) __declspec(deprecated) method
# else
# define VTK_LEGACY(method) method
# endif
#endif
// Macros to create runtime deprecation warning messages in function
// bodies. Example usage:
//
// void vtkMyClass::MyOldMethod()
// {
// VTK_LEGACY_BODY(vtkMyClass::MyOldMethod, 5.0);
// }
//
// void vtkMyClass::MyMethod()
// {
// VTK_LEGACY_REPLACED_BODY(vtkMyClass::MyMethod, 5.0,
// vtkMyClass::MyOtherMethod);
// }
#if defined(VTK_LEGACY_REMOVE) || defined(VTK_LEGACY_SILENT)
# define VTK_LEGACY_BODY(method, version)
# define VTK_LEGACY_REPLACED_BODY(method, version, replace)
#else
# define VTK_LEGACY_BODY(method, version) \
vtkGenericWarningMacro(#method " was deprecated for VTK " #version " and will be removed in a future version.")
# define VTK_LEGACY_REPLACED_BODY(method, version, replace) \
vtkGenericWarningMacro(#method " was deprecated for VTK " #version " and will be removed in a future version. Use " #replace " instead.")
#endif
#endif
......@@ -182,4 +182,5 @@ PREDEFINED = "vtkSetMacro(name,type)= \
virtual const char *GetClassName(); \
static int IsTypeOf(const char *type); \
virtual int IsA(const char *type); \
static thisClass* SafeDownCast(vtkObject *o);"
static thisClass* SafeDownCast(vtkObject *o);" \
"VTK_LEGACY(x)= x"
......@@ -80,6 +80,8 @@ SET(VTK_USE_X "@VTK_USE_X@")
SET(VTK_WRAP_JAVA "@VTK_WRAP_JAVA@")
SET(VTK_WRAP_PYTHON "@VTK_WRAP_PYTHON@")
SET(VTK_WRAP_TCL "@VTK_WRAP_TCL@")
SET(VTK_LEGACY_REMOVE "@VTK_LEGACY_REMOVE@")
SET(VTK_LEGACY_SILENT "@VTK_LEGACY_SILENT@")
SET(TK_RESOURCE_FILE "@TK_RESOURCE_FILE@")
SET(TCL_TK_STATIC "@TCL_TK_STATIC@")
......
This diff is collapsed.
......@@ -33,6 +33,7 @@
char *ReturnClass;
char *Comment;
char *Signature;
int IsLegacy;
} FunctionInfo;
typedef struct _FileInfo
......
%option yylineno
%{
/*
This file must be translated to C and modified to build everywhere.
Run flex like this:
flex vtkParse.l
Modify lex.yy.c:
- remove yyunput function
- remove TABs
*/
/* We do not care of interactive mode */
#define YY_NEVER_INTERACTIVE 1
#define YY_NO_UNPUT 1
/* Do not include unistd.h in generated source. */
#define YY_NO_UNISTD_H
/* Skip declaring this function. It is a macro. */
#define YY_SKIP_YYWRAP
#ifdef _WIN32
#pragma warning ( disable : 4127 )
#pragma warning ( disable : 4131 )
......@@ -179,6 +200,7 @@
"vtkWorldCoordinateMacro" return(WorldCoordinateMacro);
"vtkTypeMacro" return(TypeMacro);
"vtkTypeRevisionMacro" return(TypeMacro);
"VTK_LEGACY" return(VTK_LEGACY);
[0-9]+ { sscanf(yytext,"%d",&yylval.integer); return(NUM);}
......
This diff is collapsed.
......@@ -12,6 +12,8 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
%{
/*
This file must be translated to C and modified to build everywhere.
......@@ -22,10 +24,9 @@ Run yacc like this:
Modify vtkParse.tab.c:
- remove TABs
*/
*/
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -131,6 +132,10 @@ char *vtkstrdup(const char *in)
currentFunction->Signature = NULL;
}
}
void legacySig(void)
{
currentFunction->IsLegacy = 1;
}
%}
%union{
......@@ -163,6 +168,7 @@ char *vtkstrdup(const char *in)
%token STATIC
%token VAR_FUNCTION
%token ARRAY_NUM
%token VTK_LEGACY
/* macro tokens */
%token SetMacro
......@@ -203,55 +209,88 @@ class_def : CLASS VTK_ID
class_def_body: class_def_item | class_def_item class_def_body;
class_def_item: scope_type ':' | var
| function | FRIEND function | macro ';' | macro;
| operator
| FRIEND operator
| function func_body { output_function(); }
| FRIEND function func_body { output_function(); }
| legacy_function func_body { legacySig(); output_function(); }
| macro ';'
| macro;
legacy_function: VTK_LEGACY '(' function ')'
function: '~' func { preSig("~"); }
| VIRTUAL '~' func { preSig("virtual ~"); }
| func
| type func
{
currentFunction->ReturnType = $<integer>1;
}
| type CONST func
{
currentFunction->ReturnType = $<integer>1;
}
| VIRTUAL type CONST func
{
preSig("virtual ");
currentFunction->ReturnType = $<integer>2;
}
| VIRTUAL type func
{
preSig("virtual ");
currentFunction->ReturnType = $<integer>2;
}
| VIRTUAL func
{
preSig("virtual ");
};
function: '~' func { preSig("~"); output_function(); }
| VIRTUAL '~' func { preSig("virtual ~"); output_function(); }
| func
operator:
operator_sig
{
output_function();
}
| type func
| type operator_sig
{
currentFunction->ReturnType = $<integer>1;
output_function();
}
| type CONST func
}
| type CONST operator_sig
{
currentFunction->ReturnType = $<integer>1;
output_function();
}
| VIRTUAL type CONST func
}
| VIRTUAL type CONST operator_sig
{
preSig("virtual ");
currentFunction->ReturnType = $<integer>2;
output_function();
}
| VIRTUAL type func
| VIRTUAL type operator_sig
{
preSig("virtual ");
currentFunction->ReturnType = $<integer>2;
output_function();
}
| VIRTUAL func
| VIRTUAL operator_sig
{
preSig("virtual ");
output_function();
};
func: func_beg { postSig(")"); } maybe_const { postSig(";"); openSig = 0; }
func_end
operator_sig: OPERATOR maybe_other_no_semi ';'
{
currentFunction->IsOperator = 1;
fprintf(stderr," Converted operator\n");
}
func: func_sig { postSig(")"); } maybe_const { postSig(";"); openSig = 0; }
{
openSig = 1;
currentFunction->Name = $<str>1;
fprintf(stderr," Parsed func %s\n",$<str>1);
}
| OPERATOR maybe_other_no_semi ';'
{
currentFunction->IsOperator = 1;
fprintf(stderr," Converted operator\n");
}
| func_beg '=' NUM ';'
| func_sig '=' NUM
{
postSig(") = 0;");
currentFunction->Name = $<str>1;
......@@ -262,7 +301,7 @@ func: func_beg { postSig(")"); } maybe_const { postSig(";"); openSig = 0; }
maybe_const: | CONST {postSig(" const");};
func_beg: any_id '(' {postSig(" ("); } args_list ')';
func_sig: any_id '(' {postSig(" ("); } args_list ')';
const_mod: CONST {postSig("const ");};
......@@ -270,7 +309,7 @@ static_mod: STATIC {postSig("static ");};
any_id: VTK_ID {postSig($<str>1);} | ID {postSig($<str>1);};
func_end: ';'
func_body: ';'
| '{' maybe_other '}' ';'
| '{' maybe_other '}'
| ':' maybe_other_no_semi ';';
......@@ -894,6 +933,7 @@ macro:
sprintf(currentFunction->Signature, "%s *SafeDownCast (vtkObject* o);",
$<str>3);
sprintf(temps,"SafeDownCast");
currentFunction->Name = vtkstrdup(temps);
currentFunction->NumberOfArguments = 1;
currentFunction->ArgTypes[0] = 309;
currentFunction->ArgCounts[0] = 1;
......@@ -940,6 +980,7 @@ void InitFunction(FunctionInfo *func)
func->ReturnClass = NULL;
func->Comment = NULL;
func->Signature = NULL;
func->IsLegacy = 0;
sigAllocatedLength = 0;
openSig = 1;
invertSig = 0;
......
......@@ -669,9 +669,17 @@ void outputFunction(FILE *fp, FileInfo *data)
!strcmp("vtkStructuredPointsReader",data->ClassName) ||
!strcmp("vtkPolyDataReader",data->ClassName)))
{
HandleDataReader(fp,data);
wrappedFunctions[numberOfWrappedFunctions] = currentFunction;
numberOfWrappedFunctions++;
if(currentFunction->IsLegacy)
{
fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
}
HandleDataReader(fp,data);
if(currentFunction->IsLegacy)
{
fprintf(fp,"#endif\n");
}
wrappedFunctions[numberOfWrappedFunctions] = currentFunction;
numberOfWrappedFunctions++;
}
......@@ -684,6 +692,10 @@ void outputFunction(FILE *fp, FileInfo *data)
{
fprintf(fp,"\n");
if(currentFunction->IsLegacy)
{
fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
}
fprintf(fp,"extern \"C\" JNIEXPORT ");
return_result(fp);
fprintf(fp," JNICALL Java_vtk_%s_%s_1%i(JNIEnv *env, jobject obj",
......@@ -762,6 +774,10 @@ void outputFunction(FILE *fp, FileInfo *data)
}
do_return(fp);
fprintf(fp,"}\n");
if(currentFunction->IsLegacy)
{
fprintf(fp,"#endif\n");
}
wrappedFunctions[numberOfWrappedFunctions] = currentFunction;
numberOfWrappedFunctions++;
......
......@@ -569,6 +569,10 @@ void outputFunction2(FILE *fp, FileInfo *data)
}
}
if(currentFunction->IsLegacy)
{
fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
}
fprintf(fp,"static PyObject *Py%s_%s(PyObject *%s, PyObject *args)\n",
data->ClassName,currentFunction->Name,
(is_static ? "" : "self"));
......@@ -801,7 +805,12 @@ void outputFunction2(FILE *fp, FileInfo *data)
}
}
}
fprintf(fp," return NULL;\n}\n\n");
fprintf(fp," return NULL;\n}\n");
if(currentFunction->IsLegacy)
{
fprintf(fp,"#endif\n");
}
fprintf(fp,"\n");
/* clear all occurances of this method from further consideration */
for (occ = fnum + 1; occ < numberOfWrappedFunctions; occ++)
......@@ -830,6 +839,10 @@ void outputFunction2(FILE *fp, FileInfo *data)
for (fnum = 0; fnum < numberOfWrappedFunctions; fnum++)
{
if(wrappedFunctions[fnum]->IsLegacy)
{
fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
}
if (wrappedFunctions[fnum]->Name)
{
fprintf(fp," {(char*)\"%s\", (PyCFunction)Py%s_%s, 1,\n (char*)\"%s\\n\\n%s\"},\n",
......@@ -837,6 +850,10 @@ void outputFunction2(FILE *fp, FileInfo *data)
wrappedFunctions[fnum]->Name, wrappedFunctions[fnum]->Signature,
quote_string(wrappedFunctions[fnum]->Comment,1000));
}
if(wrappedFunctions[fnum]->IsLegacy)
{
fprintf(fp,"#endif\n");
}
}
if (!strcmp("vtkObject",data->ClassName))
......
......@@ -435,6 +435,10 @@ void outputFunction(FILE *fp, FileInfo *data)
(currentFunction->ArgCounts[i] ? currentFunction->ArgCounts[i] : 1);
}
if(currentFunction->IsLegacy)
{
fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
}
fprintf(fp," if ((!strcmp(\"%s\",argv[1]))&&(argc == %i))\n {\n",
currentFunction->Name, required_args + 2);
......@@ -507,6 +511,10 @@ void outputFunction(FILE *fp, FileInfo *data)
}
fprintf(fp," }\n");
if(currentFunction->IsLegacy)
{
fprintf(fp,"#endif\n");
}
wrappedFunctions[numberOfWrappedFunctions] = currentFunction;
numberOfWrappedFunctions++;
......@@ -632,6 +640,10 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
int numArgs = 0;
currentFunction = wrappedFunctions[i];
if(currentFunction->IsLegacy)
{
fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
}
/* calc the total required args */
for (j = 0; j < currentFunction->NumberOfArguments; j++)
......@@ -655,6 +667,11 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
fprintf(fp," Tcl_AppendResult(interp,\" %s\\n\",NULL);\n",
currentFunction->Name);
}
if(currentFunction->IsLegacy)
{
fprintf(fp,"#endif\n");
}
}
fprintf(fp," return TCL_OK;\n }\n");
......
......@@ -100,6 +100,10 @@
/* C++ compiler used. */
#define VTK_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
/* Compatibility settings. */
#cmakedefine VTK_LEGACY_REMOVE
#cmakedefine VTK_LEGACY_SILENT
/*--------------------------------------------------------------------------*/
/* Setup VTK based on platform features and configuration. */
......
Supports Markdown
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