diff options
author | Daniel Jasper <djasper@google.com> | 2013-10-20 16:45:46 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-10-20 16:45:46 +0000 |
commit | d489dd342bfdc2481a62633c8f8d66d6e2339dcb (patch) | |
tree | 6db628a8ba69d9886b9f51ef1f05675aadd8b249 /clang/lib/Format/ContinuationIndenter.cpp | |
parent | 80b5a9d2d094724db1da43c80739b2042975a2eb (diff) | |
download | bcm5719-llvm-d489dd342bfdc2481a62633c8f8d66d6e2339dcb.tar.gz bcm5719-llvm-d489dd342bfdc2481a62633c8f8d66d6e2339dcb.zip |
clang-format: Improve formatting of ObjC dict literals.
Before:
NSDictionary *d = @{ @"nam" : NSUserNam(), @"dte" : [NSDate date],
@"processInfo" : [NSProcessInfo processInfo]
};
After:
NSDictionary *d = @{
@"nam" : NSUserNam(),
@"dte" : [NSDate date],
@"processInfo" : [NSProcessInfo processInfo]
};
llvm-svn: 193049
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 0cf9e32ea84..63a03e0d448 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -136,6 +136,9 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { !Previous.isOneOf(tok::kw_return, tok::lessless) && Previous.Type != TT_InlineASMColon && NextIsMultilineString(State)) return true; + if (Previous.Type == TT_ObjCDictLiteral && Previous.is(tok::l_brace) && + getLengthToMatchingParen(Previous) + State.Column > getColumnLimit(State)) + return true; if (!Style.BreakBeforeBinaryOperators) { // If we need to break somewhere inside the LHS of a binary expression, we @@ -593,11 +596,15 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, // If this '[' opens an ObjC call, determine whether all parameters fit into // one line and put one per line if they don't. - if (Current.is(tok::l_square) && Current.Type == TT_ObjCMethodExpr && + if (Current.isOneOf(tok::l_brace, tok::l_square) && + (Current.Type == TT_ObjCDictLiteral || + Current.Type == TT_ObjCMethodExpr) && Current.MatchingParen != NULL) { if (getLengthToMatchingParen(Current) + State.Column > - getColumnLimit(State)) + getColumnLimit(State)) { State.Stack.back().BreakBeforeParameter = true; + State.Stack.back().AvoidBinPacking = true; + } } // If we encounter a closing ), ], } or >, we can remove a level from our |