r187672 - ObjectiveC migrator: Add another family of factory
Fariborz Jahanian
fjahanian at apple.com
Fri Aug 2 13:54:19 PDT 2013
Author: fjahanian
Date: Fri Aug 2 15:54:18 2013
New Revision: 187672
URL: http://llvm.org/viewvc/llvm-project?rev=187672&view=rev
Log:
ObjectiveC migrator: Add another family of factory
methods which can be migrated to instancetype.
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=187672&r1=187671&r2=187672&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Basic/IdentifierTable.h Fri Aug 2 15:54:18 2013
@@ -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
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=187672&r1=187671&r2=187672&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Fri Aug 2 15:54:18 2013
@@ -42,7 +42,8 @@ class ObjCMigrateASTConsumer : public AS
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::migrateMeth
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::migrateMeth
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::migrateInst
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::migrateFact
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();
Modified: cfe/trunk/lib/Basic/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/IdentifierTable.cpp?rev=187672&r1=187671&r2=187672&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/IdentifierTable.cpp (original)
+++ cfe/trunk/lib/Basic/IdentifierTable.cpp Fri Aug 2 15:54:18 2013
@@ -467,6 +467,7 @@ ObjCInstanceTypeFamily Selector::getInst
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::getInst
case 'r':
if (startsWithWord(name, "retain")) return OIT_MemManage;
break;
+ case 's':
+ if (startsWithWord(name, "shared") ||
+ startsWithWord(name, "standard"))
+ return OIT_Singleton;
default:
break;
}
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=187672&r1=187671&r2=187672&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-instancetype-2.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-instancetype-2.m Fri Aug 2 15:54:18 2013
@@ -74,3 +74,14 @@ typedef enum NSURLBookmarkResolutionOpti
+ (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
+ at interface NSUserDefaults
++ (id) standardUserDefaults;
+ at end
+
+ at interface NSNotificationCenter
++ (id) defaultCenter;
+ at end
+
+ at interface UIApplication
++ (id)sharedApplication;
+ at 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=187672&r1=187671&r2=187672&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result Fri Aug 2 15:54:18 2013
@@ -74,3 +74,14 @@ typedef enum NSURLBookmarkResolutionOpti
+ (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
+ at interface NSUserDefaults
++ (instancetype) standardUserDefaults;
+ at end
+
+ at interface NSNotificationCenter
++ (instancetype) defaultCenter;
+ at end
+
+ at interface UIApplication
++ (instancetype)sharedApplication;
+ at end
More information about the cfe-commits
mailing list