r193726 - ObjectiveC migrator: annotate all protocols/methods in
Fariborz Jahanian
fjahanian at apple.com
Wed Oct 30 17:06:59 PDT 2013
Author: fjahanian
Date: Wed Oct 30 19:06:58 2013
New Revision: 193726
URL: http://llvm.org/viewvc/llvm-project?rev=193726&view=rev
Log:
ObjectiveC migrator: annotate all protocols/methods in
a category with NSxxxDeprecated name with deprecated
annotation. // rdar://15337661
Added:
cfe/trunk/test/ARCMT/objcmt-deprecated-category.m
cfe/trunk/test/ARCMT/objcmt-deprecated-category.m.result
Modified:
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=193726&r1=193725&r2=193726&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Wed Oct 30 19:06:58 2013
@@ -44,6 +44,7 @@ class ObjCMigrateASTConsumer : public AS
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::migrateObjC
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::HandleTrans
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 =
Added: cfe/trunk/test/ARCMT/objcmt-deprecated-category.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-deprecated-category.m?rev=193726&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-deprecated-category.m (added)
+++ cfe/trunk/test/ARCMT/objcmt-deprecated-category.m Wed Oct 30 19:06:58 2013
@@ -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))
+
+ at interface NSArray
+- (int)one;
+ at end
+
+ at 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;
+
+ at end
+
+ at 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;
+ at property int P1;
+ at property int P2 DEPRECATED;
+ at end
+
+ at 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;
+ at property int P1;
+ at property int P2 DEPRECATED;
+
+ at end
Added: cfe/trunk/test/ARCMT/objcmt-deprecated-category.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-deprecated-category.m.result?rev=193726&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-deprecated-category.m.result (added)
+++ cfe/trunk/test/ARCMT/objcmt-deprecated-category.m.result Wed Oct 30 19:06:58 2013
@@ -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))
+
+ at interface NSArray
+- (int)one;
+ at end
+
+ at 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;
+
+ at end
+
+ at 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;
+ at property int P1 DEPRECATED;
+ at property int P2 DEPRECATED;
+ at end
+
+ at 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;
+ at property int P1;
+ at property int P2 DEPRECATED;
+
+ at end
More information about the cfe-commits
mailing list