This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Obj-C dictionary literals: Fixed typecast getting put on a separate line from the key
ClosedPublic

Authored by ksuther on Aug 31 2015, 1:16 PM.

Details

Reviewers
djasper
Summary

Fixes this bug: https://llvm.org/bugs/show_bug.cgi?id=22647

The following dictionary was getting formatted oddly:

NSDictionary *query = @{
    (__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword,
    (__bridge id)kSecReturnData: (__bridge id)kCFBooleanTrue,
};

It was turning into this:

NSDictionary *passwordQuery = @{
  (__bridge id) kSecClass : (__bridge id)kSecClassGenericPassword, (__bridge id)
  kSecReturnData : (__bridge id)kCFBooleanTrue, (__bridge id)
  kSecReturnAttributes : (__bridge id)kCFBooleanTrue,
};

As far as I can tell, changes to format Proto lines correctly was turning the key (e.g. kSecClass) into a TT_SelectorName, which was then force the cast to get separated from the key. I added an extra check to see if the current context is in a dictionary literal, and if so kept the type as TT_Unknown.

Diff Detail

Event Timeline

ksuther updated this revision to Diff 33618.Aug 31 2015, 1:16 PM
ksuther retitled this revision from to [clang-format] Obj-C dictionary literals: Fixed typecast getting put on a separate line from the key.
ksuther updated this object.
ksuther added a reviewer: djasper.
ksuther added a subscriber: cfe-commits.
ksuther updated this object.Aug 31 2015, 1:17 PM

Adding another comment in hopes of getting some visibility on this. Do I need to add other people as reviewers?

djasper added inline comments.Sep 17 2015, 9:25 AM
lib/Format/TokenAnnotator.cpp
377

Why the language check? If it is needed, can you add a test?

ksuther added inline comments.Sep 17 2015, 11:20 AM
lib/Format/TokenAnnotator.cpp
377

The language check is so that this only applies to Objective-C literals. Protocol Buffers already have a test suite that tests the conditional here (FormatTestProto.cpp). The reason for the check is that the tree for Objective-C literals and Protocol Buffers looks the same in this situation, but the format behavior needs to differ.

djasper accepted this revision.Sep 22 2015, 2:35 AM
djasper edited edge metadata.

Looks good. Do you have commit access?

lib/Format/TokenAnnotator.cpp
377

Ah, I see, thank you.

This revision is now accepted and ready to land.Sep 22 2015, 2:35 AM

Do I need to do anything else about this and D12489, or do they eventually get committed by someone else? Thanks!

This patch is still awaiting a commit. Sorry to repeatedly post about this, just don't want it to get lost.

Thanks!

djasper closed this revision.Oct 11 2015, 8:21 PM

Submitted as r250010.