r233304 - clang-format: Force line break in trailing calls after multline exprs.
Daniel Jasper
djasper at google.com
Thu Mar 26 11:46:29 PDT 2015
Author: djasper
Date: Thu Mar 26 13:46:28 2015
New Revision: 233304
URL: http://llvm.org/viewvc/llvm-project?rev=233304&view=rev
Log:
clang-format: Force line break in trailing calls after multline exprs.
Before:
aaaaaaaa(aaaaaaaaaa,
bbbbbbbbbb).a();
After:
aaaaaaaa(aaaaaaaaaa,
bbbbbbbbbb)
.a();
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.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=233304&r1=233303&r2=233304&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Mar 26 13:46:28 2015
@@ -221,8 +221,7 @@ bool ContinuationIndenter::mustBreak(con
if (startsSegmentOfBuilderTypeCall(Current) &&
(State.Stack.back().CallContinuation != 0 ||
- (State.Stack.back().BreakBeforeParameter &&
- State.Stack.back().ContainsUnwrappedBuilder)))
+ State.Stack.back().BreakBeforeParameter))
return true;
// The following could be precomputed as they do not depend on the state.
@@ -323,6 +322,8 @@ void ContinuationIndenter::addTokenOnCur
if (startsSegmentOfBuilderTypeCall(Current))
State.Stack.back().ContainsUnwrappedBuilder = true;
+ if (Current.is(TT_LambdaArrow))
+ State.Stack.back().NoLineBreak = true;
if (Current.isMemberAccess() && Previous.is(tok::r_paren) &&
(Previous.MatchingParen &&
(Previous.TotalLength - Previous.MatchingParen->TotalLength > 10))) {
Modified: cfe/trunk/lib/Format/FormatToken.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=233304&r1=233303&r2=233304&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Thu Mar 26 13:46:28 2015
@@ -321,7 +321,8 @@ struct FormatToken {
/// \brief Returns \c true if this is a "." or "->" accessing a member.
bool isMemberAccess() const {
return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
- !isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow);
+ !isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
+ TT_LambdaArrow);
}
bool isUnaryOperator() const {
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=233304&r1=233303&r2=233304&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Mar 26 13:46:28 2015
@@ -1624,7 +1624,6 @@ unsigned TokenAnnotator::splitPenalty(co
if (Left.is(TT_ConditionalExpr))
return prec::Conditional;
prec::Level Level = Left.getPrecedence();
-
if (Level != prec::Unknown)
return Level;
@@ -2098,8 +2097,9 @@ bool TokenAnnotator::canBreakBefore(cons
return true;
return Left.isOneOf(tok::comma, tok::coloncolon, tok::semi, tok::l_brace,
tok::kw_class, tok::kw_struct) ||
- Right.isMemberAccess() || Right.is(TT_TrailingReturnArrow) ||
- Right.isOneOf(tok::lessless, tok::colon, tok::l_square, tok::at) ||
+ Right.isMemberAccess() ||
+ Right.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow, tok::lessless,
+ tok::colon, tok::l_square, tok::at) ||
(Left.is(tok::r_paren) &&
Right.isOneOf(tok::identifier, tok::kw_const)) ||
(Left.is(tok::l_paren) && !Right.is(tok::r_paren));
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=233304&r1=233303&r2=233304&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Mar 26 13:46:28 2015
@@ -4871,7 +4871,8 @@ TEST_F(FormatTest, WrapsAtFunctionCallsI
verifyFormat("SomeMap[std::pair(aaaaaaaaaaaa, bbbbbbbbbbbbbbb)].insert(\n"
" ccccccccccccccccccccccc);");
verifyFormat("aaaaa(aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa).aaaaa(aaaaa),\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
+ " .aaaaa(aaaaa),\n"
" aaaaaaaaaaaaaaaaaaaaa);");
verifyFormat("void f() {\n"
" aaaaaaaaaaaaaaaaaaaaaaaaa(\n"
@@ -4905,9 +4906,9 @@ TEST_F(FormatTest, WrapsAtFunctionCallsI
verifyFormat("a->aaaaaa()->aaaaaaaaaaa(aaaaaaaa()->aaaaaa()->aaaaa() ||\n"
" aaaaaaaaa()->aaaaaa()->aaaaa());");
- // FIXME: Should we break before .a()?
verifyFormat("aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa).a();");
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
+ " .a();");
FormatStyle NoBinPacking = getLLVMStyle();
NoBinPacking.BinPackParameters = false;
More information about the cfe-commits
mailing list