diff options
author | Daniel Jasper <djasper@google.com> | 2014-04-09 12:08:39 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-04-09 12:08:39 +0000 |
commit | 3ae6f5a47b22a2d7ad4a70438bf143ada09a0ea3 (patch) | |
tree | 29e0b8d9e06404c1a72d4ab06a06f48693f23914 /clang/lib/Format/ContinuationIndenter.cpp | |
parent | 6bd32296160d8e2fcecff8918669d57742beaa0f (diff) | |
download | bcm5719-llvm-3ae6f5a47b22a2d7ad4a70438bf143ada09a0ea3.tar.gz bcm5719-llvm-3ae6f5a47b22a2d7ad4a70438bf143ada09a0ea3.zip |
clang-format: Improve format of calls with several lambdas.
Before:
SomeFunction([]() {
int i = 42;
return i;
},
[]() {
int j = 43;
return j;
});
After:
SomeFunction([]() {
int i = 42;
return i;
},
[]() {
int j = 43;
return j;
});
llvm-svn: 205848
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 5317fb33ffb..d25ab68e396 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -566,6 +566,8 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, Current.LastInChainOfCalls ? 0 : State.Column + Current.ColumnWidth; if (Current.Type == TT_ObjCSelectorName) State.Stack.back().ObjCSelectorNameFound = true; + if (Current.Type == TT_LambdaLSquare) + ++State.Stack.back().LambdasFound; if (Current.Type == TT_CtorInitializerColon) { // Indent 2 from the column, so: // SomeClass::SomeClass() @@ -654,7 +656,8 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, bool BreakBeforeParameter = false; if (Current.is(tok::l_brace) || Current.Type == TT_ArrayInitializerLSquare) { - if (Current.MatchingParen && Current.BlockKind == BK_Block) { + if (Current.MatchingParen && Current.BlockKind == BK_Block && + State.Stack.back().LambdasFound <= 1) { // If this is an l_brace starting a nested block, we pretend (wrt. to // indentation) that we already consumed the corresponding r_brace. // Thus, we remove all ParenStates caused by fake parentheses that end @@ -670,6 +673,10 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, // SomeFunction(a, [] { // f(); // break // }); + // + // If we have already found more than one lambda introducers on this + // level, we opt out of this because similarity between the lambdas is + // more important. for (unsigned i = 0; i != Current.MatchingParen->FakeRParens; ++i) { assert(State.Stack.size() > 1); if (State.Stack.size() == 1) { |