[PATCH] D65012: Adds support for formatting NS_CLOSED_ENUM alongside NS_ENUM.

2019-07-19 Thread Hank Heijink via Phabricator via cfe-commits
heijink created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65012

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestObjC.cpp


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -118,6 +118,11 @@
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 
+  Style = getStyle("{}", "a.h", "none",
+   "typedef NS_CLOSED_ENUM(NSInteger, Foo) {};\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
   Style = getStyle("{}", "a.h", "none", "enum Foo {};");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1716,6 +1716,8 @@
 
 TEST_F(FormatTest, FormatsNSEnums) {
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, SomeName) { AAA, BBB }");
+  verifyGoogleFormat(
+  "typedef NS_CLOSED_ENUM(NSInteger, SomeName) { AAA, BBB }");
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, MyType) {\n"
  "  // Information about someDecentlyLongValue.\n"
  "  someDecentlyLongValue,\n"
@@ -1724,6 +1726,14 @@
  "  // Information about aThirdDecentlyLongValue.\n"
  "  aThirdDecentlyLongValue\n"
  "};");
+  verifyGoogleFormat("typedef NS_CLOSED_ENUM(NSInteger, MyType) {\n"
+ "  // Information about someDecentlyLongValue.\n"
+ "  someDecentlyLongValue,\n"
+ "  // Information about anotherDecentlyLongValue.\n"
+ "  anotherDecentlyLongValue,\n"
+ "  // Information about aThirdDecentlyLongValue.\n"
+ "  aThirdDecentlyLongValue\n"
+ "};");
   verifyGoogleFormat("typedef NS_OPTIONS(NSInteger, MyType) {\n"
  "  a = 1,\n"
  "  b = 2,\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1215,7 +1215,8 @@
 case tok::kw_typedef:
   nextToken();
   if (FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS,
- Keywords.kw_CF_ENUM, Keywords.kw_CF_OPTIONS))
+ Keywords.kw_CF_ENUM, Keywords.kw_CF_OPTIONS,
+ Keywords.kw_NS_CLOSED_ENUM))
 parseEnum();
   break;
 case tok::kw_struct:
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -679,6 +679,7 @@
 kw_of = &IdentTable.get("of");
 kw_CF_ENUM = &IdentTable.get("CF_ENUM");
 kw_CF_OPTIONS = &IdentTable.get("CF_OPTIONS");
+kw_NS_CLOSED_ENUM = &IdentTable.get("NS_CLOSED_ENUM");
 kw_NS_ENUM = &IdentTable.get("NS_ENUM");
 kw_NS_OPTIONS = &IdentTable.get("NS_OPTIONS");
 
@@ -789,6 +790,7 @@
   IdentifierInfo *kw_of;
   IdentifierInfo *kw_CF_ENUM;
   IdentifierInfo *kw_CF_OPTIONS;
+  IdentifierInfo *kw_NS_CLOSED_ENUM;
   IdentifierInfo *kw_NS_ENUM;
   IdentifierInfo *kw_NS_OPTIONS;
   IdentifierInfo *kw___except;


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -118,6 +118,11 @@
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 
+  Style = getStyle("{}", "a.h", "none",
+   "typedef NS_CLOSED_ENUM(NSInteger, Foo) {};\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
   Style = getStyle("{}", "a.h", "none", "enum Foo {};");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1716,6 +1716,8 @@
 
 TEST_F(FormatTest, FormatsNSEnums) {
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, SomeName) { AAA, BBB }");
+  verifyGoogleFormat(
+  "typedef NS_CLOSED_ENUM(NSInteger, SomeName) { AAA, BBB }");
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, MyType) {\n"
  "  // Information about someDecentlyLongValue.\n"
  "  someDecently

[PATCH] D65012: Adds support for formatting NS_CLOSED_ENUM alongside NS_ENUM.

2019-07-22 Thread Hank Heijink via Phabricator via cfe-commits
heijink updated this revision to Diff 211065.
heijink edited the summary of this revision.
heijink added a comment.

Also added support for formatting CF_CLOSED_ENUM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65012/new/

https://reviews.llvm.org/D65012

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestObjC.cpp


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -118,6 +118,11 @@
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 
+  Style = getStyle("{}", "a.h", "none",
+   "typedef NS_CLOSED_ENUM(NSInteger, Foo) {};\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
   Style = getStyle("{}", "a.h", "none", "enum Foo {};");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1716,6 +1716,8 @@
 
 TEST_F(FormatTest, FormatsNSEnums) {
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, SomeName) { AAA, BBB }");
+  verifyGoogleFormat(
+  "typedef NS_CLOSED_ENUM(NSInteger, SomeName) { AAA, BBB }");
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, MyType) {\n"
  "  // Information about someDecentlyLongValue.\n"
  "  someDecentlyLongValue,\n"
@@ -1724,6 +1726,14 @@
  "  // Information about aThirdDecentlyLongValue.\n"
  "  aThirdDecentlyLongValue\n"
  "};");
+  verifyGoogleFormat("typedef NS_CLOSED_ENUM(NSInteger, MyType) {\n"
+ "  // Information about someDecentlyLongValue.\n"
+ "  someDecentlyLongValue,\n"
+ "  // Information about anotherDecentlyLongValue.\n"
+ "  anotherDecentlyLongValue,\n"
+ "  // Information about aThirdDecentlyLongValue.\n"
+ "  aThirdDecentlyLongValue\n"
+ "};");
   verifyGoogleFormat("typedef NS_OPTIONS(NSInteger, MyType) {\n"
  "  a = 1,\n"
  "  b = 2,\n"
@@ -1734,6 +1744,11 @@
  "  b = 2,\n"
  "  c = 3,\n"
  "};");
+  verifyGoogleFormat("typedef CF_CLOSED_ENUM(NSInteger, MyType) {\n"
+ "  a = 1,\n"
+ "  b = 2,\n"
+ "  c = 3,\n"
+ "};");
   verifyGoogleFormat("typedef CF_OPTIONS(NSInteger, MyType) {\n"
  "  a = 1,\n"
  "  b = 2,\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1215,7 +1215,8 @@
 case tok::kw_typedef:
   nextToken();
   if (FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS,
- Keywords.kw_CF_ENUM, Keywords.kw_CF_OPTIONS))
+ Keywords.kw_CF_ENUM, Keywords.kw_CF_OPTIONS,
+ Keywords.kw_CF_CLOSED_ENUM, 
Keywords.kw_NS_CLOSED_ENUM))
 parseEnum();
   break;
 case tok::kw_struct:
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -677,8 +677,10 @@
 kw_override = &IdentTable.get("override");
 kw_in = &IdentTable.get("in");
 kw_of = &IdentTable.get("of");
+kw_CF_CLOSED_ENUM = &IdentTable.get("CF_CLOSED_ENUM");
 kw_CF_ENUM = &IdentTable.get("CF_ENUM");
 kw_CF_OPTIONS = &IdentTable.get("CF_OPTIONS");
+kw_NS_CLOSED_ENUM = &IdentTable.get("NS_CLOSED_ENUM");
 kw_NS_ENUM = &IdentTable.get("NS_ENUM");
 kw_NS_OPTIONS = &IdentTable.get("NS_OPTIONS");
 
@@ -787,8 +789,10 @@
   IdentifierInfo *kw_override;
   IdentifierInfo *kw_in;
   IdentifierInfo *kw_of;
+  IdentifierInfo *kw_CF_CLOSED_ENUM;
   IdentifierInfo *kw_CF_ENUM;
   IdentifierInfo *kw_CF_OPTIONS;
+  IdentifierInfo *kw_NS_CLOSED_ENUM;
   IdentifierInfo *kw_NS_ENUM;
   IdentifierInfo *kw_NS_OPTIONS;
   IdentifierInfo *kw___except;


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -118,6 +118,11 @@
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 
+  Style = getStyle("{}", "a.h", "none",
+   "type

[PATCH] D65012: Adds support for formatting NS_CLOSED_ENUM and CF_CLOSED_ENUM alongside NS_ENUM and CF_ENUM.

2019-07-22 Thread Hank Heijink via Phabricator via cfe-commits
heijink updated this revision to Diff 211135.
heijink added a comment.

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.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65012/new/

https://reviews.llvm.org/D65012

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestObjC.cpp

Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -114,7 +114,12 @@
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
 
   Style =
-  getStyle("{}", "a.h", "none", "typedef NS_ENUM(NSInteger, Foo) {};\n");
+  getStyle("{}", "a.h", "none", "typedef NS_ENUM(int, Foo) {};\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none",
+   "typedef NS_CLOSED_ENUM(int, Foo) {};\n");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1716,6 +1716,8 @@
 
 TEST_F(FormatTest, FormatsNSEnums) {
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, SomeName) { AAA, BBB }");
+  verifyGoogleFormat(
+  "typedef NS_CLOSED_ENUM(NSInteger, SomeName) { AAA, BBB }");
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, MyType) {\n"
  "  // Information about someDecentlyLongValue.\n"
  "  someDecentlyLongValue,\n"
@@ -1724,6 +1726,14 @@
  "  // Information about aThirdDecentlyLongValue.\n"
  "  aThirdDecentlyLongValue\n"
  "};");
+  verifyGoogleFormat("typedef NS_CLOSED_ENUM(NSInteger, MyType) {\n"
+ "  // Information about someDecentlyLongValue.\n"
+ "  someDecentlyLongValue,\n"
+ "  // Information about anotherDecentlyLongValue.\n"
+ "  anotherDecentlyLongValue,\n"
+ "  // Information about aThirdDecentlyLongValue.\n"
+ "  aThirdDecentlyLongValue\n"
+ "};");
   verifyGoogleFormat("typedef NS_OPTIONS(NSInteger, MyType) {\n"
  "  a = 1,\n"
  "  b = 2,\n"
@@ -1734,6 +1744,11 @@
  "  b = 2,\n"
  "  c = 3,\n"
  "};");
+  verifyGoogleFormat("typedef CF_CLOSED_ENUM(NSInteger, MyType) {\n"
+ "  a = 1,\n"
+ "  b = 2,\n"
+ "  c = 3,\n"
+ "};");
   verifyGoogleFormat("typedef CF_OPTIONS(NSInteger, MyType) {\n"
  "  a = 1,\n"
  "  b = 2,\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1215,7 +1215,8 @@
 case tok::kw_typedef:
   nextToken();
   if (FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS,
- Keywords.kw_CF_ENUM, Keywords.kw_CF_OPTIONS))
+ Keywords.kw_CF_ENUM, Keywords.kw_CF_OPTIONS,
+ Keywords.kw_CF_CLOSED_ENUM, Keywords.kw_NS_CLOSED_ENUM))
 parseEnum();
   break;
 case tok::kw_struct:
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -677,8 +677,10 @@
 kw_override = &IdentTable.get("override");
 kw_in = &IdentTable.get("in");
 kw_of = &IdentTable.get("of");
+kw_CF_CLOSED_ENUM = &IdentTable.get("CF_CLOSED_ENUM");
 kw_CF_ENUM = &IdentTable.get("CF_ENUM");
 kw_CF_OPTIONS = &IdentTable.get("CF_OPTIONS");
+kw_NS_CLOSED_ENUM = &IdentTable.get("NS_CLOSED_ENUM");
 kw_NS_ENUM = &IdentTable.get("NS_ENUM");
 kw_NS_OPTIONS = &IdentTable.get("NS_OPTIONS");
 
@@ -787,8 +789,10 @@
   IdentifierInfo *kw_override;
   IdentifierInfo *kw_in;
   IdentifierInfo *kw_of;
+  IdentifierInfo *kw_CF_CLOSED_ENUM;
   IdentifierInfo *kw_CF_ENUM;
   IdentifierInfo *kw_CF_OPTIONS;
+  IdentifierInfo *kw_NS_CLOSED_ENUM;
   IdentifierInfo *kw_NS_ENUM;
   IdentifierInfo *kw_NS_OPTIONS;
   IdentifierInfo *kw___except;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1685,7 +1685,7 @@
   

[PATCH] D65012: Adds support for formatting NS_CLOSED_ENUM and CF_CLOSED_ENUM alongside NS_ENUM and CF_ENUM.

2019-07-22 Thread Hank Heijink via Phabricator via cfe-commits
heijink updated this revision to Diff 211137.
heijink added a comment.

Fixed formatting of Format.cpp.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65012/new/

https://reviews.llvm.org/D65012

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestObjC.cpp

Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -114,7 +114,12 @@
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
 
   Style =
-  getStyle("{}", "a.h", "none", "typedef NS_ENUM(NSInteger, Foo) {};\n");
+  getStyle("{}", "a.h", "none", "typedef NS_ENUM(int, Foo) {};\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none",
+   "typedef NS_CLOSED_ENUM(int, Foo) {};\n");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1716,6 +1716,8 @@
 
 TEST_F(FormatTest, FormatsNSEnums) {
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, SomeName) { AAA, BBB }");
+  verifyGoogleFormat(
+  "typedef NS_CLOSED_ENUM(NSInteger, SomeName) { AAA, BBB }");
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, MyType) {\n"
  "  // Information about someDecentlyLongValue.\n"
  "  someDecentlyLongValue,\n"
@@ -1724,6 +1726,14 @@
  "  // Information about aThirdDecentlyLongValue.\n"
  "  aThirdDecentlyLongValue\n"
  "};");
+  verifyGoogleFormat("typedef NS_CLOSED_ENUM(NSInteger, MyType) {\n"
+ "  // Information about someDecentlyLongValue.\n"
+ "  someDecentlyLongValue,\n"
+ "  // Information about anotherDecentlyLongValue.\n"
+ "  anotherDecentlyLongValue,\n"
+ "  // Information about aThirdDecentlyLongValue.\n"
+ "  aThirdDecentlyLongValue\n"
+ "};");
   verifyGoogleFormat("typedef NS_OPTIONS(NSInteger, MyType) {\n"
  "  a = 1,\n"
  "  b = 2,\n"
@@ -1734,6 +1744,11 @@
  "  b = 2,\n"
  "  c = 3,\n"
  "};");
+  verifyGoogleFormat("typedef CF_CLOSED_ENUM(NSInteger, MyType) {\n"
+ "  a = 1,\n"
+ "  b = 2,\n"
+ "  c = 3,\n"
+ "};");
   verifyGoogleFormat("typedef CF_OPTIONS(NSInteger, MyType) {\n"
  "  a = 1,\n"
  "  b = 2,\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1215,7 +1215,8 @@
 case tok::kw_typedef:
   nextToken();
   if (FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS,
- Keywords.kw_CF_ENUM, Keywords.kw_CF_OPTIONS))
+ Keywords.kw_CF_ENUM, Keywords.kw_CF_OPTIONS,
+ Keywords.kw_CF_CLOSED_ENUM, Keywords.kw_NS_CLOSED_ENUM))
 parseEnum();
   break;
 case tok::kw_struct:
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -677,8 +677,10 @@
 kw_override = &IdentTable.get("override");
 kw_in = &IdentTable.get("in");
 kw_of = &IdentTable.get("of");
+kw_CF_CLOSED_ENUM = &IdentTable.get("CF_CLOSED_ENUM");
 kw_CF_ENUM = &IdentTable.get("CF_ENUM");
 kw_CF_OPTIONS = &IdentTable.get("CF_OPTIONS");
+kw_NS_CLOSED_ENUM = &IdentTable.get("NS_CLOSED_ENUM");
 kw_NS_ENUM = &IdentTable.get("NS_ENUM");
 kw_NS_OPTIONS = &IdentTable.get("NS_OPTIONS");
 
@@ -787,8 +789,10 @@
   IdentifierInfo *kw_override;
   IdentifierInfo *kw_in;
   IdentifierInfo *kw_of;
+  IdentifierInfo *kw_CF_CLOSED_ENUM;
   IdentifierInfo *kw_CF_ENUM;
   IdentifierInfo *kw_CF_OPTIONS;
+  IdentifierInfo *kw_NS_CLOSED_ENUM;
   IdentifierInfo *kw_NS_ENUM;
   IdentifierInfo *kw_NS_OPTIONS;
   IdentifierInfo *kw___except;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1685,10 +1685,11 @@
 std::end(FoundationIdentifiers),
 FormatTok->TokenText)) ||
 FormatTok->is(TT