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();
72 if (!InCachingLexMode())
79 if (CachedTokenRangeToErase &&
80 CachedTokenRangeToErase->End == CachedLexPos) {
82 CachedTokenRangeToErase =
None;
92 EnterCachingLexMode();
99 EnterCachingLexMode();
107 void Preprocessor::EnterCachingLexMode() {
108 if (InCachingLexMode()) {
109 assert(CurLexerKind == CLK_CachingLexer &&
"Unexpected lexer kind");
113 PushIncludeMacroStack();
114 CurLexerKind = CLK_CachingLexer;
118 const Token &Preprocessor::PeekAhead(
unsigned N) {
119 assert(CachedLexPos + N >
CachedTokens.size() &&
"Confused caching.");
120 ExitCachingLexMode();
125 EnterCachingLexMode();
129 void Preprocessor::AnnotatePreviousCachedTokens(
const Token &
Tok) {
130 assert(Tok.
isAnnotation() &&
"Expected annotation token");
131 assert(CachedLexPos != 0 &&
"Expected to have some cached tokens");
133 &&
"The annotation should be until the most recent cached token");
137 for (CachedTokensTy::size_type i = CachedLexPos; i != 0; --i) {
138 CachedTokensTy::iterator AnnotBegin =
CachedTokens.begin() + i-1;
139 if (AnnotBegin->getLocation() == Tok.
getLocation()) {
140 assert((BacktrackPositions.empty() || BacktrackPositions.back() <= i) &&
141 "The backtrack pos points inside the annotated tokens!");
143 if (i < CachedLexPos)
171 assert(CachedLexPos != 0 &&
"Expected to have some cached tokens");
175 CachedLexPos += NewToks.size() - 1;
void ReplacePreviousCachedToken(ArrayRef< Token > NewToks)
Replace token in CachedLexPos - 1 in CachedTokens by the tokens in NewToks.
CachedTokensTy::size_type End
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
tok::TokenKind getKind() const
SourceLocation getAnnotationEndLoc() const
Token - This structure provides full information about a lexed token.
CachedTokensTy::size_type Begin
void CommitBacktrackedTokens()
Disable the last EnableBacktrackAtThisPos call.
bool IsPreviousCachedToken(const Token &Tok) const
Whether Tok is the most recent token (CachedLexPos - 1) in CachedTokens.
void recomputeCurLexerKind()
Recompute the current lexer kind based on the CurLexer/ 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...
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Defines the clang::Preprocessor interface.
The result type of a method or function.
SourceManager & getSourceManager() const
void Lex(Token &Result)
Lex the next token for this preprocessor.
bool isBacktrackEnabled() const
True if EnableBacktrackAtThisPos() was called and caching of tokens is on.
Dataflow Directional Tag Classes.
SourceLocation getLastCachedTokenLocation() const
Get the location of the last cached token, suitable for setting the end location of an annotation tok...
void EraseCachedTokens(CachedTokensRange TokenRange)
Erase the range of cached tokens that were lexed since EnableBacktrackAtThisPos() was previously call...
CachedTokensRange LastCachedTokenRange()
Returns the range of cached tokens that were lexed since EnableBacktrackAtThisPos() was previously ca...