ObjC migrator: Define family of methods

which are candidate for migrating to
'instancetype'. wip.

llvm-svn: 186981
This commit is contained in:
Fariborz Jahanian 2013-07-23 19:31:17 +00:00
parent b7243381c2
commit 4f3a64fd6e
2 changed files with 49 additions and 0 deletions

View File

@ -578,6 +578,20 @@ enum { ObjCMethodFamilyBitWidth = 4 };
/// \brief An invalid value of ObjCMethodFamily.
enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 };
/// \brief A family of Objective-C methods.
///
/// These are family of methods whose result type is initially 'id', but
/// but are candidate for the result type to be changed to 'instancetype'.
enum ObjCInstanceTypeFamily {
OIT_None,
OIT_Array,
OIT_Dictionary,
OIT_MemManage,
OIT_NSString,
OIT_NSSet,
OIT_NSURL
};
/// \brief Smart pointer class that efficiently represents Objective-C method
/// names.
///
@ -623,6 +637,8 @@ class Selector {
}
static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
static ObjCInstanceTypeFamily getInstTypeMethodFamilyImpl(Selector sel);
public:
friend class SelectorTable; // only the SelectorTable can create these

View File

@ -452,6 +452,39 @@ ObjCMethodFamily Selector::getMethodFamilyImpl(Selector sel) {
return OMF_None;
}
ObjCInstanceTypeFamily Selector::getInstTypeMethodFamilyImpl(Selector sel) {
IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
if (!first) return OIT_None;
StringRef name = first->getName();
if (name.empty()) return OIT_None;
switch (name.front()) {
case 'a':
if (startsWithWord(name, "alloc")) return OIT_MemManage;
else
if (startsWithWord(name, "array")) return OIT_Array;
break;
case 'd':
if (startsWithWord(name, "dictionary")) return OIT_Dictionary;
break;
case 'i':
if (startsWithWord(name, "init")) return OIT_MemManage;
break;
case 's':
if (startsWithWord(name, "string")) return OIT_NSString;
else
if (startsWithWord(name, "set")) return OIT_NSSet;
break;
case 'U':
if (startsWithWord(name, "URL")) return OIT_NSURL;
break;
default:
break;
}
return OIT_None;
}
namespace {
struct SelectorTableImpl {
llvm::FoldingSet<MultiKeywordSelector> Table;