From 00295ff212d1b99b1f32cfc4aacb8935414f5d90 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 19 Nov 2013 18:17:31 +0000 Subject: [PATCH] ObjectiveC migrator. Do not migrate categories with 'Deprecated' name suffix. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195137 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ARCMigrate/ObjCMT.cpp | 50 ++++--------------- test/ARCMT/objcmt-deprecated-category.m | 48 ------------------ .../ARCMT/objcmt-deprecated-category.m.result | 48 ------------------ test/ARCMT/objcmt-instancetype-2.m.result | 8 +-- 4 files changed, 15 insertions(+), 139 deletions(-) delete mode 100644 test/ARCMT/objcmt-deprecated-category.m delete mode 100644 test/ARCMT/objcmt-deprecated-category.m.result diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index cac0fb0aed..0f0268572e 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -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(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(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(*D)) { migrateObjCInterfaceDecl(Ctx, CatDecl); - if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) - migrateDeprecatedAnnotation(Ctx, CatDecl); } else if (ObjCProtocolDecl *PDecl = dyn_cast(*D)) ObjCProtocolDecls.insert(PDecl); diff --git a/test/ARCMT/objcmt-deprecated-category.m b/test/ARCMT/objcmt-deprecated-category.m deleted file mode 100644 index 5939e5a50a..0000000000 --- a/test/ARCMT/objcmt-deprecated-category.m +++ /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 index 3cb100044e..0000000000 --- a/test/ARCMT/objcmt-deprecated-category.m.result +++ /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 diff --git a/test/ARCMT/objcmt-instancetype-2.m.result b/test/ARCMT/objcmt-instancetype-2.m.result index 8837e971ad..7a32894f57 100644 --- a/test/ARCMT/objcmt-instancetype-2.m.result +++ b/test/ARCMT/objcmt-instancetype-2.m.result @@ -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 -- 2.40.0