]> granicus.if.org Git - clang/commitdiff
Change the Lexer ctor used in the non _Pragma case to take a FileID instead
authorChris Lattner <sabre@nondot.org>
Sat, 17 Jan 2009 08:03:42 +0000 (08:03 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 17 Jan 2009 08:03:42 +0000 (08:03 +0000)
of a SourceLocation.  This should speed it up and definitely simplifies it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62422 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/Lexer.h
lib/Lex/Lexer.cpp
lib/Lex/PPLexerChange.cpp

index ff89e8197d9e341c3e6bb26d08d140c8764fd533..00cf68eff5373f558ac439f94dd9c8be2e6bc673 100644 (file)
@@ -77,7 +77,7 @@ public:
   /// with the specified preprocessor managing the lexing process.  This lexer
   /// assumes that the associated file buffer and Preprocessor objects will
   /// outlive it, so it doesn't take ownership of either of them.
-  Lexer(SourceLocation FileLoc, Preprocessor &PP);
+  Lexer(FileID FID, Preprocessor &PP);
   Lexer(SourceLocation FileLoc, Preprocessor &PP,
         const char *BufStart, const char *BufEnd);
   
index c379f58b0c6c8c5b5812deb2ddcfc9d2a349416d..772a4d9684ddbac501a28e67705cb94635ea411e 100644 (file)
@@ -94,17 +94,12 @@ void Lexer::InitLexer(const char *BufStart, const char *BufPtr,
 /// with the specified preprocessor managing the lexing process.  This lexer
 /// assumes that the associated file buffer and Preprocessor objects will
 /// outlive it, so it doesn't take ownership of either of them.
-Lexer::Lexer(SourceLocation fileloc, Preprocessor &PP)
-// FIXME: This is really horrible and only needed for _Pragma lexers, split this
-// out of the main lexer path!
-: PreprocessorLexer(&PP, 
-                    PP.getSourceManager().getCanonicalFileID(
-                               PP.getSourceManager().getSpellingLoc(fileloc))),
-  FileLoc(fileloc),
-  Features(PP.getLangOptions()) {
+Lexer::Lexer(FileID FID, Preprocessor &PP)
+  : PreprocessorLexer(&PP, FID),
+    FileLoc(PP.getSourceManager().getLocForStartOfFile(FID)),
+    Features(PP.getLangOptions()) {
   
-  SourceManager &SourceMgr = PP.getSourceManager();
-  const llvm::MemoryBuffer *InputFile = SourceMgr.getBuffer(getFileID());
+  const llvm::MemoryBuffer *InputFile = PP.getSourceManager().getBuffer(FID);
   
   InitLexer(InputFile->getBufferStart(), InputFile->getBufferStart(),
             InputFile->getBufferEnd());
@@ -124,7 +119,7 @@ Lexer::Lexer(SourceLocation fileloc, Preprocessor &PP,
   : PreprocessorLexer(&PP, 
                       PP.getSourceManager().getCanonicalFileID(
                       PP.getSourceManager().getSpellingLoc(fileloc))),
-                      FileLoc(fileloc),
+    FileLoc(fileloc),
     Features(PP.getLangOptions()) {
       
   InitLexer(PP.getSourceManager().getBuffer(getFileID())->getBufferStart(),
index cc8ccc4c107878e7fe6b75d7b7fd402292d569a1..60d42386d7a0ca12787960bde0f73faef9ceed3d 100644 (file)
@@ -74,16 +74,10 @@ void Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir) {
     MaxIncludeStackDepth = IncludeMacroStack.size();
 
   if (PTH) {
-    PTHLexer *PL = PTH->CreateLexer(FID, SourceMgr.getFileEntryForID(FID));
-
-    if (PL) {
-      EnterSourceFileWithPTH(PL, CurDir);
-      return;
-    }
+    if (PTHLexer *PL = PTH->CreateLexer(FID, SourceMgr.getFileEntryForID(FID)))
+      return EnterSourceFileWithPTH(PL, CurDir);
   }
-  
-  Lexer *TheLexer = new Lexer(SourceMgr.getLocForStartOfFile(FID), *this);
-  EnterSourceFileWithLexer(TheLexer, CurDir);
+  EnterSourceFileWithLexer(new Lexer(FID, *this), CurDir);
 }  
 
 /// EnterSourceFileWithLexer - Add a source file to the top of the include stack