From: Daniel Jasper Date: Wed, 23 Jan 2013 12:27:43 +0000 (+0000) Subject: Removing the penalty for breaking after "=". X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7006e7ebc0098b7627bd3cc13367ea576c25dcbb;p=clang Removing the penalty for breaking after "=". Having seen more cases, this actually was not a good thing to do in the first place. We can still improve on what we do now, but breaking after the "=" is good in many cases. Before: aaaaaaaaaaaaa = aa->aaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaa)); After: aaaaaaaaaaaaa = aa->aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaa)); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173257 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 2d9bd2cc06..c75b8ef834 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -702,11 +702,6 @@ private: return prec::Assignment; prec::Level Level = getPrecedence(Left); - // Breaking after an assignment leads to a bad result as the two sides of - // the assignment are visually very close together. - if (Level == prec::Assignment) - return 50; - if (Level != prec::Unknown) return Level; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 3a1cfb261b..279b61c262 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1030,15 +1030,15 @@ TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) { " ccccccccccccccccccccccccc) {\n}"); } -TEST_F(FormatTest, PrefersNotToBreakAfterAssignments) { +TEST_F(FormatTest, BreaksAfterAssignments) { verifyFormat( - "unsigned Cost = TTI.getMemoryOpCost(I->getOpcode(), VectorTy,\n" - " SI->getAlignment(),\n" - " SI->getPointerAddressSpaceee());\n"); + "unsigned Cost =\n" + " TTI.getMemoryOpCost(I->getOpcode(), VectorTy, SI->getAlignment(),\n" + " SI->getPointerAddressSpaceee());\n"); verifyFormat( - "CharSourceRange LineRange = CharSourceRange::getTokenRange(\n" - " Line.Tokens.front().Tok.getLocation(),\n" - " Line.Tokens.back().Tok.getLocation());"); + "CharSourceRange LineRange =\n" + " CharSourceRange::getTokenRange(Line.Tokens.front().Tok.getLoc(),\n" + " Line.Tokens.back().Tok.getLoc());"); } TEST_F(FormatTest, AlignsAfterAssignments) { @@ -1055,9 +1055,9 @@ TEST_F(FormatTest, AlignsAfterAssignments) { "int Result = (aaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaa +\n" " aaaaaaaaaaaaaaaaaaaaaaaaa);"); verifyFormat( - "double LooooooooooooooooooooooooongResult = aaaaaaaaaaaaaaaaaaaaaaaa +\n" - " aaaaaaaaaaaaaaaaaaaaaaaa +\n" - " aaaaaaaaaaaaaaaaaaaaaaaa;"); + "double LooooooooooooooooooooooooongResult =\n" + " aaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaa +\n" + " aaaaaaaaaaaaaaaaaaaaaaaa;"); } TEST_F(FormatTest, AlignsAfterReturn) { @@ -1133,9 +1133,8 @@ TEST_F(FormatTest, UnderstandsEquals) { "}"); verifyFormat( - // FIXME: Does an expression like this ever make sense? If yes, fix. - "if (int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 100000000 +\n" - " 10000000) {\n}"); + "if (int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n" + " 100000000 + 10000000) {\n}"); } TEST_F(FormatTest, WrapsAtFunctionCallsIfNecessary) {