]> granicus.if.org Git - clang/commitdiff
ObjC migrator: more knobs toward doing
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 23 Jul 2013 22:42:28 +0000 (22:42 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 23 Jul 2013 22:42:28 +0000 (22:42 +0000)
instancetype migration.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187000 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/IdentifierTable.h
lib/ARCMigrate/ObjCMT.cpp
lib/Basic/IdentifierTable.cpp

index 86f9d9b61e14ec2b4a21c531a380a71a01dc40c2..8e12b972ed34511f671c3d3feaa0368065a7359e 100644 (file)
@@ -637,8 +637,6 @@ class Selector {
   }
 
   static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
-  
-  static ObjCInstanceTypeFamily getInstTypeMethodFamilyImpl(Selector sel);
 
 public:
   friend class SelectorTable; // only the SelectorTable can create these
@@ -714,6 +712,8 @@ public:
   static Selector getTombstoneMarker() {
     return Selector(uintptr_t(-2));
   }
+  
+  static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel);
 };
 
 /// \brief This table allows us to fully hide how we implement
index 153ebbcca16dfde9e7d0084d859d330fee32f81f..b5aaa3b196b0990ff32fc82b13275b807e10bd00 100644 (file)
@@ -38,6 +38,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
                                   const ObjCImplementationDecl *ImpDecl);
   void migrateNSEnumDecl(ASTContext &Ctx, const EnumDecl *EnumDcl,
                      const TypedefDecl *TypedefDcl);
+  void migrateInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl);
 
 public:
   std::string MigrateDir;
@@ -546,6 +547,43 @@ void ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx,
   Editor->commit(commit);
 }
 
+static void
+migrateMethodInstanceType(ASTContext &Ctx,
+                          ObjCContainerDecl *CDecl,
+                          ObjCMethodDecl *OM) {
+  ObjCInstanceTypeFamily OIT_Family =
+    Selector::getInstTypeMethodFamily(OM->getSelector());
+  if (OIT_Family == OIT_None)
+    return;
+  // TODO. Many more to come
+  if (OIT_Family != OIT_Array)
+    return;
+  if (!OM->getResultType()->isObjCIdType())
+    return;
+  
+  ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl);
+  if (!IDecl) {
+    if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl))
+      IDecl = CatDecl->getClassInterface();
+    else if (ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(CDecl))
+      IDecl = ImpDecl->getClassInterface();
+  }
+  if (!IDecl || !IDecl->lookupInheritedClass(&Ctx.Idents.get("NSArray")))
+    return;
+  
+}
+
+void ObjCMigrateASTConsumer::migrateInstanceType(ASTContext &Ctx,
+                                                 ObjCContainerDecl *CDecl) {
+  // migrate methods which can have instancetype as their result type.
+  for (ObjCContainerDecl::method_iterator M = CDecl->meth_begin(),
+       MEnd = CDecl->meth_end();
+       M != MEnd; ++M) {
+    ObjCMethodDecl *Method = (*M);
+    migrateMethodInstanceType(Ctx, CDecl, Method);
+  }
+}
+
 namespace {
 
 class RewritesReceiver : public edit::EditsReceiver {
@@ -584,6 +622,9 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
           if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(*N))
             migrateNSEnumDecl(Ctx, ED, TD);
       }
+      // migrate methods which can have instancetype as their result type.
+      if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(*D))
+        migrateInstanceType(Ctx, CDecl);
     }
   
   Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
index faff4d886350e843242652bcc69413acd2eecb85..fa021f0501e6226a86bea04f9d1a746d30bc24b0 100644 (file)
@@ -452,7 +452,7 @@ ObjCMethodFamily Selector::getMethodFamilyImpl(Selector sel) {
   return OMF_None;
 }
 
-ObjCInstanceTypeFamily Selector::getInstTypeMethodFamilyImpl(Selector sel) {
+ObjCInstanceTypeFamily Selector::getInstTypeMethodFamily(Selector sel) {
   IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
   if (!first) return OIT_None;