Skip to content

Commit 7539bcf

Browse files
[clang-format][NFC] AlignTokenSequence: Rename Changes[i] to CurrentC…
…hange To improve debugging experience.
1 parent b4a076a commit 7539bcf

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
307307
SmallVector<unsigned, 16> ScopeStack;
308308

309309
for (unsigned i = Start; i != End; ++i) {
310+
auto &CurrentChange = Changes[i];
310311
if (ScopeStack.size() != 0 &&
311-
Changes[i].indentAndNestingLevel() <
312+
CurrentChange.indentAndNestingLevel() <
312313
Changes[ScopeStack.back()].indentAndNestingLevel()) {
313314
ScopeStack.pop_back();
314315
}
@@ -320,42 +321,42 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
320321
Changes[PreviousNonComment].Tok->is(tok::comment)) {
321322
--PreviousNonComment;
322323
}
323-
if (i != Start && Changes[i].indentAndNestingLevel() >
324+
if (i != Start && CurrentChange.indentAndNestingLevel() >
324325
Changes[PreviousNonComment].indentAndNestingLevel()) {
325326
ScopeStack.push_back(i);
326327
}
327328

328329
bool InsideNestedScope = ScopeStack.size() != 0;
329330
bool ContinuedStringLiteral = i > Start &&
330-
Changes[i].Tok->is(tok::string_literal) &&
331+
CurrentChange.Tok->is(tok::string_literal) &&
331332
Changes[i - 1].Tok->is(tok::string_literal);
332333
bool SkipMatchCheck = InsideNestedScope || ContinuedStringLiteral;
333334

334-
if (Changes[i].NewlinesBefore > 0 && !SkipMatchCheck) {
335+
if (CurrentChange.NewlinesBefore > 0 && !SkipMatchCheck) {
335336
Shift = 0;
336337
FoundMatchOnLine = false;
337338
}
338339

339340
// If this is the first matching token to be aligned, remember by how many
340341
// spaces it has to be shifted, so the rest of the changes on the line are
341342
// shifted by the same amount
342-
if (!FoundMatchOnLine && !SkipMatchCheck && Matches(Changes[i])) {
343+
if (!FoundMatchOnLine && !SkipMatchCheck && Matches(CurrentChange)) {
343344
FoundMatchOnLine = true;
344-
Shift = Column - (RightJustify ? Changes[i].TokenLength : 0) -
345-
Changes[i].StartOfTokenColumn;
346-
Changes[i].Spaces += Shift;
345+
Shift = Column - (RightJustify ? CurrentChange.TokenLength : 0) -
346+
CurrentChange.StartOfTokenColumn;
347+
CurrentChange.Spaces += Shift;
347348
// FIXME: This is a workaround that should be removed when we fix
348349
// http://llvm.org/PR53699. An assertion later below verifies this.
349-
if (Changes[i].NewlinesBefore == 0) {
350-
Changes[i].Spaces =
351-
std::max(Changes[i].Spaces,
352-
static_cast<int>(Changes[i].Tok->SpacesRequiredBefore));
350+
if (CurrentChange.NewlinesBefore == 0) {
351+
CurrentChange.Spaces =
352+
std::max(CurrentChange.Spaces,
353+
static_cast<int>(CurrentChange.Tok->SpacesRequiredBefore));
353354
}
354355
}
355356

356357
// This is for function parameters that are split across multiple lines,
357358
// as mentioned in the ScopeStack comment.
358-
if (InsideNestedScope && Changes[i].NewlinesBefore > 0) {
359+
if (InsideNestedScope && CurrentChange.NewlinesBefore > 0) {
359360
unsigned ScopeStart = ScopeStack.back();
360361
auto ShouldShiftBeAdded = [&] {
361362
// Function declaration
@@ -378,47 +379,47 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
378379
TT_TemplateCloser) &&
379380
Changes[ScopeStart - 1].Tok->is(tok::l_paren) &&
380381
Changes[ScopeStart].Tok->isNot(TT_LambdaLSquare)) {
381-
if (Changes[i].Tok->MatchingParen &&
382-
Changes[i].Tok->MatchingParen->is(TT_LambdaLBrace)) {
382+
if (CurrentChange.Tok->MatchingParen &&
383+
CurrentChange.Tok->MatchingParen->is(TT_LambdaLBrace)) {
383384
return false;
384385
}
385386
if (Changes[ScopeStart].NewlinesBefore > 0)
386387
return false;
387-
if (Changes[i].Tok->is(tok::l_brace) &&
388-
Changes[i].Tok->is(BK_BracedInit)) {
388+
if (CurrentChange.Tok->is(tok::l_brace) &&
389+
CurrentChange.Tok->is(BK_BracedInit)) {
389390
return true;
390391
}
391392
return Style.BinPackArguments;
392393
}
393394

394395
// Ternary operator
395-
if (Changes[i].Tok->is(TT_ConditionalExpr))
396+
if (CurrentChange.Tok->is(TT_ConditionalExpr))
396397
return true;
397398

398399
// Period Initializer .XXX = 1.
399-
if (Changes[i].Tok->is(TT_DesignatedInitializerPeriod))
400+
if (CurrentChange.Tok->is(TT_DesignatedInitializerPeriod))
400401
return true;
401402

402403
// Continued ternary operator
403-
if (Changes[i].Tok->Previous &&
404-
Changes[i].Tok->Previous->is(TT_ConditionalExpr)) {
404+
if (CurrentChange.Tok->Previous &&
405+
CurrentChange.Tok->Previous->is(TT_ConditionalExpr)) {
405406
return true;
406407
}
407408

408409
// Continued direct-list-initialization using braced list.
409410
if (ScopeStart > Start + 1 &&
410411
Changes[ScopeStart - 2].Tok->is(tok::identifier) &&
411412
Changes[ScopeStart - 1].Tok->is(tok::l_brace) &&
412-
Changes[i].Tok->is(tok::l_brace) &&
413-
Changes[i].Tok->is(BK_BracedInit)) {
413+
CurrentChange.Tok->is(tok::l_brace) &&
414+
CurrentChange.Tok->is(BK_BracedInit)) {
414415
return true;
415416
}
416417

417418
// Continued braced list.
418419
if (ScopeStart > Start + 1 &&
419420
Changes[ScopeStart - 2].Tok->isNot(tok::identifier) &&
420421
Changes[ScopeStart - 1].Tok->is(tok::l_brace) &&
421-
Changes[i].Tok->isNot(tok::r_brace)) {
422+
CurrentChange.Tok->isNot(tok::r_brace)) {
422423
for (unsigned OuterScopeStart : llvm::reverse(ScopeStack)) {
423424
// Lambda.
424425
if (OuterScopeStart > Start &&
@@ -439,26 +440,26 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
439440
};
440441

441442
if (ShouldShiftBeAdded())
442-
Changes[i].Spaces += Shift;
443+
CurrentChange.Spaces += Shift;
443444
}
444445

445446
if (ContinuedStringLiteral)
446-
Changes[i].Spaces += Shift;
447+
CurrentChange.Spaces += Shift;
447448

448449
// We should not remove required spaces unless we break the line before.
449450
assert(Shift >= 0 || Changes[i].NewlinesBefore > 0 ||
450-
Changes[i].Spaces >=
451+
CurrentChange.Spaces >=
451452
static_cast<int>(Changes[i].Tok->SpacesRequiredBefore) ||
452-
Changes[i].Tok->is(tok::eof));
453+
CurrentChange.Tok->is(tok::eof));
453454

454-
Changes[i].StartOfTokenColumn += Shift;
455+
CurrentChange.StartOfTokenColumn += Shift;
455456
if (i + 1 != Changes.size())
456457
Changes[i + 1].PreviousEndOfTokenColumn += Shift;
457458

458459
// If PointerAlignment is PAS_Right, keep *s or &s next to the token
459460
if ((Style.PointerAlignment == FormatStyle::PAS_Right ||
460461
Style.ReferenceAlignment == FormatStyle::RAS_Right) &&
461-
Changes[i].Spaces != 0) {
462+
CurrentChange.Spaces != 0) {
462463
const bool ReferenceNotRightAligned =
463464
Style.ReferenceAlignment != FormatStyle::RAS_Right &&
464465
Style.ReferenceAlignment != FormatStyle::RAS_Pointer;

0 commit comments

Comments
 (0)