]> granicus.if.org Git - clang/commitdiff
ObjectiveC migrator. Do not migrate categories with
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 19 Nov 2013 18:17:31 +0000 (18:17 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 19 Nov 2013 18:17:31 +0000 (18:17 +0000)
'Deprecated' name suffix.

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

lib/ARCMigrate/ObjCMT.cpp
test/ARCMT/objcmt-deprecated-category.m [deleted file]
test/ARCMT/objcmt-deprecated-category.m.result [deleted file]
test/ARCMT/objcmt-instancetype-2.m.result

index cac0fb0aed1b63adabab2784fac733565247196e..0f0268572e95284000f70f860511e150a4be6a59 100644 (file)
@@ -45,7 +45,6 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
   
   void migrateDecl(Decl *D);
   void migrateObjCInterfaceDecl(ASTContext &Ctx, ObjCContainerDecl *D);
-  void migrateDeprecatedAnnotation(ASTContext &Ctx, ObjCCategoryDecl *CatDecl);
   void migrateProtocolConformance(ASTContext &Ctx,
                                   const ObjCImplementationDecl *ImpDecl);
   void CacheObjCNSIntegerTypedefed(const TypedefDecl *TypedefDcl);
@@ -426,11 +425,19 @@ static void rewriteToObjCProperty(const ObjCMethodDecl *Getter,
   }
 }
 
+static bool IsCategoryNameWithDeprecatedSuffix(ObjCContainerDecl *D) {
+  if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(D)) {
+    StringRef Name = CatDecl->getName();
+    return Name.endswith("Deprecated");
+  }
+  return false;
+}
+
 void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx,
                                                       ObjCContainerDecl *D) {
-  if (D->isDeprecated())
+  if (D->isDeprecated() || IsCategoryNameWithDeprecatedSuffix(D))
     return;
-  
+    
   for (ObjCContainerDecl::method_iterator M = D->meth_begin(), MEnd = D->meth_end();
        M != MEnd; ++M) {
     ObjCMethodDecl *Method = (*M);
@@ -457,39 +464,6 @@ void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx,
   }
 }
 
-void ObjCMigrateASTConsumer::migrateDeprecatedAnnotation(ASTContext &Ctx,
-                                                           ObjCCategoryDecl *CatDecl) {
-  StringRef Name = CatDecl->getName();
-  if (!Name.endswith("Deprecated"))
-    return;
-  
-  if (!Ctx.Idents.get("DEPRECATED").hasMacroDefinition())
-    return;
-  
-  ObjCContainerDecl *D = cast<ObjCContainerDecl>(CatDecl);
-  
-  for (ObjCContainerDecl::method_iterator M = D->meth_begin(), MEnd = D->meth_end();
-       M != MEnd; ++M) {
-    ObjCMethodDecl *Method = (*M);
-    if (Method->isDeprecated() || Method->isImplicit())
-      continue;
-    // Annotate with DEPRECATED
-    edit::Commit commit(*Editor);
-    commit.insertBefore(Method->getLocEnd(), " DEPRECATED");
-    Editor->commit(commit);
-  }
-  for (ObjCContainerDecl::prop_iterator P = D->prop_begin(),
-       E = D->prop_end(); P != E; ++P) {
-    ObjCPropertyDecl *Prop = *P;
-    if (Prop->isDeprecated())
-      continue;
-    // Annotate with DEPRECATED
-    edit::Commit commit(*Editor);
-    commit.insertAfterToken(Prop->getLocEnd(), " DEPRECATED");
-    Editor->commit(commit);
-  }
-}
-
 static bool
 ClassImplementsAllMethodsAndProperties(ASTContext &Ctx,
                                       const ObjCImplementationDecl *ImpDecl,
@@ -1153,7 +1127,7 @@ void ObjCMigrateASTConsumer::migratePropertyNsReturnsInnerPointer(ASTContext &Ct
 
 void ObjCMigrateASTConsumer::migrateAllMethodInstaceType(ASTContext &Ctx,
                                                  ObjCContainerDecl *CDecl) {
-  if (CDecl->isDeprecated())
+  if (CDecl->isDeprecated() || IsCategoryNameWithDeprecatedSuffix(CDecl))
     return;
   
   // migrate methods which can have instancetype as their result type.
@@ -1627,8 +1601,6 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
         migrateObjCInterfaceDecl(Ctx, CDecl);
       if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(*D)) {
         migrateObjCInterfaceDecl(Ctx, CatDecl);
-        if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation)
-          migrateDeprecatedAnnotation(Ctx, CatDecl);
       }
       else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(*D))
         ObjCProtocolDecls.insert(PDecl);
diff --git a/test/ARCMT/objcmt-deprecated-category.m b/test/ARCMT/objcmt-deprecated-category.m
deleted file mode 100644 (file)
index 5939e5a..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-// RUN: rm -rf %t
-// RUN: %clang_cc1 -objcmt-migrate-annotation -mt-migrate-directory %t %s -x objective-c -triple x86_64-apple-darwin11
-// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s.result
-// rdar://15337661
-
-#define DEPRECATED  __attribute__((deprecated)) 
-
-@interface NSArray
-- (int)one;
-@end
-
-@interface NSArray (NSDraggingSourceDeprecated)
-
-/* This method is unsafe because it could potentially cause buffer overruns. You should use -getObjects:range: instead.
-*/
-- (void)getObjects:(id __unsafe_unretained [])objects;
-- (void)dep_getObjects:(id __unsafe_unretained [])dep_objects DEPRECATED;
-
-@end
-
-@interface NSArray (NSDeprecated)
-
-/* This method is unsafe because it could potentially cause buffer overruns. You should use -getObjects:range: instead.
-*/
-- (void)dep_getObjects:(id __unsafe_unretained [])dep_objects DEPRECATED;
-- (void)getObjects:(id __unsafe_unretained [])objects;
-@property int P1;
-@property int P2 DEPRECATED;
-@end
-
-@interface NSArray (DraggingSourceDeprecated)
-
-/* This method is unsafe because it could potentially cause buffer overruns. You should use -getObjects:range: instead.
-*/
-- (void)getObjects:(id __unsafe_unretained [])objects;
-- (void)dep_getObjects:(id __unsafe_unretained [])dep_objects DEPRECATED;
-@property int P1;
-@property int P2 DEPRECATED;
-
-@end
-
-@interface NSArray (Deprecated)
-- (void)getObjects:(id __unsafe_unretained [])objects;
-- (void)dep_getObjects:(id __unsafe_unretained [])dep_objects DEPRECATED;
-@property int P1;
-@property int P2 DEPRECATED;
-@end
diff --git a/test/ARCMT/objcmt-deprecated-category.m.result b/test/ARCMT/objcmt-deprecated-category.m.result
deleted file mode 100644 (file)
index 3cb1000..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-// RUN: rm -rf %t
-// RUN: %clang_cc1 -objcmt-migrate-annotation -mt-migrate-directory %t %s -x objective-c -triple x86_64-apple-darwin11
-// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s.result
-// rdar://15337661
-
-#define DEPRECATED  __attribute__((deprecated)) 
-
-@interface NSArray
-- (int)one;
-@end
-
-@interface NSArray (NSDraggingSourceDeprecated)
-
-/* This method is unsafe because it could potentially cause buffer overruns. You should use -getObjects:range: instead.
-*/
-- (void)getObjects:(id __unsafe_unretained [])objects DEPRECATED;
-- (void)dep_getObjects:(id __unsafe_unretained [])dep_objects DEPRECATED;
-
-@end
-
-@interface NSArray (NSDeprecated)
-
-/* This method is unsafe because it could potentially cause buffer overruns. You should use -getObjects:range: instead.
-*/
-- (void)dep_getObjects:(id __unsafe_unretained [])dep_objects DEPRECATED;
-- (void)getObjects:(id __unsafe_unretained [])objects DEPRECATED;
-@property int P1 DEPRECATED;
-@property int P2 DEPRECATED;
-@end
-
-@interface NSArray (DraggingSourceDeprecated)
-
-/* This method is unsafe because it could potentially cause buffer overruns. You should use -getObjects:range: instead.
-*/
-- (void)getObjects:(id __unsafe_unretained [])objects DEPRECATED;
-- (void)dep_getObjects:(id __unsafe_unretained [])dep_objects DEPRECATED;
-@property int P1 DEPRECATED;
-@property int P2 DEPRECATED;
-
-@end
-
-@interface NSArray (Deprecated)
-- (void)getObjects:(id __unsafe_unretained [])objects DEPRECATED;
-- (void)dep_getObjects:(id __unsafe_unretained [])dep_objects DEPRECATED;
-@property int P1 DEPRECATED;
-@property int P2 DEPRECATED;
-@end
index 8837e971ad270fe5ada9be88ff73b325f174b26f..7a32894f5706022d73ed09b4c4eb73215028fb7f 100644 (file)
@@ -16,10 +16,10 @@ typedef char BOOL;
 
 @class NSString, NSURL;
 @interface NSString (NSStringDeprecated)
-+ (instancetype)stringWithContentsOfFile:(NSString *)path __attribute__((availability(macosx,introduced=10.0 ,message="" )));
-+ (instancetype)stringWithContentsOfURL:(NSURL *)url __attribute__((availability(macosx,introduced=10.0 ,message="" )));
-+ (instancetype)stringWithCString:(const char *)bytes length:(NSUInteger)length __attribute__((availability(macosx,introduced=10.0 ,message="" )));
-+ (instancetype)stringWithCString:(const char *)bytes __attribute__((availability(macosx,introduced=10.0 ,message="" )));
++ (id)stringWithContentsOfFile:(NSString *)path __attribute__((availability(macosx,introduced=10.0 ,message="" )));
++ (id)stringWithContentsOfURL:(NSURL *)url __attribute__((availability(macosx,introduced=10.0 ,message="" )));
++ (id)stringWithCString:(const char *)bytes length:(NSUInteger)length __attribute__((availability(macosx,introduced=10.0 ,message="" )));
++ (id)stringWithCString:(const char *)bytes __attribute__((availability(macosx,introduced=10.0 ,message="" )));
 @end