[PATCH] D45521: [clang-format] Improve ObjC guessing heuristic by supporting all @keywords

2018-04-12 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL329918: [clang-format] Improve ObjC guessing heuristic by 
supporting all @keywords (authored by benhamilton, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D45521

Files:
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -1465,6 +1465,7 @@
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
+"NSBlockOperation",
 "NSBundle",
 "NSCache",
 "NSCalendar",
@@ -1480,6 +1481,7 @@
 "NSIndexPath",
 "NSIndexSet",
 "NSInteger",
+"NSInvocationOperation",
 "NSLocale",
 "NSMapTable",
 "NSMutableArray",
@@ -1494,9 +1496,13 @@
 "NSNumber",
 "NSNumberFormatter",
 "NSObject",
+"NSOperation",
+"NSOperationQueue",
+"NSOperationQueuePriority",
 "NSOrderedSet",
 "NSPoint",
 "NSPointerArray",
+"NSQualityOfService",
 "NSRange",
 "NSRect",
 "NSRegularExpression",
@@ -1518,10 +1524,7 @@
   for (const FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
- (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
-  FormatTok->isObjCAtKeyword(tok::objc_implementation) ||
-  FormatTok->isObjCAtKeyword(tok::objc_protocol) ||
-  FormatTok->isObjCAtKeyword(tok::objc_end) ||
+ (FormatTok->Tok.getObjCKeywordID() != tok::objc_not_keyword ||
   FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
  tok::l_brace))) ||
 (FormatTok->Tok.isAnyIdentifier() &&
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -12118,6 +12118,12 @@
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.mm", ""));
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", ""));
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.h", "@interface 
Foo\n@end\n"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "#define TRY(x, y) @try { x; } @finally { y; }"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "#define AVAIL(x) @available(x, *))"));
+  EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.h", "@class Foo;"));
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo", ""));
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo", "@interface 
Foo\n@end\n"));
   EXPECT_EQ(FormatStyle::LK_ObjC,


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -1465,6 +1465,7 @@
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
+"NSBlockOperation",
 "NSBundle",
 "NSCache",
 "NSCalendar",
@@ -1480,6 +1481,7 @@
 "NSIndexPath",
 "NSIndexSet",
 "NSInteger",
+"NSInvocationOperation",
 "NSLocale",
 "NSMapTable",
 "NSMutableArray",
@@ -1494,9 +1496,13 @@
 "NSNumber",
 "NSNumberFormatter",
 "NSObject",
+"NSOperation",
+"NSOperationQueue",
+"NSOperationQueuePriority",
 "NSOrderedSet",
 "NSPoint",
 "NSPointerArray",
+"NSQualityOfService",
 "NSRange",
 "NSRect",
 "NSRegularExpression",
@@ -1518,10 +1524,7 @@
   for (const FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
- (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
-  FormatTok->isObjCAtKeyword(tok::objc_implementation) ||
-  FormatTok->isObjCAtKeyword(tok::objc_protocol) ||
-  FormatTok->isObjCAtKeyword(tok::objc_end) ||
+ (FormatTok->Tok.getObjCKeywordID() != tok::objc_not_keyword ||
   FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
  tok::l_brace))) ||
 (FormatTok->Tok.isAnyIdentifier() &&
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -12118,6 +12118,12 @@
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.mm", ""));
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h

[PATCH] D45521: [clang-format] Improve ObjC guessing heuristic by supporting all @keywords

2018-04-12 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.


Repository:
  rC Clang

https://reviews.llvm.org/D45521



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45521: [clang-format] Improve ObjC guessing heuristic by supporting all @keywords

2018-04-11 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, jolesiak.
Herald added subscribers: cfe-commits, klimek.

This diff improves the Objective-C guessing heuristic by
replacing the hard-coded list of a subset of Objective-C @keywords
with a general check which supports all @keywords.

I also added a few more Foundation keywords which were missing from
the heuristic.

Test Plan: Unit tests updated. Ran tests with:

  % make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D45521

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12101,6 +12101,12 @@
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.mm", ""));
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", ""));
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.h", "@interface 
Foo\n@end\n"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "#define TRY(x, y) @try { x; } @finally { y; }"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "#define AVAIL(x) @available(x, *))"));
+  EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.h", "@class Foo;"));
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo", ""));
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo", "@interface 
Foo\n@end\n"));
   EXPECT_EQ(FormatStyle::LK_ObjC,
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1465,6 +1465,7 @@
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
+"NSBlockOperation",
 "NSBundle",
 "NSCache",
 "NSCalendar",
@@ -1480,6 +1481,7 @@
 "NSIndexPath",
 "NSIndexSet",
 "NSInteger",
+"NSInvocationOperation",
 "NSLocale",
 "NSMapTable",
 "NSMutableArray",
@@ -1494,9 +1496,13 @@
 "NSNumber",
 "NSNumberFormatter",
 "NSObject",
+"NSOperation",
+"NSOperationQueue",
+"NSOperationQueuePriority",
 "NSOrderedSet",
 "NSPoint",
 "NSPointerArray",
+"NSQualityOfService",
 "NSRange",
 "NSRect",
 "NSRegularExpression",
@@ -1518,10 +1524,7 @@
   for (const FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
- (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
-  FormatTok->isObjCAtKeyword(tok::objc_implementation) ||
-  FormatTok->isObjCAtKeyword(tok::objc_protocol) ||
-  FormatTok->isObjCAtKeyword(tok::objc_end) ||
+ (FormatTok->Tok.getObjCKeywordID() != tok::objc_not_keyword ||
   FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
  tok::l_brace))) ||
 (FormatTok->Tok.isAnyIdentifier() &&


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12101,6 +12101,12 @@
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.mm", ""));
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", ""));
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.h", "@interface Foo\n@end\n"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "#define TRY(x, y) @try { x; } @finally { y; }"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "#define AVAIL(x) @available(x, *))"));
+  EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.h", "@class Foo;"));
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo", ""));
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo", "@interface Foo\n@end\n"));
   EXPECT_EQ(FormatStyle::LK_ObjC,
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1465,6 +1465,7 @@
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
+"NSBlockOperation",
 "NSBundle",
 "NSCache",
 "NSCalendar",
@@ -1480,6 +1481,7 @@
 "NSIndexPath",
 "NSIndexSet",
 "NSInteger",
+"NSInvocationOperation",
 "NSLocale",
 "NSMapTable",
 "NSMutableArray",
@@ -1494,9 +1496,13 @@
 "NSNumber",
 "NSNumberFormatter",
 "NSObject",
+"NSOperation",
+"NSOperationQueue",
+"NSOperationQueuePriority",
 "NSOrderedSet",
 "NSPoint",
 "NSPointerArray",
+"NSQualityOfService",
 "NSRange",
 "NSRect",
 "NSRegularExpression",
@@ -1518,10 +1524,7 @@