summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-12-17 04:44:43 +0000
committerTed Kremenek <kremenek@apple.com>2010-12-17 04:44:43 +0000
commitedb1cdff77a4ee34dc1abe9d1b5b125d74dc4b2a (patch)
treeaf72b70e566215ebbf2f40dac6e890cadb73eba5 /clang/lib
parent3a9a2a551c1593e3aeaf2b8a4c25a6b2faca7138 (diff)
downloadbcm5719-llvm-edb1cdff77a4ee34dc1abe9d1b5b125d74dc4b2a.tar.gz
bcm5719-llvm-edb1cdff77a4ee34dc1abe9d1b5b125d74dc4b2a.zip
Revise Cocoa conventions detection: 'copy' and 'mutableCopy'
only indicates the create rule if it starts at the beginning of the method name, not within the method name. llvm-svn: 122036
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Checker/CocoaConventions.cpp84
1 files changed, 30 insertions, 54 deletions
diff --git a/clang/lib/Checker/CocoaConventions.cpp b/clang/lib/Checker/CocoaConventions.cpp
index b446a048d48..8a3abc8bae7 100644
--- a/clang/lib/Checker/CocoaConventions.cpp
+++ b/clang/lib/Checker/CocoaConventions.cpp
@@ -63,72 +63,48 @@ cocoa::NamingConvention cocoa::deriveNamingConvention(Selector S) {
// A method/function name may contain a prefix. We don't know it is there,
// however, until we encounter the first '_'.
- bool InPossiblePrefix = true;
- bool AtBeginning = true;
- NamingConvention C = NoConvention;
-
while (*s != '\0') {
- // Skip '_'.
- if (*s == '_') {
- if (InPossiblePrefix) {
- // If we already have a convention, return it. Otherwise, skip
- // the prefix as if it wasn't there.
- if (C != NoConvention)
- break;
-
- InPossiblePrefix = false;
- AtBeginning = true;
- assert(C == NoConvention);
- }
- ++s;
- continue;
- }
-
- // Skip numbers, ':', etc.
- if (!isalpha(*s)) {
+ // Skip '_', numbers, ':', etc.
+ if (*s == '_' || !isalpha(*s)) {
++s;
continue;
}
+ break;
+ }
- const char *wordEnd = parseWord(s);
- assert(wordEnd > s);
- unsigned len = wordEnd - s;
+ // Parse the first word, and look for specific keywords.
+ const char *wordEnd = parseWord(s);
+ assert(wordEnd > s);
+ unsigned len = wordEnd - s;
- switch (len) {
+ switch (len) {
default:
- break;
+ return NoConvention;
case 3:
// Methods starting with 'new' follow the create rule.
- if (AtBeginning && StringRef(s, len).equals_lower("new"))
- C = CreateRule;
- break;
+ return (memcmp(s, "new", 3) == 0) ? CreateRule : NoConvention;
case 4:
- // Methods starting with 'alloc' or contain 'copy' follow the
- // create rule
- if (C == NoConvention && StringRef(s, len).equals_lower("copy"))
- C = CreateRule;
- else // Methods starting with 'init' follow the init rule.
- if (AtBeginning && StringRef(s, len).equals_lower("init"))
- C = InitRule;
- break;
+ // Methods starting with 'copy' follow the create rule.
+ if (memcmp(s, "copy", 4) == 0)
+ return CreateRule;
+ // Methods starting with 'init' follow the init rule.
+ if (memcmp(s, "init", 4) == 0)
+ return InitRule;
+ return NoConvention;
case 5:
- if (AtBeginning && StringRef(s, len).equals_lower("alloc"))
- C = CreateRule;
- break;
- }
-
- // If we aren't in the prefix and have a derived convention then just
- // return it now.
- if (!InPossiblePrefix && C != NoConvention)
- return C;
-
- AtBeginning = false;
- s = wordEnd;
+ return (memcmp(s, "alloc", 5) == 0) ? CreateRule : NoConvention;
+ case 7:
+ // Methods starting with 'mutableCopy' follow the create rule.
+ if (memcmp(s, "mutable", 7) == 0) {
+ // Look at the next word to see if it is "Copy".
+ s = wordEnd;
+ wordEnd = parseWord(s);
+ len = wordEnd - s;
+ if (len == 4 && memcmp(s, "Copy", 4) == 0)
+ return CreateRule;
+ }
+ return NoConvention;
}
-
- // We will get here if there wasn't more than one word
- // after the prefix.
- return C;
}
bool cocoa::isRefType(QualType RetTy, llvm::StringRef Prefix,
OpenPOWER on IntegriCloud