ObjC migrator: more knobs toward doing

instancetype migration.

llvm-svn: 187000
This commit is contained in:
Fariborz Jahanian 2013-07-23 22:42:28 +00:00
parent 0f2fe74aaf
commit 7122135fc3
3 changed files with 44 additions and 3 deletions

View 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

View 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());

View 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;