]> granicus.if.org Git - clang/commitdiff
ObjectiveC migrator: add support to migrate to
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 19 Jul 2013 01:05:49 +0000 (01:05 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 19 Jul 2013 01:05:49 +0000 (01:05 +0000)
NS_OPTIONS.

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

lib/ARCMigrate/ObjCMT.cpp
test/ARCMT/objcmt-ns-macros.m
test/ARCMT/objcmt-ns-macros.m.result

index 7542a697b5b28d964bfcdcd9d961418f53bbd434..2f4a3e7401cf0e76b50132b447bf08b7eea882e0 100644 (file)
@@ -382,8 +382,10 @@ static bool rewriteToObjCInterfaceDecl(const ObjCInterfaceDecl *IDecl,
 
 static bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl,
                                 const TypedefDecl *TypedefDcl,
-                                const NSAPI &NS, edit::Commit &commit) {
-  std::string ClassString = "typedef NS_ENUM(NSInteger, ";
+                                const NSAPI &NS, edit::Commit &commit,
+                                bool IsNSIntegerType) {
+  std::string ClassString = 
+    IsNSIntegerType ? "typedef NS_ENUM(NSInteger, " : "typedef NS_OPTIONS(NSUInteger, ";
   ClassString += TypedefDcl->getIdentifier()->getName();
   ClassString += ')';
   SourceRange R(EnumDcl->getLocStart(), EnumDcl->getLocStart());
@@ -462,14 +464,19 @@ void ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx,
     return;
   
   QualType qt = TypedefDcl->getTypeSourceInfo()->getType();
-  if (!NSAPIObj->isObjCNSIntegerType(qt))
+  bool IsNSIntegerType = NSAPIObj->isObjCNSIntegerType(qt);
+  bool IsNSUIntegerType = !IsNSIntegerType && NSAPIObj->isObjCNSUIntegerType(qt);
+  if (!IsNSIntegerType && !IsNSUIntegerType)
     return;
   
   // NS_ENUM must be available.
-  if (!Ctx.Idents.get("NS_ENUM").hasMacroDefinition())
+  if (IsNSIntegerType && !Ctx.Idents.get("NS_ENUM").hasMacroDefinition())
+    return;
+  // NS_OPTIONS must be available.
+  if (IsNSUIntegerType && !Ctx.Idents.get("NS_OPTIONS").hasMacroDefinition())
     return;
   edit::Commit commit(*Editor);
-  rewriteToNSEnumDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit);
+  rewriteToNSEnumDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit, IsNSIntegerType);
   Editor->commit(commit);
 }
 
index e6b608a4ac393dac4ab15330cb9bf2b8033b7f99..e56c4cf2dd020c1bbcbeb2ff4e2f5b19bb7627a8 100644 (file)
@@ -4,10 +4,26 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties %s.result
 
 typedef long NSInteger;
+typedef unsigned long NSUInteger;
+
 #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
+#define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
 
 enum {
   blah,
   blarg
 };
 typedef NSInteger wibble;
+
+enum {
+    UIViewAutoresizingNone                 = 0,
+    UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
+    UIViewAutoresizingFlexibleWidth        = 1 << 1,
+    UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
+    UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
+    UIViewAutoresizingFlexibleHeight       = 1 << 4,
+    UIViewAutoresizingFlexibleBottomMargin = 1 << 5
+};
+
+typedef NSUInteger UITableViewCellStyle;
+
index c8c6686a7e4d9f868ef531de2274ec34af10670a..8a09bff3b892e757b4ab41deef7d2f9cfe5c8efd 100644 (file)
@@ -4,10 +4,26 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties %s.result
 
 typedef long NSInteger;
+typedef unsigned long NSUInteger;
+
 #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
+#define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
 
 typedef NS_ENUM(NSInteger, wibble) {
   blah,
   blarg
 };
 
+
+typedef NS_OPTIONS(NSUInteger, UITableViewCellStyle) {
+    UIViewAutoresizingNone                 = 0,
+    UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
+    UIViewAutoresizingFlexibleWidth        = 1 << 1,
+    UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
+    UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
+    UIViewAutoresizingFlexibleHeight       = 1 << 4,
+    UIViewAutoresizingFlexibleBottomMargin = 1 << 5
+};
+
+
+