diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-08-22 21:27:50 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-08-22 21:27:50 +0000 |
| commit | a65490c5df2c9075ba12ef41be4e85d3134550b4 (patch) | |
| tree | fd0371e5ed28062187baa444bfe6d8d57c243a6c /clang/lib/Lex | |
| parent | 9f0d0639cad2cd3fa19425b016c0c5df4a1eac34 (diff) | |
| download | bcm5719-llvm-a65490c5df2c9075ba12ef41be4e85d3134550b4.tar.gz bcm5719-llvm-a65490c5df2c9075ba12ef41be4e85d3134550b4.zip | |
Allow nested backtracks.
llvm-svn: 55204
Diffstat (limited to 'clang/lib/Lex')
| -rw-r--r-- | clang/lib/Lex/PPCaching.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/clang/lib/Lex/PPCaching.cpp b/clang/lib/Lex/PPCaching.cpp index 794e9c4e765..e69eac65ff5 100644 --- a/clang/lib/Lex/PPCaching.cpp +++ b/clang/lib/Lex/PPCaching.cpp @@ -15,6 +15,38 @@ #include "clang/Lex/Preprocessor.h" using namespace clang; +/// EnableBacktrackAtThisPos - From the point that this method is called, and
+/// until DisableBacktrack() or Backtrack() is called, the Preprocessor keeps
+/// track of the lexed tokens so that a subsequent Backtrack() call will make
+/// the Preprocessor re-lex the same tokens.
+///
+/// Nested backtracks are allowed, meaning that EnableBacktrackAtThisPos can
+/// be called multiple times and DisableBacktrack/Backtrack calls will be
+/// combined with the EnableBacktrackAtThisPos calls in reverse order.
+void Preprocessor::EnableBacktrackAtThisPos() {
+ CacheTokens = true;
+ BacktrackPositions.push_back(CachedLexPos);
+ EnterCachingLexMode();
+}
+ +/// DisableBacktrack - Disable the last EnableBacktrackAtThisPos() call.
+void Preprocessor::DisableBacktrack() {
+ assert(!BacktrackPositions.empty()
+ && "EnableBacktrackAtThisPos was not called!");
+ BacktrackPositions.pop_back();
+ CacheTokens = !BacktrackPositions.empty();
+}
+
+/// Backtrack - Make Preprocessor re-lex the tokens that were lexed since
+/// EnableBacktrackAtThisPos() was previously called.
+void Preprocessor::Backtrack() {
+ assert(!BacktrackPositions.empty()
+ && "EnableBacktrackAtThisPos was not called!");
+ CachedLexPos = BacktrackPositions.back();
+ BacktrackPositions.pop_back();
+ CacheTokens = !BacktrackPositions.empty();
+}
+ void Preprocessor::CachingLex(Token &Result) { if (CachedLexPos < CachedTokens.size()) { Result = CachedTokens[CachedLexPos++]; |

