summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/ContinuationIndenter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index ed5098bf48f..199fc022048 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -47,6 +47,12 @@ static bool startsBinaryExpression(const FormatToken &Tok) {
return false;
}
+// Returns \c true if \c Tok is the "." or "->" of a call and starts the next
+// segment of a builder type call.
+static bool startsSegmentOfBuilderTypeCall(const FormatToken &Tok) {
+ return Tok.isMemberAccess() && Tok.Previous && Tok.Previous->closesScope();
+}
+
ContinuationIndenter::ContinuationIndenter(const FormatStyle &Style,
SourceManager &SourceMgr,
const AnnotatedLine &Line,
@@ -99,6 +105,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
// As they hide "DoSomething" and are generally bad for readability.
if (Previous.opensScope() && State.LowestLevelOnLine < State.StartOfLineLevel)
return false;
+ if (Current.isMemberAccess() && State.Stack.back().ContainsUnwrappedBuilder)
+ return false;
return !State.Stack.back().NoLineBreak;
}
@@ -178,6 +186,9 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
Line.MightBeFunctionDecl && State.Stack.back().BreakBeforeParameter &&
State.ParenLevel == 0)
return true;
+ if (startsSegmentOfBuilderTypeCall(Current) &&
+ State.Stack.back().CallContinuation != 0)
+ return true;
return false;
}
@@ -232,8 +243,7 @@ unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline,
} else if (Current.is(tok::lessless) &&
State.Stack.back().FirstLessLess != 0) {
State.Column = State.Stack.back().FirstLessLess;
- } else if (Current.isOneOf(tok::period, tok::arrow) &&
- Current.Type != TT_DesignatedInitializerPeriod) {
+ } else if (Current.isMemberAccess()) {
if (State.Stack.back().CallContinuation == 0) {
State.Column = ContinuationIndent;
State.Stack.back().CallContinuation = State.Column;
@@ -299,8 +309,7 @@ unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline,
if (!Current.isTrailingComment())
State.Stack.back().LastSpace = State.Column;
- if (Current.isOneOf(tok::arrow, tok::period) &&
- Current.Type != TT_DesignatedInitializerPeriod)
+ if (Current.isMemberAccess())
State.Stack.back().LastSpace += Current.CodePointCount;
State.StartOfLineLevel = State.ParenLevel;
State.LowestLevelOnLine = State.ParenLevel;
@@ -369,6 +378,8 @@ unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline,
if (Previous.is(tok::comma) && !Current.isTrailingComment() &&
State.Stack.back().AvoidBinPacking)
State.Stack.back().NoLineBreak = true;
+ if (startsSegmentOfBuilderTypeCall(Current))
+ State.Stack.back().ContainsUnwrappedBuilder = true;
State.Column += Spaces;
if (Current.is(tok::l_paren) && Previous.isOneOf(tok::kw_if, tok::kw_for))
@@ -401,8 +412,7 @@ unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline,
bool HasTrailingCall = false;
if (Previous.MatchingParen) {
const FormatToken *Next = Previous.MatchingParen->getNextNonComment();
- if (Next && Next->isOneOf(tok::period, tok::arrow))
- HasTrailingCall = true;
+ HasTrailingCall = Next && Next->isMemberAccess();
}
if (HasMultipleParameters ||
(HasTrailingCall &&
@@ -431,7 +441,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
if (!Current.opensScope() && !Current.closesScope())
State.LowestLevelOnLine =
std::min(State.LowestLevelOnLine, State.ParenLevel);
- if (Current.isOneOf(tok::period, tok::arrow))
+ if (Current.isMemberAccess())
State.Stack.back().StartOfFunctionCall =
Current.LastInChainOfCalls ? 0 : State.Column + Current.CodePointCount;
if (Current.Type == TT_CtorInitializerColon) {
OpenPOWER on IntegriCloud