diff options
author | John McCall <rjmccall@apple.com> | 2011-03-02 01:50:55 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-03-02 01:50:55 +0000 |
commit | 85f3d76c0ecfdefcf83ea44a57b7a16119c8a045 (patch) | |
tree | 17c4f0f29745d2882c474b044579594bf16a9002 /lib/Basic | |
parent | fa0b409ef81f1f70edfa72857c4e211ff50998d5 (diff) |
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
Diffstat (limited to 'lib/Basic')
-rw-r--r-- | lib/Basic/IdentifierTable.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/Basic/IdentifierTable.cpp b/lib/Basic/IdentifierTable.cpp index ef11d658ed..7647f0776d 100644 --- a/lib/Basic/IdentifierTable.cpp +++ b/lib/Basic/IdentifierTable.cpp @@ -364,6 +364,56 @@ std::string Selector::getAsString() const { 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 { |