This is an archive of the discontinued LLVM Phabricator instance.

[clang-format/ObjC] Fix NS_SWIFT_NAME(foo(bar:baz:)) after ObjC method decl
ClosedPublic

Authored by benhamilton on Jun 27 2018, 3:51 PM.

Details

Summary

In D44638, I partially fixed NS_SWIFT_NAME(foo(bar:baz:))-style
annotations on C functions, but didn't add a test for Objective-C
method declarations.

For ObjC method declarations which are annotated with NS_SWIFT_NAME(...),
we currently fail to annotate the final component of the selector
name as TT_SelectorName.

Because the token type is left unknown, clang-format will happily
cause a compilation error when it changes the following:

@interface Foo
- (void)doStuffWithFoo:(id)name
                   bar:(id)bar
                   baz:(id)baz
    NS_SWIFT_NAME(doStuff(withFoo:bar:baz:));
@end

to:

@interface Foo
- (void)doStuffWithFoo:(id)name
                   bar:(id)bar
                   baz:(id)baz
    NS_SWIFT_NAME(doStuff(withFoo:bar:baz
:));
@end

(note the linebreak before the final :).

The logic which decides whether or not to annotate the token before a
: with TT_SelectorName is pretty fragile, and has to handle some
pretty odd cases like pair-parameters:

[I drawRectOn:surface ofSize:aa:bbb atOrigin:cc:dd];

So, to minimize the effect of this change, I decided to only annotate
unknown identifiers before a : as TT_SelectorName for Objective-C
declaration lines.

Test Plan: New tests included. Confirmed tests failed before change and

passed after change. Ran tests with:
% make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests

Diff Detail

Repository
rL LLVM

Event Timeline

benhamilton created this revision.Jun 27 2018, 3:51 PM
krasimir accepted this revision.Jun 29 2018, 7:38 AM
This revision is now accepted and ready to land.Jun 29 2018, 7:38 AM
This revision was automatically updated to reflect the committed changes.