VTK
vtkParsePreprocess.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkParsePreprocess.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16  Copyright (c) 2010 David Gobbi.
17 
18  Contributed to the VisualizationToolkit by the author in June 2010
19  under the terms of the Visualization Toolkit 2008 copyright.
20 -------------------------------------------------------------------------*/
21 
43 #ifndef VTK_PARSE_PREPROCESS_H
44 #define VTK_PARSE_PREPROCESS_H
45 
46 #include "vtkParseString.h"
47 
51 #if defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
52 typedef __int64 preproc_int_t;
53 typedef unsigned __int64 preproc_uint_t;
54 #else
55 typedef long long preproc_int_t;
56 typedef unsigned long long preproc_uint_t;
57 #endif
58 
62 typedef struct _MacroInfo
63 {
64  const char *Name;
65  const char *Definition;
66  const char *Comment; /* unused */
67  int NumberOfParameters; /* only if IsFunction == 1 */
68  const char **Parameters; /* symbols for parameters */
69  int IsFunction; /* this macro requires arguments */
70  int IsVariadic; /* this macro can take unlimited arguments */
71  int IsExternal; /* this macro is from an included file */
72  int IsExcluded; /* do not expand this macro */
73 } MacroInfo;
74 
79 typedef struct _PreprocessInfo
80 {
81  const char *FileName; /* the file that is being parsed */
82  MacroInfo ***MacroHashTable; /* hash table for macro lookup */
84  const char **IncludeDirectories;
85  int NumberOfIncludeFiles; /* all included files */
86  const char **IncludeFiles;
87  StringCache *Strings; /* to aid string allocation */
88  int IsExternal; /* label all macros as "external" */
89  int ConditionalDepth; /* internal state variable */
90  int ConditionalDone; /* internal state variable */
92 
98 };
99 
105  VTK_PARSE_SKIP = 1, /* skip next block */
106  VTK_PARSE_PREPROC_DOUBLE = 2, /* encountered a double */
107  VTK_PARSE_PREPROC_FLOAT = 3, /* encountered a float */
108  VTK_PARSE_PREPROC_STRING = 4, /* encountered a string */
109  VTK_PARSE_MACRO_UNDEFINED = 5, /* macro lookup failed */
110  VTK_PARSE_MACRO_REDEFINED = 6, /* attempt to redefine a macro */
111  VTK_PARSE_FILE_NOT_FOUND = 7, /* include file not found */
112  VTK_PARSE_FILE_OPEN_ERROR = 8, /* include file not readable */
113  VTK_PARSE_FILE_READ_ERROR = 9, /* error during read */
114  VTK_PARSE_MACRO_NUMARGS = 10, /* wrong number of args to func macro */
115  VTK_PARSE_SYNTAX_ERROR = 11, /* any and all syntax errors */
116  VTK_PARSE_OUT_OF_MEMORY = 12 /* out-of-memory */
117 };
118 
122 #define VTK_PARSE_FATAL_ERROR 0xF8
123 
124 #ifdef __cplusplus
125 extern "C" {
126 #endif
127 
139  PreprocessInfo *info, const char *directive);
140 
151  PreprocessInfo *info, const char *text,
152  preproc_int_t *val, int *is_unsigned);
153 
160  PreprocessInfo *info, int platform);
161 
167  PreprocessInfo *info, const char *name, const char *definition);
168 
174  PreprocessInfo *info, const char *name);
175 
180  PreprocessInfo *info, const char *name);
181 
188  PreprocessInfo *info, MacroInfo *macro, const char *argstring);
189 
194  PreprocessInfo *info, MacroInfo *macro, const char *text);
195 
201  PreprocessInfo *info, const char *text);
202 
210  PreprocessInfo *info, const char *text);
211 
217  PreprocessInfo *info, const char *name);
218 
227  PreprocessInfo *info, const char *filename, int system_first,
228  int *already_loaded);
229 
234 
239 
244  PreprocessInfo *info, const char *filename);
245 
250 
251 #ifdef __cplusplus
252 } /* extern "C" */
253 #endif
254 
255 #endif
const char * vtkParsePreprocess_ProcessString(PreprocessInfo *info, const char *text)
Fully process a string with the preprocessor, and return a new string or NULL if a fatal error occurr...
_preproc_platform_t
Platforms.
Contains all symbols defined thus far (including those defined in any included header files)...
const char * Name
void vtkParsePreprocess_InitMacro(MacroInfo *symbol)
Initialize a preprocessor symbol struct.
MacroInfo * vtkParsePreprocess_GetMacro(PreprocessInfo *info, const char *name)
Return a preprocessor symbol struct, or NULL if not found.
int vtkParsePreprocess_HandleDirective(PreprocessInfo *info, const char *directive)
Handle a preprocessor directive.
struct _PreprocessInfo PreprocessInfo
Contains all symbols defined thus far (including those defined in any included header files)...
struct _MacroInfo MacroInfo
Struct to describe a preprocessor symbol.
_preproc_return_t
Directive return values.
Struct to describe a preprocessor symbol.
void vtkParsePreprocess_Init(PreprocessInfo *info, const char *filename)
Initialize a preprocessor struct.
const char * FileName
unsigned long long preproc_uint_t
const char * vtkParsePreprocess_FindIncludeFile(PreprocessInfo *info, const char *filename, int system_first, int *already_loaded)
Find an include file in the path.
const char ** IncludeDirectories
void vtkParsePreprocess_Free(PreprocessInfo *info)
Free a preprocessor struct and its contents;.
const char * Comment
MacroInfo *** MacroHashTable
void vtkParsePreprocess_AddStandardMacros(PreprocessInfo *info, int platform)
Add all standard preprocessor symbols.
void vtkParsePreprocess_FreeProcessedString(PreprocessInfo *info, const char *text)
Free a processed string.
int vtkParsePreprocess_AddMacro(PreprocessInfo *info, const char *name, const char *definition)
Add a preprocessor symbol, including a definition.
int vtkParsePreprocess_RemoveMacro(PreprocessInfo *info, const char *name)
Remove a preprocessor symbol.
StringCache * Strings
StringCache provides a simple way of allocating strings centrally.
long long preproc_int_t
This file provides subroutines to assist in preprocessing C/C++ header files.
const char ** IncludeFiles
const char ** Parameters
const char * vtkParsePreprocess_ExpandMacro(PreprocessInfo *info, MacroInfo *macro, const char *argstring)
Expand a macro.
void vtkParsePreprocess_FreeMacro(MacroInfo *macro)
Free a preprocessor macro struct.
int vtkParsePreprocess_EvaluateExpression(PreprocessInfo *info, const char *text, preproc_int_t *val, int *is_unsigned)
Evaluate a preprocessor expression, providing an integer result in "val", and whether it is unsigned ...
void vtkParsePreprocess_FreeMacroExpansion(PreprocessInfo *info, MacroInfo *macro, const char *text)
Free an expanded macro.
void vtkParsePreprocess_IncludeDirectory(PreprocessInfo *info, const char *name)
Add an include directory.
const char * Definition