mirror of
https://github.com/cc65/cc65.git
synced 2024-11-19 06:31:31 +00:00
Fixed __FILE__ and __LINE__ macros for preprocessor.
This commit is contained in:
parent
8605393953
commit
0063f73f8a
@ -396,6 +396,10 @@ void Compile (const char* FileName)
|
||||
DefineNumericMacro ("__EAGERLY_INLINE_FUNCS__", 1);
|
||||
}
|
||||
|
||||
/* Placeholders for __FILE__ and __LINE__ macros */
|
||||
DefineTextMacro ("__FILE__", "");
|
||||
DefineTextMacro ("__LINE__", "");
|
||||
|
||||
/* __TIME__ and __DATE__ macros */
|
||||
Time = time (0);
|
||||
TM = localtime (&Time);
|
||||
|
@ -42,6 +42,7 @@
|
||||
|
||||
/* cc65 */
|
||||
#include "error.h"
|
||||
#include "preproc.h"
|
||||
#include "macrotab.h"
|
||||
|
||||
|
||||
@ -246,6 +247,10 @@ Macro* FindMacro (const char* Name)
|
||||
Macro* M = MacroTab[Hash];
|
||||
while (M) {
|
||||
if (strcmp (M->Name, Name) == 0) {
|
||||
/* Check for some special macro names */
|
||||
if (Name[0] == '_') {
|
||||
HandleSpecialMacro (M, Name);
|
||||
}
|
||||
/* Found it */
|
||||
return M;
|
||||
}
|
||||
|
@ -1533,6 +1533,24 @@ static int ParseDirectives (unsigned ModeFlags)
|
||||
|
||||
|
||||
|
||||
void HandleSpecialMacro (Macro* M, const char* Name)
|
||||
/* Handle special mandatory macros */
|
||||
{
|
||||
if (strcmp (Name, "__LINE__") == 0) {
|
||||
/* Replace __LINE__ with the current line number */
|
||||
SB_Printf (&M->Replacement, "%u", GetCurrentLine ());
|
||||
} else if (strcmp (Name, "__FILE__") == 0) {
|
||||
/* Replace __FILE__ with the current filename */
|
||||
StrBuf B = AUTO_STRBUF_INITIALIZER;
|
||||
SB_InitFromString (&B, GetCurrentFile ());
|
||||
SB_Clear (&M->Replacement);
|
||||
Stringize (&B, &M->Replacement);
|
||||
SB_Done (&B);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Preprocessing */
|
||||
/*****************************************************************************/
|
||||
|
@ -38,6 +38,16 @@
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Forwards */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
typedef struct Macro Macro;
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
@ -80,6 +90,9 @@ void InitPreprocess (void);
|
||||
void DonePreprocess (void);
|
||||
/* Done with preprocessor */
|
||||
|
||||
void HandleSpecialMacro (Macro* M, const char* Name);
|
||||
/* Handle special mandatory macros */
|
||||
|
||||
|
||||
|
||||
/* End of preproc.h */
|
||||
|
@ -835,16 +835,7 @@ void NextToken (void)
|
||||
/* No reserved word, check for special symbols */
|
||||
if (token[0] == '_' && token[1] == '_') {
|
||||
/* Special symbols */
|
||||
if (strcmp (token+2, "FILE__") == 0) {
|
||||
NextTok.SVal = AddLiteral (GetCurrentFile());
|
||||
NextTok.Tok = TOK_SCONST;
|
||||
return;
|
||||
} else if (strcmp (token+2, "LINE__") == 0) {
|
||||
NextTok.Tok = TOK_ICONST;
|
||||
NextTok.IVal = GetCurrentLine();
|
||||
NextTok.Type = type_int;
|
||||
return;
|
||||
} else if (strcmp (token+2, "func__") == 0) {
|
||||
if (strcmp (token+2, "func__") == 0) {
|
||||
/* __func__ is only defined in functions */
|
||||
if (CurrentFunc) {
|
||||
NextTok.SVal = AddLiteral (F_GetFuncName (CurrentFunc));
|
||||
|
Loading…
Reference in New Issue
Block a user