r206161 - clang-format: With ColumnLimit=0, keep short array literals on a line.
Daniel Jasper
djasper at google.com
Mon Apr 14 05:05:05 PDT 2014
Author: djasper
Date: Mon Apr 14 07:05:05 2014
New Revision: 206161
URL: http://llvm.org/viewvc/llvm-project?rev=206161&view=rev
Log:
clang-format: With ColumnLimit=0, keep short array literals on a line.
Before:
NSArray* a = [[NSArray alloc] initWithArray:@[
@"a"
]
copyItems:YES];
After:
NSArray* a = [[NSArray alloc] initWithArray:@[ @"a" ]
copyItems:YES];
This fixed llvm.org/PR19080.
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=206161&r1=206160&r2=206161&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Apr 14 07:05:05 2014
@@ -142,6 +142,7 @@ bool ContinuationIndenter::mustBreak(con
return true;
if (((Previous.Type == TT_DictLiteral && Previous.is(tok::l_brace)) ||
Previous.Type == TT_ArrayInitializerLSquare) &&
+ (Style.ColumnLimit > 0 || Previous.ParameterCount > 1) &&
getLengthToMatchingParen(Previous) + State.Column > getColumnLimit(State))
return true;
if (Current.Type == TT_CtorInitializerColon &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=206161&r1=206160&r2=206161&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Apr 14 07:05:05 2014
@@ -8148,6 +8148,20 @@ TEST_F(FormatTest, FormatsWithWebKitStyl
format("#define aNumber \\\n"
" 10",
Style));
+
+ // Keep empty and one-element array literals on a single line.
+ verifyFormat("NSArray* a = [[NSArray alloc] initWithArray:@[]\n"
+ " copyItems:YES];",
+ Style);
+ verifyFormat("NSArray* a = [[NSArray alloc] initWithArray:@[ @\"a\" ]\n"
+ " copyItems:YES];",
+ Style);
+ verifyFormat("NSArray* a = [[NSArray alloc] initWithArray:@[\n"
+ " @\"a\",\n"
+ " @\"a\"\n"
+ " ]\n"
+ " copyItems:YES];",
+ Style);
}
TEST_F(FormatTest, FormatsLambdas) {
More information about the cfe-commits
mailing list