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