26 assert(LexLevel == 0 &&
"cannot use lookahead while lexing");
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();
49 if (!InCachingLexMode())
53 assert(LexLevel == 1 &&
54 "should not use token caching within the preprocessor");
67 EnterCachingLexModeUnchecked();
74 EnterCachingLexModeUnchecked();
82void Preprocessor::EnterCachingLexMode() {
87 assert(LexLevel == 0 &&
88 "entered caching lex mode while lexing something else");
90 if (InCachingLexMode()) {
91 assert(CurLexerCallback == CLK_CachingLexer &&
"Unexpected lexer kind");
95 EnterCachingLexModeUnchecked();
98void Preprocessor::EnterCachingLexModeUnchecked() {
99 assert(CurLexerCallback != CLK_CachingLexer &&
"already in caching lex mode");
100 PushIncludeMacroStack();
101 CurLexerCallback = CLK_CachingLexer;
105const Token &Preprocessor::PeekAhead(
unsigned N) {
106 assert(CachedLexPos + N >
CachedTokens.size() &&
"Confused caching.");
107 ExitCachingLexMode();
112 EnterCachingLexMode();
116void Preprocessor::AnnotatePreviousCachedTokens(
const Token &Tok) {
117 assert(Tok.
isAnnotation() &&
"Expected annotation token");
118 assert(CachedLexPos != 0 &&
"Expected to have some cached tokens");
120 &&
"The annotation should be until the most recent cached token");
124 for (CachedTokensTy::size_type i = CachedLexPos; i != 0; --i) {
125 CachedTokensTy::iterator AnnotBegin =
CachedTokens.begin() + i-1;
126 if (AnnotBegin->getLocation() == Tok.
getLocation()) {
127 assert((BacktrackPositions.empty() || BacktrackPositions.back() <= i) &&
128 "The backtrack pos points inside the annotated tokens!");
130 if (i < CachedLexPos)
158 assert(CachedLexPos != 0 &&
"Expected to have some cached tokens");
162 CachedLexPos += NewToks.size() - 1;
Defines the clang::Preprocessor interface.
bool IsPreviousCachedToken(const Token &Tok) const
Whether Tok is the most recent token (CachedLexPos - 1) in CachedTokens.
void CommitBacktrackedTokens()
Disable the last EnableBacktrackAtThisPos call.
void Lex(Token &Result)
Lex the next token for this preprocessor.
void Backtrack()
Make Preprocessor re-lex the tokens that were lexed since EnableBacktrackAtThisPos() was previously c...
SourceManager & getSourceManager() const
bool isBacktrackEnabled() const
True if EnableBacktrackAtThisPos() was called and caching of tokens is on.
void recomputeCurLexerKind()
Recompute the current lexer kind based on the CurLexer/ CurTokenLexer pointers.
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...
void EnableBacktrackAtThisPos()
From the point that this method is called, and until CommitBacktrackedTokens() or Backtrack() is call...
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
SourceLocation getAnnotationEndLoc() const
tok::TokenKind getKind() const
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
@ Result
The result type of a method or function.