r193049 - clang-format: Improve formatting of ObjC dict literals.

Daniel Jasper djasper at google.com
Sun Oct 20 23:41:14 PDT 2013


The FIXME did not make sense to me anymore as there was no test about array
literals (thus, nothing to fix in the test file). For tracking stuff we
still have to do, there is bugzilla (as you already pointed out). Also, I
am close to finishing a patch for array literals and it should go in before
the end of the week.


On Sun, Oct 20, 2013 at 10:45 PM, Nico Weber <thakis at chromium.org> wrote:

> \o/ Thanks!
>
>
> On Sun, Oct 20, 2013 at 9:45 AM, Daniel Jasper <djasper at google.com> wrote:
>
>> Author: djasper
>> Date: Sun Oct 20 11:45:46 2013
>> New Revision: 193049
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=193049&view=rev
>> Log:
>> 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]
>>   };
>>
>> Modified:
>>     cfe/trunk/lib/Format/ContinuationIndenter.cpp
>>     cfe/trunk/unittests/Format/FormatTest.cpp
>>
>> Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=193049&r1=193048&r2=193049&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
>> +++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sun Oct 20 11:45:46 2013
>> @@ -136,6 +136,9 @@ bool ContinuationIndenter::mustBreak(con
>>        !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::moveState
>>
>>    // 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
>>
>> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=193049&r1=193048&r2=193049&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
>> +++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Oct 20 11:45:46 2013
>> @@ -5363,14 +5363,17 @@ TEST_F(FormatTest, ObjCLiterals) {
>>    verifyFormat(
>>        "NSDictionary *settings = @{ AVEncoderKey : @(AVAudioQualityMax)
>> };");
>>
>> -  // FIXME: Nested and multi-line array and dictionary literals need
>> more work.
>>
>
> The FIXME for array literals should remain, right? (PR15231)
>
>
>>    verifyFormat(
>> -      "NSDictionary *d = @{ @\"nam\" : NSUserNam(), @\"dte\" : [NSDate
>> date],\n"
>> -      "                     @\"processInfo\" : [NSProcessInfo
>> processInfo] };");
>> +      "NSDictionary *d = @{\n"
>> +      "  @\"nam\" : NSUserNam(),\n"
>> +      "  @\"dte\" : [NSDate date],\n"
>> +      "  @\"processInfo\" : [NSProcessInfo processInfo]\n"
>> +      "};");
>>    verifyFormat(
>> -      "@{ NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
>> :\n"
>> -      "   regularFont, };");
>> -
>> +      "@{\n"
>> +      "  NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee :
>> "
>> +      "regularFont,\n"
>> +      "};");
>>  }
>>
>>  TEST_F(FormatTest, ReformatRegionAdjustsIndent) {
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131021/5a617d6a/attachment.html>


More information about the cfe-commits mailing list