#ifndef LLVM_CLANG_ANALYSIS_DS_COCOA
#define LLVM_CLANG_ANALYSIS_DS_COCOA
+#include "llvm/ADT/StringRef.h"
#include "clang/AST/Type.h"
namespace clang {
bool isRefType(QualType RetTy, llvm::StringRef Prefix,
llvm::StringRef Name = llvm::StringRef());
-
+
+ bool isCocoaObjectRef(QualType T);
+
+}
+
+namespace coreFoundation {
bool isCFObjectRef(QualType T);
- bool isCocoaObjectRef(QualType T);
+ bool followsCreateRule(llvm::StringRef functionName);
+}
-}}}
+}} // end: "clang:ento"
#endif
return Name.startswith(Prefix);
}
-bool cocoa::isCFObjectRef(QualType T) {
- return isRefType(T, "CF") || // Core Foundation.
- isRefType(T, "CG") || // Core Graphics.
- isRefType(T, "DADisk") || // Disk Arbitration API.
- isRefType(T, "DADissenter") ||
- isRefType(T, "DASessionRef");
+bool coreFoundation::isCFObjectRef(QualType T) {
+ return cocoa::isRefType(T, "CF") || // Core Foundation.
+ cocoa::isRefType(T, "CG") || // Core Graphics.
+ cocoa::isRefType(T, "DADisk") || // Disk Arbitration API.
+ cocoa::isRefType(T, "DADissenter") ||
+ cocoa::isRefType(T, "DASessionRef");
}
return false;
}
+
+bool coreFoundation::followsCreateRule(llvm::StringRef functionName) {
+ return functionName.find("Create") != StringRef::npos ||
+ functionName.find("Copy") != StringRef::npos;
+}
continue;
// Ignore CF references, which can be toll-free bridged.
- if (cocoa::isCFObjectRef(ArgTy))
+ if (coreFoundation::isCFObjectRef(ArgTy))
continue;
// Generate only one error node to use for all bug reports.
RetainSummary*
RetainSummaryManager::getCFCreateGetRuleSummary(const FunctionDecl* FD,
StringRef FName) {
- if (FName.find("Create") != StringRef::npos ||
- FName.find("Copy") != StringRef::npos)
+ if (coreFoundation::followsCreateRule(FName))
return getCFSummaryCreateRule(FD);
return getCFSummaryGetRule(FD);
assert(ScratchArgs.isEmpty());
// 'init' methods conceptually return a newly allocated object and claim
// the receiver.
- if (cocoa::isCocoaObjectRef(RetTy) || cocoa::isCFObjectRef(RetTy))
+ if (cocoa::isCocoaObjectRef(RetTy) ||
+ coreFoundation::isCFObjectRef(RetTy))
return getPersistentSummary(ObjCInitRetE, DecRefMsg);
return getDefaultSummary();
}
// Look for methods that return an owned core foundation object.
- if (cocoa::isCFObjectRef(RetTy)) {
+ if (coreFoundation::isCFObjectRef(RetTy)) {
RetEffect E = cocoa::followsFundamentalRule(S, MD)
? RetEffect::MakeOwned(RetEffect::CF, true)
: RetEffect::MakeNotOwned(RetEffect::CF);