diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-07-12 18:49:30 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-07-12 18:49:30 +0000 |
commit | c2924de667fc366075bd2ed5cae2dbc14706b488 (patch) | |
tree | 938ae5075329444ed7b28583031dda8473ac9682 /clang/lib/Lex/PPCaching.cpp | |
parent | ae9da1481a0574de1865d4e510789c4eb857184d (diff) | |
download | bcm5719-llvm-c2924de667fc366075bd2ed5cae2dbc14706b488.tar.gz bcm5719-llvm-c2924de667fc366075bd2ed5cae2dbc14706b488.zip |
If we are past tok::eof and in caching lex mode, avoid caching repeated tok::eofs.
llvm-svn: 108175
Diffstat (limited to 'clang/lib/Lex/PPCaching.cpp')
-rw-r--r-- | clang/lib/Lex/PPCaching.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/clang/lib/Lex/PPCaching.cpp b/clang/lib/Lex/PPCaching.cpp index 20e3b3dd9d8..16fcaa365cb 100644 --- a/clang/lib/Lex/PPCaching.cpp +++ b/clang/lib/Lex/PPCaching.cpp @@ -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() { |