]> granicus.if.org Git - clang/commitdiff
If we are past tok::eof and in caching lex mode, avoid caching repeated tok::eofs.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 12 Jul 2010 18:49:30 +0000 (18:49 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 12 Jul 2010 18:49:30 +0000 (18:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108175 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/Preprocessor.h
lib/Lex/PPCaching.cpp

index f90cb0a68799d990f990ca36a3fe9231b60fc368..6c9b9fb96e1c4f12a6fb5ebe41d511393e7f1808 100644 (file)
@@ -871,7 +871,11 @@ private:
   //===--------------------------------------------------------------------===//
   // Caching stuff.
   void CachingLex(Token &Result);
-  bool InCachingLexMode() const { return CurPPLexer == 0 && CurTokenLexer == 0;}
+  bool InCachingLexMode() const {
+    // If the Lexer pointers are 0 and IncludeMacroStack is empty, it means
+    // that we are past EOF, not that we are in CachingLex mode.
+    return CurPPLexer == 0 && CurTokenLexer == 0 && !IncludeMacroStack.empty();
+  }
   void EnterCachingLexMode();
   void ExitCachingLexMode() {
     if (InCachingLexMode())
index 20e3b3dd9d8e7bb55e9be064f6e48d51aa57fec9..16fcaa365cb4a5bc911a75be03ea9d15420ba2b6 100644 (file)
@@ -45,13 +45,19 @@ void Preprocessor::Backtrack() {
 }
 
 void Preprocessor::CachingLex(Token &Result) {
+  if (!InCachingLexMode())
+    return;
+
   if (CachedLexPos < CachedTokens.size()) {
     Result = CachedTokens[CachedLexPos++];
     return;
   }
 
   ExitCachingLexMode();
-  Lex(Result);
+  // True if we consumed everything already.
+  bool PastEOF =  CurPPLexer == 0 && CurTokenLexer == 0;
+  if (!PastEOF)
+    Lex(Result);
 
   if (!isBacktrackEnabled()) {
     // All cached tokens were consumed.
@@ -60,10 +66,12 @@ void Preprocessor::CachingLex(Token &Result) {
     return;
   }
 
-  // Cache the lexed token.
+  // Cache the lexed token if it's not a repeated tok::eof.
   EnterCachingLexMode();
-  CachedTokens.push_back(Result);
-  ++CachedLexPos;
+  if (!PastEOF) {
+    CachedTokens.push_back(Result);
+    ++CachedLexPos;
+  }
 }
 
 void Preprocessor::EnterCachingLexMode() {