@@ -640,6 +640,14 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
640
640
FormatTok = Tokens->setPosition (StoredPosition);
641
641
}
642
642
643
+ // Sets the token type of the directly previous right brace.
644
+ void UnwrappedLineParser::setPreviousRBraceType (TokenType Type) {
645
+ if (auto Prev = FormatTok->getPreviousNonComment ();
646
+ Prev && Prev->is (tok::r_brace)) {
647
+ Prev->setFinalizedType (Type);
648
+ }
649
+ }
650
+
643
651
template <class T >
644
652
static inline void hash_combine (std::size_t &seed, const T &v) {
645
653
std::hash<T> hasher;
@@ -2756,6 +2764,7 @@ FormatToken *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
2756
2764
CompoundStatementIndenter Indenter (this , Style , Line->Level );
2757
2765
parseBlock (/* MustBeDeclaration=*/ false , /* AddLevels=*/ 1u ,
2758
2766
/* MunchSemi=*/ true , KeepIfBraces, &IfBlockKind);
2767
+ setPreviousRBraceType (TT_ControlStatementRBrace);
2759
2768
if (Style .BraceWrapping .BeforeElse )
2760
2769
addUnwrappedLine ();
2761
2770
else
@@ -2794,6 +2803,7 @@ FormatToken *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
2794
2803
FormatToken *IfLBrace =
2795
2804
parseBlock (/* MustBeDeclaration=*/ false , /* AddLevels=*/ 1u ,
2796
2805
/* MunchSemi=*/ true , KeepElseBraces, &ElseBlockKind);
2806
+ setPreviousRBraceType (TT_ElseRBrace);
2797
2807
if (FormatTok->is (tok::kw_else)) {
2798
2808
KeepElseBraces = KeepElseBraces ||
2799
2809
ElseBlockKind == IfStmtKind::IfOnly ||
@@ -3057,12 +3067,12 @@ void UnwrappedLineParser::parseLoopBody(bool KeepBraces, bool WrapRightBrace) {
3057
3067
keepAncestorBraces ();
3058
3068
3059
3069
if (isBlockBegin (*FormatTok)) {
3060
- if (!KeepBraces)
3061
- FormatTok->setFinalizedType (TT_ControlStatementLBrace);
3070
+ FormatTok->setFinalizedType (TT_ControlStatementLBrace);
3062
3071
FormatToken *LeftBrace = FormatTok;
3063
3072
CompoundStatementIndenter Indenter (this , Style , Line->Level );
3064
3073
parseBlock (/* MustBeDeclaration=*/ false , /* AddLevels=*/ 1u ,
3065
3074
/* MunchSemi=*/ true , KeepBraces);
3075
+ setPreviousRBraceType (TT_ControlStatementRBrace);
3066
3076
if (!KeepBraces) {
3067
3077
assert (!NestedTooDeep.empty ());
3068
3078
if (!NestedTooDeep.back ())
@@ -3196,7 +3206,9 @@ void UnwrappedLineParser::parseSwitch() {
3196
3206
3197
3207
if (FormatTok->is (tok::l_brace)) {
3198
3208
CompoundStatementIndenter Indenter (this , Style , Line->Level );
3209
+ FormatTok->setFinalizedType (TT_ControlStatementLBrace);
3199
3210
parseBlock ();
3211
+ setPreviousRBraceType (TT_ControlStatementRBrace);
3200
3212
addUnwrappedLine ();
3201
3213
} else {
3202
3214
addUnwrappedLine ();
@@ -3713,10 +3725,7 @@ bool UnwrappedLineParser::parseEnum() {
3713
3725
nextToken ();
3714
3726
addUnwrappedLine ();
3715
3727
}
3716
- if (auto Prev = FormatTok->getPreviousNonComment ();
3717
- Prev && Prev->is (tok::r_brace)) {
3718
- Prev->setFinalizedType (TT_EnumRBrace);
3719
- }
3728
+ setPreviousRBraceType (TT_EnumRBrace);
3720
3729
return true ;
3721
3730
3722
3731
// There is no addUnwrappedLine() here so that we fall through to parsing a
@@ -3950,10 +3959,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
3950
3959
unsigned AddLevels = Style .IndentAccessModifiers ? 2u : 1u ;
3951
3960
parseBlock (/* MustBeDeclaration=*/ true , AddLevels, /* MunchSemi=*/ false );
3952
3961
}
3953
- if (auto Prev = FormatTok->getPreviousNonComment ();
3954
- Prev && Prev->is (tok::r_brace)) {
3955
- Prev->setFinalizedType (ClosingBraceType);
3956
- }
3962
+ setPreviousRBraceType (ClosingBraceType);
3957
3963
}
3958
3964
// There is no addUnwrappedLine() here so that we fall through to parsing a
3959
3965
// structural element afterwards. Thus, in "class A {} n, m;",
0 commit comments