Page MenuHomePhabricator

Adds support for formatting NS_CLOSED_ENUM and CF_CLOSED_ENUM alongside NS_ENUM and CF_ENUM.
ClosedPublic

Authored by heijink on Fri, Jul 19, 1:16 PM.

Details

Summary

Addresses the formatting of NS_CLOSED_ENUM and CF_CLOSED_ENUM, introduced in Swift 5.

Before:

typedef NS_CLOSED_ENUM(NSInteger, Foo){FooValueOne = 1, FooValueTwo,
                                       FooValueThree};

After:

typedef NS_CLOSED_ENUM(NSInteger, Foo) {
  FooValueOne = 1,
  FooValueTwo,
  FooValueThree
};

Diff Detail

Repository
rL LLVM

Event Timeline

heijink created this revision.Fri, Jul 19, 1:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptFri, Jul 19, 1:16 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
heijink edited the summary of this revision. (Show Details)Fri, Jul 19, 1:23 PM
heijink added reviewers: benhamilton, krasimir.
benhamilton requested changes to this revision.Fri, Jul 19, 2:52 PM

Thanks! Don't forget the CF version.

clang/lib/Format/FormatToken.h
793 ↗(On Diff #210883)

We'll also need CF_CLOSED_ENUM.

clang/lib/Format/UnwrappedLineParser.cpp
1219 ↗(On Diff #210883)

Keywords.CF_CLOSED_ENUM here as well.

clang/unittests/Format/FormatTest.cpp
1717–1736 ↗(On Diff #210883)

Please also add a test for CF_CLOSED_ENUM.

This revision now requires changes to proceed.Fri, Jul 19, 2:52 PM
heijink updated this revision to Diff 211065.Mon, Jul 22, 5:53 AM
heijink edited the summary of this revision. (Show Details)

Also added support for formatting CF_CLOSED_ENUM.

heijink marked 3 inline comments as done.Mon, Jul 22, 5:55 AM
heijink retitled this revision from Adds support for formatting NS_CLOSED_ENUM alongside NS_ENUM. to Adds support for formatting NS_CLOSED_ENUM and CF_CLOSED_ENUM alongside NS_ENUM and CF_ENUM..
heijink edited the summary of this revision. (Show Details)
benhamilton accepted this revision.Mon, Jul 22, 9:33 AM

LGTM, thanks!

This revision is now accepted and ready to land.Mon, Jul 22, 9:33 AM

Oh, I forgot there's one more place you should touch — the Objective-C style guesser for headers will need to be updated to understand that NS_CLOSED_ENUM indicates Objective-C:

https://reviews.llvm.org/source/llvm-github/browse/master/clang/lib/Format/Format.cpp$1688

Can you update this as well?

heijink updated this revision to Diff 211135.Mon, Jul 22, 9:48 AM

Adds NS_CLOSED_ENUM to the keywords that cause LLVM to detect Objective-C. Changed NSInteger to int in the unit tests, because NSInteger also signals Objective-C.

heijink updated this revision to Diff 211137.Mon, Jul 22, 10:06 AM

Fixed formatting of Format.cpp.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMon, Jul 22, 11:23 AM