VTK
dox/Wrapping/Tools/vtkParsePreprocess.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkParsePreprocess.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 /*-------------------------------------------------------------------------
00016   Copyright (c) 2010 David Gobbi.
00017 
00018   Contributed to the VisualizationToolkit by the author in June 2010
00019   under the terms of the Visualization Toolkit 2008 copyright.
00020 -------------------------------------------------------------------------*/
00021 
00043 #ifndef VTK_PARSE_PREPROCESS_H
00044 #define VTK_PARSE_PREPROCESS_H
00045 
00046 #include "vtkParseString.h"
00047 
00051 #if defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
00052 typedef __int64 preproc_int_t;
00053 typedef unsigned __int64 preproc_uint_t;
00054 #else
00055 typedef long long preproc_int_t;
00056 typedef unsigned long long preproc_uint_t;
00057 #endif
00058 
00062 typedef struct _MacroInfo
00063 {
00064   const char    *Name;
00065   const char    *Definition;
00066   const char    *Comment; /* unused */
00067   int            NumberOfParameters; /* only if IsFunction == 1 */
00068   const char   **Parameters; /* symbols for parameters */
00069   int            IsFunction; /* this macro requires arguments */
00070   int            IsVariadic; /* this macro can take unlimited arguments */
00071   int            IsExternal; /* this macro is from an included file */
00072   int            IsExcluded; /* do not expand this macro */
00073 } MacroInfo;
00074 
00079 typedef struct _PreprocessInfo
00080 {
00081   const char    *FileName;         /* the file that is being parsed */
00082   MacroInfo   ***MacroHashTable;   /* hash table for macro lookup */
00083   int            NumberOfIncludeDirectories;
00084   const char   **IncludeDirectories;
00085   int            NumberOfIncludeFiles; /* all included files */
00086   const char   **IncludeFiles;
00087   StringCache   *Strings;          /* to aid string allocation */
00088   int            IsExternal;       /* label all macros as "external" */
00089   int            ConditionalDepth; /* internal state variable */
00090   int            ConditionalDone;  /* internal state variable */
00091 } PreprocessInfo;
00092 
00096 enum _preproc_platform_t {
00097   VTK_PARSE_NATIVE = 0
00098 };
00099 
00103 enum _preproc_return_t {
00104   VTK_PARSE_OK = 0,
00105   VTK_PARSE_SKIP = 1,            /* skip next block */
00106   VTK_PARSE_PREPROC_DOUBLE = 2,  /* encountered a double */
00107   VTK_PARSE_PREPROC_FLOAT = 3,   /* encountered a float */
00108   VTK_PARSE_PREPROC_STRING = 4,  /* encountered a string */
00109   VTK_PARSE_MACRO_UNDEFINED = 5, /* macro lookup failed */
00110   VTK_PARSE_MACRO_REDEFINED = 6, /* attempt to redefine a macro */
00111   VTK_PARSE_FILE_NOT_FOUND = 7,  /* include file not found */
00112   VTK_PARSE_FILE_OPEN_ERROR = 8, /* include file not readable */
00113   VTK_PARSE_FILE_READ_ERROR = 9, /* error during read */
00114   VTK_PARSE_MACRO_NUMARGS = 10,  /* wrong number of args to func macro */
00115   VTK_PARSE_SYNTAX_ERROR = 11    /* any and all syntax errors */
00116 };
00117 
00121 #define VTK_PARSE_FATAL_ERROR 0xF8
00122 
00123 #ifdef __cplusplus
00124 extern "C" {
00125 #endif
00126 
00137 int vtkParsePreprocess_HandleDirective(
00138   PreprocessInfo *info, const char *directive);
00139 
00149 int vtkParsePreprocess_EvaluateExpression(
00150   PreprocessInfo *info, const char *text,
00151   preproc_int_t *val, int *is_unsigned);
00152 
00158 void vtkParsePreprocess_AddStandardMacros(
00159   PreprocessInfo *info, int platform);
00160 
00165 int vtkParsePreprocess_AddMacro(
00166   PreprocessInfo *info, const char *name, const char *definition);
00167 
00172 int vtkParsePreprocess_RemoveMacro(
00173   PreprocessInfo *info, const char *name);
00174 
00178 MacroInfo *vtkParsePreprocess_GetMacro(
00179   PreprocessInfo *info, const char *name);
00180 
00186 const char *vtkParsePreprocess_ExpandMacro(
00187   PreprocessInfo *info, MacroInfo *macro, const char *argstring);
00188 
00192 void vtkParsePreprocess_FreeMacroExpansion(
00193   PreprocessInfo *info, MacroInfo *macro, const char *text);
00194 
00199 const char *vtkParsePreprocess_ProcessString(
00200   PreprocessInfo *info, const char *text);
00201 
00208 void vtkParsePreprocess_FreeProcessedString(
00209   PreprocessInfo *info, const char *text);
00210 
00215 void vtkParsePreprocess_IncludeDirectory(
00216   PreprocessInfo *info, const char *name);
00217 
00225 const char *vtkParsePreprocess_FindIncludeFile(
00226   PreprocessInfo *info, const char *filename, int system_first,
00227   int *already_loaded);
00228 
00232 void vtkParsePreprocess_InitMacro(MacroInfo *symbol);
00233 
00237 void vtkParsePreprocess_FreeMacro(MacroInfo *macro);
00238 
00242 void vtkParsePreprocess_Init(
00243   PreprocessInfo *info, const char *filename);
00244 
00248 void vtkParsePreprocess_Free(PreprocessInfo *info);
00249 
00250 #ifdef __cplusplus
00251 } /* extern "C" */
00252 #endif
00253 
00254 #endif