r186164 - clang-format: Improve <<-formatting.
Daniel Jasper
djasper at google.com
Fri Jul 12 08:14:05 PDT 2013
Author: djasper
Date: Fri Jul 12 10:14:05 2013
New Revision: 186164
URL: http://llvm.org/viewvc/llvm-project?rev=186164&view=rev
Log:
clang-format: Improve <<-formatting.
This fixes a regression caused by r186115.
Before:
Diag(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
bbbbbbbbb) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<< aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
After:
Diag(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
<< aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<< aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
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=186164&r1=186163&r2=186164&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Jul 12 10:14:05 2013
@@ -1174,6 +1174,11 @@ private:
State.Stack.back().BreakBeforeParameter)
return true;
+ // Same as above, but for the first "<<" operator.
+ if (Current.is(tok::lessless) && State.Stack.back().BreakBeforeParameter &&
+ State.Stack.back().FirstLessLess == 0)
+ return true;
+
// FIXME: Comparing LongestObjCSelectorName to 0 is a hacky way of finding
// out whether it is the first parameter. Clean this up.
if (Current.Type == TT_ObjCSelectorName &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=186164&r1=186163&r2=186164&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jul 12 10:14:05 2013
@@ -3026,6 +3026,11 @@ TEST_F(FormatTest, AlignsPipes) {
" << aaaaaaaaaaaaaaaaaaaaaaaaaaaa;",
getLLVMStyleWithColumns(70));
+ // But sometimes, breaking before the first "<<" is necessary.
+ verifyFormat("Diag(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)\n"
+ " << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;");
+
verifyFormat(
"llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
" .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();");
More information about the cfe-commits
mailing list