16 using namespace clang;
27 BacktrackPositions.push_back(CachedLexPos);
28 EnterCachingLexMode();
33 assert(!BacktrackPositions.empty()
34 &&
"EnableBacktrackAtThisPos was not called!");
35 BacktrackPositions.pop_back();
41 assert(!BacktrackPositions.empty()
42 &&
"EnableBacktrackAtThisPos was not called!");
43 CachedLexPos = BacktrackPositions.back();
44 BacktrackPositions.pop_back();
48 void Preprocessor::CachingLex(
Token &Result) {
49 if (!InCachingLexMode())
62 EnterCachingLexMode();
69 EnterCachingLexMode();
77 void Preprocessor::EnterCachingLexMode() {
78 if (InCachingLexMode())
81 PushIncludeMacroStack();
82 CurLexerKind = CLK_CachingLexer;
86 const Token &Preprocessor::PeekAhead(
unsigned N) {
87 assert(CachedLexPos + N >
CachedTokens.size() &&
"Confused caching.");
93 EnterCachingLexMode();
97 void Preprocessor::AnnotatePreviousCachedTokens(
const Token &Tok) {
98 assert(Tok.
isAnnotation() &&
"Expected annotation token");
99 assert(CachedLexPos != 0 &&
"Expected to have some cached tokens");
101 &&
"The annotation should be until the most recent cached token");
105 for (CachedTokensTy::size_type i = CachedLexPos; i != 0; --i) {
106 CachedTokensTy::iterator AnnotBegin =
CachedTokens.begin() + i-1;
107 if (AnnotBegin->getLocation() == Tok.
getLocation()) {
108 assert((BacktrackPositions.empty() || BacktrackPositions.back() < i) &&
109 "The backtrack pos points inside the annotated tokens!");
111 if (i < CachedLexPos)
void CommitBacktrackedTokens()
Disable the last EnableBacktrackAtThisPos call.
void recomputeCurLexerKind()
Recompute the current lexer kind based on the CurLexer/CurPTHLexer/ CurTokenLexer pointers...
void Backtrack()
Make Preprocessor re-lex the tokens that were lexed since EnableBacktrackAtThisPos() was previously c...
void EnableBacktrackAtThisPos()
Defines the clang::Preprocessor interface.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
SourceLocation getAnnotationEndLoc() const
void Lex(Token &Result)
Lex the next token for this preprocessor.
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
bool isBacktrackEnabled() const
True if EnableBacktrackAtThisPos() was called and caching of tokens is on.