35 #ifndef __OGRE_CPREPROCESSOR_H__ 36 #define __OGRE_CPREPROCESSOR_H__ 38 #include <forward_list> 124 Token (
Kind iType,
const char *iString,
size_t iLength) :
125 Type (iType), Allocated (0),
String (iString), Length (iLength)
138 {
if (Allocated) free (
Buffer); }
143 if (Allocated) free (
Buffer);
153 void Append (
const char *iString,
size_t iLength);
173 if (iOther.
Length != Length)
196 Macro(
const Token& iName) : Name(iName), ExpandFunc(NULL), Expanding(false) {}
199 Token Expand (
const std::vector<Token>& iArgs, std::forward_list<Macro>& iMacros);
357 Token GetArguments (std::vector<Token>& oArgs,
bool iExpand,
bool shouldAppendArg);
389 bool GetValue (
const Token &iToken,
long &oValue,
int iLine);
443 static void Error (
int iLine,
const char *iError,
const Token *iToken = NULL);
463 void Define (
const char *iMacroName,
size_t iMacroNameLen,
464 const char *iMacroValue,
size_t iMacroValueLen);
475 void Define (
const char *iMacroName,
size_t iMacroNameLen,
long iMacroValue);
486 bool Undef (
const char *iMacroName,
size_t iMacroNameLen);
510 char *
Parse (
const char *iSource,
size_t iLength,
size_t &oLength);
534 #endif // __OGRE_CPREPROCESSOR_H__ bool GetValueDef(const Token &iToken, long &oValue, int iLine)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: OgreGLSLPreprocessor.cpp:1048
std::vector< Token > Args
The names of the arguments.
Definition: OgreGLSLPreprocessor.h:186
static void Error(int iLine, const char *iError, const Token *iToken=NULL)
Call the error handler.
Definition: OgreGLSLPreprocessor.cpp:231
This is a simplistic C/C++-like preprocessor.
Definition: OgreGLSLPreprocessor.h:68
static Token ExpandDefined(CPreprocessor *iParent, const std::vector< Token > &iArgs)
The implementation of the defined() preprocessor function.
Definition: OgreGLSLPreprocessor.cpp:1036
Token ExpandMacro(const Token &iToken)
Expand the given macro, if it exists.
Definition: OgreGLSLPreprocessor.cpp:398
Token(Kind iType)
Definition: OgreGLSLPreprocessor.h:121
Token HandleDirective(Token &iToken, int iLine)
Handle a preprocessor directive.
Definition: OgreGLSLPreprocessor.cpp:1129
bool HandleIfDef(Token &iBody, int iLine)
Handle an #ifdef directive.
Definition: OgreGLSLPreprocessor.cpp:1007
int Line
Current line number.
Definition: OgreGLSLPreprocessor.h:209
Definition: OgreGLSLPreprocessor.h:97
const char * Source
The current source text input.
Definition: OgreGLSLPreprocessor.h:205
Definition: OgreGLSLPreprocessor.h:92
const char * SourceEnd
The end of the source text.
Definition: OgreGLSLPreprocessor.h:207
Definition: OgreGLSLPreprocessor.h:95
bool GetValue(long &oValue) const
Get the numeric value of the token.
Definition: OgreGLSLPreprocessor.cpp:105
Token GetToken(bool iExpand)
Stateless tokenizer: Parse the input text and return the next token.
Definition: OgreGLSLPreprocessor.cpp:255
void(* ErrorHandlerFunc)(int iLine, const char *iError, const Token *iToken)
Call the error handler.
Definition: OgreGLSLPreprocessor.h:521
Definition: OgreGLSLPreprocessor.h:99
void SetValue(long iValue)
Set the numeric value of the token.
Definition: OgreGLSLPreprocessor.cpp:155
Definition: OgreGLSLPreprocessor.h:89
A input token.
Definition: OgreGLSLPreprocessor.h:84
bool HandleElif(Token &iBody, int iLine)
Handle an #elif directive.
Definition: OgreGLSLPreprocessor.cpp:1069
Token GetExpression(Token &oResult, int iLine, int iOpPriority=0)
Parse an expression, compute it and return the result.
Definition: OgreGLSLPreprocessor.cpp:462
Token Body
Unparsed macro body (keeps the whole raw unparsed macro body)
Definition: OgreGLSLPreprocessor.h:190
bool Undef(const char *iMacroName, size_t iMacroNameLen)
Undefine a macro.
Definition: OgreGLSLPreprocessor.cpp:1251
Token Parse(const Token &iSource)
Parse the input string and return a token containing the whole output.
Definition: OgreGLSLPreprocessor.cpp:1271
std::forward_list< Macro > MacroList
The list of macros defined so far.
Definition: OgreGLSLPreprocessor.h:216
Token GetArguments(std::vector< Token > &oArgs, bool iExpand, bool shouldAppendArg)
Get all the arguments of a macro: '(' arg1 { ',' arg2 { ',' ...
Definition: OgreGLSLPreprocessor.cpp:830
Definition: OgreGLSLPreprocessor.h:100
A macro definition.
Definition: OgreGLSLPreprocessor.h:180
Kind Type
Token type.
Definition: OgreGLSLPreprocessor.h:105
bool BOL
True if we are at beginning of line.
Definition: OgreGLSLPreprocessor.h:211
void AppendNL(int iCount)
Append given number of newlines to this token.
Definition: OgreGLSLPreprocessor.cpp:165
Definition: OgreGLSLPreprocessor.h:98
unsigned EnableElif
Definition: OgreGLSLPreprocessor.h:214
Definition: OgreGLSLPreprocessor.h:91
Kind
Definition: OgreGLSLPreprocessor.h:87
virtual ~CPreprocessor()
Destroy the preprocessor object.
Definition: OgreGLSLPreprocessor.cpp:253
char * Buffer
A memory-allocated string.
Definition: OgreGLSLPreprocessor.h:113
size_t Length
Token length in bytes.
Definition: OgreGLSLPreprocessor.h:116
Definition: OgreGLSLPreprocessor.h:90
Definition: OgreGLSLPreprocessor.h:94
const char * String
A pointer somewhere into the input buffer.
Definition: OgreGLSLPreprocessor.h:111
static ErrorHandlerFunc ErrorHandler
A pointer to the preprocessor's error handler.
Definition: OgreGLSLPreprocessor.h:528
CPreprocessor()
Create an empty preprocessor object.
Definition: OgreGLSLPreprocessor.h:447
bool HandleUnDef(Token &iBody, int iLine)
Undefine a previously defined macro.
Definition: OgreGLSLPreprocessor.cpp:961
int CountNL()
Count number of newlines in this token.
Definition: OgreGLSLPreprocessor.cpp:180
void Append(const char *iString, size_t iLength)
Append a string to this token.
Definition: OgreGLSLPreprocessor.cpp:59
~Token()
Definition: OgreGLSLPreprocessor.h:137
bool Expanding
true if macro expansion is in progress
Definition: OgreGLSLPreprocessor.h:194
Token Value
The macro value.
Definition: OgreGLSLPreprocessor.h:188
bool HandleElse(Token &iBody, int iLine)
Handle an #else directive.
Definition: OgreGLSLPreprocessor.cpp:1093
Definition: OgreGLSLPreprocessor.h:93
Token Name
Macro name.
Definition: OgreGLSLPreprocessor.h:184
size_t Allocated
True if string was allocated (and must be freed)
Definition: OgreGLSLPreprocessor.h:107
Definition: OgreGLSLPreprocessor.cpp:43
Token & operator=(const Token &iOther)
Assignment operator.
Definition: OgreGLSLPreprocessor.h:141
bool operator==(const Token &iOther)
Test two tokens for equality.
Definition: OgreGLSLPreprocessor.h:171
Macro(const Token &iName)
Definition: OgreGLSLPreprocessor.h:196
Token GetArgument(Token &oArg, bool iExpand, bool shouldAppendArg)
Get a single function argument until next ',' or ')'.
Definition: OgreGLSLPreprocessor.cpp:726
bool HandleEndIf(Token &iBody, int iLine)
Handle an #endif directive.
Definition: OgreGLSLPreprocessor.cpp:1112
void Define(const char *iMacroName, size_t iMacroNameLen, const char *iMacroValue, size_t iMacroValueLen)
Define a macro without parameters.
Definition: OgreGLSLPreprocessor.cpp:1235
bool HandleIf(Token &iBody, int iLine)
Handle an #if directive.
Definition: OgreGLSLPreprocessor.cpp:1063
Definition: OgreGLSLPreprocessor.h:101
Token()
Definition: OgreGLSLPreprocessor.h:118
Definition: OgreGLSLPreprocessor.h:96
Token(const Token &iOther)
Definition: OgreGLSLPreprocessor.h:128
bool HandleDefine(Token &iBody, int iLine)
Handle a #define directive.
Definition: OgreGLSLPreprocessor.cpp:901
Macro * IsDefined(const Token &iToken)
Check if a macro is defined, and if so, return it.
Definition: OgreGLSLPreprocessor.cpp:388
unsigned EnableOutput
A stack of 32 booleans packed into one value :)
Definition: OgreGLSLPreprocessor.h:213
Token(Kind iType, const char *iString, size_t iLength)
Definition: OgreGLSLPreprocessor.h:124