summaryrefslogtreecommitdiffstats
path: root/clang/lib/ARCMigrate
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-10-10 18:23:13 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-10-10 18:23:13 +0000
commit7c87b43d28f134f3902261786a62f309e99538c4 (patch)
tree078ef02f6d3a055f281ceb8b17aceb1efb5e91ed /clang/lib/ARCMigrate
parent9b971f95909034bb380b131996650c5235685100 (diff)
downloadbcm5719-llvm-7c87b43d28f134f3902261786a62f309e99538c4.tar.gz
bcm5719-llvm-7c87b43d28f134f3902261786a62f309e99538c4.zip
ObjectiveC migrator: For 'default' and 'shared' family of
methods, infer their self's type as their result type. // rdar://15145218 llvm-svn: 192377
Diffstat (limited to 'clang/lib/ARCMigrate')
-rw-r--r--clang/lib/ARCMigrate/ObjCMT.cpp32
1 files changed, 30 insertions, 2 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) {
OpenPOWER on IntegriCloud