aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-03-15 14:57:30 +0000
committerDaniel Jasper <djasper@google.com>2013-03-15 14:57:30 +0000
commit3af59ce065310fd3d0820a6e2644d4ca688be810 (patch)
tree53ce9c8c0870e9ecb17c6c3b9535408b82800c5f /lib/Format/Format.cpp
parent1fdd8b351e28ee175157e61dac1b3f62b79b7a62 (diff)
Improve formatting of chained calls.
clang-format already prevented sequences like: ... SomeParameter).someFunction( ... as those are quite confusing. This failed on: ... SomeParameter).someFunction(otherFunction( ... Fixed in this patch. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177157 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index aa715e692d..a17823f4ce 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -985,14 +985,6 @@ private:
!(State.NextToken->is(tok::r_brace) &&
State.Stack.back().BreakBeforeClosingBrace))
return false;
- // This prevents breaks like:
- // ...
- // SomeParameter, OtherParameter).DoSomething(
- // ...
- // As they hide "DoSomething" and generally bad for readability.
- if (State.NextToken->Parent->is(tok::l_paren) &&
- State.ParenLevel <= State.StartOfLineLevel)
- return false;
// Trying to insert a parameter on a new line if there are already more than
// one parameter on the current line is bin packing.
if (State.Stack.back().HasMultiParameterLine &&
@@ -1031,9 +1023,25 @@ private:
return true;
if (State.NextToken->Type == TT_InlineASMColon)
return true;
+ // This prevents breaks like:
+ // ...
+ // SomeParameter, OtherParameter).DoSomething(
+ // ...
+ // As they hide "DoSomething" and generally bad for readability.
+ if (State.NextToken->isOneOf(tok::period, tok::arrow) &&
+ getRemainingLength(State) + State.Column > getColumnLimit() &&
+ State.ParenLevel < State.StartOfLineLevel)
+ return true;
return false;
}
+ // Returns the total number of columns required for the remaining tokens.
+ unsigned getRemainingLength(const LineState &State) {
+ if (State.NextToken && State.NextToken->Parent)
+ return Line.Last->TotalLength - State.NextToken->Parent->TotalLength;
+ return 0;
+ }
+
FormatStyle Style;
SourceManager &SourceMgr;
const AnnotatedLine &Line;