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