diff options
-rw-r--r-- | clang/include/clang/Basic/IdentifierTable.h | 4 | ||||
-rw-r--r-- | clang/lib/ARCMigrate/ObjCMT.cpp | 41 | ||||
-rw-r--r-- | clang/lib/Basic/IdentifierTable.cpp | 2 |
3 files changed, 44 insertions, 3 deletions
diff --git a/clang/include/clang/Basic/IdentifierTable.h b/clang/include/clang/Basic/IdentifierTable.h index 86f9d9b61e1..8e12b972ed3 100644 --- a/clang/include/clang/Basic/IdentifierTable.h +++ b/clang/include/clang/Basic/IdentifierTable.h @@ -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 diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index 153ebbcca16..b5aaa3b196b 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -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()); diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index faff4d88635..fa021f0501e 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -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; |