forked from OSchip/llvm-project
clang-format: Force line break in trailing calls after multline exprs.
Before: aaaaaaaa(aaaaaaaaaa, bbbbbbbbbb).a(); After: aaaaaaaa(aaaaaaaaaa, bbbbbbbbbb) .a(); llvm-svn: 233304
This commit is contained in:
parent
4c8713969c
commit
05cd92922d
|
@ -221,8 +221,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
|
|||
|
||||
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::addTokenOnCurrentLine(LineState &State, bool DryRun,
|
|||
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))) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1624,7 +1624,6 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
|
|||
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(const AnnotatedLine &Line,
|
|||
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));
|
||||
|
|
|
@ -4871,7 +4871,8 @@ TEST_F(FormatTest, WrapsAtFunctionCallsIfNecessary) {
|
|||
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, WrapsAtFunctionCallsIfNecessary) {
|
|||
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;
|
||||
|
|
Loading…
Reference in New Issue