From 9fc56f2636137fcde8acb38865555ed6c7b84dfd Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 14 Feb 2013 15:01:34 +0000 Subject: [PATCH] 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 --- lib/Format/TokenAnnotator.cpp | 19 +++++++++++-------- lib/Format/TokenAnnotator.h | 2 +- unittests/Format/FormatTest.cpp | 4 ++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index ace6d25467..44593f358f 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -107,8 +107,7 @@ private: 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 @@ private: } 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 @@ private: } 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 @@ private: } 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 5ce84af96a..850b6ddede 100644 --- a/lib/Format/TokenAnnotator.h +++ b/lib/Format/TokenAnnotator.h @@ -73,7 +73,7 @@ public: : 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 38f926a7e2..9dab260512 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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) { -- 2.40.0