//===--------------------------------------------------------------------===//
// 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())
}
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.
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() {