r234304 - clang-format: Improve nested block formatting.
Daniel Jasper
djasper at google.com
Tue Apr 7 01:20:35 PDT 2015
Author: djasper
Date: Tue Apr 7 03:20:35 2015
New Revision: 234304
URL: http://llvm.org/viewvc/llvm-project?rev=234304&view=rev
Log:
clang-format: Improve nested block formatting.
Before:
functionA(functionB({
int i;
int j;
}),
aaaa, bbbb, cccc);
After:
functionA(functionB({
int i;
int j;
}),
aaaa, bbbb, cccc);
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=234304&r1=234303&r2=234304&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Apr 7 03:20:35 2015
@@ -849,7 +849,8 @@ void ContinuationIndenter::moveStatePast
bool NoLineBreak = State.Stack.back().NoLineBreak ||
(Current.is(TT_TemplateOpener) &&
State.Stack.back().ContainsUnwrappedBuilder);
- unsigned NestedBlockIndent = State.Stack.back().NestedBlockIndent;
+ unsigned NestedBlockIndent = std::max(State.Stack.back().StartOfFunctionCall,
+ State.Stack.back().NestedBlockIndent);
State.Stack.push_back(ParenState(NewIndent, NewIndentLevel,
State.Stack.back().LastSpace,
AvoidBinPacking, NoLineBreak));
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=234304&r1=234303&r2=234304&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Apr 7 03:20:35 2015
@@ -3048,35 +3048,38 @@ TEST_F(FormatTest, FormatsJoinedLinesOnS
}
TEST_F(FormatTest, LayoutBlockInsideParens) {
- EXPECT_EQ("functionCall({ int i; });", format(" functionCall ( {int i;} );"));
- EXPECT_EQ("functionCall({\n"
- " int i;\n"
- " int j;\n"
- "});",
- format(" functionCall ( {int i;int j;} );"));
- EXPECT_EQ("functionCall({\n"
- " int i;\n"
- " int j;\n"
- "}, aaaa, bbbb, cccc);",
- format(" functionCall ( {int i;int j;}, aaaa, bbbb, cccc);"));
- EXPECT_EQ("functionCall(\n"
- " {\n"
- " int i;\n"
- " int j;\n"
- " },\n"
- " aaaa, bbbb, // comment\n"
- " cccc);",
- format(" functionCall ( {int i;int j;}, aaaa, bbbb, // comment\n"
- "cccc);"));
- EXPECT_EQ("functionCall(aaaa, bbbb, { int i; });",
- format(" functionCall (aaaa, bbbb, {int i;});"));
- EXPECT_EQ("functionCall(aaaa, bbbb, {\n"
- " int i;\n"
- " int j;\n"
- "});",
- format(" functionCall (aaaa, bbbb, {int i;int j;});"));
- EXPECT_EQ("functionCall(aaaa, bbbb, { int i; });",
- format(" functionCall (aaaa, bbbb, {int i;});"));
+ verifyFormat("functionCall({ int i; });");
+ verifyFormat("functionCall({\n"
+ " int i;\n"
+ " int j;\n"
+ "});");
+ verifyFormat("functionCall({\n"
+ " int i;\n"
+ " int j;\n"
+ "}, aaaa, bbbb, cccc);");
+ verifyFormat("functionA(functionB({\n"
+ " int i;\n"
+ " int j;\n"
+ " }),\n"
+ " aaaa, bbbb, cccc);");
+ verifyFormat("functionCall(\n"
+ " {\n"
+ " int i;\n"
+ " int j;\n"
+ " },\n"
+ " aaaa, bbbb, // comment\n"
+ " cccc);");
+ verifyFormat("functionA(functionB({\n"
+ " int i;\n"
+ " int j;\n"
+ " }),\n"
+ " aaaa, bbbb, // comment\n"
+ " cccc);");
+ verifyFormat("functionCall(aaaa, bbbb, { int i; });");
+ verifyFormat("functionCall(aaaa, bbbb, {\n"
+ " int i;\n"
+ " int j;\n"
+ "});");
verifyFormat(
"Aaa(\n" // FIXME: There shouldn't be a linebreak here.
" {\n"
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=234304&r1=234303&r2=234304&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Apr 7 03:20:35 2015
@@ -408,10 +408,9 @@ TEST_F(FormatTestJS, MultipleFunctionLit
" body();\n"
" });");
- // FIXME: This is bad, but it used to be formatted correctly by accident.
- verifyFormat("getSomeLongPromise().then(function(value) {\n"
- " body();\n"
- "}).thenCatch(function(error) { body(); });");
+ verifyFormat("getSomeLongPromise()\n"
+ " .then(function(value) { body(); })\n"
+ " .thenCatch(function(error) { body(); });");
}
TEST_F(FormatTestJS, ReturnStatements) {
More information about the cfe-commits
mailing list