diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/ARCMigrate/ObjCMT.cpp | 32 | ||||
-rw-r--r-- | clang/lib/Basic/IdentifierTable.cpp | 6 |
2 files changed, 33 insertions, 5 deletions
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index a1d7a978426..21ba06cc2cf 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -696,6 +696,28 @@ static void ReplaceWithInstancetype(const ObjCMigrateASTConsumer &ASTC, ASTC.Editor->commit(commit); } +static void ReplaceWithClasstype(const ObjCMigrateASTConsumer &ASTC, + ObjCMethodDecl *OM) { + ObjCInterfaceDecl *IDecl = OM->getClassInterface(); + SourceRange R; + std::string ClassString; + if (TypeSourceInfo *TSInfo = OM->getResultTypeSourceInfo()) { + TypeLoc TL = TSInfo->getTypeLoc(); + R = SourceRange(TL.getBeginLoc(), TL.getEndLoc()); { + ClassString = IDecl->getName(); + ClassString += "*"; + } + } + else { + R = SourceRange(OM->getLocStart(), OM->getLocStart()); + ClassString = "+ ("; + ClassString += IDecl->getName(); ClassString += "*)"; + } + edit::Commit commit(*ASTC.Editor); + commit.replace(R, ClassString); + ASTC.Editor->commit(commit); +} + void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl, ObjCMethodDecl *OM) { @@ -720,6 +742,9 @@ void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx, if (OM->getResultType()->isObjCIdType()) ReplaceWithInstancetype(*this, OM); return; + case OIT_ReturnsSelf: + migrateFactoryMethod(Ctx, CDecl, OM, OIT_ReturnsSelf); + return; } if (!OM->getResultType()->isObjCIdType()) return; @@ -965,7 +990,7 @@ void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx, return; std::string MethodName = MethodIdName->getName(); - if (OIT_Family == OIT_Singleton) { + if (OIT_Family == OIT_Singleton || OIT_Family == OIT_ReturnsSelf) { StringRef STRefMethodName(MethodName); size_t len = 0; if (STRefMethodName.startswith("standard")) @@ -991,7 +1016,10 @@ void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx, LoweredMethodName = StringLoweredMethodName; if (!LoweredMethodName.startswith(ClassNamePostfix)) return; - ReplaceWithInstancetype(*this, OM); + if (OIT_Family == OIT_ReturnsSelf) + ReplaceWithClasstype(*this, OM); + else + ReplaceWithInstancetype(*this, OM); } static bool IsVoidStarType(QualType Ty) { diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index 2c70b9933a7..500e732eef3 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -464,12 +464,12 @@ ObjCInstanceTypeFamily Selector::getInstTypeMethodFamily(Selector sel) { if (startsWithWord(name, "array")) return OIT_Array; break; case 'd': + if (startsWithWord(name, "default")) return OIT_ReturnsSelf; if (startsWithWord(name, "dictionary")) return OIT_Dictionary; break; case 's': - if (startsWithWord(name, "shared") || - startsWithWord(name, "standard")) - return OIT_Singleton; + if (startsWithWord(name, "shared")) return OIT_ReturnsSelf; + if (startsWithWord(name, "standard")) return OIT_Singleton; case 'i': if (startsWithWord(name, "init")) return OIT_Init; default: |