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