15#ifndef LLVM_CLANG_LIB_FORMAT_FORMATTOKENSOURCE_H
16#define LLVM_CLANG_LIB_FORMAT_FORMATTOKENSOURCE_H
20#define DEBUG_TYPE "format-token-source"
81 }
while (Tok->
is(tok::comment));
89 : Tokens(Tokens), Position(-1) {}
92 if (Position >= 0 &&
isEOF()) {
94 llvm::dbgs() <<
"Next ";
97 return Tokens[Position];
99 Position = successor(Position);
101 llvm::dbgs() <<
"Next ";
104 return Tokens[Position];
108 assert(Position <= 0 || Tokens[Position - 1]->isNot(tok::eof));
109 return Position > 0 ? Tokens[Position - 1] :
nullptr;
114 return Tokens[Position];
115 int Next = successor(Position);
117 while (Tokens[Next]->is(tok::comment))
118 Next = successor(Next);
120 llvm::dbgs() <<
"Peeking ";
127 return Position == -1 ?
false : Tokens[Position]->is(tok::eof);
131 LLVM_DEBUG(llvm::dbgs() <<
"Getting Position: " << Position <<
"\n");
132 assert(Position >= 0);
137 LLVM_DEBUG(llvm::dbgs() <<
"Setting Position: " <<
P <<
"\n");
139 return Tokens[Position];
143 assert(Position != -1);
144 assert((*New.rbegin())->Tok.is(tok::eof));
145 int Next = Tokens.size();
146 Tokens.append(New.begin(), New.end());
148 llvm::dbgs() <<
"Inserting:\n";
149 for (
int I = Next,
E = Tokens.size(); I !=
E; ++I)
151 llvm::dbgs() <<
" Jump from: " << (Tokens.size() - 1) <<
" -> "
154 Jumps[Tokens.size() - 1] = Position;
157 llvm::dbgs() <<
"At inserted token ";
160 return Tokens[Position];
166 int successor(
int Current)
const {
167 int Next = Current + 1;
168 auto it = Jumps.find(Next);
169 if (it != Jumps.end()) {
171 assert(!Jumps.contains(Next));
176 void dbgToken(
int Position, StringRef Indent =
"") {
177 FormatToken *Tok = Tokens[Position];
178 llvm::dbgs() << Indent <<
"[" << Position
179 <<
"] Token: " << Tok->Tok.getName() <<
" / " << Tok->TokenText
180 <<
", Macro: " << !!Tok->MacroCtx <<
"\n";
183 SmallVector<FormatToken *> Tokens;
188 llvm::DenseMap<int, int> Jumps;
195 : Line(Line), TokenSource(TokenSource), ResetToken(ResetToken),
196 PreviousLineLevel(Line.Level), PreviousTokenSource(TokenSource),
197 Token(nullptr), PreviousToken(nullptr) {
202 Line.InPPDirective =
true;
207 TokenSource = PreviousTokenSource;
211 Line.
Level = PreviousLineLevel;
218 PreviousToken =
Token;
235 bool isEOF()
override {
return PreviousTokenSource->
isEOF(); }
240 PreviousToken =
nullptr;
246 llvm_unreachable(
"Cannot insert tokens while parsing a macro.");
259 FormatTokenSource *&TokenSource;
260 FormatToken *&ResetToken;
261 unsigned PreviousLineLevel;
262 FormatTokenSource *PreviousTokenSource;
265 FormatToken *PreviousToken;
This file contains the declaration of the UnwrappedLineParser, which turns a stream of tokens into Un...
Token - This structure provides full information about a lexed token.
void setKind(tok::TokenKind K)
void startToken()
Reset all flags to cleared.
The JSON file list parser is used to communicate input to InstallAPI.