summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-07-16 19:50:36 +0000
committerTed Kremenek <kremenek@apple.com>2011-07-16 19:50:36 +0000
commit6dcbbe85479269c867b6e64690fd649457de27d7 (patch)
tree381eb62f7747d460f16b2365fdcd3cf4eab9817a /clang/lib/Analysis
parentc85964ed90bc18b6b605405d8d9e4a6668badec7 (diff)
downloadbcm5719-llvm-6dcbbe85479269c867b6e64690fd649457de27d7.tar.gz
bcm5719-llvm-6dcbbe85479269c867b6e64690fd649457de27d7.zip
[analyzer] Per discussions with the Cocoa team, extend CF naming conventions to extend to camel case functions instead of just title case functions. Fixes <rdar://problem/9732321>.
llvm-svn: 135350
Diffstat (limited to 'clang/lib/Analysis')
-rw-r--r--clang/lib/Analysis/CocoaConventions.cpp43
1 files changed, 41 insertions, 2 deletions
diff --git a/clang/lib/Analysis/CocoaConventions.cpp b/clang/lib/Analysis/CocoaConventions.cpp
index 428032bee54..90f7092f90e 100644
--- a/clang/lib/Analysis/CocoaConventions.cpp
+++ b/clang/lib/Analysis/CocoaConventions.cpp
@@ -128,6 +128,45 @@ bool cocoa::isCocoaObjectRef(QualType Ty) {
}
bool coreFoundation::followsCreateRule(llvm::StringRef functionName) {
- return functionName.find("Create") != StringRef::npos ||
- functionName.find("Copy") != StringRef::npos;
+ llvm::StringRef::iterator it = functionName.begin();
+ llvm::StringRef::iterator start = it;
+ llvm::StringRef::iterator endI = functionName.end();
+
+ while (true) {
+ // Scan for the start of 'create' or 'copy'.
+ for ( ; it != endI ; ++it) {
+ // Search for the first character. It can either be 'C' or 'c'.
+ char ch = *it;
+ if (ch == 'C' || ch == 'c') {
+ ++it;
+ break;
+ }
+ }
+
+ // Did we hit the end of the string? If so, we didn't find a match.
+ if (it == endI)
+ return false;
+
+ // Scan for *lowercase* 'reate' or 'opy', followed by no lowercase
+ // character.
+ llvm::StringRef suffix = functionName.substr(it - start);
+ if (suffix.startswith("reate")) {
+ it += 5;
+ }
+ else if (suffix.startswith("opy")) {
+ it += 3;
+ }
+ else {
+ // Keep scanning.
+ continue;
+ }
+
+ if (it == endI || !islower(*it))
+ return true;
+
+ // If we matched a lowercase character, it isn't the end of the
+ // word. Keep scanning.
+ }
+
+ return false;
}
OpenPOWER on IntegriCloud