summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/ContinuationIndenter.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-10-08 05:11:18 +0000
committerDaniel Jasper <djasper@google.com>2013-10-08 05:11:18 +0000
commitec01cd6e7fbb6f24844514cb1c83d7dea93672b8 (patch)
treeb571ba569c95e3a32ceac557747a4279e598d89d /clang/lib/Format/ContinuationIndenter.cpp
parent53f31af7ea0d4460e299055ffbd1daba650ce136 (diff)
downloadbcm5719-llvm-ec01cd6e7fbb6f24844514cb1c83d7dea93672b8.tar.gz
bcm5719-llvm-ec01cd6e7fbb6f24844514cb1c83d7dea93672b8.zip
clang-format: Improve constructor initializer linewrapping.
Specifically make ConstructorInitializerAllOnOneLineOrOnePerLine work nicely with BreakConstructorInitializersBeforeComma. This fixes llvm.org/PR17395. llvm-svn: 192168
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 6a5f8763d9b..ff1f1aa8534 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -44,6 +44,18 @@ static bool startsSegmentOfBuilderTypeCall(const FormatToken &Tok) {
return Tok.isMemberAccess() && Tok.Previous && Tok.Previous->closesScope();
}
+// Returns \c true if \c Current starts a new parameter.
+static bool startsNextParameter(const FormatToken &Current,
+ const FormatStyle &Style) {
+ const FormatToken &Previous = *Current.Previous;
+ if (Current.Type == TT_CtorInitializerComma &&
+ Style.BreakConstructorInitializersBeforeComma)
+ return true;
+ return Previous.is(tok::comma) && !Current.isTrailingComment() &&
+ (Previous.Type != TT_CtorInitializerComma ||
+ !Style.BreakConstructorInitializersBeforeComma);
+}
+
ContinuationIndenter::ContinuationIndenter(const FormatStyle &Style,
SourceManager &SourceMgr,
WhitespaceManager &Whitespaces,
@@ -113,15 +125,9 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
return true;
if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
return true;
- if (Style.BreakConstructorInitializersBeforeComma) {
- if (Previous.Type == TT_CtorInitializerComma)
- return false;
- if (Current.Type == TT_CtorInitializerComma)
- return true;
- }
- if ((Previous.isOneOf(tok::comma, tok::semi) || Current.is(tok::question) ||
- (Current.Type == TT_ConditionalExpr &&
- !(Current.is(tok::colon) && Previous.is(tok::question)))) &&
+ if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
+ Current.is(tok::question) ||
+ (Current.Type == TT_ConditionalExpr && Previous.isNot(tok::question))) &&
State.Stack.back().BreakBeforeParameter && !Current.isTrailingComment() &&
!Current.isOneOf(tok::r_paren, tok::r_brace))
return true;
@@ -250,8 +256,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
if (Previous.opensScope() && Previous.Type != TT_ObjCMethodExpr &&
Current.Type != TT_LineComment)
State.Stack.back().Indent = State.Column + Spaces;
- if (Previous.is(tok::comma) && !Current.isTrailingComment() &&
- State.Stack.back().AvoidBinPacking)
+ if (State.Stack.back().AvoidBinPacking && startsNextParameter(Current, Style))
State.Stack.back().NoLineBreak = true;
if (startsSegmentOfBuilderTypeCall(Current))
State.Stack.back().ContainsUnwrappedBuilder = true;
OpenPOWER on IntegriCloud