ObjC migrator: Define family of methods
which are candidate for migrating to
'instancetype'. wip.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186981 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/IdentifierTable.h b/include/clang/Basic/IdentifierTable.h
index a195fc3..86f9d9b 100644
--- a/include/clang/Basic/IdentifierTable.h
+++ b/include/clang/Basic/IdentifierTable.h
@@ -578,6 +578,20 @@
 /// \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 @@
   }
 
   static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
+  
+  static ObjCInstanceTypeFamily getInstTypeMethodFamilyImpl(Selector sel);
 
 public:
   friend class SelectorTable; // only the SelectorTable can create these
diff --git a/lib/Basic/IdentifierTable.cpp b/lib/Basic/IdentifierTable.cpp
index b8ba4ba..faff4d8 100644
--- a/lib/Basic/IdentifierTable.cpp
+++ b/lib/Basic/IdentifierTable.cpp
@@ -452,6 +452,39 @@
   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;