From 10b7435cebebf7d5bebf465a4701fa1302663a2e Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 24 Sep 2013 20:20:52 +0000 Subject: [PATCH] ObjectiveC migrator: iDOn't mangle names when NS_RETURNS_INNER_POINTER annotation is suggested on a property. // rdar://15044991 llvm-svn: 191332 --- clang/lib/ARCMigrate/ObjCMT.cpp | 26 ++++++++++++++++--- .../ARCMT/objcmt-ns-returns-inner-pointer.m | 18 +++++++++++++ .../objcmt-ns-returns-inner-pointer.m.result | 18 +++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index 5cb5d2cb2eff..871c8ece054e 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -53,6 +53,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer { ObjCMethodDecl *OM); bool migrateProperty(ASTContext &Ctx, ObjCContainerDecl *D, ObjCMethodDecl *OM); void migrateNsReturnsInnerPointer(ASTContext &Ctx, ObjCMethodDecl *OM); + void migratePropertyNsReturnsInnerPointer(ASTContext &Ctx, ObjCPropertyDecl *P); void migrateFactoryMethod(ASTContext &Ctx, ObjCContainerDecl *CDecl, ObjCMethodDecl *OM, ObjCInstanceTypeFamily OIT_Family = OIT_None); @@ -350,8 +351,14 @@ void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx, ObjCMethodDecl *Method = (*M); if (Method->isDeprecated()) continue; - if (!migrateProperty(Ctx, D, Method)) - migrateNsReturnsInnerPointer(Ctx, Method); + migrateProperty(Ctx, D, Method); + migrateNsReturnsInnerPointer(Ctx, Method); + } + for (ObjCContainerDecl::prop_iterator P = D->prop_begin(), + E = D->prop_end(); P != E; ++P) { + ObjCPropertyDecl *Prop = *P; + if (!P->isDeprecated()) + migratePropertyNsReturnsInnerPointer(Ctx, Prop); } } @@ -831,7 +838,8 @@ bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx, void ObjCMigrateASTConsumer::migrateNsReturnsInnerPointer(ASTContext &Ctx, ObjCMethodDecl *OM) { - if (OM->hasAttr()) + if (OM->isImplicit() || + OM->hasAttr()) return; QualType RT = OM->getResultType(); @@ -844,6 +852,18 @@ void ObjCMigrateASTConsumer::migrateNsReturnsInnerPointer(ASTContext &Ctx, Editor->commit(commit); } +void ObjCMigrateASTConsumer::migratePropertyNsReturnsInnerPointer(ASTContext &Ctx, + ObjCPropertyDecl *P) { + QualType T = P->getType(); + + if (!TypeIsInnerPointer(T) || + !Ctx.Idents.get("NS_RETURNS_INNER_POINTER").hasMacroDefinition()) + return; + edit::Commit commit(*Editor); + commit.insertBefore(P->getLocEnd(), " NS_RETURNS_INNER_POINTER "); + Editor->commit(commit); +} + void ObjCMigrateASTConsumer::migrateMethods(ASTContext &Ctx, ObjCContainerDecl *CDecl) { if (CDecl->isDeprecated()) diff --git a/clang/test/ARCMT/objcmt-ns-returns-inner-pointer.m b/clang/test/ARCMT/objcmt-ns-returns-inner-pointer.m index 404928398fe5..d046317b1b45 100644 --- a/clang/test/ARCMT/objcmt-ns-returns-inner-pointer.m +++ b/clang/test/ARCMT/objcmt-ns-returns-inner-pointer.m @@ -36,6 +36,8 @@ #define NS_RETURNS_AUTORELEASED __attribute__((ns_returns_autoreleased)) #endif +#define NS_AVAILABLE __attribute__((availability(macosx,introduced=10.0))) + CF_IMPLICIT_BRIDGING_ENABLED typedef unsigned long CFTypeID; @@ -104,3 +106,19 @@ CF_IMPLICIT_BRIDGING_DISABLED - (TTJSObjectRef)JSObject1; - (JSObjectRef*)JSObject2; @end + +// rdar://15044991 +typedef void *SecTrustRef; + +@interface NSURLProtectionSpace +@property (readonly) SecTrustRef serverTrust NS_AVAILABLE; +- (void *) FOO NS_AVAILABLE; +@property (readonly) void * mitTrust NS_AVAILABLE; + +@property (readonly) void * mittiTrust; + +@property (readonly) SecTrustRef XserverTrust; + +- (SecTrustRef) FOO1 NS_AVAILABLE; + +@end diff --git a/clang/test/ARCMT/objcmt-ns-returns-inner-pointer.m.result b/clang/test/ARCMT/objcmt-ns-returns-inner-pointer.m.result index c3f151ab2231..8331e1669b12 100644 --- a/clang/test/ARCMT/objcmt-ns-returns-inner-pointer.m.result +++ b/clang/test/ARCMT/objcmt-ns-returns-inner-pointer.m.result @@ -36,6 +36,8 @@ #define NS_RETURNS_AUTORELEASED __attribute__((ns_returns_autoreleased)) #endif +#define NS_AVAILABLE __attribute__((availability(macosx,introduced=10.0))) + CF_IMPLICIT_BRIDGING_ENABLED typedef unsigned long CFTypeID; @@ -104,3 +106,19 @@ CF_IMPLICIT_BRIDGING_DISABLED - (TTJSObjectRef)JSObject1; - (JSObjectRef*)JSObject2 NS_RETURNS_INNER_POINTER; @end + +// rdar://15044991 +typedef void *SecTrustRef; + +@interface NSURLProtectionSpace +@property (readonly) SecTrustRef NS_RETURNS_INNER_POINTER serverTrust NS_AVAILABLE; +- (void *) FOO NS_AVAILABLE NS_RETURNS_INNER_POINTER; +@property (readonly) void * NS_RETURNS_INNER_POINTER mitTrust NS_AVAILABLE; + +@property (readonly) void * NS_RETURNS_INNER_POINTER mittiTrust; + +@property (readonly) SecTrustRef NS_RETURNS_INNER_POINTER XserverTrust; + +- (SecTrustRef) FOO1 NS_AVAILABLE NS_RETURNS_INNER_POINTER; + +@end