r176087 - In range-based for-loops, prefer splitting after ":".
Daniel Jasper
djasper at google.com
Tue Feb 26 05:18:08 PST 2013
Author: djasper
Date: Tue Feb 26 07:18:08 2013
New Revision: 176087
URL: http://llvm.org/viewvc/llvm-project?rev=176087&view=rev
Log:
In range-based for-loops, prefer splitting after ":".
Before:
for (const aaaaaaaaaaaaaaaaaaaaa &
aaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
After:
for (const aaaaaaaaaaaaaaaaaaaaa &aaaaaaaaa :
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=176087&r1=176086&r2=176087&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Feb 26 07:18:08 2013
@@ -886,7 +886,7 @@ unsigned TokenAnnotator::splitPenalty(co
if (Left.Type == TT_RangeBasedForLoopColon ||
Left.Type == TT_InheritanceColon)
- return 5;
+ return 2;
if (Right.is(tok::arrow) || Right.is(tok::period)) {
if (Line.Type == LT_BuilderTypeCall)
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=176087&r1=176086&r2=176087&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Feb 26 07:18:08 2013
@@ -318,6 +318,8 @@ TEST_F(FormatTest, RangeBasedForLoops) {
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n}");
verifyFormat("for (auto aaaaaaaaaaaaaaaaaaaaa :\n"
" aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa, aaaaaaaaaaaaa)) {\n}");
+ verifyFormat("for (const aaaaaaaaaaaaaaaaaaaaa &aaaaaaaaa :\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n}");
}
TEST_F(FormatTest, FormatsWhileLoop) {
@@ -601,10 +603,10 @@ TEST_F(FormatTest, CommentsInStaticIniti
" b\n"
"}"));
EXPECT_EQ("S s = { a, b };", format("S s = {\n"
- " a,\n"
- "\n"
- " b\n"
- "};"));
+ " a,\n"
+ "\n"
+ " b\n"
+ "};"));
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list