aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/PPLexerChange.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-07-09 22:46:46 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-07-09 22:46:46 +0000
commit9e0ed0bd5a3a7bac73973980ff32132a7724e674 (patch)
tree5d270e415040308a46ac31f70d708996e840580d /lib/Lex/PPLexerChange.cpp
parenta80e448eb2ebe10df43f77b9c8bf47fdf84274da (diff)
Add Preprocessor::LookNext method, which implements an efficient way to 'take a peek' at the next token without consuming it.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53375 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/PPLexerChange.cpp')
-rw-r--r--lib/Lex/PPLexerChange.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp
index c15675114d..bef522e346 100644
--- a/lib/Lex/PPLexerChange.cpp
+++ b/lib/Lex/PPLexerChange.cpp
@@ -85,6 +85,10 @@ Token Preprocessor::LookAhead(unsigned N) {
// size we new to a multiple of 16 tokens. If the previous buffer has space
// left, we can just grow it. This means we only have to do the new 1/16th as
// often.
+
+ // Optimized LookAhead(0) case.
+ if (N == 0)
+ return LookNext();
Token *LookaheadTokens = new Token[N+1];
@@ -122,6 +126,28 @@ Token Preprocessor::LookAhead(unsigned N) {
return Tok;
}
+/// PeekToken - Lexes one token into PeekedToken and pushes CurLexer,
+/// CurLexerToken into the IncludeMacroStack before setting them to null.
+void Preprocessor::PeekToken() {
+ Lex(PeekedToken);
+ // Cache the current Lexer, TokenLexer and set them both to null.
+ // When Lex() is called, PeekedToken will be "consumed".
+ IncludeMacroStack.push_back(IncludeStackInfo(CurLexer, CurDirLookup,
+ CurTokenLexer));
+ CurLexer = 0;
+ CurTokenLexer = 0;
+}
+
+/// ConsumedPeekedToken - Called when Lex() is about to return the PeekedToken
+/// and have it "consumed".
+void Preprocessor::ConsumedPeekedToken() {
+ assert(PeekedToken.getLocation().isValid() && "Confused Peeking?");
+ // Restore CurLexer, TokenLexer.
+ RemoveTopOfLexerStack();
+ // Make PeekedToken invalid.
+ PeekedToken.startToken();
+}
+
//===----------------------------------------------------------------------===//
// Methods for Entering and Callbacks for leaving various contexts