r256831 - clang-format: Avoid creating hanging indents in call sequences.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 5 05:03:59 PST 2016
Author: djasper
Date: Tue Jan 5 07:03:59 2016
New Revision: 256831
URL: http://llvm.org/viewvc/llvm-project?rev=256831&view=rev
Log:
clang-format: Avoid creating hanging indents in call sequences.
Before:
aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaa)
.aaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
After:
aaaaaaaaaaaaaaaa
.aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaa)
.aaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.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=256831&r1=256830&r2=256831&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Jan 5 07:03:59 2016
@@ -38,6 +38,12 @@ static unsigned getLengthToMatchingParen
return End->TotalLength - Tok.TotalLength + 1;
}
+static unsigned getLengthToNextOperator(const FormatToken &Tok) {
+ if (!Tok.NextOperator)
+ return 0;
+ return Tok.NextOperator->TotalLength - Tok.TotalLength;
+}
+
// 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) {
@@ -174,6 +180,10 @@ bool ContinuationIndenter::mustBreak(con
if (State.Column < NewLineColumn)
return false;
+ if (Current.isMemberAccess() &&
+ State.Column + getLengthToNextOperator(Current) > Style.ColumnLimit)
+ return true;
+
if (Style.AlwaysBreakBeforeMultilineStrings &&
(NewLineColumn == State.FirstIndent + Style.ContinuationIndentWidth ||
Previous.is(tok::comma) || Current.NestingLevel < 2) &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=256831&r1=256830&r2=256831&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jan 5 07:03:59 2016
@@ -4157,8 +4157,9 @@ TEST_F(FormatTest, FormatsBuilderPattern
verifyFormat("return aaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa() <\n"
" aaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa();");
verifyFormat(
- "aaaaaaa->aaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
+ "aaaaaaa->aaaaaaa\n"
+ " ->aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
" ->aaaaaaaa(aaaaaaaaaaaaaaa);");
verifyFormat(
"aaaaaaa->aaaaaaa\n"
@@ -4243,6 +4244,13 @@ TEST_F(FormatTest, FormatsBuilderPattern
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
verifyFormat("aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaa().aaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
+ verifyFormat("aaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaa)\n"
+ " .aaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);",
+ getLLVMStyleWithColumns(60));
+ verifyFormat("aaaaaaaaaaaaaaaaaa\n"
+ " .aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaa)\n"
+ " .aaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);",
+ getLLVMStyleWithColumns(59));
}
TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {
More information about the cfe-commits
mailing list