r189520 - ObjectiveC migrator: In suggesting 'instancetype' use clang's
Fariborz Jahanian
fjahanian at apple.com
Wed Aug 28 14:23:00 PDT 2013
Author: fjahanian
Date: Wed Aug 28 16:23:00 2013
New Revision: 189520
URL: http://llvm.org/viewvc/llvm-project?rev=189520&view=rev
Log:
ObjectiveC migrator: In suggesting 'instancetype' use clang's
hasRelatedResultType() as it knows of methods which have
related result type by default. Such methods do not need
a redundant 'instancetype'.
Modified:
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result
cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result
cfe/trunk/test/ARCMT/objcmt-instancetype.m.result
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=189520&r1=189519&r2=189520&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Wed Aug 28 16:23:00 2013
@@ -660,6 +660,11 @@ static void ReplaceWithInstancetype(cons
void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx,
ObjCContainerDecl *CDecl,
ObjCMethodDecl *OM) {
+ // bail out early and do not suggest 'instancetype' when the method already
+ // has a related result type,
+ if (OM->hasRelatedResultType())
+ return;
+
ObjCInstanceTypeFamily OIT_Family =
Selector::getInstTypeMethodFamily(OM->getSelector());
@@ -668,11 +673,15 @@ void ObjCMigrateASTConsumer::migrateMeth
case OIT_None:
migrateFactoryMethod(Ctx, CDecl, OM);
return;
+ case OIT_Array:
+ ClassName = "NSArray";
+ break;
+ case OIT_Dictionary:
+ ClassName = "NSDictionary";
+ break;
// For methods where Clang automatically infers instancetype from the selector
// (e.g., all -init* methods), we should not suggest "instancetype" because it
// is redundant,
- case OIT_Array:
- case OIT_Dictionary:
case OIT_MemManage:
return;
case OIT_Singleton:
Modified: cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result?rev=189520&r1=189519&r2=189520&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result Wed Aug 28 16:23:00 2013
@@ -181,12 +181,12 @@ NSFastEnumerationState;
@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
- (NSUInteger)count;
- (id)initWithObjects:(const id [])objects count:(NSUInteger)cnt;
-+ (id)arrayWithObject:(id)anObject;
-+ (id)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt;
-+ (id)arrayWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
++ (instancetype)arrayWithObject:(id)anObject;
++ (instancetype)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt;
++ (instancetype)arrayWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
- (id)initWithArray:(NSArray *)array;
- at end @interface NSArray (NSArrayCreation) + (id)array;
+ at end @interface NSArray (NSArrayCreation) + (instancetype)array;
@end @interface NSAutoreleasePool : NSObject {
}
- (void)drain;
@@ -207,12 +207,12 @@ typedef double NSTimeInterval;
@end @class NSLocale, NSDate, NSCalendar, NSTimeZone, NSError, NSArray, NSMutableDictionary;
@interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
- (NSUInteger)count;
-+ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
-+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;
++ (instancetype)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
++ (instancetype)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;
@end
@interface NSMutableDictionary : NSDictionary - (void)removeObjectForKey:(id)aKey;
- (void)setObject:(id)anObject forKey:(id)aKey;
- at end @interface NSMutableDictionary (NSMutableDictionaryCreation) + (id)dictionaryWithCapacity:(NSUInteger)numItems;
+ at end @interface NSMutableDictionary (NSMutableDictionaryCreation) + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
@end typedef double CGFloat;
struct CGSize {
};
@@ -350,7 +350,7 @@ CF_IMPLICIT_BRIDGING_DISABLED
@interface NSMutableArray : NSObject
- (void)addObject:(id)object;
-+ (id)array;
++ (instancetype)array;
@end
// This is how NSMakeCollectable is declared in the OS X 10.8 headers.
Modified: cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result?rev=189520&r1=189519&r2=189520&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result Wed Aug 28 16:23:00 2013
@@ -51,7 +51,7 @@ typedef enum NSURLBookmarkResolutionOpti
@interface NSMutableDictionary @end
@interface NSMutableDictionary (NSSharedKeySetDictionary)
-+ (id )dictionaryWithSharedKeySet:(id)keyset __attribute__((availability(macosx,introduced=10.8)));
++ (instancetype )dictionaryWithSharedKeySet:(id)keyset __attribute__((availability(macosx,introduced=10.8)));
@end
@interface NSProtocolChecker
Modified: cfe/trunk/test/ARCMT/objcmt-instancetype.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-instancetype.m.result?rev=189520&r1=189519&r2=189520&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-instancetype.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-instancetype.m.result Wed Aug 28 16:23:00 2013
@@ -21,11 +21,11 @@ typedef signed char BOOL;
@end
@interface NSArray (NSArrayCreation)
-+ (id)array;
-+ (id)arrayWithObject:(id)anObject;
-+ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
-+ (id)arrayWithObjects:(id)firstObj, ...;
-+ arrayWithArray:(NSArray *)array;
++ (instancetype)array;
++ (instancetype)arrayWithObject:(id)anObject;
++ (instancetype)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
++ (instancetype)arrayWithObjects:(id)firstObj, ...;
++ (instancetype) arrayWithArray:(NSArray *)array;
- (id)initWithObjects:(const id [])objects count:(unsigned long)cnt;
- (id)initWithObjects:(id)firstObj, ...;
@@ -44,12 +44,12 @@ typedef signed char BOOL;
@end
@interface NSDictionary (NSDictionaryCreation)
-+ (id)dictionary;
-+ (id)dictionaryWithObject:(id)object forKey:(id)key;
-+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
-+ dictionaryWithObjectsAndKeys:(id)firstObject, ...;
-+ (id)dictionaryWithDictionary:(NSDictionary *)dict;
-+ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
++ (instancetype)dictionary;
++ (instancetype)dictionaryWithObject:(id)object forKey:(id)key;
++ (instancetype)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
++ (instancetype) dictionaryWithObjectsAndKeys:(id)firstObject, ...;
++ (instancetype)dictionaryWithDictionary:(NSDictionary *)dict;
++ (instancetype)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
- (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
- (id)initWithObjectsAndKeys:(id)firstObject, ...;
More information about the cfe-commits
mailing list