29 #ifndef __OGRE_CPREPROCESSOR_H__
30 #define __OGRE_CPREPROCESSOR_H__
116 Token (
Kind iType,
const char *iString,
size_t iLength) :
145 void Append (
const char *iString,
size_t iLength);
370 bool GetValue (
const Token &iToken,
long &oValue,
int iLine);
422 void Error (
int iLine,
const char *iError,
const Token *iToken = NULL);
443 void Define (
const char *iMacroName,
size_t iMacroNameLen,
444 const char *iMacroValue,
size_t iMacroValueLen);
455 void Define (
const char *iMacroName,
size_t iMacroNameLen,
long iMacroValue);
466 bool Undef (
const char *iMacroName,
size_t iMacroNameLen);
490 char *
Parse (
const char *iSource,
size_t iLength,
size_t &oLength);
508 void *iData,
int iLine,
const char *iError,
509 const char *iToken,
size_t iTokenLen);
524 #endif // __OGRE_CPREPROCESSOR_H__
bool HandleUnDef(Token &iBody, int iLine)
Undefine a previously defined macro.
unsigned EnableOutput
A stack of 32 booleans packed into one value :)
const char * Source
The current source text input.
static ErrorHandlerFunc ErrorHandler
A pointer to the preprocessor's error handler.
void(* ErrorHandlerFunc)(void *iData, int iLine, const char *iError, const char *iToken, size_t iTokenLen)
An error handler function type.
size_t Length
Token length in bytes.
static Token ExpandDefined(CPreprocessor *iParent, int iNumArgs, Token *iArgs)
The implementation of the defined() preprocessor function.
Token * Args
The names of the arguments.
Token(Kind iType, const char *iString, size_t iLength)
bool BOL
True if we are at beginning of line.
Token Value
The macro value.
const char * String
A pointer somewhere into the input buffer.
int NumArgs
Number of arguments.
size_t Allocated
True if string was allocated (and must be freed)
bool GetValue(long &oValue) const
Get the numeric value of the token.
char * Buffer
A memory-allocated string.
Token Expand(int iNumArgs, Token *iArgs, Macro *iMacros)
Expand the macro value (will not work for functions)
int Line
Current line number.
This is a simplistic C/C++-like preprocessor.
Token GetToken(bool iExpand)
Stateless tokenizer: Parse the input text and return the next token.
Token(const Token &iOther)
const char * SourceEnd
The end of the source text.
void Define(const char *iMacroName, size_t iMacroNameLen, const char *iMacroValue, size_t iMacroValueLen)
Define a macro without parameters.
Token GetExpression(Token &oResult, int iLine, int iOpPriority=0)
Parse an expression, compute it and return the result.
Token GetArguments(int &oNumArgs, Token *&oArgs, bool iExpand)
Get all the arguments of a macro: '(' arg1 { ',' arg2 { ',' ...
void SetValue(long iValue)
Set the numeric value of the token.
bool Expanding
true if macro expansion is in progress
Token(* ExpandFunc)(CPreprocessor *iParent, int iNumArgs, Token *iArgs)
A pointer to function implementation (if macro is really a func)
Token ExpandMacro(const Token &iToken)
Expand the given macro, if it exists.
bool HandleEndIf(Token &iBody, int iLine)
Handle an #endif directive.
int CountNL()
Count number of newlines in this token.
Macro * Next
Next macro in chained list.
Token & operator=(const Token &iOther)
Assignment operator.
bool HandleIf(Token &iBody, int iLine)
Handle an #if directive.
bool HandleDefine(Token &iBody, int iLine)
Handle a #define directive.
Token Parse(const Token &iSource)
Parse the input string and return a token containing the whole output.
Token Body
Unparsed macro body (keeps the whole raw unparsed macro body)
bool HandleElse(Token &iBody, int iLine)
Handle an #else directive.
bool HandleIfDef(Token &iBody, int iLine)
Handle an #ifdef directive.
void AppendNL(int iCount)
Append given number of newlines to this token.
void Error(int iLine, const char *iError, const Token *iToken=NULL)
Call the error handler.
CPreprocessor()
Create an empty preprocessor object.
Token HandleDirective(Token &iToken, int iLine)
Handle a preprocessor directive.
Macro(const Token &iName)
virtual ~CPreprocessor()
Destroy the preprocessor object.
bool operator==(const Token &iOther)
Test two tokens for equality.
Token GetArgument(Token &oArg, bool iExpand)
Get a single function argument until next ',' or ')'.
bool GetValue(const Token &iToken, long &oValue, int iLine)
Get the numeric value of a token.
Macro * IsDefined(const Token &iToken)
Check if a macro is defined, and if so, return it.
Macro * MacroList
The list of macros defined so far.
void Append(const char *iString, size_t iLength)
Append a string to this token.
bool Undef(const char *iMacroName, size_t iMacroNameLen)
Undefine a macro.
void * ErrorData
User-specific storage, passed to Error()