r192377 - ObjectiveC migrator: For 'default' and 'shared' family of
Fariborz Jahanian
fjahanian at apple.com
Thu Oct 10 11:23:13 PDT 2013
Author: fjahanian
Date: Thu Oct 10 13:23:13 2013
New Revision: 192377
URL: http://llvm.org/viewvc/llvm-project?rev=192377&view=rev
Log:
ObjectiveC migrator: For 'default' and 'shared' family of
methods, infer their self's type as their result type.
// rdar://15145218
Modified:
cfe/trunk/include/clang/Basic/IdentifierTable.h
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/lib/Basic/IdentifierTable.cpp
cfe/trunk/test/ARCMT/objcmt-instancetype-2.m
cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result
Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=192377&r1=192376&r2=192377&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Basic/IdentifierTable.h Thu Oct 10 13:23:13 2013
@@ -587,7 +587,8 @@ enum ObjCInstanceTypeFamily {
OIT_Array,
OIT_Dictionary,
OIT_Singleton,
- OIT_Init
+ OIT_Init,
+ OIT_ReturnsSelf
};
/// \brief Smart pointer class that efficiently represents Objective-C method
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=192377&r1=192376&r2=192377&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Thu Oct 10 13:23:13 2013
@@ -696,6 +696,28 @@ static void ReplaceWithInstancetype(cons
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::migrateMeth
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::migrateFact
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::migrateFact
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) {
Modified: cfe/trunk/lib/Basic/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/IdentifierTable.cpp?rev=192377&r1=192376&r2=192377&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/IdentifierTable.cpp (original)
+++ cfe/trunk/lib/Basic/IdentifierTable.cpp Thu Oct 10 13:23:13 2013
@@ -464,12 +464,12 @@ ObjCInstanceTypeFamily Selector::getInst
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:
Modified: cfe/trunk/test/ARCMT/objcmt-instancetype-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-instancetype-2.m?rev=192377&r1=192376&r2=192377&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-instancetype-2.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-instancetype-2.m Thu Oct 10 13:23:13 2013
@@ -80,10 +80,12 @@ typedef enum NSURLBookmarkResolutionOpti
@interface NSNotificationCenter
+ (id) defaultCenter;
++ sharedCenter;
@end
@interface UIApplication
+ (id)sharedApplication;
++ defaultApplication;
@end
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result?rev=192377&r1=192376&r2=192377&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result Thu Oct 10 13:23:13 2013
@@ -79,11 +79,13 @@ typedef enum NSURLBookmarkResolutionOpti
@end
@interface NSNotificationCenter
-+ (id) defaultCenter;
++ (NSNotificationCenter*) defaultCenter;
++ (NSNotificationCenter*) sharedCenter;
@end
@interface UIApplication
-+ (instancetype)sharedApplication;
++ (UIApplication*)sharedApplication;
++ (UIApplication*) defaultApplication;
@end
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list