summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-08-02 20:54:18 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-08-02 20:54:18 +0000
commit9275c688ea050b0a2be88cf8b1b038051e7c9085 (patch)
treee1f677381195326f62a1e9eb64ad7d5000ae1898
parentfcf67781726d052158bacdbb13e271be5c8c5a94 (diff)
downloadbcm5719-llvm-9275c688ea050b0a2be88cf8b1b038051e7c9085.tar.gz
bcm5719-llvm-9275c688ea050b0a2be88cf8b1b038051e7c9085.zip
ObjectiveC migrator: Add another family of factory
methods which can be migrated to instancetype. llvm-svn: 187672
-rw-r--r--clang/include/clang/Basic/IdentifierTable.h3
-rw-r--r--clang/lib/ARCMigrate/ObjCMT.cpp30
-rw-r--r--clang/lib/Basic/IdentifierTable.cpp5
-rw-r--r--clang/test/ARCMT/objcmt-instancetype-2.m11
-rw-r--r--clang/test/ARCMT/objcmt-instancetype-2.m.result11
5 files changed, 52 insertions, 8 deletions
diff --git a/clang/include/clang/Basic/IdentifierTable.h b/clang/include/clang/Basic/IdentifierTable.h
index 0bc13e6555f..4a54728dff2 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -586,7 +586,8 @@ enum ObjCInstanceTypeFamily {
OIT_None,
OIT_Array,
OIT_Dictionary,
- OIT_MemManage
+ OIT_MemManage,
+ OIT_Singleton
};
/// \brief Smart pointer class that efficiently represents Objective-C method
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp
index bd1f57f9f8a..706a4ec1065 100644
--- a/clang/lib/ARCMigrate/ObjCMT.cpp
+++ b/clang/lib/ARCMigrate/ObjCMT.cpp
@@ -42,7 +42,8 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
void migrateMethodInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl,
ObjCMethodDecl *OM);
void migrateFactoryMethod(ASTContext &Ctx, ObjCContainerDecl *CDecl,
- ObjCMethodDecl *OM);
+ ObjCMethodDecl *OM,
+ ObjCInstanceTypeFamily OIT_Family = OIT_None);
public:
std::string MigrateDir;
@@ -575,12 +576,12 @@ void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx,
ObjCMethodDecl *OM) {
ObjCInstanceTypeFamily OIT_Family =
Selector::getInstTypeMethodFamily(OM->getSelector());
- if (OIT_Family == OIT_None) {
- migrateFactoryMethod(Ctx, CDecl, OM);
- return;
- }
+
std::string ClassName;
switch (OIT_Family) {
+ case OIT_None:
+ migrateFactoryMethod(Ctx, CDecl, OM);
+ return;
case OIT_Array:
ClassName = "NSArray";
break;
@@ -590,7 +591,8 @@ void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx,
case OIT_MemManage:
ClassName = "NSObject";
break;
- default:
+ case OIT_Singleton:
+ migrateFactoryMethod(Ctx, CDecl, OM, OIT_Singleton);
return;
}
if (!OM->getResultType()->isObjCIdType())
@@ -624,7 +626,8 @@ void ObjCMigrateASTConsumer::migrateInstanceType(ASTContext &Ctx,
void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx,
ObjCContainerDecl *CDecl,
- ObjCMethodDecl *OM) {
+ ObjCMethodDecl *OM,
+ ObjCInstanceTypeFamily OIT_Family) {
if (OM->isInstanceMethod() || !OM->getResultType()->isObjCIdType())
return;
@@ -647,6 +650,19 @@ void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx,
IdentifierInfo *MethodIdName = OM->getSelector().getIdentifierInfoForSlot(0);
std::string MethodName = MethodIdName->getName();
+ if (OIT_Family == OIT_Singleton) {
+ StringRef STRefMethodName(MethodName);
+ size_t len = 0;
+ if (STRefMethodName.startswith("standard"))
+ len = strlen("standard");
+ else if (STRefMethodName.startswith("shared"))
+ len = strlen("shared");
+ else if (STRefMethodName.startswith("default"))
+ len = strlen("default");
+ else
+ return;
+ MethodName = STRefMethodName.substr(len);
+ }
std::string MethodNameSubStr = MethodName.substr(0, 3);
StringRef MethodNamePrefix(MethodNameSubStr);
std::string StringLoweredMethodNamePrefix = MethodNamePrefix.lower();
diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp
index 3572930903f..b1a22eea7ec 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -467,6 +467,7 @@ ObjCInstanceTypeFamily Selector::getInstTypeMethodFamily(Selector sel) {
break;
case 'd':
if (startsWithWord(name, "dictionary")) return OIT_Dictionary;
+ if (startsWithWord(name, "default")) return OIT_Singleton;
break;
case 'i':
if (startsWithWord(name, "init")) return OIT_MemManage;
@@ -474,6 +475,10 @@ ObjCInstanceTypeFamily Selector::getInstTypeMethodFamily(Selector sel) {
case 'r':
if (startsWithWord(name, "retain")) return OIT_MemManage;
break;
+ case 's':
+ if (startsWithWord(name, "shared") ||
+ startsWithWord(name, "standard"))
+ return OIT_Singleton;
default:
break;
}
diff --git a/clang/test/ARCMT/objcmt-instancetype-2.m b/clang/test/ARCMT/objcmt-instancetype-2.m
index aff99984dc5..325f2217a75 100644
--- a/clang/test/ARCMT/objcmt-instancetype-2.m
+++ b/clang/test/ARCMT/objcmt-instancetype-2.m
@@ -74,3 +74,14 @@ typedef enum NSURLBookmarkResolutionOptions {
+ (id)dateWithYear:(NSInteger)year month:(NSUInteger)month day:(NSUInteger)day hour:(NSUInteger)hour minute:(NSUInteger)minute second:(NSUInteger)second timeZone:(NSTimeZone *)aTimeZone __attribute__((availability(macosx,introduced=10.4)));
@end
+@interface NSUserDefaults
++ (id) standardUserDefaults;
+@end
+
+@interface NSNotificationCenter
++ (id) defaultCenter;
+@end
+
+@interface UIApplication
++ (id)sharedApplication;
+@end
diff --git a/clang/test/ARCMT/objcmt-instancetype-2.m.result b/clang/test/ARCMT/objcmt-instancetype-2.m.result
index ba664806539..7077f454896 100644
--- a/clang/test/ARCMT/objcmt-instancetype-2.m.result
+++ b/clang/test/ARCMT/objcmt-instancetype-2.m.result
@@ -74,3 +74,14 @@ typedef enum NSURLBookmarkResolutionOptions {
+ (instancetype)dateWithYear:(NSInteger)year month:(NSUInteger)month day:(NSUInteger)day hour:(NSUInteger)hour minute:(NSUInteger)minute second:(NSUInteger)second timeZone:(NSTimeZone *)aTimeZone __attribute__((availability(macosx,introduced=10.4)));
@end
+@interface NSUserDefaults
++ (instancetype) standardUserDefaults;
+@end
+
+@interface NSNotificationCenter
++ (instancetype) defaultCenter;
+@end
+
+@interface UIApplication
++ (instancetype)sharedApplication;
+@end
OpenPOWER on IntegriCloud