diff options
author | Daniel Jasper <djasper@google.com> | 2014-11-21 13:38:53 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-11-21 13:38:53 +0000 |
commit | 4b444495ed95c433d8a4fa757ac4db37d6b71d4d (patch) | |
tree | 89bf3acea2bc48fbb4b6df69b94521a369d05e3f /clang/lib/Format/ContinuationIndenter.cpp | |
parent | 45bac8d4e8cba53abf6476417233fa7d7eb7b45c (diff) | |
download | bcm5719-llvm-4b444495ed95c433d8a4fa757ac4db37d6b71d4d.tar.gz bcm5719-llvm-4b444495ed95c433d8a4fa757ac4db37d6b71d4d.zip |
clang-format: Use nested block special case for all languages.
Previously this was only used for JavaScript.
Before:
functionCall({
int i;
int j;
},
aaaa, bbbb, cccc);
After:
functionCall({
int i;
int j;
}, aaaa, bbbb, cccc);
llvm-svn: 222531
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 40b50dde851..825a88ebae0 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -117,9 +117,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) { // Don't create a 'hanging' indent if there are multiple blocks in a single // statement. - if (Style.Language == FormatStyle::LK_JavaScript && - Previous.is(tok::l_brace) && State.Stack.size() > 1 && - State.Stack[State.Stack.size() - 2].JSFunctionInlined && + if (Previous.is(tok::l_brace) && State.Stack.size() > 1 && + State.Stack[State.Stack.size() - 2].NestedBlockInlined && State.Stack[State.Stack.size() - 2].HasMultipleNestedBlocks) return false; @@ -453,11 +452,10 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, // Any break on this level means that the parent level has been broken // and we need to avoid bin packing there. - bool JavaScriptFormat = Style.Language == FormatStyle::LK_JavaScript && - Current.is(tok::r_brace) && - State.Stack.size() > 1 && - State.Stack[State.Stack.size() - 2].JSFunctionInlined; - if (!JavaScriptFormat) { + bool NestedBlockSpecialCase = + Current.is(tok::r_brace) && State.Stack.size() > 1 && + State.Stack[State.Stack.size() - 2].NestedBlockInlined; + if (!NestedBlockSpecialCase) { for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i) { State.Stack[i].BreakBeforeParameter = true; } @@ -520,7 +518,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { : State.Stack.back().Indent; if (Current.isOneOf(tok::r_brace, tok::r_square)) { if (State.Stack.size() > 1 && - State.Stack[State.Stack.size() - 2].JSFunctionInlined) + State.Stack[State.Stack.size() - 2].NestedBlockInlined) return State.FirstIndent; if (Current.closesBlockTypeList(Style) || (Current.MatchingParen && @@ -666,22 +664,21 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, // foo(); // bar(); // }, a, b, c); - if (Style.Language == FormatStyle::LK_JavaScript) { - if (Current.isNot(tok::comment) && Previous && Previous->is(tok::l_brace) && - State.Stack.size() > 1) { - if (State.Stack[State.Stack.size() - 2].JSFunctionInlined && Newline) { - for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i) { - State.Stack[i].NoLineBreak = true; - } + if (Current.isNot(tok::comment) && Previous && Previous->is(tok::l_brace) && + State.Stack.size() > 1) { + if (State.Stack[State.Stack.size() - 2].NestedBlockInlined && Newline) { + for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i) { + State.Stack[i].NoLineBreak = true; } - State.Stack[State.Stack.size() - 2].JSFunctionInlined = false; } - if (Current.is(Keywords.kw_function)) - State.Stack.back().JSFunctionInlined = - !Newline && Previous && Previous->Type != TT_DictLiteral && - // If the unnamed function is the only parameter to another function, - // we can likely inline it and come up with a good format. - (Previous->isNot(tok::l_paren) || Previous->ParameterCount > 1); + State.Stack[State.Stack.size() - 2].NestedBlockInlined = false; + } + if (Previous && (Previous->isOneOf(tok::l_paren, tok::comma, tok::colon) || + Previous->isOneOf(TT_BinaryOperator, TT_ConditionalExpr)) && + !Previous->isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) { + State.Stack.back().NestedBlockInlined = + !Newline && + (Previous->isNot(tok::l_paren) || Previous->ParameterCount > 1) && !Newline; } moveStatePastFakeLParens(State, Newline); |