diff options
author | Daniel Jasper <djasper@google.com> | 2013-07-09 11:57:27 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-07-09 11:57:27 +0000 |
commit | bd05888fa0a3c600e7a75704d38f786b8fe549cf (patch) | |
tree | db06040efb7e48eed883e1a12aab8e09d15bb260 /clang/lib/Format/Format.cpp | |
parent | 0f12aa2b0f5c919148efa76e755af580581fdb5d (diff) | |
download | bcm5719-llvm-bd05888fa0a3c600e7a75704d38f786b8fe549cf.tar.gz bcm5719-llvm-bd05888fa0a3c600e7a75704d38f786b8fe549cf.zip |
Avoid confusing indentations for chained function calls.
Basically treat a function with a trailing call similar to a function
with multiple parameters.
Before:
aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa))
.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();
After:
aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa))
.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();
Also fix typo.
llvm-svn: 185930
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r-- | clang/lib/Format/Format.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 34ed8ea07c4..fb931490dc7 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -672,10 +672,24 @@ private: State.Stack.back().LastSpace = State.Column; else if (Previous.Type == TT_InheritanceColon) State.Stack.back().Indent = State.Column; - else if (Previous.opensScope() && !Current.FakeLParens.empty()) - // If this function has multiple parameters or a binary expression - // parameter, indent nested calls from the start of the first parameter. - State.Stack.back().LastSpace = State.Column; + else if (Previous.opensScope()) { + // If a function has multiple parameters (including a single parameter + // that is a binary expression) or a trailing call, indented all + // parameters from the opening parenthesis. This avoids confusing + // indents like: + // OuterFunction(InnerFunctionCall( + // ParameterToInnerFunction), + // SecondParameterToOuterFunction); + bool HasMultipleParameters = !Current.FakeLParens.empty(); + bool HasTrailingCall = false; + if (Previous.MatchingParen) { + const FormatToken *Next = Previous.MatchingParen->getNextNonComment(); + if (Next && Next->isOneOf(tok::period, tok::arrow)) + HasTrailingCall = true; + } + if (HasMultipleParameters || HasTrailingCall) + State.Stack.back().LastSpace = State.Column; + } } return moveStateToNextToken(State, DryRun); |