15 using namespace clang;
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();
82 void Preprocessor::EnterCachingLexMode() {
87 assert(LexLevel == 0 &&
88 "entered caching lex mode while lexing something else");
90 if (InCachingLexMode()) {
91 assert(CurLexerKind == CLK_CachingLexer &&
"Unexpected lexer kind");
95 EnterCachingLexModeUnchecked();
98 void Preprocessor::EnterCachingLexModeUnchecked() {
99 assert(CurLexerKind != CLK_CachingLexer &&
"already in caching lex mode");
100 PushIncludeMacroStack();
101 CurLexerKind = CLK_CachingLexer;
105 const Token &Preprocessor::PeekAhead(
unsigned N) {
106 assert(CachedLexPos + N >
CachedTokens.size() &&
"Confused caching.");
107 ExitCachingLexMode();
112 EnterCachingLexMode();
116 void 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;
void ReplacePreviousCachedToken(ArrayRef< Token > NewToks)
Replace token in CachedLexPos - 1 in CachedTokens by the tokens in NewToks.
void setFlag(TokenFlags Flag)
Set the specified flag.
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.
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...