diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2013-08-02 16:00:08 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2013-08-02 16:00:08 +0000 |
commit | 11fe914549c46a3f28823bc0b7bfaa7d86239f0a (patch) | |
tree | 5dd07ed6014831b784ff1fe04bb8bfafb8c560d4 /clang/lib | |
parent | 6df7083be430bd40a5f46e7c14b7d5247cca0a8f (diff) | |
download | bcm5719-llvm-11fe914549c46a3f28823bc0b7bfaa7d86239f0a.tar.gz bcm5719-llvm-11fe914549c46a3f28823bc0b7bfaa7d86239f0a.zip |
ObjectiveC migration. Check-in patch reverted in r187634.
Also removed check for "NS" prefix for class name.
llvm-svn: 187655
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/ARCMigrate/ObjCMT.cpp | 81 | ||||
-rw-r--r-- | clang/lib/Basic/IdentifierTable.cpp | 8 |
2 files changed, 64 insertions, 25 deletions
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index 2b2f9224e99..f7a36e28471 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -41,6 +41,8 @@ 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; @@ -549,13 +551,34 @@ 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) + if (OIT_Family == OIT_None) { + migrateFactoryMethod(Ctx, CDecl, OM); return; + } std::string ClassName; switch (OIT_Family) { case OIT_Array: @@ -581,24 +604,11 @@ void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx, IDecl = ImpDecl->getClassInterface(); } if (!IDecl || - !IDecl->lookupInheritedClass(&Ctx.Idents.get(ClassName))) + !IDecl->lookupInheritedClass(&Ctx.Idents.get(ClassName))) { + migrateFactoryMethod(Ctx, CDecl, OM); 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)"; - } - edit::Commit commit(*Editor); - commit.replace(R, ClassString); - Editor->commit(commit); + ReplaceWithInstancetype(*this, OM); } void ObjCMigrateASTConsumer::migrateInstanceType(ASTContext &Ctx, @@ -612,6 +622,43 @@ 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; + + std::string StringClassName = IDecl->getName(); + StringRef LoweredClassName(StringClassName); + LoweredClassName = LoweredClassName.lower(); + IdentifierInfo *MethodIdName = OM->getSelector().getIdentifierInfoForSlot(0); + std::string MethodName = MethodIdName->getName(); + std::string MethodNameSubStr = MethodName.substr(0, 3); + StringRef MethodNamePrefix(MethodNameSubStr); + MethodNamePrefix = MethodNamePrefix.lower(); + size_t Ix = LoweredClassName.rfind(MethodNamePrefix); + if (Ix == StringRef::npos) + return; + std::string ClassNamePostfix = LoweredClassName.substr(Ix); + StringRef LoweredMethodName(MethodName); + LoweredMethodName = LoweredMethodName.lower(); + if (!LoweredMethodName.startswith(ClassNamePostfix)) + return; + ReplaceWithInstancetype(*this, OM); +} + namespace { class RewritesReceiver : public edit::EditsReceiver { diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index 96d9e56b6c3..3572930903f 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -474,14 +474,6 @@ ObjCInstanceTypeFamily Selector::getInstTypeMethodFamily(Selector sel) { case 'r': if (startsWithWord(name, "retain")) return OIT_MemManage; break; - case 's': - if (startsWithWord(name, "string")) return OIT_NSString; - else - if (startsWithWord(name, "set")) return OIT_NSSet; - break; - case 'U': - if (startsWithWord(name, "URL")) return OIT_NSURL; - break; default: break; } |