From 6d754e9a9d6591e8fc5eedc144cc70a7e539ba6f Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 31 Oct 2013 00:06:58 +0000 Subject: [PATCH] ObjectiveC migrator: annotate all protocols/methods in a category with NSxxxDeprecated name with deprecated annotation. // rdar://15337661 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193726 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ARCMigrate/ObjCMT.cpp | 43 +++++++++++++++++-- test/ARCMT/objcmt-deprecated-category.m | 41 ++++++++++++++++++ .../ARCMT/objcmt-deprecated-category.m.result | 41 ++++++++++++++++++ 3 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 test/ARCMT/objcmt-deprecated-category.m create mode 100644 test/ARCMT/objcmt-deprecated-category.m.result diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 382bab759a..b2a6980944 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -44,6 +44,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer { void migrateDecl(Decl *D); void migrateObjCInterfaceDecl(ASTContext &Ctx, ObjCContainerDecl *D); + void migregateDeprecatedAnnotation(ASTContext &Ctx, ObjCCategoryDecl *CatDecl); void migrateProtocolConformance(ASTContext &Ctx, const ObjCImplementationDecl *ImpDecl); void CacheObjCNSIntegerTypedefed(const TypedefDecl *TypedefDcl); @@ -419,12 +420,45 @@ void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx, E = D->prop_end(); P != E; ++P) { ObjCPropertyDecl *Prop = *P; if ((ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) && - !P->isDeprecated()) + !Prop->isDeprecated()) migratePropertyNsReturnsInnerPointer(Ctx, Prop); } } -static bool +void ObjCMigrateASTConsumer::migregateDeprecatedAnnotation(ASTContext &Ctx, + ObjCCategoryDecl *CatDecl) { + StringRef Name = CatDecl->getName(); + if (!Name.startswith("NS") || !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, const ObjCInterfaceDecl *IDecl, @@ -1504,8 +1538,11 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { if (ObjCInterfaceDecl *CDecl = dyn_cast(*D)) migrateObjCInterfaceDecl(Ctx, CDecl); - if (ObjCCategoryDecl *CatDecl = dyn_cast(*D)) + if (ObjCCategoryDecl *CatDecl = dyn_cast(*D)) { migrateObjCInterfaceDecl(Ctx, CatDecl); + if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) + migregateDeprecatedAnnotation(Ctx, CatDecl); + } else if (ObjCProtocolDecl *PDecl = dyn_cast(*D)) ObjCProtocolDecls.insert(PDecl); else if (const ObjCImplementationDecl *ImpDecl = diff --git a/test/ARCMT/objcmt-deprecated-category.m b/test/ARCMT/objcmt-deprecated-category.m new file mode 100644 index 0000000000..0b7c1cf1bd --- /dev/null +++ b/test/ARCMT/objcmt-deprecated-category.m @@ -0,0 +1,41 @@ +// 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 diff --git a/test/ARCMT/objcmt-deprecated-category.m.result b/test/ARCMT/objcmt-deprecated-category.m.result new file mode 100644 index 0000000000..4d2a6b64de --- /dev/null +++ b/test/ARCMT/objcmt-deprecated-category.m.result @@ -0,0 +1,41 @@ +// 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; +- (void)dep_getObjects:(id __unsafe_unretained [])dep_objects DEPRECATED; +@property int P1; +@property int P2 DEPRECATED; + +@end -- 2.40.0