29 #ifndef __OGRE_CPREPROCESSOR_H__ 30 #define __OGRE_CPREPROCESSOR_H__ 116 Token (
Kind iType,
const char *iString,
size_t iLength) :
117 Type (iType), Allocated (0),
String (iString), Length (iLength)
123 Allocated = iOther.Allocated;
124 iOther.Allocated = 0;
126 Length = iOther.Length;
130 {
if (Allocated) free (
Buffer); }
135 if (Allocated) free (
Buffer);
137 Allocated = iOther.Allocated;
138 iOther.Allocated = 0;
140 Length = iOther.Length;
145 void Append (
const char *iString,
size_t iLength);
165 if (iOther.Length != Length)
167 return (memcmp (
String, iOther.String, Length) == 0);
193 Name (iName), NumArgs (0), Args (NULL), Next (NULL),
194 ExpandFunc (NULL), Expanding (false)
199 {
delete [] Args;
delete Next; }
371 bool GetValue (
const Token &iToken,
long &oValue,
int iLine);
423 void Error (
int iLine,
const char *iError,
const Token *iToken = NULL);
444 void Define (
const char *iMacroName,
size_t iMacroNameLen,
445 const char *iMacroValue,
size_t iMacroValueLen);
456 void Define (
const char *iMacroName,
size_t iMacroNameLen,
long iMacroValue);
467 bool Undef (
const char *iMacroName,
size_t iMacroNameLen);
491 char *
Parse (
const char *iSource,
size_t iLength,
size_t &oLength);
509 void *iData,
int iLine,
const char *iError,
510 const char *iToken,
size_t iTokenLen);
525 #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.
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.
bool GetValue(long &oValue) const
Get the numeric value of the token.
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 GetArguments(int &oNumArgs, Token *&oArgs, bool iExpand)
Get all the arguments of a macro: '(' arg1 { ',' arg2 { ',' ...
bool Undef(const char *iMacroName, size_t iMacroNameLen)
Undefine a macro.
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.
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 HandleElse(Token &iBody, int iLine)
Handle an #else directive.
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.
This source file is part of OGRE (Object-oriented Graphics Rendering Engine) For the latest info...
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.
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 ')'.
void(* ErrorHandlerFunc)(void *iData, int iLine, const char *iError, const char *iToken, size_t iTokenLen)
An error handler function type.
unsigned EnableOutput
A stack of 32 booleans packed into one value :)
Token(Kind iType, const char *iString, size_t iLength)