Lines Matching full:token

29 // Call \p Call for each token in the unwrapped line given, passing
30 // the token, its parent and whether it is the first token in the line.
55 forEachToken(Line, [&](FormatToken *Token, FormatToken *Parent, bool First, in addLine()
56 unsigned Level) { add(Token, Parent, First, Level); }); in addLine()
70 // Reconstruct the position of the next \p Token, given its parent \p
72 // is the first token in a given unwrapped line.
73 void MacroCallReconstructor::add(FormatToken *Token, in add() argument
77 llvm::dbgs() << "MCR: Token: " << Token->TokenText << ", Parent: " in add()
80 // In order to be able to find the correct parent in the reconstructed token in add()
82 // given token if it is part of the reconstructed token stream. in add()
91 // The outer macro call will be C(a, {b}), and the hidden token '}' can be in add()
92 // found in the reconstructed token stream of that expansion level. in add()
93 // In the expanded token stream in add()
97 // so we later set the spelled token 'b' as a child of the ','. in add()
98 if (!ActiveExpansions.empty() && Token->MacroCtx && in add()
99 (Token->MacroCtx->Role != MR_Hidden || in add()
100 ActiveExpansions.size() != Token->MacroCtx->ExpandedFrom.size())) { in add()
101 if (/*PassedMacroComma = */ reconstructActiveCallUntil(Token)) in add()
107 if (Token->MacroCtx) { in add()
108 // If this token was generated by a macro call, add the reconstructed in add()
109 // equivalent of the token. in add()
110 reconstruct(Token); in add()
113 appendToken(Token); in add()
127 // reconstructed replacement token as a parent (when possible) - that is, the
128 // last token in \c ActiveReconstructedLines[ActiveReconstructedLines.size()-2]
164 // If we are at the first token in a new line, we want to also in prepareParent()
179 // If we're not the first token in a new line, pop lines until we find in prepareParent()
191 // For a given \p Parent in the incoming expanded token stream, find the
199 // If we use a different token than the parent in the expanded token stream in getParentInResult()
206 // Reconstruct a \p Token that was expanded from a macro call.
207 void MacroCallReconstructor::reconstruct(FormatToken *Token) { in reconstruct() argument
208 assert(Token->MacroCtx); in reconstruct()
209 // A single token can be the only result of a macro call: in reconstruct()
213 if (Token->MacroCtx->StartOfExpansion) { in reconstruct()
214 startReconstruction(Token); in reconstruct()
215 // If the order of tokens in the expanded token stream is not the in reconstruct()
218 if (Token->MacroCtx->Role != MR_Hidden) in reconstruct()
219 reconstructActiveCallUntil(Token); in reconstruct()
223 assert(ActiveExpansions.size() == Token->MacroCtx->ExpandedFrom.size()); in reconstruct()
224 if (Token->MacroCtx->Role != MR_Hidden) { in reconstruct()
225 // The current token in the reconstructed token stream must be the token in reconstruct()
227 // which initiates the stream to the first token, or after in reconstruct()
228 // continueReconstructionUntil skipped until the expected token in the in reconstruct()
230 assert(ActiveExpansions.back().SpelledI->Tok == Token); in reconstruct()
233 // Map all hidden tokens to the last visible token in the output. in reconstruct()
234 // If the hidden token is a parent, we'll use the last visible in reconstruct()
235 // token as the parent of the hidden token's children. in reconstruct()
236 SpelledParentToReconstructedParent[Token] = in reconstruct()
243 SpelledParentToReconstructedParent[Token] = (*I)->Tokens.back()->Tok; in reconstruct()
249 if (Token->MacroCtx->EndOfExpansion) in reconstruct()
250 endReconstruction(Token); in reconstruct()
253 // Given a \p Token that starts an expansion, reconstruct the beginning of the
258 void MacroCallReconstructor::startReconstruction(FormatToken *Token) { in startReconstruction() argument
259 assert(Token->MacroCtx); in startReconstruction()
260 assert(!Token->MacroCtx->ExpandedFrom.empty()); in startReconstruction()
261 assert(ActiveExpansions.size() <= Token->MacroCtx->ExpandedFrom.size()); in startReconstruction()
263 // Check that the token's reconstruction stack matches our current in startReconstruction()
267 Token->MacroCtx in startReconstruction()
268 ->ExpandedFrom[Token->MacroCtx->ExpandedFrom.size() - 1 - I]); in startReconstruction()
271 // Start reconstruction for all calls for which this token is the first token in startReconstruction()
273 // Note that the token's expanded from stack is inside-to-outside, and the in startReconstruction()
274 // expansions for which this token is not the first are the outermost ones. in startReconstruction()
276 ArrayRef(Token->MacroCtx->ExpandedFrom) in startReconstruction()
278 assert(StartedMacros.size() == Token->MacroCtx->StartOfExpansion); in startReconstruction()
286 // Put the reconstructed macro call's token into our reconstruction stack. in startReconstruction()
303 // given \p Token.
304 bool MacroCallReconstructor::reconstructActiveCallUntil(FormatToken *Token) { in reconstructActiveCallUntil() argument
307 // FIXME: If Token was already expanded earlier, due to in reconstructActiveCallUntil()
311 ActiveExpansions.back().SpelledI->Tok != Token) { in reconstructActiveCallUntil()
317 // End all reconstructions for which \p Token is the final token.
318 void MacroCallReconstructor::endReconstruction(FormatToken *Token) { in endReconstruction() argument
319 assert(Token->MacroCtx && in endReconstruction()
320 (ActiveExpansions.size() >= Token->MacroCtx->EndOfExpansion)); in endReconstruction()
321 for (size_t I = 0; I < Token->MacroCtx->EndOfExpansion; ++I) { in endReconstruction()
328 FormatToken *Token = T->Tok; in endReconstruction() local
331 !Token->MacroCtx && Token->is(tok::r_paren); in endReconstruction()
332 bool TrailingComment = Token->isTrailingComment(); in endReconstruction()
334 Token->MacroCtx && in endReconstruction()
335 (ActiveExpansions.size() < Token->MacroCtx->ExpandedFrom.size()); in endReconstruction()
337 llvm::dbgs() << "At token: " << Token->TokenText << "\n"; in endReconstruction()
385 // If visible, add the next token of the reconstructed token sequence to the
389 FormatToken *Token = ActiveExpansions.back().SpelledI->Tok; in processNextReconstructed() local
391 if (Token->MacroCtx) { in processNextReconstructed()
393 if (Token->MacroCtx->Role == MR_Hidden) in processNextReconstructed()
403 if (ActiveExpansions.size() < Token->MacroCtx->ExpandedFrom.size()) in processNextReconstructed()
408 if (!Token->MacroCtx) { in processNextReconstructed()
413 if (Token->is(tok::l_paren)) { in processNextReconstructed()
415 currentLine(), parentLine().Tokens.back()->Tok, Token)); in processNextReconstructed()
416 // All tokens that are children of the previous line's last token in the in processNextReconstructed()
417 // reconstructed token stream will now be children of the l_paren token. in processNextReconstructed()
422 // <null> parent will then become children of the l_paren token of the in processNextReconstructed()
425 .ParentLastToken] = Token; in processNextReconstructed()
426 appendToken(Token); in processNextReconstructed()
427 prepareParent(Token, /*NewLine=*/true, in processNextReconstructed()
429 Token->MacroParent = true; in processNextReconstructed()
433 if (Token->is(tok::comma)) { in processNextReconstructed()
434 // Make new lines inside the next argument children of the comma token. in processNextReconstructed()
436 [MacroCallStructure.back().Line->Tokens.back()->Tok] = Token; in processNextReconstructed()
437 Token->MacroParent = true; in processNextReconstructed()
438 appendToken(Token, MacroCallStructure.back().Line); in processNextReconstructed()
439 prepareParent(Token, /*NewLine=*/true, in processNextReconstructed()
443 if (Token->is(tok::r_paren)) { in processNextReconstructed()
444 appendToken(Token, MacroCallStructure.back().Line); in processNextReconstructed()
456 // 'b' will be part of the reconstructed token stream, but tagged MR_None. in processNextReconstructed()
458 // pushing the (unformatted) token. in processNextReconstructed()
461 appendToken(Token); in processNextReconstructed()
472 // the the toplevel null token. in finalize()
482 // Every subsequent line will become a child of the last token in the previous in finalize()
483 // line, which is the token prior to the first token in the line. in finalize()
490 // Mark the previous line's last token as generated by a macro expansion in finalize()
499 void MacroCallReconstructor::appendToken(FormatToken *Token, in appendToken() argument
502 LLVM_DEBUG(llvm::dbgs() << "-> " << Token->TokenText << "\n"); in appendToken()
503 L->Tokens.push_back(std::make_unique<LineNode>(Token)); in appendToken()