@@ -307,8 +307,9 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
307
307
SmallVector<unsigned , 16 > ScopeStack;
308
308
309
309
for (unsigned i = Start; i != End; ++i) {
310
+ auto &CurrentChange = Changes[i];
310
311
if (ScopeStack.size () != 0 &&
311
- Changes[i] .indentAndNestingLevel () <
312
+ CurrentChange .indentAndNestingLevel () <
312
313
Changes[ScopeStack.back ()].indentAndNestingLevel ()) {
313
314
ScopeStack.pop_back ();
314
315
}
@@ -320,42 +321,42 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
320
321
Changes[PreviousNonComment].Tok ->is (tok::comment)) {
321
322
--PreviousNonComment;
322
323
}
323
- if (i != Start && Changes[i] .indentAndNestingLevel () >
324
+ if (i != Start && CurrentChange .indentAndNestingLevel () >
324
325
Changes[PreviousNonComment].indentAndNestingLevel ()) {
325
326
ScopeStack.push_back (i);
326
327
}
327
328
328
329
bool InsideNestedScope = ScopeStack.size () != 0 ;
329
330
bool ContinuedStringLiteral = i > Start &&
330
- Changes[i] .Tok ->is (tok::string_literal) &&
331
+ CurrentChange .Tok ->is (tok::string_literal) &&
331
332
Changes[i - 1 ].Tok ->is (tok::string_literal);
332
333
bool SkipMatchCheck = InsideNestedScope || ContinuedStringLiteral;
333
334
334
- if (Changes[i] .NewlinesBefore > 0 && !SkipMatchCheck) {
335
+ if (CurrentChange .NewlinesBefore > 0 && !SkipMatchCheck) {
335
336
Shift = 0 ;
336
337
FoundMatchOnLine = false ;
337
338
}
338
339
339
340
// If this is the first matching token to be aligned, remember by how many
340
341
// spaces it has to be shifted, so the rest of the changes on the line are
341
342
// shifted by the same amount
342
- if (!FoundMatchOnLine && !SkipMatchCheck && Matches (Changes[i] )) {
343
+ if (!FoundMatchOnLine && !SkipMatchCheck && Matches (CurrentChange )) {
343
344
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;
347
348
// FIXME: This is a workaround that should be removed when we fix
348
349
// 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 ));
353
354
}
354
355
}
355
356
356
357
// This is for function parameters that are split across multiple lines,
357
358
// as mentioned in the ScopeStack comment.
358
- if (InsideNestedScope && Changes[i] .NewlinesBefore > 0 ) {
359
+ if (InsideNestedScope && CurrentChange .NewlinesBefore > 0 ) {
359
360
unsigned ScopeStart = ScopeStack.back ();
360
361
auto ShouldShiftBeAdded = [&] {
361
362
// Function declaration
@@ -378,47 +379,47 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
378
379
TT_TemplateCloser) &&
379
380
Changes[ScopeStart - 1 ].Tok ->is (tok::l_paren) &&
380
381
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)) {
383
384
return false ;
384
385
}
385
386
if (Changes[ScopeStart].NewlinesBefore > 0 )
386
387
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)) {
389
390
return true ;
390
391
}
391
392
return Style .BinPackArguments ;
392
393
}
393
394
394
395
// Ternary operator
395
- if (Changes[i] .Tok ->is (TT_ConditionalExpr))
396
+ if (CurrentChange .Tok ->is (TT_ConditionalExpr))
396
397
return true ;
397
398
398
399
// Period Initializer .XXX = 1.
399
- if (Changes[i] .Tok ->is (TT_DesignatedInitializerPeriod))
400
+ if (CurrentChange .Tok ->is (TT_DesignatedInitializerPeriod))
400
401
return true ;
401
402
402
403
// 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)) {
405
406
return true ;
406
407
}
407
408
408
409
// Continued direct-list-initialization using braced list.
409
410
if (ScopeStart > Start + 1 &&
410
411
Changes[ScopeStart - 2 ].Tok ->is (tok::identifier) &&
411
412
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)) {
414
415
return true ;
415
416
}
416
417
417
418
// Continued braced list.
418
419
if (ScopeStart > Start + 1 &&
419
420
Changes[ScopeStart - 2 ].Tok ->isNot (tok::identifier) &&
420
421
Changes[ScopeStart - 1 ].Tok ->is (tok::l_brace) &&
421
- Changes[i] .Tok ->isNot (tok::r_brace)) {
422
+ CurrentChange .Tok ->isNot (tok::r_brace)) {
422
423
for (unsigned OuterScopeStart : llvm::reverse (ScopeStack)) {
423
424
// Lambda.
424
425
if (OuterScopeStart > Start &&
@@ -439,26 +440,26 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
439
440
};
440
441
441
442
if (ShouldShiftBeAdded ())
442
- Changes[i] .Spaces += Shift;
443
+ CurrentChange .Spaces += Shift;
443
444
}
444
445
445
446
if (ContinuedStringLiteral)
446
- Changes[i] .Spaces += Shift;
447
+ CurrentChange .Spaces += Shift;
447
448
448
449
// We should not remove required spaces unless we break the line before.
449
450
assert (Shift >= 0 || Changes[i].NewlinesBefore > 0 ||
450
- Changes[i] .Spaces >=
451
+ CurrentChange .Spaces >=
451
452
static_cast <int >(Changes[i].Tok ->SpacesRequiredBefore ) ||
452
- Changes[i] .Tok ->is (tok::eof));
453
+ CurrentChange .Tok ->is (tok::eof));
453
454
454
- Changes[i] .StartOfTokenColumn += Shift;
455
+ CurrentChange .StartOfTokenColumn += Shift;
455
456
if (i + 1 != Changes.size ())
456
457
Changes[i + 1 ].PreviousEndOfTokenColumn += Shift;
457
458
458
459
// If PointerAlignment is PAS_Right, keep *s or &s next to the token
459
460
if ((Style .PointerAlignment == FormatStyle::PAS_Right ||
460
461
Style .ReferenceAlignment == FormatStyle::RAS_Right) &&
461
- Changes[i] .Spaces != 0 ) {
462
+ CurrentChange .Spaces != 0 ) {
462
463
const bool ReferenceNotRightAligned =
463
464
Style .ReferenceAlignment != FormatStyle::RAS_Right &&
464
465
Style .ReferenceAlignment != FormatStyle::RAS_Pointer;
@@ -579,16 +580,17 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
579
580
580
581
unsigned i = StartAt;
581
582
for (unsigned e = Changes.size (); i != e; ++i) {
582
- if (Changes[i].indentAndNestingLevel () < IndentAndNestingLevel)
583
+ auto &CurrentChange = Changes[i];
584
+ if (CurrentChange.indentAndNestingLevel () < IndentAndNestingLevel)
583
585
break ;
584
586
585
- if (Changes[i] .NewlinesBefore != 0 ) {
587
+ if (CurrentChange .NewlinesBefore != 0 ) {
586
588
CommasBeforeMatch = 0 ;
587
589
EndOfSequence = i;
588
590
589
591
// Whether to break the alignment sequence because of an empty line.
590
592
bool EmptyLineBreak =
591
- (Changes[i] .NewlinesBefore > 1 ) && !ACS.AcrossEmptyLines ;
593
+ (CurrentChange .NewlinesBefore > 1 ) && !ACS.AcrossEmptyLines ;
592
594
593
595
// Whether to break the alignment sequence because of a line without a
594
596
// match.
@@ -600,27 +602,27 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
600
602
601
603
// A new line starts, re-initialize line status tracking bools.
602
604
// Keep the match state if a string literal is continued on this line.
603
- if (i == 0 || Changes[i] .Tok ->isNot (tok::string_literal) ||
605
+ if (i == 0 || CurrentChange .Tok ->isNot (tok::string_literal) ||
604
606
Changes[i - 1 ].Tok ->isNot (tok::string_literal)) {
605
607
FoundMatchOnLine = false ;
606
608
}
607
609
LineIsComment = true ;
608
610
}
609
611
610
- if (Changes[i] .Tok ->isNot (tok::comment))
612
+ if (CurrentChange .Tok ->isNot (tok::comment))
611
613
LineIsComment = false ;
612
614
613
- if (Changes[i] .Tok ->is (tok::comma)) {
615
+ if (CurrentChange .Tok ->is (tok::comma)) {
614
616
++CommasBeforeMatch;
615
- } else if (Changes[i] .indentAndNestingLevel () > IndentAndNestingLevel) {
617
+ } else if (CurrentChange .indentAndNestingLevel () > IndentAndNestingLevel) {
616
618
// Call AlignTokens recursively, skipping over this scope block.
617
619
unsigned StoppedAt =
618
620
AlignTokens (Style , Matches, Changes, i, ACS, RightJustify);
619
621
i = StoppedAt - 1 ;
620
622
continue ;
621
623
}
622
624
623
- if (!Matches (Changes[i] ))
625
+ if (!Matches (CurrentChange ))
624
626
continue ;
625
627
626
628
// If there is more than one matching token per line, or if the number of
@@ -634,16 +636,16 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
634
636
if (StartOfSequence == 0 )
635
637
StartOfSequence = i;
636
638
637
- unsigned ChangeWidthLeft = Changes[i] .StartOfTokenColumn ;
639
+ unsigned ChangeWidthLeft = CurrentChange .StartOfTokenColumn ;
638
640
unsigned ChangeWidthAnchor = 0 ;
639
641
unsigned ChangeWidthRight = 0 ;
640
642
if (RightJustify)
641
643
if (ACS.PadOperators )
642
- ChangeWidthAnchor = Changes[i] .TokenLength ;
644
+ ChangeWidthAnchor = CurrentChange .TokenLength ;
643
645
else
644
- ChangeWidthLeft += Changes[i] .TokenLength ;
646
+ ChangeWidthLeft += CurrentChange .TokenLength ;
645
647
else
646
- ChangeWidthRight = Changes[i] .TokenLength ;
648
+ ChangeWidthRight = CurrentChange .TokenLength ;
647
649
for (unsigned j = i + 1 ; j != e && Changes[j].NewlinesBefore == 0 ; ++j) {
648
650
ChangeWidthRight += Changes[j].Spaces ;
649
651
// Changes are generally 1:1 with the tokens, but a change could also be
0 commit comments