[cfe-commits] r173695 - Fix a bug that would lead to bad line break decisions in for loops.
Daniel Jasper
djasper at google.com
Mon Jan 28 09:30:17 PST 2013
Author: djasper
Date: Mon Jan 28 11:30:17 2013
New Revision: 173695
URL: http://llvm.org/viewvc/llvm-project?rev=173695&view=rev
Log:
Fix a bug that would lead to bad line break decisions in for loops.
Before:
for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa = aaaaaaaaaaaaaaa
.aaaaaaaaaaaaaaaa;
aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {}
After:
for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa =
aaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaa;
aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {}
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=173695&r1=173694&r2=173695&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Jan 28 11:30:17 2013
@@ -723,6 +723,12 @@ private:
if (Left.Type == TT_RangeBasedForLoopColon)
return 5;
+ if (Right.is(tok::arrow) || Right.is(tok::period)) {
+ if (Left.is(tok::r_paren) && Line.Type == LT_BuilderTypeCall)
+ return 5; // Should be smaller than breaking at a nested comma.
+ return 150;
+ }
+
// In for-loops, prefer breaking at ',' and ';'.
if (RootToken.is(tok::kw_for) &&
(Left.isNot(tok::comma) && Left.isNot(tok::semi)))
@@ -753,12 +759,6 @@ private:
if (Level != prec::Unknown)
return Level;
- if (Right.is(tok::arrow) || Right.is(tok::period)) {
- if (Left.is(tok::r_paren) && Line.Type == LT_BuilderTypeCall)
- return 5; // Should be smaller than breaking at a nested comma.
- return 150;
- }
-
return 3;
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=173695&r1=173694&r2=173695&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 28 11:30:17 2013
@@ -239,6 +239,18 @@ TEST_F(FormatTest, FormatsForLoop) {
verifyFormat(
"for (MachineFun::iterator IIII = PrevIt, EEEE = F.end(); IIII != EEEE;\n"
" ++IIIII) {\n}");
+ verifyFormat(
+ "for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa =\n"
+ " aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa;\n"
+ " aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {\n}");
+
+ // FIXME: Not sure whether we want extra identation in line 3 here:
+ verifyFormat(
+ "for (aaaaaaaaaaaaaaaaa aaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa !=\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);\n"
+ " ++aaaaaaaaaaa) {\n}");
}
TEST_F(FormatTest, RangeBasedForLoops) {
More information about the cfe-commits
mailing list