]> granicus.if.org Git - clang/commitdiff
ObjectiveC migrator. also support migration to
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 11 Oct 2013 21:34:56 +0000 (21:34 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 11 Oct 2013 21:34:56 +0000 (21:34 +0000)
NS_ENUM/NS_OPTIONS macros when typedef declaration
precedes enum declaration. // rdar://15200915

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

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

index cd4b284e7dfb4e8a54e277d98eb982714151dccf..7b8aebbac5d66fb3e10d4aac6b02b10eb86e6b24 100644 (file)
@@ -46,7 +46,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
   void migrateObjCInterfaceDecl(ASTContext &Ctx, ObjCContainerDecl *D);
   void migrateProtocolConformance(ASTContext &Ctx,
                                   const ObjCImplementationDecl *ImpDecl);
-  void migrateNSEnumDecl(ASTContext &Ctx, const EnumDecl *EnumDcl,
+  bool migrateNSEnumDecl(ASTContext &Ctx, const EnumDecl *EnumDcl,
                      const TypedefDecl *TypedefDcl);
   void migrateAllMethodInstaceType(ASTContext &Ctx, ObjCContainerDecl *CDecl);
   void migrateMethodInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl,
@@ -638,13 +638,13 @@ void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx,
   Editor->commit(commit);
 }
 
-void ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx,
+bool ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx,
                                            const EnumDecl *EnumDcl,
                                            const TypedefDecl *TypedefDcl) {
   if (!EnumDcl->isCompleteDefinition() || EnumDcl->getIdentifier() ||
       !TypedefDcl->getIdentifier() ||
       EnumDcl->isDeprecated() || TypedefDcl->isDeprecated())
-    return;
+    return false;
   
   QualType qt = TypedefDcl->getTypeSourceInfo()->getType();
   bool IsNSIntegerType = NSAPIObj->isObjCNSIntegerType(qt);
@@ -657,29 +657,30 @@ void ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx,
         bool NSOptions = UseNSOptionsMacro(PP, Ctx, EnumDcl);
         if (NSOptions) {
           if (!Ctx.Idents.get("NS_OPTIONS").hasMacroDefinition())
-            return;
+            return false;
         }
         else if (!Ctx.Idents.get("NS_ENUM").hasMacroDefinition())
-          return;
+          return false;
         edit::Commit commit(*Editor);
         rewriteToNSMacroDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit, !NSOptions);
         Editor->commit(commit);
       }
     }
-    return;
+    return false;
   }
   
   // We may still use NS_OPTIONS based on what we find in the enumertor list.
   bool NSOptions = UseNSOptionsMacro(PP, Ctx, EnumDcl);
   // NS_ENUM must be available.
   if (IsNSIntegerType && !Ctx.Idents.get("NS_ENUM").hasMacroDefinition())
-    return;
+    return false;
   // NS_OPTIONS must be available.
   if (IsNSUIntegerType && !Ctx.Idents.get("NS_OPTIONS").hasMacroDefinition())
-    return;
+    return false;
   edit::Commit commit(*Editor);
   rewriteToNSEnumDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit, IsNSIntegerType, NSOptions);
   Editor->commit(commit);
+  return true;
 }
 
 static void ReplaceWithInstancetype(const ObjCMigrateASTConsumer &ASTC,
@@ -1435,8 +1436,21 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
         ++N;
         if (N != DEnd)
           if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(*N)) {
-            if (ASTMigrateActions & FrontendOptions::ObjCMT_NsMacros)
-              migrateNSEnumDecl(Ctx, ED, TD);
+            if (ASTMigrateActions & FrontendOptions::ObjCMT_NsMacros) {
+              if (migrateNSEnumDecl(Ctx, ED, TD))
+                D++;
+            }
+          }
+      }
+      else if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(*D)) {
+        DeclContext::decl_iterator N = D;
+        ++N;
+        if (N != DEnd)
+          if (const EnumDecl *ED = dyn_cast<EnumDecl>(*N)) {
+            if (ASTMigrateActions & FrontendOptions::ObjCMT_NsMacros) {
+              if (migrateNSEnumDecl(Ctx, ED, TD))
+                ++D;
+            }
           }
       }
       else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*D)) {
index b83857de7d7913ecc189abc69ed6f27461132456..b8715716d6e4eb16890797a4d16d6ec613b4827b 100644 (file)
@@ -215,3 +215,39 @@ enum {
     NSModalResponseContinue             = (-1002), 
 } NS_ENUM_AVAILABLE_MAC(10.9);
 typedef NSInteger NSModalResponse NS_AVAILABLE_MAC(10.9);
+
+// rdar://15200915
+typedef NSUInteger NSWorkspaceLaunchOptions;
+enum {
+     NSWorkspaceLaunchAndPrint =                 0x00000002,
+     NSWorkspaceLaunchWithErrorPresentation    = 0x00000040,
+     NSWorkspaceLaunchInhibitingBackgroundOnly = 0x00000080,
+     NSWorkspaceLaunchWithoutAddingToRecents   = 0x00000100,
+     NSWorkspaceLaunchWithoutActivation        = 0x00000200,
+     NSWorkspaceLaunchAsync                    = 0x00010000,
+     NSWorkspaceLaunchAllowingClassicStartup   = 0x00020000,
+     NSWorkspaceLaunchPreferringClassic        = 0x00040000,
+     NSWorkspaceLaunchNewInstance              = 0x00080000,
+     NSWorkspaceLaunchAndHide                  = 0x00100000,
+     NSWorkspaceLaunchAndHideOthers            = 0x00200000,
+     NSWorkspaceLaunchDefault = NSWorkspaceLaunchAsync | 
+NSWorkspaceLaunchAllowingClassicStartup
+};
+
+typedef NSUInteger NSWorkspaceIconCreationOptions;
+enum {
+    NSExcludeQuickDrawElementsIconCreationOption    = 1 << 1,
+    NSExclude10_4ElementsIconCreationOption         = 1 << 2
+};
+
+typedef NSUInteger NSWorkspaceCreationOptions;
+enum {
+    NSExcludeQuickDrawElementsCreationOption    = 1 << 1,
+    NSExclude10_4ElementsCreationOption         = 1 << 2
+};
+
+enum {
+    NSExcludeQuickDrawElementsIconOption    = 1 << 1,
+    NSExclude10_4ElementsIconOption         = 1 << 2
+};
+typedef NSUInteger NSWorkspaceIconOptions;
index f8bbbefe669412ad57b35b355f287e1fe3d8c9bb..62f1cd7342c876308deaedff356308865655c21b 100644 (file)
@@ -205,3 +205,35 @@ typedef NS_ENUM(NSInteger, NSModalResponse) {
     NSModalResponseAbort                = (-1001),
     NSModalResponseContinue             = (-1002), 
 } NS_ENUM_AVAILABLE_MAC(10.9);
+
+// rdar://15200915
+typedef NS_OPTIONS(NSUInteger, NSWorkspaceLaunchOptions) {
+     NSWorkspaceLaunchAndPrint =                 0x00000002,
+     NSWorkspaceLaunchWithErrorPresentation    = 0x00000040,
+     NSWorkspaceLaunchInhibitingBackgroundOnly = 0x00000080,
+     NSWorkspaceLaunchWithoutAddingToRecents   = 0x00000100,
+     NSWorkspaceLaunchWithoutActivation        = 0x00000200,
+     NSWorkspaceLaunchAsync                    = 0x00010000,
+     NSWorkspaceLaunchAllowingClassicStartup   = 0x00020000,
+     NSWorkspaceLaunchPreferringClassic        = 0x00040000,
+     NSWorkspaceLaunchNewInstance              = 0x00080000,
+     NSWorkspaceLaunchAndHide                  = 0x00100000,
+     NSWorkspaceLaunchAndHideOthers            = 0x00200000,
+     NSWorkspaceLaunchDefault = NSWorkspaceLaunchAsync | 
+NSWorkspaceLaunchAllowingClassicStartup
+};
+
+typedef NS_OPTIONS(NSUInteger, NSWorkspaceIconCreationOptions) {
+    NSExcludeQuickDrawElementsIconCreationOption    = 1 << 1,
+    NSExclude10_4ElementsIconCreationOption         = 1 << 2
+};
+
+typedef NS_OPTIONS(NSUInteger, NSWorkspaceCreationOptions) {
+    NSExcludeQuickDrawElementsCreationOption    = 1 << 1,
+    NSExclude10_4ElementsCreationOption         = 1 << 2
+};
+
+typedef NS_OPTIONS(NSUInteger, NSWorkspaceIconOptions) {
+    NSExcludeQuickDrawElementsIconOption    = 1 << 1,
+    NSExclude10_4ElementsIconOption         = 1 << 2
+};