Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
Fix counting of parameters so that r175162 works as expected.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
djasper-gh committed Feb 14, 2013
1 parent fc75908 commit 9fc56f2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
19 changes: 11 additions & 8 deletions lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ class AnnotatingParser {
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;
}
Expand Down Expand Up @@ -175,8 +174,7 @@ class AnnotatingParser {
}
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;
}
Expand Down Expand Up @@ -240,8 +238,7 @@ class AnnotatingParser {
}
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;
}
Expand All @@ -263,13 +260,19 @@ class AnnotatingParser {
}
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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Format/TokenAnnotator.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AnnotatedToken {
: 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) {
}
Expand Down
4 changes: 4 additions & 0 deletions unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,10 @@ TEST_F(FormatTest, WrapsAtFunctionCallsIfNecessary) {
"aaaaaaaaaaa->aaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaa->aaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa));\n");

verifyFormat(
"aaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa().aaaaaaaaaaaaaaaaa());");
}

TEST_F(FormatTest, WrapsTemplateDeclarations) {
Expand Down

0 comments on commit 9fc56f2

Please sign in to comment.