From 641645f00c22e1f55794537a43646214402e99a1 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 17 Sep 2013 21:56:04 +0000 Subject: [PATCH] ObjectiveC migrator. Ignore migrating 'deprecated' entities. // rdar://14989365 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190890 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ARCMigrate/ObjCMT.cpp | 21 +++++++++++++------ test/ARCMT/objcmt-arc-cf-annotations.m.result | 4 ++-- test/ARCMT/objcmt-instancetype-2.m | 8 +++---- test/ARCMT/objcmt-instancetype-2.m.result | 8 +++---- test/ARCMT/objcmt-ns-macros.m | 16 ++++++++++++++ test/ARCMT/objcmt-ns-macros.m.result | 16 ++++++++++++++ test/ARCMT/objcmt-property.m | 18 ++++++++++++++++ test/ARCMT/objcmt-property.m.result | 18 ++++++++++++++++ 8 files changed, 93 insertions(+), 16 deletions(-) diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index b51f8bb493..d0d6b8794f 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -340,9 +340,14 @@ static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter, void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx, ObjCContainerDecl *D) { + if (D->isDeprecated()) + return; + for (ObjCContainerDecl::method_iterator M = D->meth_begin(), MEnd = D->meth_end(); M != MEnd; ++M) { ObjCMethodDecl *Method = (*M); + if (Method->isDeprecated()) + continue; if (!migrateProperty(Ctx, D, Method)) migrateNsReturnsInnerPointer(Ctx, Method); } @@ -532,7 +537,7 @@ static bool UseNSOptionsMacro(Preprocessor &PP, ASTContext &Ctx, void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx, const ObjCImplementationDecl *ImpDecl) { const ObjCInterfaceDecl *IDecl = ImpDecl->getClassInterface(); - if (!IDecl || ObjCProtocolDecls.empty()) + if (!IDecl || ObjCProtocolDecls.empty() || IDecl->isDeprecated()) return; // Find all implicit conforming protocols for this class // and make them explicit. @@ -590,7 +595,8 @@ void ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx, const EnumDecl *EnumDcl, const TypedefDecl *TypedefDcl) { if (!EnumDcl->isCompleteDefinition() || EnumDcl->getIdentifier() || - !TypedefDcl->getIdentifier()) + !TypedefDcl->getIdentifier() || + EnumDcl->isDeprecated() || TypedefDcl->isDeprecated()) return; QualType qt = TypedefDcl->getTypeSourceInfo()->getType(); @@ -813,6 +819,8 @@ void ObjCMigrateASTConsumer::migrateMethods(ASTContext &Ctx, MEnd = CDecl->meth_end(); M != MEnd; ++M) { ObjCMethodDecl *Method = (*M); + if (Method->isDeprecated()) + continue; migrateMethodInstanceType(Ctx, CDecl, Method); } } @@ -944,6 +952,9 @@ void ObjCMigrateASTConsumer::AnnotateImplicitBridging(ASTContext &Ctx) { } void ObjCMigrateASTConsumer::migrateCFAnnotation(ASTContext &Ctx, const Decl *Decl) { + if (Decl->isDeprecated()) + return; + if (Decl->hasAttr()) { assert(CFFunctionIBCandidates.empty() && "Cannot have audited functions/methods inside user " @@ -1084,7 +1095,7 @@ ObjCMigrateASTConsumer::CF_BRIDGING_KIND void ObjCMigrateASTConsumer::migrateARCSafeAnnotation(ASTContext &Ctx, ObjCContainerDecl *CDecl) { - if (!isa(CDecl)) + if (!isa(CDecl) || CDecl->isDeprecated()) return; // migrate methods which can have instancetype as their result type. @@ -1234,10 +1245,8 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { D != DEnd; ++D) { if (unsigned FID = PP.getSourceManager().getFileID((*D)->getLocation()).getHashValue()) - if (FileId && FileId != FID) { - assert(!CFFunctionIBCandidates.empty()); + if (FileId && FileId != FID) AnnotateImplicitBridging(Ctx); - } if (ObjCInterfaceDecl *CDecl = dyn_cast(*D)) migrateObjCInterfaceDecl(Ctx, CDecl); diff --git a/test/ARCMT/objcmt-arc-cf-annotations.m.result b/test/ARCMT/objcmt-arc-cf-annotations.m.result index e55b0b3712..43537c85d8 100644 --- a/test/ARCMT/objcmt-arc-cf-annotations.m.result +++ b/test/ARCMT/objcmt-arc-cf-annotations.m.result @@ -231,10 +231,10 @@ CF_IMPLICIT_BRIDGING_ENABLED io_service_t IOServiceGetMatchingService( mach_port_t masterPort, CFDictionaryRef matching ); kern_return_t IOServiceGetMatchingServices( mach_port_t masterPort, CFDictionaryRef matching, io_iterator_t * existing ); -kern_return_t IOServiceAddNotification( mach_port_t masterPort, const io_name_t notificationType, CFDictionaryRef matching, mach_port_t wakePort, uintptr_t reference, io_iterator_t * notification ) __attribute__((deprecated)); CF_IMPLICIT_BRIDGING_DISABLED - // expected-note {{'IOServiceAddNotification' declared here}} + +kern_return_t IOServiceAddNotification( mach_port_t masterPort, const io_name_t notificationType, CFDictionaryRef matching, mach_port_t wakePort, uintptr_t reference, io_iterator_t * notification ) __attribute__((deprecated)); // expected-note {{'IOServiceAddNotification' declared here}} kern_return_t IOServiceAddMatchingNotification( IONotificationPortRef notifyPort, const io_name_t notificationType, CFDictionaryRef CF_CONSUMED matching, IOServiceMatchingCallback callback, void * refCon, io_iterator_t * notification ); CF_IMPLICIT_BRIDGING_ENABLED diff --git a/test/ARCMT/objcmt-instancetype-2.m b/test/ARCMT/objcmt-instancetype-2.m index 2fdbcf9cca..4f1a509c4f 100644 --- a/test/ARCMT/objcmt-instancetype-2.m +++ b/test/ARCMT/objcmt-instancetype-2.m @@ -16,10 +16,10 @@ typedef char BOOL; @class NSString, NSURL; @interface NSString (NSStringDeprecated) -+ (id)stringWithContentsOfFile:(NSString *)path __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.4,message="" ))); -+ (id)stringWithContentsOfURL:(NSURL *)url __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.4,message="" ))); -+ (id)stringWithCString:(const char *)bytes length:(NSUInteger)length __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.4,message="" ))); -+ (id)stringWithCString:(const char *)bytes __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.4,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 diff --git a/test/ARCMT/objcmt-instancetype-2.m.result b/test/ARCMT/objcmt-instancetype-2.m.result index b6bd05adeb..e9ca594ed0 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 ,deprecated=10.4,message="" ))); -+ (instancetype)stringWithContentsOfURL:(NSURL *)url __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.4,message="" ))); -+ (instancetype)stringWithCString:(const char *)bytes length:(NSUInteger)length __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.4,message="" ))); -+ (instancetype)stringWithCString:(const char *)bytes __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.4,message="" ))); ++ (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="" ))); @end diff --git a/test/ARCMT/objcmt-ns-macros.m b/test/ARCMT/objcmt-ns-macros.m index ec6e3d44c7..ccf666c1e0 100644 --- a/test/ARCMT/objcmt-ns-macros.m +++ b/test/ARCMT/objcmt-ns-macros.m @@ -8,6 +8,7 @@ typedef unsigned long NSUInteger; #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type #define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type +#define DEPRECATED __attribute__((deprecated)) enum { blah, @@ -110,3 +111,18 @@ enum { }; typedef NSUInteger NSAlertStyle; +enum { + D_NSTIFFFileType, + D_NSBMPFileType, + D_NSGIFFileType, + D_NSJPEGFileType, + D_NSPNGFileType, + D_NSJPEG2000FileType +}; +typedef NSUInteger D_NSBitmapImageFileType DEPRECATED; + +typedef enum { + D_NSTickMarkBelow = 0, + D_NSTickMarkAbove = 1 +} D_NSTickMarkPosition DEPRECATED; + diff --git a/test/ARCMT/objcmt-ns-macros.m.result b/test/ARCMT/objcmt-ns-macros.m.result index 80c84bdfbe..b94b31b882 100644 --- a/test/ARCMT/objcmt-ns-macros.m.result +++ b/test/ARCMT/objcmt-ns-macros.m.result @@ -8,6 +8,7 @@ typedef unsigned long NSUInteger; #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type #define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type +#define DEPRECATED __attribute__((deprecated)) typedef NS_ENUM(NSInteger, wibble) { blah, @@ -110,3 +111,18 @@ typedef NS_ENUM(NSUInteger, NSAlertStyle) { }; +enum { + D_NSTIFFFileType, + D_NSBMPFileType, + D_NSGIFFileType, + D_NSJPEGFileType, + D_NSPNGFileType, + D_NSJPEG2000FileType +}; +typedef NSUInteger D_NSBitmapImageFileType DEPRECATED; + +typedef enum { + D_NSTickMarkBelow = 0, + D_NSTickMarkAbove = 1 +} D_NSTickMarkPosition DEPRECATED; + diff --git a/test/ARCMT/objcmt-property.m b/test/ARCMT/objcmt-property.m index 9ddd9edb9b..5b11c4aa3a 100644 --- a/test/ARCMT/objcmt-property.m +++ b/test/ARCMT/objcmt-property.m @@ -6,6 +6,7 @@ #define WEBKIT_OBJC_METHOD_ANNOTATION(ANNOTATION) ANNOTATION #define WEAK_IMPORT_ATTRIBUTE __attribute__((objc_arc_weak_reference_unavailable)) #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER +#define DEPRECATED __attribute__((deprecated)) typedef char BOOL; @class NSString; @@ -158,3 +159,20 @@ typedef char BOOL; - (BOOL) getMANY; - (BOOL) getSome; @end + +DEPRECATED +@interface I_DEP +- (BOOL) isinValid; +- (void) setInValid : (BOOL) arg; +@end + +@interface AnotherOne +- (BOOL) isinValid DEPRECATED; +- (void) setInValid : (BOOL) arg; +- (id)MYtarget; +- (void)setMYtarget: (id)target DEPRECATED; +- (BOOL) getM DEPRECATED; + +- (id)xxxdelegateYYY DEPRECATED; +- (void)setXxxdelegateYYY:(id)delegate DEPRECATED; +@end diff --git a/test/ARCMT/objcmt-property.m.result b/test/ARCMT/objcmt-property.m.result index 355a8c124c..39b0a8740f 100644 --- a/test/ARCMT/objcmt-property.m.result +++ b/test/ARCMT/objcmt-property.m.result @@ -6,6 +6,7 @@ #define WEBKIT_OBJC_METHOD_ANNOTATION(ANNOTATION) ANNOTATION #define WEAK_IMPORT_ATTRIBUTE __attribute__((objc_arc_weak_reference_unavailable)) #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER +#define DEPRECATED __attribute__((deprecated)) typedef char BOOL; @class NSString; @@ -158,3 +159,20 @@ typedef char BOOL; @property(nonatomic, getter=getMANY, readonly) BOOL MANY; @property(nonatomic, getter=getSome, readonly) BOOL some; @end + +DEPRECATED +@interface I_DEP +- (BOOL) isinValid; +- (void) setInValid : (BOOL) arg; +@end + +@interface AnotherOne +- (BOOL) isinValid DEPRECATED; +- (void) setInValid : (BOOL) arg; +- (id)MYtarget; +- (void)setMYtarget: (id)target DEPRECATED; +- (BOOL) getM DEPRECATED; + +- (id)xxxdelegateYYY DEPRECATED; +- (void)setXxxdelegateYYY:(id)delegate DEPRECATED; +@end -- 2.40.0