@@ -5405,6 +5405,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
5405
5405
return true ;
5406
5406
}
5407
5407
5408
+ const auto *BeforeLeft = Left.Previous ;
5409
+ const auto *AfterRight = Right.Next ;
5410
+
5408
5411
if (Style .isCSharp ()) {
5409
5412
if (Left.is (TT_FatArrow) && Right.is (tok::l_brace) &&
5410
5413
Style .BraceWrapping .AfterFunction ) {
@@ -5416,7 +5419,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
5416
5419
}
5417
5420
if (Right.is (TT_CSharpGenericTypeConstraint))
5418
5421
return true ;
5419
- if (Right. Next && Right. Next ->is (TT_FatArrow) &&
5422
+ if (AfterRight && AfterRight ->is (TT_FatArrow) &&
5420
5423
(Right.is (tok::numeric_constant) ||
5421
5424
(Right.is (tok::identifier) && Right.TokenText == " _" ))) {
5422
5425
return true ;
@@ -5433,15 +5436,14 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
5433
5436
Left.is (tok::r_square) && Right.is (tok::l_square)) {
5434
5437
return true ;
5435
5438
}
5436
-
5437
5439
} else if (Style .isJavaScript ()) {
5438
5440
// FIXME: This might apply to other languages and token kinds.
5439
- if (Right.is (tok::string_literal) && Left.is (tok::plus) && Left. Previous &&
5440
- Left. Previous ->is (tok::string_literal)) {
5441
+ if (Right.is (tok::string_literal) && Left.is (tok::plus) && BeforeLeft &&
5442
+ BeforeLeft ->is (tok::string_literal)) {
5441
5443
return true ;
5442
5444
}
5443
5445
if (Left.is (TT_DictLiteral) && Left.is (tok::l_brace) && Line.Level == 0 &&
5444
- Left. Previous && Left. Previous ->is (tok::equal) &&
5446
+ BeforeLeft && BeforeLeft ->is (tok::equal) &&
5445
5447
Line.First ->isOneOf (tok::identifier, Keywords.kw_import , tok::kw_export,
5446
5448
tok::kw_const) &&
5447
5449
// kw_var/kw_let are pseudo-tokens that are tok::identifier, so match
@@ -5460,8 +5462,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
5460
5462
// instead of bin-packing.
5461
5463
return true ;
5462
5464
}
5463
- if (Right.is (tok::r_brace) && Left.is (tok::l_brace) && Left. Previous &&
5464
- Left. Previous ->is (TT_FatArrow)) {
5465
+ if (Right.is (tok::r_brace) && Left.is (tok::l_brace) && BeforeLeft &&
5466
+ BeforeLeft ->is (TT_FatArrow)) {
5465
5467
// JS arrow function (=> {...}).
5466
5468
switch (Style .AllowShortLambdasOnASingleLine ) {
5467
5469
case FormatStyle::SLS_All:
@@ -5489,8 +5491,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
5489
5491
FormatStyle::SFS_InlineOnly);
5490
5492
}
5491
5493
} else if (Style .Language == FormatStyle::LK_Java) {
5492
- if (Right.is (tok::plus) && Left.is (tok::string_literal) && Right. Next &&
5493
- Right. Next ->is (tok::string_literal)) {
5494
+ if (Right.is (tok::plus) && Left.is (tok::string_literal) && AfterRight &&
5495
+ AfterRight ->is (tok::string_literal)) {
5494
5496
return true ;
5495
5497
}
5496
5498
} else if (Style .isVerilog ()) {
@@ -5543,8 +5545,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
5543
5545
}
5544
5546
return Style .BreakArrays ;
5545
5547
}
5546
- }
5547
- if (Style .isTableGen ()) {
5548
+ } else if (Style .isTableGen ()) {
5548
5549
// Break the comma in side cond operators.
5549
5550
// !cond(case1:1,
5550
5551
// case2:0);
@@ -5600,8 +5601,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
5600
5601
return true ;
5601
5602
if (Left.IsUnterminatedLiteral )
5602
5603
return true ;
5603
- if (Right.is (tok::lessless) && Right. Next && Left.is (tok::string_literal) &&
5604
- Right. Next ->is (tok::string_literal)) {
5604
+ if (Right.is (tok::lessless) && AfterRight && Left.is (tok::string_literal) &&
5605
+ AfterRight ->is (tok::string_literal)) {
5605
5606
return true ;
5606
5607
}
5607
5608
if (Right.is (TT_RequiresClause)) {
@@ -5678,8 +5679,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
5678
5679
// string literal accordingly. Thus, we try keep existing line breaks.
5679
5680
return Right.IsMultiline && Right.NewlinesBefore > 0 ;
5680
5681
}
5681
- if ((Left.is (tok::l_brace) || (Left. is (tok::less) && Left. Previous &&
5682
- Left. Previous ->is (tok::equal))) &&
5682
+ if ((Left.is (tok::l_brace) ||
5683
+ (Left. is (tok::less) && BeforeLeft && BeforeLeft ->is (tok::equal))) &&
5683
5684
Right.NestingLevel == 1 && Style .Language == FormatStyle::LK_Proto) {
5684
5685
// Don't put enums or option definitions onto single lines in protocol
5685
5686
// buffers.
@@ -5793,7 +5794,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
5793
5794
//
5794
5795
// We ensure elsewhere that extensions are always on their own line.
5795
5796
if (Style .isProto () && Right.is (TT_SelectorName) &&
5796
- Right.isNot (tok::r_square) && Right. Next ) {
5797
+ Right.isNot (tok::r_square) && AfterRight ) {
5797
5798
// Keep `@submessage` together in:
5798
5799
// @submessage { key: value }
5799
5800
if (Left.is (tok::at))
@@ -5802,7 +5803,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
5802
5803
// selector { ...
5803
5804
// selector: { ...
5804
5805
// selector: @base { ...
5805
- FormatToken *LBrace = Right. Next ;
5806
+ const auto *LBrace = AfterRight ;
5806
5807
if (LBrace && LBrace->is (tok::colon)) {
5807
5808
LBrace = LBrace->Next ;
5808
5809
if (LBrace && LBrace->is (tok::at)) {
0 commit comments