[cfe-commits] r38600 - in /cfe/cfe/trunk: Lex/Preprocessor.cpp include/clang/Lex/Preprocessor.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:23:05 PDT 2007


Author: sabre
Date: Wed Jul 11 11:23:05 2007
New Revision: 38600

URL: http://llvm.org/viewvc/llvm-project?rev=38600&view=rev
Log:
Implement __FILE__

Modified:
    cfe/cfe/trunk/Lex/Preprocessor.cpp
    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=38600&r1=38599&r2=38600&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:05 2007
@@ -434,6 +434,7 @@
 void Preprocessor::RegisterBuiltinMacros() {
   // FIXME: implement them all, including _Pragma.
   Ident__LINE__ = RegisterBuiltinMacro("__LINE__");
+  Ident__FILE__ = RegisterBuiltinMacro("__FILE__");
   Ident__DATE__ = RegisterBuiltinMacro("__DATE__");
   Ident__TIME__ = RegisterBuiltinMacro("__TIME__");
 }
@@ -547,6 +548,9 @@
   char TmpBuffer[100];
   
   
+  Tok.SetIdentifierInfo(0);
+  Tok.ClearFlag(LexerToken::NeedsCleaning);
+  
   if (ITI == Ident__LINE__) {
     // __LINE__ expands to a simple numeric value.
     sprintf(TmpBuffer, "%u", SourceMgr.getLineNumber(Tok.getLocation()));
@@ -554,26 +558,24 @@
     Tok.SetKind(tok::numeric_constant);
     Tok.SetLength(Length);
     Tok.SetLocation(ScratchBuf->getToken(TmpBuffer, Length, Tok.getLocation()));
-    Tok.SetIdentifierInfo(0);
-    Tok.ClearFlag(LexerToken::NeedsCleaning);
+  } else if (ITI == Ident__FILE__) {
+    // FIXME: Escape this correctly.
+    std::string FN = '"' + SourceMgr.getSourceName(Tok.getLocation()) + '"';
+    Tok.SetKind(tok::string_literal);
+    Tok.SetLength(FN.size());
+    Tok.SetLocation(ScratchBuf->getToken(&FN[0], FN.size(), Tok.getLocation()));
   } else if (ITI == Ident__DATE__) {
     if (!DATELoc.isValid())
       ComputeDATE_TIME(DATELoc, TIMELoc, ScratchBuf);
     Tok.SetKind(tok::string_literal);
     Tok.SetLength(strlen("\"Mmm dd yyyy\""));
     Tok.SetLocation(SourceMgr.getInstantiationLoc(DATELoc, Tok.getLocation()));
-    Tok.SetIdentifierInfo(0);
-    Tok.ClearFlag(LexerToken::NeedsCleaning);
-    
   } else if (ITI == Ident__TIME__) {
     if (!TIMELoc.isValid())
       ComputeDATE_TIME(DATELoc, TIMELoc, ScratchBuf);
     Tok.SetKind(tok::string_literal);
     Tok.SetLength(strlen("\"hh:mm:ss\""));
     Tok.SetLocation(SourceMgr.getInstantiationLoc(TIMELoc, Tok.getLocation()));
-    Tok.SetIdentifierInfo(0);
-    Tok.ClearFlag(LexerToken::NeedsCleaning);
-   
   } else {
     assert(0 && "Unknown identifier!");
   }  

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=38600&r1=38599&r2=38600&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 11 11:23:05 2007
@@ -93,7 +93,7 @@
   bool NoCurDirSearch;
   
   /// Identifiers for builtin macros.
-  IdentifierTokenInfo *Ident__LINE__; // __LINE__
+  IdentifierTokenInfo *Ident__LINE__, *Ident__FILE__; // __LINE__, __FILE__
   IdentifierTokenInfo *Ident__DATE__, *Ident__TIME__; // __DATE__, __TIME__
   SourceLocation DATELoc, TIMELoc;
 public:





More information about the cfe-commits mailing list