Fix counting of parameters so that r175162 works as expected.
Before:
aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
.aaaaaaaaaaaaaaaaa());
After:
aaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa().aaaaaaaaaaaaaaaaa());
Not sure which of the formattings above is better, but we should not pick
one by accident.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175165 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index ace6d25..44593f3 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -107,8 +107,7 @@
if (CurrentToken->is(tok::pipepipe) || CurrentToken->is(tok::ampamp) ||
CurrentToken->is(tok::question) || CurrentToken->is(tok::colon))
return false;
- if (CurrentToken->is(tok::comma))
- ++Left->ParameterCount;
+ updateParameterCount(Left, CurrentToken);
if (!consumeToken())
return false;
}
@@ -175,8 +174,7 @@
}
if (CurrentToken->is(tok::r_square) || CurrentToken->is(tok::r_brace))
return false;
- if (CurrentToken->is(tok::comma))
- ++Left->ParameterCount;
+ updateParameterCount(Left, CurrentToken);
if (!consumeToken())
return false;
}
@@ -240,8 +238,7 @@
}
if (CurrentToken->is(tok::r_paren) || CurrentToken->is(tok::r_brace))
return false;
- if (CurrentToken->is(tok::comma))
- ++Left->ParameterCount;
+ updateParameterCount(Left, CurrentToken);
if (!consumeToken())
return false;
}
@@ -263,13 +260,19 @@
}
if (CurrentToken->is(tok::r_paren) || CurrentToken->is(tok::r_square))
return false;
- if (CurrentToken->is(tok::comma))
- ++Left->ParameterCount;
+ updateParameterCount(Left, CurrentToken);
if (!consumeToken())
return false;
}
return true;
}
+
+ void updateParameterCount(AnnotatedToken *Left, AnnotatedToken *Current) {
+ if (Current->is(tok::comma))
+ ++Left->ParameterCount;
+ else if (Left->ParameterCount == 0 && Current->isNot(tok::comment))
+ Left->ParameterCount = 1;
+ }
bool parseConditional() {
while (CurrentToken != NULL) {
diff --git a/lib/Format/TokenAnnotator.h b/lib/Format/TokenAnnotator.h
index 5ce84af..850b6dd 100644
--- a/lib/Format/TokenAnnotator.h
+++ b/lib/Format/TokenAnnotator.h
@@ -73,7 +73,7 @@
: FormatTok(FormatTok), Type(TT_Unknown), SpacesRequiredBefore(0),
CanBreakBefore(false), MustBreakBefore(false),
ClosesTemplateDeclaration(false), MatchingParen(NULL),
- ParameterCount(1), BindingStrength(0), SplitPenalty(0),
+ ParameterCount(0), BindingStrength(0), SplitPenalty(0),
LongestObjCSelectorName(0), Parent(NULL), FakeLParens(0),
FakeRParens(0) {
}
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 38f926a..9dab260 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1453,6 +1453,10 @@
"aaaaaaaaaaa->aaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaa->aaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa));\n");
+
+ verifyFormat(
+ "aaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa().aaaaaaaaaaaaaaaaa());");
}
TEST_F(FormatTest, WrapsTemplateDeclarations) {