forked from OSchip/llvm-project
ObjC migrator: Define family of methods
which are candidate for migrating to 'instancetype'. wip. llvm-svn: 186981
This commit is contained in:
parent
b7243381c2
commit
4f3a64fd6e
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue