;
17std::pair<Preprocessor::CachedTokensTy::size_type, bool>
18Preprocessor::LastBacktrackPos() {
20 autoBacktrackPos = BacktrackPositions.back();
22 static_cast<CachedTokensTy::difference_type
>(BacktrackPos) < 0;
23 return{Unannotated ? ~BacktrackPos : BacktrackPos, Unannotated};
35assert(LexLevel == 0 &&
"cannot use lookahead while lexing");
36BacktrackPositions.push_back(Unannotated ? ~CachedLexPos : CachedLexPos);
39EnterCachingLexMode();
44 auto[UnannotatedTokens, NumCachedToks] =
45std::move(UnannotatedBacktrackTokens.back());
46UnannotatedBacktrackTokens.pop_back();
50UnannotatedBacktrackTokens.back().first.append(
51UnannotatedTokens.begin() + NumCachedToks, UnannotatedTokens.end());
52 returnstd::move(UnannotatedTokens);
58 auto[BacktrackPos, Unannotated] = LastBacktrackPos();
59BacktrackPositions.pop_back();
61PopUnannotatedBacktrackTokens();
68 auto[BacktrackPos, Unannotated] = LastBacktrackPos();
69BacktrackPositions.pop_back();
70CachedLexPos = BacktrackPos;
77 if(!InCachingLexMode())
81assert(LexLevel == 1 &&
82 "should not use token caching within the preprocessor");
95EnterCachingLexModeUnchecked();
99UnannotatedBacktrackTokens.back().first.push_back(
Result);
104EnterCachingLexModeUnchecked();
112voidPreprocessor::EnterCachingLexMode() {
117assert(LexLevel == 0 &&
118 "entered caching lex mode while lexing something else");
120 if(InCachingLexMode()) {
121assert(CurLexerCallback == CLK_CachingLexer &&
"Unexpected lexer kind");
125EnterCachingLexModeUnchecked();
128voidPreprocessor::EnterCachingLexModeUnchecked() {
129assert(CurLexerCallback != CLK_CachingLexer &&
"already in caching lex mode");
130PushIncludeMacroStack();
131CurLexerCallback = CLK_CachingLexer;
135const Token&Preprocessor::PeekAhead(
unsignedN) {
136assert(CachedLexPos + N >
CachedTokens.size() &&
"Confused caching.");
137ExitCachingLexMode();
138 for(
size_t C= CachedLexPos + N -
CachedTokens.size();
C> 0; --
C) {
142UnannotatedBacktrackTokens.back().first.push_back(
CachedTokens.back());
144EnterCachingLexMode();
148voidPreprocessor::AnnotatePreviousCachedTokens(
const Token&Tok) {
149assert(Tok.
isAnnotation() &&
"Expected annotation token");
150assert(CachedLexPos != 0 &&
"Expected to have some cached tokens");
152&&
"The annotation should be until the most recent cached token");
156 for(CachedTokensTy::size_type i = CachedLexPos; i != 0; --i) {
157CachedTokensTy::iterator AnnotBegin =
CachedTokens.begin() + i-1;
158 if(AnnotBegin->getLocation() == Tok.
getLocation()) {
160 "The backtrack pos points inside the annotated tokens!");
162 if(i < CachedLexPos)
190assert(CachedLexPos != 0 &&
"Expected to have some cached tokens");
194CachedLexPos += 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.
bool isUnannotatedBacktrackEnabled() const
True if EnableBacktrackAtThisPos() was called and caching of unannotated 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.
void EnableBacktrackAtThisPos(bool Unannotated=false)
From the point that this method is called, and until CommitBacktrackedTokens() or Backtrack() is call...
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.
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.
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4