Added support for the popular __COUNTER__ macro.
This commit is contained in:
@@ -396,9 +396,10 @@ void Compile (const char* FileName)
|
||||
DefineNumericMacro ("__EAGERLY_INLINE_FUNCS__", 1);
|
||||
}
|
||||
|
||||
/* Placeholders for __FILE__ and __LINE__ macros */
|
||||
/* Placeholders for __FILE__, __LINE__ and __COUNTER__ macros */
|
||||
DefineTextMacro ("__FILE__", "");
|
||||
DefineTextMacro ("__LINE__", "");
|
||||
DefineTextMacro ("__COUNTER__", "");
|
||||
|
||||
/* __TIME__ and __DATE__ macros */
|
||||
Time = time (0);
|
||||
|
||||
@@ -106,6 +106,9 @@ static Collection AFiles = STATIC_COLLECTION_INITIALIZER;
|
||||
/* Input stack used when preprocessing. */
|
||||
static Collection InputStack = STATIC_COLLECTION_INITIALIZER;
|
||||
|
||||
/* Counter for the __COUNTER__ macro */
|
||||
static unsigned MainFileCounter;
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -280,6 +283,9 @@ void OpenMainFile (const char* Name)
|
||||
** the main file before the first line is read.
|
||||
*/
|
||||
UpdateLineInfo (MainFile->Input, MainFile->Line, Line);
|
||||
|
||||
/* Initialize the __COUNTER__ counter */
|
||||
MainFileCounter = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -658,6 +664,14 @@ void SetCurrentFilename (const char* Name)
|
||||
|
||||
|
||||
|
||||
unsigned GetCurrentCounter (void)
|
||||
/* Return the counter number in the current input file */
|
||||
{
|
||||
return MainFileCounter++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void WriteEscaped (FILE* F, const char* Name)
|
||||
/* Write a file name to a dependency file escaping spaces */
|
||||
{
|
||||
|
||||
@@ -128,6 +128,9 @@ void SetCurrentLine (unsigned LineNum);
|
||||
void SetCurrentFilename (const char* Name);
|
||||
/* Set the presumed name of the current input file */
|
||||
|
||||
unsigned GetCurrentCounter (void);
|
||||
/* Return the counter number in the current input file */
|
||||
|
||||
void CreateDependencies (void);
|
||||
/* Create dependency files requested by the user */
|
||||
|
||||
|
||||
@@ -1630,9 +1630,15 @@ static int ParseDirectives (unsigned ModeFlags)
|
||||
|
||||
|
||||
void HandleSpecialMacro (Macro* M, const char* Name)
|
||||
/* Handle special mandatory macros */
|
||||
/* Handle special "magic" macros that may change */
|
||||
{
|
||||
if (strcmp (Name, "__LINE__") == 0) {
|
||||
if (strcmp (Name, "__COUNTER__") == 0) {
|
||||
/* Replace __COUNTER__ with the current counter number */
|
||||
if (IS_Get (&Standard) < STD_CC65) {
|
||||
PPWarning ("__COUNTER__ is a cc65 extension");
|
||||
}
|
||||
SB_Printf (&M->Replacement, "%u", GetCurrentCounter ());
|
||||
} else if (strcmp (Name, "__LINE__") == 0) {
|
||||
/* Replace __LINE__ with the current line number */
|
||||
SB_Printf (&M->Replacement, "%u", GetCurrentLine ());
|
||||
} else if (strcmp (Name, "__FILE__") == 0) {
|
||||
|
||||
@@ -91,7 +91,7 @@ void DonePreprocess (void);
|
||||
/* Done with preprocessor */
|
||||
|
||||
void HandleSpecialMacro (Macro* M, const char* Name);
|
||||
/* Handle special mandatory macros */
|
||||
/* Handle special "magic" macros that may change */
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user