[analyzer] Add 'bool ignorePrefix' parameter to cocoa::deriveNamingConvention to control whether
the prefix should be ignored.
E.g. if ignorePrefix is true, "_init" and "init" selectors will both be result in InitRule, but if
ignorePrefix is false, only "init" will return InitRule.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123262 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/CocoaConventions.cpp b/lib/Analysis/CocoaConventions.cpp
index 2c263ca..4226525 100644
--- a/lib/Analysis/CocoaConventions.cpp
+++ b/lib/Analysis/CocoaConventions.cpp
@@ -54,7 +54,8 @@
return s;
}
-cocoa::NamingConvention cocoa::deriveNamingConvention(Selector S) {
+cocoa::NamingConvention cocoa::deriveNamingConvention(Selector S,
+ bool ignorePrefix) {
IdentifierInfo *II = S.getIdentifierInfoForSlot(0);
if (!II)
@@ -62,6 +63,7 @@
const char *s = II->getNameStart();
+ const char *orig = s;
// A method/function name may contain a prefix. We don't know it is there,
// however, until we encounter the first '_'.
while (*s != '\0') {
@@ -73,6 +75,9 @@
break;
}
+ if (!ignorePrefix && s != orig)
+ return NoConvention;
+
// Parse the first word, and look for specific keywords.
const char *wordEnd = parseWord(s);
assert(wordEnd > s);