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.");
89 for (
unsigned C = CachedLexPos + N -
CachedTokens.size();
C > 0; --
C) {
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) {
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)
139 assert(CachedLexPos != 0 &&
"Expected to have some cached tokens");
143 CachedLexPos += NewToks.size() - 1;
SourceManager & getSourceManager() const
void ReplacePreviousCachedToken(ArrayRef< Token > NewToks)
Replace token in CachedLexPos - 1 in CachedTokens by the tokens in NewToks.
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.
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
const TemplateArgument * iterator
void Lex(Token &Result)
Lex the next token for this preprocessor.
bool IsPreviousCachedToken(const Token &Tok) const
Whether Tok is the most recent token (CachedLexPos - 1) in CachedTokens.
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.