16 using namespace clang;
27 BacktrackPositions.push_back(CachedLexPos);
28 EnterCachingLexMode();
33 assert(!BacktrackPositions.empty()
34 &&
"EnableBacktrackAtThisPos was not called!");
35 BacktrackPositions.pop_back();
40 auto PrevCachedLexPos = BacktrackPositions.back();
45 assert(TokenRange.
Begin <= TokenRange.
End);
46 if (CachedLexPos == TokenRange.
Begin && TokenRange.
Begin != TokenRange.
End) {
49 assert(!CachedTokenRangeToErase);
50 CachedTokenRangeToErase = TokenRange;
54 assert(TokenRange.
End == CachedLexPos);
57 CachedLexPos = TokenRange.
Begin;
64 assert(!BacktrackPositions.empty()
65 &&
"EnableBacktrackAtThisPos was not called!");
66 CachedLexPos = BacktrackPositions.back();
67 BacktrackPositions.pop_back();
71 void Preprocessor::CachingLex(
Token &Result) {
72 if (!InCachingLexMode())
79 if (CachedTokenRangeToErase &&
80 CachedTokenRangeToErase->End == CachedLexPos) {
82 CachedTokenRangeToErase =
None;
92 EnterCachingLexMode();
99 EnterCachingLexMode();
107 void Preprocessor::EnterCachingLexMode() {
108 if (InCachingLexMode())
111 PushIncludeMacroStack();
112 CurLexerKind = CLK_CachingLexer;
116 const Token &Preprocessor::PeekAhead(
unsigned N) {
117 assert(CachedLexPos + N >
CachedTokens.size() &&
"Confused caching.");
118 ExitCachingLexMode();
119 for (
size_t C = CachedLexPos + N -
CachedTokens.size();
C > 0; --
C) {
123 EnterCachingLexMode();
127 void Preprocessor::AnnotatePreviousCachedTokens(
const Token &Tok) {
128 assert(Tok.
isAnnotation() &&
"Expected annotation token");
129 assert(CachedLexPos != 0 &&
"Expected to have some cached tokens");
131 &&
"The annotation should be until the most recent cached token");
135 for (CachedTokensTy::size_type i = CachedLexPos; i != 0; --i) {
136 CachedTokensTy::iterator AnnotBegin =
CachedTokens.begin() + i-1;
137 if (AnnotBegin->getLocation() == Tok.
getLocation()) {
138 assert((BacktrackPositions.empty() || BacktrackPositions.back() <= i) &&
139 "The backtrack pos points inside the annotated tokens!");
141 if (i < CachedLexPos)
169 assert(CachedLexPos != 0 &&
"Expected to have some cached tokens");
173 CachedLexPos += NewToks.size() - 1;
SourceManager & getSourceManager() const
void ReplacePreviousCachedToken(ArrayRef< Token > NewToks)
Replace token in CachedLexPos - 1 in CachedTokens by the tokens in NewToks.
CachedTokensTy::size_type End
SourceLocation getLastCachedTokenLocation() const
Get the location of the last cached token, suitable for setting the end location of an annotation tok...
Token - This structure provides full information about a lexed token.
CachedTokensTy::size_type Begin
void CommitBacktrackedTokens()
Disable the last EnableBacktrackAtThisPos call.
tok::TokenKind getKind() const
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()
From the point that this method is called, and until CommitBacktrackedTokens() or Backtrack() is call...
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.
void EraseCachedTokens(CachedTokensRange TokenRange)
Erase the range of cached tokens that were lexed since EnableBacktrackAtThisPos() was previously call...
bool IsPreviousCachedToken(const Token &Tok) const
Whether Tok is the most recent token (CachedLexPos - 1) in CachedTokens.
CachedTokensRange LastCachedTokenRange()
Returns the range of cached tokens that were lexed since EnableBacktrackAtThisPos() was previously ca...
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.