summaryrefslogtreecommitdiffstats
path: root/clang/lib/ARCMigrate/ObjCMT.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/ARCMigrate/ObjCMT.cpp')
-rw-r--r--clang/lib/ARCMigrate/ObjCMT.cpp80
1 files changed, 17 insertions, 63 deletions
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp
index 62f3c6b7e79..2b2f9224e99 100644
--- a/clang/lib/ARCMigrate/ObjCMT.cpp
+++ b/clang/lib/ARCMigrate/ObjCMT.cpp
@@ -41,8 +41,6 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
void migrateInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl);
void migrateMethodInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl,
ObjCMethodDecl *OM);
- void migrateFactoryMethod(ASTContext &Ctx, ObjCContainerDecl *CDecl,
- ObjCMethodDecl *OM);
public:
std::string MigrateDir;
@@ -551,34 +549,13 @@ void ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx,
Editor->commit(commit);
}
-static void ReplaceWithInstancetype(const ObjCMigrateASTConsumer &ASTC,
- ObjCMethodDecl *OM) {
- SourceRange R;
- std::string ClassString;
- if (TypeSourceInfo *TSInfo = OM->getResultTypeSourceInfo()) {
- TypeLoc TL = TSInfo->getTypeLoc();
- R = SourceRange(TL.getBeginLoc(), TL.getEndLoc());
- ClassString = "instancetype";
- }
- else {
- R = SourceRange(OM->getLocStart(), OM->getLocStart());
- ClassString = OM->isInstanceMethod() ? '-' : '+';
- ClassString += " (instancetype)";
- }
- edit::Commit commit(*ASTC.Editor);
- commit.replace(R, ClassString);
- ASTC.Editor->commit(commit);
-}
-
void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx,
ObjCContainerDecl *CDecl,
ObjCMethodDecl *OM) {
ObjCInstanceTypeFamily OIT_Family =
Selector::getInstTypeMethodFamily(OM->getSelector());
- if (OIT_Family == OIT_None) {
- migrateFactoryMethod(Ctx, CDecl, OM);
+ if (OIT_Family == OIT_None)
return;
- }
std::string ClassName;
switch (OIT_Family) {
case OIT_Array:
@@ -604,11 +581,24 @@ void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx,
IDecl = ImpDecl->getClassInterface();
}
if (!IDecl ||
- !IDecl->lookupInheritedClass(&Ctx.Idents.get(ClassName))) {
- migrateFactoryMethod(Ctx, CDecl, OM);
+ !IDecl->lookupInheritedClass(&Ctx.Idents.get(ClassName)))
return;
+
+ SourceRange R;
+ std::string ClassString;
+ if (TypeSourceInfo *TSInfo = OM->getResultTypeSourceInfo()) {
+ TypeLoc TL = TSInfo->getTypeLoc();
+ R = SourceRange(TL.getBeginLoc(), TL.getEndLoc());
+ ClassString = "instancetype";
+ }
+ else {
+ R = SourceRange(OM->getLocStart(), OM->getLocStart());
+ ClassString = OM->isInstanceMethod() ? '-' : '+';
+ ClassString += " (instancetype)";
}
- ReplaceWithInstancetype(*this, OM);
+ edit::Commit commit(*Editor);
+ commit.replace(R, ClassString);
+ Editor->commit(commit);
}
void ObjCMigrateASTConsumer::migrateInstanceType(ASTContext &Ctx,
@@ -622,42 +612,6 @@ void ObjCMigrateASTConsumer::migrateInstanceType(ASTContext &Ctx,
}
}
-void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx,
- ObjCContainerDecl *CDecl,
- ObjCMethodDecl *OM) {
- if (OM->isInstanceMethod() || !OM->getResultType()->isObjCIdType())
- return;
-
- // Candidate factory methods are + (id) NaMeXXX : ... which belong to a class
- // NSYYYNamE with matching names be at least 3 characters long.
- 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)
- return;
-
- StringRef ClassName = IDecl->getName();
- if (!ClassName.startswith("NS"))
- return;
-
- ClassName = ClassName.lower();
- IdentifierInfo *MethodIdName = OM->getSelector().getIdentifierInfoForSlot(0);
- StringRef MethodName = MethodIdName->getName();
- StringRef MethodNamePrefix = MethodName.substr(0, 3).lower();
- size_t Ix = ClassName.rfind(MethodNamePrefix);
- if (Ix == StringRef::npos)
- return;
- StringRef ClassNamePostfix = ClassName.substr(Ix);
- MethodName = MethodName.lower();
- if (!MethodName.startswith(ClassNamePostfix))
- return;
- ReplaceWithInstancetype(*this, OM);
-}
-
namespace {
class RewritesReceiver : public edit::EditsReceiver {
OpenPOWER on IntegriCloud