diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-11-08 16:17:04 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-11-08 16:17:04 +0000 |
commit | c7e67a04c396ff684b5f4478b02f9959ac38635d (patch) | |
tree | 699b58e23b36f9ba347916f5dc9d94c8ed0a0cbe /clang/lib | |
parent | f4485de48ab519b0ae0de434f0aa7ce2d7ec1ce1 (diff) | |
download | bcm5719-llvm-c7e67a04c396ff684b5f4478b02f9959ac38635d.tar.gz bcm5719-llvm-c7e67a04c396ff684b5f4478b02f9959ac38635d.zip |
Introduce annotation tokens, a special kind of token, created and used only by the parser to replace a group of tokens with a single token encoding semantic information.
Will be fully utilized later for C++ nested-name-specifiers.
llvm-svn: 58911
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Lex/PPCaching.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/clang/lib/Lex/PPCaching.cpp b/clang/lib/Lex/PPCaching.cpp index 822b207cdcb..1af79b4ba37 100644 --- a/clang/lib/Lex/PPCaching.cpp +++ b/clang/lib/Lex/PPCaching.cpp @@ -93,3 +93,27 @@ const Token &Preprocessor::PeekAhead(unsigned N) { EnterCachingLexMode(); return CachedTokens.back(); } + +void Preprocessor::AnnotatePreviousCachedTokens(const Token &Tok) { + assert(Tok.isAnnotationToken() && "Expected annotation token"); + assert(CachedLexPos != 0 && "Expected to have some cached tokens"); + assert(CachedTokens[CachedLexPos-1].getLocation() == Tok.getAnnotationEndLoc() + && "The annotation should be until the most recent cached token"); + + // Start from the end of the cached tokens list and look for the token + // that is the beginning of the annotation token. + for (CachedTokensTy::size_type i = CachedLexPos; i != 0; --i) { + CachedTokensTy::iterator AnnotBegin = CachedTokens.begin() + i-1; + if (AnnotBegin->getLocation() == Tok.getLocation()) { + assert((BacktrackPositions.empty() || BacktrackPositions.back() < i) && + "The backtrack pos points inside the annotated tokens!"); + // Replace the cached tokens with the single annotation token. + CachedTokens.erase(AnnotBegin + 1, CachedTokens.begin() + CachedLexPos); + *AnnotBegin = Tok; + CachedLexPos = i; + return; + } + } + + assert(0&&"Didn't find the first token represented by the annotation token!"); +} |