<div dir="ltr">\o/ Thanks!<div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Oct 20, 2013 at 9:45 AM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: djasper<br>
Date: Sun Oct 20 11:45:46 2013<br>
New Revision: 193049<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=193049&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=193049&view=rev</a><br>
Log:<br>
clang-format: Improve formatting of ObjC dict literals.<br>
<br>
Before:<br>
  NSDictionary *d = @{ @"nam" : NSUserNam(), @"dte" : [NSDate date],<br>
                       @"processInfo" : [NSProcessInfo processInfo]<br>
  };<br>
<br>
After:<br>
  NSDictionary *d = @{<br>
    @"nam" : NSUserNam(),<br>
    @"dte" : [NSDate date],<br>
    @"processInfo" : [NSProcessInfo processInfo]<br>
  };<br>
<br>
Modified:<br>
    cfe/trunk/lib/Format/ContinuationIndenter.cpp<br>
    cfe/trunk/unittests/Format/FormatTest.cpp<br>
<br>
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=193049&r1=193048&r2=193049&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=193049&r1=193048&r2=193049&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)<br>
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sun Oct 20 11:45:46 2013<br>
@@ -136,6 +136,9 @@ bool ContinuationIndenter::mustBreak(con<br>
       !Previous.isOneOf(tok::kw_return, tok::lessless) &&<br>
       Previous.Type != TT_InlineASMColon && NextIsMultilineString(State))<br>
     return true;<br>
+  if (Previous.Type == TT_ObjCDictLiteral && Previous.is(tok::l_brace) &&<br>
+      getLengthToMatchingParen(Previous) + State.Column > getColumnLimit(State))<br>
+    return true;<br>
<br>
   if (!Style.BreakBeforeBinaryOperators) {<br>
     // If we need to break somewhere inside the LHS of a binary expression, we<br>
@@ -593,11 +596,15 @@ unsigned ContinuationIndenter::moveState<br>
<br>
   // If this '[' opens an ObjC call, determine whether all parameters fit into<br>
   // one line and put one per line if they don't.<br>
-  if (Current.is(tok::l_square) && Current.Type == TT_ObjCMethodExpr &&<br>
+  if (Current.isOneOf(tok::l_brace, tok::l_square) &&<br>
+      (Current.Type == TT_ObjCDictLiteral ||<br>
+       Current.Type == TT_ObjCMethodExpr) &&<br>
       Current.MatchingParen != NULL) {<br>
     if (getLengthToMatchingParen(Current) + State.Column ><br>
-        getColumnLimit(State))<br>
+        getColumnLimit(State)) {<br>
       State.Stack.back().BreakBeforeParameter = true;<br>
+      State.Stack.back().AvoidBinPacking = true;<br>
+    }<br>
   }<br>
<br>
   // If we encounter a closing ), ], } or >, we can remove a level from our<br>
<br>
Modified: cfe/trunk/unittests/Format/FormatTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=193049&r1=193048&r2=193049&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=193049&r1=193048&r2=193049&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Oct 20 11:45:46 2013<br>
@@ -5363,14 +5363,17 @@ TEST_F(FormatTest, ObjCLiterals) {<br>
   verifyFormat(<br>
       "NSDictionary *settings = @{ AVEncoderKey : @(AVAudioQualityMax) };");<br>
<br>
-  // FIXME: Nested and multi-line array and dictionary literals need more work.<br></blockquote><div><br></div><div>The FIXME for array literals should remain, right? (PR15231)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

   verifyFormat(<br>
-      "NSDictionary *d = @{ @\"nam\" : NSUserNam(), @\"dte\" : [NSDate date],\n"<br>
-      "                     @\"processInfo\" : [NSProcessInfo processInfo] };");<br>
+      "NSDictionary *d = @{\n"<br>
+      "  @\"nam\" : NSUserNam(),\n"<br>
+      "  @\"dte\" : [NSDate date],\n"<br>
+      "  @\"processInfo\" : [NSProcessInfo processInfo]\n"<br>
+      "};");<br>
   verifyFormat(<br>
-      "@{ NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee :\n"<br>
-      "   regularFont, };");<br>
-<br>
+      "@{\n"<br>
+      "  NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : "<br>
+      "regularFont,\n"<br>
+      "};");<br>
 }<br>
<br>
 TEST_F(FormatTest, ReformatRegionAdjustsIndent) {<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>