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 2d9bd2c..c75b8ef 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -702,11 +702,6 @@
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 3a1cfb2..279b61c 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1030,15 +1030,15 @@
" 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 @@
"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 @@
"}");
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) {