From f498da5e420c024a784079256f5a61415793db95 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 4 Feb 2024 10:45:02 +0100 Subject: [PATCH] Add __DATE__ and __TIME__ defines --- oscar64/Scanner.cpp | 30 +++++++++++++++++++++++++++++- oscar64/Scanner.h | 1 + oscar64/oscar64.cpp | 14 ++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/oscar64/Scanner.cpp b/oscar64/Scanner.cpp index d13cd48..df2ca5a 100644 --- a/oscar64/Scanner.cpp +++ b/oscar64/Scanner.cpp @@ -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 { diff --git a/oscar64/Scanner.h b/oscar64/Scanner.h index ccf7149..45bc4a2 100644 --- a/oscar64/Scanner.h +++ b/oscar64/Scanner.h @@ -150,6 +150,7 @@ enum Token TK_PREP_FOR, TK_PREP_CONCAT, + TK_PREP_IDENT, TK_NAMESPACE, TK_USING, diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index be8b2dd..c28fc98 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -9,6 +9,7 @@ #endif #include "Compiler.h" #include "DiskImage.h" +#include #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])