Move some of the logic about classifying Objective-C methods into
conventional categories into Basic and AST.  Update the self-init checker
to use this logic;  CFRefCountChecker is complicated enough that I didn't
want to touch it.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126817 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/IdentifierTable.cpp b/lib/Basic/IdentifierTable.cpp
index ef11d65..7647f07 100644
--- a/lib/Basic/IdentifierTable.cpp
+++ b/lib/Basic/IdentifierTable.cpp
@@ -364,6 +364,56 @@
   return reinterpret_cast<MultiKeywordSelector *>(InfoPtr)->getName();
 }
 
+/// Interpreting the given string using the normal CamelCase
+/// conventions, determine whether the given string starts with the
+/// given "word", which is assumed to end in a lowercase letter.
+static bool startsWithWord(llvm::StringRef name, llvm::StringRef word) {
+  if (name.size() < word.size()) return false;
+  return ((name.size() == word.size() ||
+           !islower(name[word.size()]))
+          && name.startswith(word));
+}
+
+ObjCMethodFamily Selector::getMethodFamilyImpl(Selector sel) {
+  IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
+  if (!first) return OMF_None;
+
+  llvm::StringRef name = first->getName();
+  if (sel.isUnarySelector()) {
+    if (name == "autorelease") return OMF_autorelease;
+    if (name == "dealloc") return OMF_dealloc;
+    if (name == "release") return OMF_release;
+    if (name == "retain") return OMF_retain;
+    if (name == "retainCount") return OMF_retainCount;
+  }
+
+  // The other method families may begin with a prefix of underscores.
+  while (!name.empty() && name.front() == '_')
+    name = name.substr(1);
+
+  if (name.empty()) return OMF_None;
+  switch (name.front()) {
+  case 'a':
+    if (startsWithWord(name, "alloc")) return OMF_alloc;
+    break;
+  case 'c':
+    if (startsWithWord(name, "copy")) return OMF_copy;
+    break;
+  case 'i':
+    if (startsWithWord(name, "init")) return OMF_init;
+    break;
+  case 'm':
+    if (startsWithWord(name, "mutableCopy")) return OMF_mutableCopy;
+    break;
+  case 'n':
+    if (startsWithWord(name, "new")) return OMF_new;
+    break;
+  default:
+    break;
+  }
+
+  return OMF_None;
+}
 
 namespace {
   struct SelectorTableImpl {