diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-07-16 19:50:36 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-07-16 19:50:36 +0000 |
commit | 797a7be0de6fbedaa85082b07ec9ce0674f30773 (patch) | |
tree | 09ef0b72ffa54e2f81d990eaaa2b7bdacb0ddb1d /lib/Analysis/CocoaConventions.cpp | |
parent | 0556048ae8ff743d0abb9fa88a0d0ee8e9123742 (diff) |
[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>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135350 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/CocoaConventions.cpp')
-rw-r--r-- | lib/Analysis/CocoaConventions.cpp | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/lib/Analysis/CocoaConventions.cpp b/lib/Analysis/CocoaConventions.cpp index 428032bee5..90f7092f90 100644 --- a/lib/Analysis/CocoaConventions.cpp +++ b/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; } |