summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2016-03-17 12:00:22 +0000
committerDaniel Jasper <djasper@google.com>2016-03-17 12:00:22 +0000
commit710f8493c898a31a36237353b37e39ea9f6a9777 (patch)
tree9c6f6e087cc39f148fead454729bde581316bf1d
parent16f2460575e6f65b277cb0000667a83500f5fce3 (diff)
downloadbcm5719-llvm-710f8493c898a31a36237353b37e39ea9f6a9777.tar.gz
bcm5719-llvm-710f8493c898a31a36237353b37e39ea9f6a9777.zip
clang-format: Slightly weaken AlignAfterOpenBracket=AlwaysBreak.
If a call takes a single argument, using AlwaysBreak can lead to lots of wasted lines and additional indentation without improving the readability in a significant way. Before: caaaaaaaaaaaall( caaaaaaaaaaaall( caaaaaaaaaaaall( caaaaaaaaaaaaaaaaaaaaaaall(aaaaaaaaaaaaaa, aaaaaaaaa)))); After: caaaaaaaaaaaall(caaaaaaaaaaaall(caaaaaaaaaaaall( caaaaaaaaaaaaaaaaaaaaaaall(aaaaaaaaaaaaaa, aaaaaaaaa)))); llvm-svn: 263709
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp12
-rw-r--r--clang/unittests/Format/FormatTest.cpp29
2 files changed, 35 insertions, 6 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 4e5a29426a2..9cff34bc3df 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -356,7 +356,17 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
Previous.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) &&
State.Column > getNewLineColumn(State) &&
(!Previous.Previous ||
- !Previous.Previous->isOneOf(tok::kw_for, tok::kw_while, tok::kw_switch)))
+ !Previous.Previous->isOneOf(tok::kw_for, tok::kw_while,
+ tok::kw_switch)) &&
+ // Don't do this for simple (no expressions) one-argument function calls
+ // as that feels like needlessly wasting whitespace, e.g.:
+ //
+ // caaaaaaaaaaaall(
+ // caaaaaaaaaaaall(
+ // caaaaaaaaaaaall(
+ // caaaaaaaaaaaaaaaaaaaaaaall(aaaaaaaaaaaaaa, aaaaaaaaa))));
+ Current.FakeLParens.size() > 0 &&
+ Current.FakeLParens.back() > prec::Unknown)
State.Stack.back().NoLineBreak = true;
if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 6e57dcc23f9..ff932c88c7c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4461,12 +4461,31 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
" aaaaaaaaaaa aaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);",
Style);
- verifyFormat("SomeLongVariableName->someFunction(\n"
- " foooooooo(\n"
- " aaaaaaaaaaaaaaa,\n"
- " aaaaaaaaaaaaaaaaaaaaa,\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa));",
+ verifyFormat("SomeLongVariableName->someFunction(foooooooo(\n"
+ " aaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa));",
Style);
+ verifyFormat(
+ "aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa)));",
+ Style);
+ verifyFormat(
+ "aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaa.aaaaaaaaaa(\n"
+ " aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa)));",
+ Style);
+ verifyFormat(
+ "aaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa)),\n"
+ " aaaaaaaaaaaaaaaa);",
+ Style);
+ verifyFormat(
+ "aaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa)) &&\n"
+ " aaaaaaaaaaaaaaaa);",
+ Style);
}
TEST_F(FormatTest, ParenthesesAndOperandAlignment) {
OpenPOWER on IntegriCloud