]> granicus.if.org Git - clang/commitdiff
clang-format: Support NS_OPTIONS, CF_ENUM and CF_OPTIONS.
authorDaniel Jasper <djasper@google.com>
Fri, 5 Dec 2014 10:42:21 +0000 (10:42 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 5 Dec 2014 10:42:21 +0000 (10:42 +0000)
This fixes llvm.org/PR21756.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223458 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/FormatToken.h
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 11c4925d0105ef056af7c2755f4c7a2c20e5cedd..df4742101225e1eb32ee1bd9a7885fd5f82afe46 100644 (file)
@@ -535,7 +535,10 @@ private:
 struct AdditionalKeywords {
   AdditionalKeywords(IdentifierTable &IdentTable) {
     kw_in = &IdentTable.get("in");
+    kw_CF_ENUM = &IdentTable.get("CF_ENUM");
+    kw_CF_OPTIONS = &IdentTable.get("CF_OPTIONS");
     kw_NS_ENUM = &IdentTable.get("NS_ENUM");
+    kw_NS_OPTIONS = &IdentTable.get("NS_OPTIONS");
 
     kw_finally = &IdentTable.get("finally");
     kw_function = &IdentTable.get("function");
@@ -560,7 +563,10 @@ struct AdditionalKeywords {
 
   // ObjC context sensitive keywords.
   IdentifierInfo *kw_in;
+  IdentifierInfo *kw_CF_ENUM;
+  IdentifierInfo *kw_CF_OPTIONS;
   IdentifierInfo *kw_NS_ENUM;
+  IdentifierInfo *kw_NS_OPTIONS;
 
   // JavaScript keywords.
   IdentifierInfo *kw_finally;
index 21f0e7bad1bd3da5030e2635cd2fa1417ef219c9..d0c899ffe0b0577bce5b4c804a4acf50724bf5ec 100644 (file)
@@ -747,7 +747,8 @@ void UnwrappedLineParser::parseStructuralElement() {
       break;
     case tok::kw_typedef:
       nextToken();
-      if (FormatTok->is(Keywords.kw_NS_ENUM))
+      if (FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS,
+                             Keywords.kw_CF_ENUM, Keywords.kw_CF_OPTIONS))
         parseEnum();
       break;
     case tok::kw_struct:
index 6481a3122f62771af797da9ab1a84f20a9d25a9a..cf2d8097f7b220377660dbdf4884e086162d8dd8 100644 (file)
@@ -2069,6 +2069,21 @@ TEST_F(FormatTest, FormatsNSEnums) {
                      "  // Information about aThirdDecentlyLongValue.\n"
                      "  aThirdDecentlyLongValue\n"
                      "};");
+  verifyGoogleFormat("typedef NS_OPTIONS(NSInteger, MyType) {\n"
+                     "  a = 1,\n"
+                     "  b = 2,\n"
+                     "  c = 3,\n"
+                     "};");
+  verifyGoogleFormat("typedef CF_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"
+                     "  c = 3,\n"
+                     "};");
 }
 
 TEST_F(FormatTest, FormatsBitfields) {