]> granicus.if.org Git - clang/commitdiff
ObjectiveC migrator: Another use case of enum
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 19 Jul 2013 20:18:36 +0000 (20:18 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 19 Jul 2013 20:18:36 +0000 (20:18 +0000)
declaration which can be migrated to NS_ENUM.

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

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

index 282006b57697dda1c4893d49c00506a8e082075d..e4ec0c83c500df8b5adb7d19728d4df73364e706 100644 (file)
@@ -384,7 +384,7 @@ static bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl,
                                 const TypedefDecl *TypedefDcl,
                                 const NSAPI &NS, edit::Commit &commit,
                                 bool IsNSIntegerType) {
-  std::string ClassString = 
+  std::string ClassString =
     IsNSIntegerType ? "typedef NS_ENUM(NSInteger, " : "typedef NS_OPTIONS(NSUInteger, ";
   ClassString += TypedefDcl->getIdentifier()->getName();
   ClassString += ')';
@@ -399,6 +399,19 @@ static bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl,
   return false;
 }
 
+static bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl,
+                                const TypedefDecl *TypedefDcl,
+                                const NSAPI &NS, edit::Commit &commit) {
+  std::string ClassString = "NS_ENUM(NSInteger, ";
+  ClassString += TypedefDcl->getIdentifier()->getName();
+  ClassString += ')';
+  SourceRange R(EnumDcl->getLocStart(), EnumDcl->getLocStart());
+  commit.replace(R, ClassString);
+  SourceLocation TypedefLoc = TypedefDcl->getLocEnd();
+  commit.remove(SourceRange(TypedefLoc, TypedefLoc));
+  return true;
+}
+
 void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx,   
                                             const ObjCImplementationDecl *ImpDecl) {
   const ObjCInterfaceDecl *IDecl = ImpDecl->getClassInterface();
@@ -466,8 +479,24 @@ void ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx,
   QualType qt = TypedefDcl->getTypeSourceInfo()->getType();
   bool IsNSIntegerType = NSAPIObj->isObjCNSIntegerType(qt);
   bool IsNSUIntegerType = !IsNSIntegerType && NSAPIObj->isObjCNSUIntegerType(qt);
-  if (!IsNSIntegerType && !IsNSUIntegerType)
-    return;
+  if (!IsNSIntegerType && !IsNSUIntegerType) {
+    // Also check for typedef enum {...} TD;
+    if (const EnumType *EnumTy = qt->getAs<EnumType>()) {
+      if (EnumTy->getDecl() == EnumDcl) {
+        // NS_ENUM must be available.
+        if (!Ctx.Idents.get("NS_ENUM").hasMacroDefinition())
+          return;
+        edit::Commit commit(*Editor);
+        rewriteToNSEnumDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit);
+        Editor->commit(commit);
+        return;
+      }
+      else
+        return;
+    }
+    else
+      return;
+  }
   
   // NS_ENUM must be available.
   if (IsNSIntegerType && !Ctx.Idents.get("NS_ENUM").hasMacroDefinition())
index b9069f579232493939781973b8d575025eafba24..42d7d2cd8f69895f770b7333dcd054760c54e94e 100644 (file)
@@ -27,6 +27,14 @@ enum {
 
 typedef NSUInteger UITableViewCellStyle;
 
+typedef enum {
+    UIViewAnimationTransitionNone,
+    UIViewAnimationTransitionFlipFromLeft,
+    UIViewAnimationTransitionFlipFromRight,
+    UIViewAnimationTransitionCurlUp,
+    UIViewAnimationTransitionCurlDown,
+} UIViewAnimationTransition;
+
 enum {
   UNOne,
   UNTwo
index fcfe077039c8bb7532b4b7f09b1d0d0807114fca..ee9b60596ffe3293f5399b58631b325166ad99f4 100644 (file)
@@ -27,6 +27,14 @@ typedef NS_OPTIONS(NSUInteger, UITableViewCellStyle) {
 
 
 
+typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {
+    UIViewAnimationTransitionNone,
+    UIViewAnimationTransitionFlipFromLeft,
+    UIViewAnimationTransitionFlipFromRight,
+    UIViewAnimationTransitionCurlUp,
+    UIViewAnimationTransitionCurlDown,
+} ;
+
 enum {
   UNOne,
   UNTwo