[cfe-commits] r38602 - in /cfe/cfe/trunk: Lex/Preprocessor.cpp include/clang/Basic/DiagnosticKinds.def include/clang/Lex/Preprocessor.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:23:06 PDT 2007
Author: sabre
Date: Wed Jul 11 11:23:06 2007
New Revision: 38602
URL: http://llvm.org/viewvc/llvm-project?rev=38602&view=rev
Log:
Implement __TIMESTAMP__
Modified:
cfe/cfe/trunk/Lex/Preprocessor.cpp
cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/cfe/trunk/include/clang/Lex/Preprocessor.h
Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38602&r1=38601&r2=38602&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:06 2007
@@ -31,7 +31,7 @@
//
// TODO: Implement the include guard optimization.
//
-// Predefined Macros: _Pragma, __TIMESTAMP__, ...
+// Predefined Macros: _Pragma, ...
//
//===----------------------------------------------------------------------===//
@@ -441,7 +441,7 @@
// GCC Extensions.
Ident__BASE_FILE__ = RegisterBuiltinMacro("__BASE_FILE__");
Ident__INCLUDE_LEVEL__ = RegisterBuiltinMacro("__INCLUDE_LEVEL__");
- // __TIMESTAMP__
+ Ident__TIMESTAMP__ = RegisterBuiltinMacro("__TIMESTAMP__");
// _Pragma
//Pseudo #defines.
@@ -613,6 +613,37 @@
Tok.SetKind(tok::numeric_constant);
Tok.SetLength(Length);
Tok.SetLocation(ScratchBuf->getToken(TmpBuffer, Length, Tok.getLocation()));
+ } else if (ITI == Ident__TIMESTAMP__) {
+ // MSVC, ICC, GCC, VisualAge C++ extension. The generated string should be
+ // of the form "Ddd Mmm dd hh::mm::ss yyyy", which is returned by asctime.
+ Diag(Tok, diag::ext_pp_timestamp);
+
+ // Get the file that we are lexing out of. If we're currently lexing from
+ // a macro, dig into the include stack.
+ const FileEntry *CurFile = 0;
+ Lexer *TheLexer = CurLexer;
+ if (TheLexer == 0 && !IncludeStack.empty())
+ TheLexer = IncludeStack.back().TheLexer;
+
+ if (TheLexer)
+ CurFile = SourceMgr.getFileEntryForFileID(TheLexer->getCurFileID());
+
+ // If this file is older than the file it depends on, emit a diagnostic.
+ const char *Result;
+ if (CurFile) {
+ time_t TT = CurFile->getModificationTime();
+ struct tm *TM = localtime(&TT);
+ Result = asctime(TM);
+ } else {
+ Result = "??? ??? ?? ??:??:?? ????\n";
+ }
+ TmpBuffer[0] = '"';
+ strcpy(TmpBuffer+1, Result);
+ unsigned Len = strlen(TmpBuffer);
+ TmpBuffer[Len-1] = '"'; // Replace the newline with a quote.
+ Tok.SetKind(tok::string_literal);
+ Tok.SetLength(Len);
+ Tok.SetLocation(ScratchBuf->getToken(TmpBuffer, Len, Tok.getLocation()));
} else {
assert(0 && "Unknown identifier!");
}
Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=38602&r1=38601&r2=38602&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:23:06 2007
@@ -114,6 +114,8 @@
"__BASE_FILE__ is a language extension")
DIAG(ext_pp_include_level, EXTENSION,
"__INCLUDE_LEVEL__ is a language extension")
+DIAG(ext_pp_timestamp, EXTENSION,
+ "__TIMESTAMP__ is a language extension")
DIAG(err_pp_invalid_directive, ERROR,
"invalid preprocessing directive")
Modified: cfe/cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=38602&r1=38601&r2=38602&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 11 11:23:06 2007
@@ -97,6 +97,7 @@
IdentifierTokenInfo *Ident__DATE__, *Ident__TIME__; // __DATE__, __TIME__
IdentifierTokenInfo *Ident__INCLUDE_LEVEL__; // __INCLUDE_LEVEL__
IdentifierTokenInfo *Ident__BASE_FILE__; // __BASE_FILE__
+ IdentifierTokenInfo *Ident__TIMESTAMP__; // __TIMESTAMP__
SourceLocation DATELoc, TIMELoc;
public:
More information about the cfe-commits
mailing list