diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2013-10-31 00:06:58 +0000 |
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2013-10-31 00:06:58 +0000 |
| commit | 9d2ffea486f6d918cfb2b25984ca6688deab12b9 (patch) | |
| tree | 3382fc942f4351fa4edaf5bf8237115f1dda41bb | |
| parent | 28d5b6bb11ac3cb04ca185e7ee6d8f8d13c71ad9 (diff) | |
| download | bcm5719-llvm-9d2ffea486f6d918cfb2b25984ca6688deab12b9.tar.gz bcm5719-llvm-9d2ffea486f6d918cfb2b25984ca6688deab12b9.zip | |
ObjectiveC migrator: annotate all protocols/methods in
a category with NSxxxDeprecated name with deprecated
annotation. // rdar://15337661
llvm-svn: 193726
| -rw-r--r-- | clang/lib/ARCMigrate/ObjCMT.cpp | 43 | ||||
| -rw-r--r-- | clang/test/ARCMT/objcmt-deprecated-category.m | 41 | ||||
| -rw-r--r-- | clang/test/ARCMT/objcmt-deprecated-category.m.result | 41 |
3 files changed, 122 insertions, 3 deletions
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index 382bab759af..b2a6980944d 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/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<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, const ObjCInterfaceDecl *IDecl, @@ -1504,8 +1538,11 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { if (ObjCInterfaceDecl *CDecl = dyn_cast<ObjCInterfaceDecl>(*D)) migrateObjCInterfaceDecl(Ctx, CDecl); - if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(*D)) + if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(*D)) { migrateObjCInterfaceDecl(Ctx, CatDecl); + if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) + migregateDeprecatedAnnotation(Ctx, CatDecl); + } else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(*D)) ObjCProtocolDecls.insert(PDecl); else if (const ObjCImplementationDecl *ImpDecl = diff --git a/clang/test/ARCMT/objcmt-deprecated-category.m b/clang/test/ARCMT/objcmt-deprecated-category.m new file mode 100644 index 00000000000..0b7c1cf1bda --- /dev/null +++ b/clang/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/clang/test/ARCMT/objcmt-deprecated-category.m.result b/clang/test/ARCMT/objcmt-deprecated-category.m.result new file mode 100644 index 00000000000..4d2a6b64de8 --- /dev/null +++ b/clang/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 |

