Add __DATE__ and __TIME__ defines

This commit is contained in:
drmortalwombat 2024-02-04 10:45:02 +01:00
parent 7d6eb36ee7
commit f498da5e42
3 changed files with 44 additions and 1 deletions

View File

@ -151,6 +151,7 @@ const char* TokenNames[] =
"'#embed'",
"'#for'",
"'##'",
"'#string'",
"'namespace'",
"'using'",
@ -750,6 +751,30 @@ void Scanner::NextPreToken(void)
mOffset++;
}
}
else if (mToken == TK_PREP_IDENT)
{
Macro* def = nullptr;
if (mDefineArguments)
def = mDefineArguments->Lookup(mTokenIdent);
if (!def)
def = mDefines->Lookup(mTokenIdent);
if (def)
{
if (def->mNumArguments == -1)
{
mToken = TK_STRING;
int i = 0;
while (mTokenString[i] = def->mString[i])
i++;
return;
}
else
mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Invalid preprocessor command", mTokenIdent);
}
else
mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Invalid preprocessor command", mTokenIdent);
}
else if (mToken == TK_PREP_UNDEF)
{
NextRawToken();
@ -1414,7 +1439,10 @@ void Scanner::NextRawToken(void)
else if (!strcmp(tkprep, "for"))
mToken = TK_PREP_FOR;
else
mErrors->Error(mLocation, EERR_INVALID_PREPROCESSOR, "Invalid preprocessor command", tkprep);
{
mToken = TK_PREP_IDENT;
mTokenIdent = Ident::Unique(tkprep);
}
}
else
{

View File

@ -150,6 +150,7 @@ enum Token
TK_PREP_FOR,
TK_PREP_CONCAT,
TK_PREP_IDENT,
TK_NAMESPACE,
TK_USING,

View File

@ -9,6 +9,7 @@
#endif
#include "Compiler.h"
#include "DiskImage.h"
#include <time.h>
#ifdef _WIN32
bool GetProductAndVersion(char* strProductName, char* strProductVersion)
@ -466,6 +467,19 @@ int main2(int argc, const char** argv)
printf("Starting %s %s\n", strProductName, strProductVersion);
}
{
char dstring[100], tstring[100];
time_t now = time(NULL);
struct tm t;
localtime_s(&t, &now);
strftime(dstring, sizeof(tstring) - 1, "\"%b %d %Y\"", &t);
strftime(tstring, sizeof(dstring) - 1, "\"%H:%M:%S\"", &t);
compiler->AddDefine(Ident::Unique("__DATE__"), dstring);
compiler->AddDefine(Ident::Unique("__TIME__"), tstring);
}
// Add runtime module
if (crtPath[0])