r187068 - Objective-C migrator: some cleanup.

Fariborz Jahanian fjahanian at apple.com
Wed Jul 24 12:18:37 PDT 2013


Author: fjahanian
Date: Wed Jul 24 14:18:37 2013
New Revision: 187068

URL: http://llvm.org/viewvc/llvm-project?rev=187068&view=rev
Log:
Objective-C migrator: some cleanup.
Expose static type of init/alloc/retain with
instance type as well. Ad-hoc cases are coming
next.

Modified:
    cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
    cfe/trunk/lib/Basic/IdentifierTable.cpp
    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=187068&r1=187067&r2=187068&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Wed Jul 24 14:18:37 2013
@@ -556,11 +556,16 @@ void ObjCMigrateASTConsumer::migrateMeth
     Selector::getInstTypeMethodFamily(OM->getSelector());
   if (OIT_Family == OIT_None)
     return;
-  // TODO. Many more to come
+  std::string ClassName;
   switch (OIT_Family) {
     case OIT_Array:
+      ClassName = "NSArray";
       break;
     case OIT_Dictionary:
+      ClassName = "NSDictionary";
+      break;
+    case OIT_MemManage:
+      ClassName = "NSObject";
       break;
     default:
       return;
@@ -575,14 +580,8 @@ void ObjCMigrateASTConsumer::migrateMeth
     else if (ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(CDecl))
       IDecl = ImpDecl->getClassInterface();
   }
-  if (!IDecl)
-    return;
-  
-  if (OIT_Family ==  OIT_Array &&
-      !IDecl->lookupInheritedClass(&Ctx.Idents.get("NSArray")))
-    return;
-  else if (OIT_Family == OIT_Dictionary &&
-           !IDecl->lookupInheritedClass(&Ctx.Idents.get("NSDictionary")))
+  if (!IDecl ||
+      !IDecl->lookupInheritedClass(&Ctx.Idents.get(ClassName)))
     return;
   
   SourceRange R;

Modified: cfe/trunk/lib/Basic/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/IdentifierTable.cpp?rev=187068&r1=187067&r2=187068&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/IdentifierTable.cpp (original)
+++ cfe/trunk/lib/Basic/IdentifierTable.cpp Wed Jul 24 14:18:37 2013
@@ -471,6 +471,9 @@ ObjCInstanceTypeFamily Selector::getInst
     case 'i':
       if (startsWithWord(name, "init")) return OIT_MemManage;
       break;
+    case 'r':
+      if (startsWithWord(name, "retain")) return OIT_MemManage;
+      break;
     case 's':
       if (startsWithWord(name, "string")) return OIT_NSString;
       else

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=187068&r1=187067&r2=187068&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-instancetype.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-instancetype.m.result Wed Jul 24 14:18:37 2013
@@ -7,12 +7,12 @@ typedef signed char BOOL;
 #define nil ((void*) 0)
 
 @interface NSObject
-+ (id)alloc;
++ (instancetype)alloc;
 @end
 
 @interface NSString : NSObject
 + (id)stringWithString:(NSString *)string;
-- (id)initWithString:(NSString *)aString;
+- (instancetype)initWithString:(NSString *)aString;
 @end
 
 @interface NSArray : NSObject
@@ -27,9 +27,9 @@ typedef signed char BOOL;
 + (instancetype)arrayWithObjects:(id)firstObj, ...;
 + (instancetype) arrayWithArray:(NSArray *)array;
 
-- (id)initWithObjects:(const id [])objects count:(unsigned long)cnt;
-- (id)initWithObjects:(id)firstObj, ...;
-- (id)initWithArray:(NSArray *)array;
+- (instancetype)initWithObjects:(const id [])objects count:(unsigned long)cnt;
+- (instancetype)initWithObjects:(id)firstObj, ...;
+- (instancetype)initWithArray:(NSArray *)array;
 
 - (id)objectAtIndex:(unsigned long)index;
 @end
@@ -51,10 +51,10 @@ typedef signed char BOOL;
 + (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, ...;
-- (id)initWithDictionary:(NSDictionary *)otherDictionary;
-- (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
+- (instancetype)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
+- (instancetype)initWithObjectsAndKeys:(id)firstObject, ...;
+- (instancetype)initWithDictionary:(NSDictionary *)otherDictionary;
+- (instancetype)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
 
 - (id)objectForKey:(id)aKey;
 @end





More information about the cfe-commits mailing list