@@ -3682,17 +3682,17 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
3682
3682
const FormatToken &Current,
3683
3683
const AnnotatedLine &Line,
3684
3684
FormatToken *&ClosingParen) {
3685
- assert (Current.Previous );
3686
-
3687
3685
if (Current.is (TT_FunctionDeclarationName))
3688
3686
return true ;
3689
3687
3690
3688
if (!Current.Tok .getIdentifierInfo ())
3691
3689
return false ;
3692
3690
3693
- const auto &Previous = *Current.Previous ;
3691
+ const auto *Prev = Current.getPreviousNonComment ();
3692
+ assert (Prev);
3693
+ const auto &Previous = *Prev;
3694
3694
3695
- if (const auto *PrevPrev = Previous.Previous ;
3695
+ if (const auto *PrevPrev = Previous.getPreviousNonComment () ;
3696
3696
PrevPrev && PrevPrev->is (TT_ObjCDecl)) {
3697
3697
return false ;
3698
3698
}
@@ -3859,20 +3859,20 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
3859
3859
First->TotalLength = First->IsMultiline
3860
3860
? Style.ColumnLimit
3861
3861
: Line.FirstStartColumn + First->ColumnWidth ;
3862
- FormatToken *Current = First->Next ;
3863
- bool InFunctionDecl = Line.MightBeFunctionDecl ;
3864
3862
bool AlignArrayOfStructures =
3865
3863
(Style.AlignArrayOfStructures != FormatStyle::AIAS_None &&
3866
3864
Line.Type == LT_ArrayOfStructInitializer);
3867
3865
if (AlignArrayOfStructures)
3868
3866
calculateArrayInitializerColumnList (Line);
3869
3867
3868
+ const auto *FirstNonComment = Line.getFirstNonComment ();
3870
3869
bool SeenName = false ;
3871
3870
bool LineIsFunctionDeclaration = false ;
3872
- FormatToken *ClosingParen = nullptr ;
3873
3871
FormatToken *AfterLastAttribute = nullptr ;
3872
+ FormatToken *ClosingParen = nullptr ;
3874
3873
3875
- for (auto *Tok = Current; Tok; Tok = Tok->Next ) {
3874
+ for (auto *Tok = FirstNonComment ? FirstNonComment->Next : nullptr ; Tok;
3875
+ Tok = Tok->Next ) {
3876
3876
if (Tok->is (TT_StartOfName))
3877
3877
SeenName = true ;
3878
3878
if (Tok->Previous ->EndsCppAttributeGroup )
@@ -3894,7 +3894,9 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
3894
3894
}
3895
3895
}
3896
3896
3897
- if (IsCpp && (LineIsFunctionDeclaration || First->is (TT_CtorDtorDeclName)) &&
3897
+ if (IsCpp &&
3898
+ (LineIsFunctionDeclaration ||
3899
+ (FirstNonComment && FirstNonComment->is (TT_CtorDtorDeclName))) &&
3898
3900
Line.endsWith (tok::semi, tok::r_brace)) {
3899
3901
auto *Tok = Line.Last ->Previous ;
3900
3902
while (Tok->isNot (tok::r_brace))
@@ -3917,7 +3919,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
3917
3919
if (IsCpp) {
3918
3920
if (!LineIsFunctionDeclaration) {
3919
3921
// Annotate */&/&& in `operator` function calls as binary operators.
3920
- for (const auto *Tok = First ; Tok; Tok = Tok->Next ) {
3922
+ for (const auto *Tok = FirstNonComment ; Tok; Tok = Tok->Next ) {
3921
3923
if (Tok->isNot (tok::kw_operator))
3922
3924
continue ;
3923
3925
do {
@@ -3960,7 +3962,8 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
3960
3962
}
3961
3963
}
3962
3964
3963
- while (Current) {
3965
+ bool InFunctionDecl = Line.MightBeFunctionDecl ;
3966
+ for (auto *Current = First->Next ; Current; Current = Current->Next ) {
3964
3967
const FormatToken *Prev = Current->Previous ;
3965
3968
if (Current->is (TT_LineComment)) {
3966
3969
if (Prev->is (BK_BracedInit) && Prev->opensScope ()) {
@@ -4050,13 +4053,11 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
4050
4053
} else {
4051
4054
Current->SplitPenalty += 20 * Current->BindingStrength ;
4052
4055
}
4053
-
4054
- Current = Current->Next ;
4055
4056
}
4056
4057
4057
4058
calculateUnbreakableTailLengths (Line);
4058
4059
unsigned IndentLevel = Line.Level ;
4059
- for (Current = First; Current; Current = Current->Next ) {
4060
+ for (auto * Current = First; Current; Current = Current->Next ) {
4060
4061
if (Current->Role )
4061
4062
Current->Role ->precomputeFormattingInfos (Current);
4062
4063
if (Current->MatchingParen &&
0 commit comments