r194268 - clang-format: Don't auto-break short macros in WebKit style.
Daniel Jasper
djasper at google.com
Fri Nov 8 09:33:27 PST 2013
Author: djasper
Date: Fri Nov 8 11:33:27 2013
New Revision: 194268
URL: http://llvm.org/viewvc/llvm-project?rev=194268&view=rev
Log:
clang-format: Don't auto-break short macros in WebKit style.
This fixes llvm.org/PR17842.
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=194268&r1=194267&r2=194268&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Nov 8 11:33:27 2013
@@ -391,7 +391,8 @@ public:
if (Indent > Style.ColumnLimit)
return 0;
- unsigned Limit = Style.ColumnLimit - Indent;
+ unsigned Limit =
+ Style.ColumnLimit == 0 ? UINT_MAX : Style.ColumnLimit - Indent;
// If we already exceed the column limit, we set 'Limit' to 0. The different
// tryMerge..() functions can then decide whether to still do merging.
Limit = TheLine->Last->TotalLength > Limit
@@ -757,6 +758,7 @@ private:
assert(!B.First->Previous);
A.Last->Next = B.First;
B.First->Previous = A.Last;
+ B.First->CanBreakBefore = true;
unsigned LengthA = A.Last->TotalLength + B.First->SpacesRequiredBefore;
for (FormatToken *Tok = B.First; Tok; Tok = Tok->Next) {
Tok->TotalLength += LengthA;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=194268&r1=194267&r2=194268&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Nov 8 11:33:27 2013
@@ -7081,6 +7081,15 @@ TEST_F(FormatTest, FormatsWithWebKitStyl
" i++;\n"
"}",
format("if (aaaaaaaaaaaaaaa || bbbbbbbbbbbbbbb) { i++; }", Style));
+
+ // Don't automatically break all macro definitions (llvm.org/PR17842).
+ verifyFormat("#define aNumber 10", Style);
+ // However, generally keep the line breaks that the user authored.
+ EXPECT_EQ("#define aNumber \\\n"
+ " 10",
+ format("#define aNumber \\\n"
+ " 10",
+ Style));
}
TEST_F(FormatTest, FormatsProtocolBufferDefinitions) {
More information about the cfe-commits
mailing list