@@ -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;
0 commit comments