@@ -126,7 +126,7 @@ class AnnotatingParser {
126
126
const AdditionalKeywords &Keywords,
127
127
SmallVector<ScopeType> &Scopes)
128
128
: Style (Style ), Line(Line), CurrentToken(Line.First), AutoFound(false ),
129
- Keywords (Keywords), Scopes(Scopes) {
129
+ IsCpp ( Style .isCpp()), Keywords(Keywords), Scopes(Scopes) {
130
130
Contexts.push_back (Context (tok::unknown, 1 , /* IsExpression=*/ false ));
131
131
resetTokenMetadata ();
132
132
}
@@ -676,26 +676,25 @@ class AnnotatingParser {
676
676
// In C++, this can happen either in array of templates (foo<int>[10])
677
677
// or when array is a nested template type (unique_ptr<type1<type2>[]>).
678
678
bool CppArrayTemplates =
679
- Style . isCpp () && Parent && Parent->is (TT_TemplateCloser) &&
679
+ IsCpp && Parent && Parent->is (TT_TemplateCloser) &&
680
680
(Contexts.back ().CanBeExpression || Contexts.back ().IsExpression ||
681
681
Contexts.back ().ContextType == Context::TemplateArgument);
682
682
683
683
const bool IsInnerSquare = Contexts.back ().InCpp11AttributeSpecifier ;
684
684
const bool IsCpp11AttributeSpecifier =
685
- isCppAttribute (Style . isCpp () , *Left) || IsInnerSquare;
685
+ isCppAttribute (IsCpp , *Left) || IsInnerSquare;
686
686
687
687
// Treat C# Attributes [STAThread] much like C++ attributes [[...]].
688
688
bool IsCSharpAttributeSpecifier =
689
689
isCSharpAttributeSpecifier (*Left) ||
690
690
Contexts.back ().InCSharpAttributeSpecifier ;
691
691
692
692
bool InsideInlineASM = Line.startsWith (tok::kw_asm);
693
- bool IsCppStructuredBinding = Left->isCppStructuredBinding (Style );
693
+ bool IsCppStructuredBinding = Left->isCppStructuredBinding (IsCpp );
694
694
bool StartsObjCMethodExpr =
695
695
!IsCppStructuredBinding && !InsideInlineASM && !CppArrayTemplates &&
696
- Style .isCpp () && !IsCpp11AttributeSpecifier &&
697
- !IsCSharpAttributeSpecifier && Contexts.back ().CanBeExpression &&
698
- Left->isNot (TT_LambdaLSquare) &&
696
+ IsCpp && !IsCpp11AttributeSpecifier && !IsCSharpAttributeSpecifier &&
697
+ Contexts.back ().CanBeExpression && Left->isNot (TT_LambdaLSquare) &&
699
698
!CurrentToken->isOneOf (tok::l_brace, tok::r_square) &&
700
699
(!Parent ||
701
700
Parent->isOneOf (tok::colon, tok::l_square, tok::l_paren,
@@ -723,7 +722,7 @@ class AnnotatingParser {
723
722
Contexts.back ().ContextKind == tok::l_brace &&
724
723
Parent->isOneOf (tok::l_brace, tok::comma)) {
725
724
Left->setType (TT_JsComputedPropertyName);
726
- } else if (Style . isCpp () && Contexts.back ().ContextKind == tok::l_brace &&
725
+ } else if (IsCpp && Contexts.back ().ContextKind == tok::l_brace &&
727
726
Parent && Parent->isOneOf (tok::l_brace, tok::comma)) {
728
727
Left->setType (TT_DesignatedInitializerLSquare);
729
728
} else if (IsCSharpAttributeSpecifier) {
@@ -1161,7 +1160,7 @@ class AnnotatingParser {
1161
1160
if (Previous->is (TT_JsTypeOptionalQuestion))
1162
1161
Previous = Previous->getPreviousNonComment ();
1163
1162
if ((CurrentToken->is (tok::colon) && !Style .isTableGen () &&
1164
- (!Contexts.back ().ColonIsDictLiteral || !Style . isCpp () )) ||
1163
+ (!Contexts.back ().ColonIsDictLiteral || !IsCpp )) ||
1165
1164
Style .isProto ()) {
1166
1165
OpeningBrace.setType (TT_DictLiteral);
1167
1166
if (Previous->Tok .getIdentifierInfo () ||
@@ -1230,7 +1229,7 @@ class AnnotatingParser {
1230
1229
}
1231
1230
1232
1231
bool consumeToken () {
1233
- if (Style . isCpp () ) {
1232
+ if (IsCpp ) {
1234
1233
const auto *Prev = CurrentToken->getPreviousNonComment ();
1235
1234
if (Prev && Prev->is (tok::r_square) && Prev->is (TT_AttributeSquare) &&
1236
1235
CurrentToken->isOneOf (tok::kw_if, tok::kw_switch, tok::kw_case,
@@ -1424,7 +1423,7 @@ class AnnotatingParser {
1424
1423
if (CurrentToken && CurrentToken->is (Keywords.kw_await ))
1425
1424
next ();
1426
1425
}
1427
- if (Style . isCpp () && CurrentToken && CurrentToken->is (tok::kw_co_await))
1426
+ if (IsCpp && CurrentToken && CurrentToken->is (tok::kw_co_await))
1428
1427
next ();
1429
1428
Contexts.back ().ColonIsForRangeExpr = true ;
1430
1429
if (!CurrentToken || CurrentToken->isNot (tok::l_paren))
@@ -2590,7 +2589,7 @@ class AnnotatingParser {
2590
2589
// / Determine whether '(' is starting a C++ cast.
2591
2590
bool lParenStartsCppCast (const FormatToken &Tok) {
2592
2591
// C-style casts are only used in C++.
2593
- if (!Style . isCpp () )
2592
+ if (!IsCpp )
2594
2593
return false ;
2595
2594
2596
2595
FormatToken *LeftOfParens = Tok.getPreviousNonComment ();
@@ -2611,10 +2610,8 @@ class AnnotatingParser {
2611
2610
// / Determine whether ')' is ending a cast.
2612
2611
bool rParenEndsCast (const FormatToken &Tok) {
2613
2612
// C-style casts are only used in C++, C# and Java.
2614
- if (!Style .isCSharp () && !Style .isCpp () &&
2615
- Style .Language != FormatStyle::LK_Java) {
2613
+ if (!Style .isCSharp () && !IsCpp && Style .Language != FormatStyle::LK_Java)
2616
2614
return false ;
2617
- }
2618
2615
2619
2616
// Empty parens aren't casts and there are no casts at the end of the line.
2620
2617
if (Tok.Previous == Tok.MatchingParen || !Tok.Next || !Tok.MatchingParen )
@@ -2691,7 +2688,7 @@ class AnnotatingParser {
2691
2688
if (Tok.Next ->isOneOf (tok::kw_noexcept, tok::kw_volatile, tok::kw_const,
2692
2689
tok::kw_requires, tok::kw_throw, tok::arrow,
2693
2690
Keywords.kw_override , Keywords.kw_final ) ||
2694
- isCppAttribute (Style . isCpp () , *Tok.Next )) {
2691
+ isCppAttribute (IsCpp , *Tok.Next )) {
2695
2692
return false ;
2696
2693
}
2697
2694
@@ -3012,6 +3009,7 @@ class AnnotatingParser {
3012
3009
AnnotatedLine &Line;
3013
3010
FormatToken *CurrentToken;
3014
3011
bool AutoFound;
3012
+ bool IsCpp;
3015
3013
const AdditionalKeywords &Keywords;
3016
3014
3017
3015
SmallVector<ScopeType> &Scopes;
@@ -3559,7 +3557,7 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
3559
3557
ExpressionParser ExprParser (Style , Keywords, Line);
3560
3558
ExprParser.parse ();
3561
3559
3562
- if (Style . isCpp () ) {
3560
+ if (IsCpp ) {
3563
3561
auto *Tok = getFunctionName (Line);
3564
3562
if (Tok && ((!Scopes.empty () && Scopes.back () == ST_Class) ||
3565
3563
Line.endsWith (TT_FunctionLBrace) || isCtorOrDtorName (Tok))) {
@@ -3766,7 +3764,6 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
3766
3764
if (AlignArrayOfStructures)
3767
3765
calculateArrayInitializerColumnList (Line);
3768
3766
3769
- const bool IsCpp = Style .isCpp ();
3770
3767
bool SeenName = false ;
3771
3768
bool LineIsFunctionDeclaration = false ;
3772
3769
FormatToken *ClosingParen = nullptr ;
@@ -3779,7 +3776,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
3779
3776
AfterLastAttribute = Tok;
3780
3777
if (const bool IsCtorOrDtor = Tok->is (TT_CtorDtorDeclName);
3781
3778
IsCtorOrDtor ||
3782
- isFunctionDeclarationName (Style . isCpp () , *Tok, Line, ClosingParen)) {
3779
+ isFunctionDeclarationName (IsCpp , *Tok, Line, ClosingParen)) {
3783
3780
if (!IsCtorOrDtor)
3784
3781
Tok->setFinalizedType (TT_FunctionDeclarationName);
3785
3782
LineIsFunctionDeclaration = true ;
@@ -4717,7 +4714,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
4717
4714
if (Left.is (tok::star) && Right.is (tok::comment))
4718
4715
return true ;
4719
4716
4720
- if (Style . isCpp () ) {
4717
+ if (IsCpp ) {
4721
4718
if (Left.is (TT_OverloadedOperator) &&
4722
4719
Right.isOneOf (TT_TemplateOpener, TT_TemplateCloser)) {
4723
4720
return true ;
@@ -5425,7 +5422,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
5425
5422
if (!Keywords.isVerilogBegin (Right) && Keywords.isVerilogEndOfLabel (Left))
5426
5423
return true ;
5427
5424
} else if (Style .BreakAdjacentStringLiterals &&
5428
- (Style . isCpp () || Style .isProto () ||
5425
+ (IsCpp || Style .isProto () ||
5429
5426
Style .Language == FormatStyle::LK_TableGen)) {
5430
5427
if (Left.isStringLiteral () && Right.isStringLiteral ())
5431
5428
return true ;
0 commit comments