[cfe-commits] r122040 - in /cfe/trunk: include/clang/Analysis/DomainSpecific/ include/clang/Analysis/DomainSpecific/CocoaConventions.h include/clang/Checker/DomainSpecific/CocoaConventions.h lib/Analysis/CMakeLists.txt lib/Analysis/CocoaConventions.cpp lib/Checker/CFRefCount.cpp lib/Checker/CMakeLists.txt lib/Checker/CocoaConventions.cpp
Ted Kremenek
kremenek at apple.com
Thu Dec 16 21:21:58 PST 2010
Author: kremenek
Date: Thu Dec 16 23:21:58 2010
New Revision: 122040
URL: http://llvm.org/viewvc/llvm-project?rev=122040&view=rev
Log:
Move CocoaConventions.[h,cpp] from libChecker
to libAnalysis. Similar to Format (format string checking),
CocoaConventions has the
potential to serve clients other than the
static analyzer.
Added:
cfe/trunk/include/clang/Analysis/DomainSpecific/
cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h
- copied, changed from r122036, cfe/trunk/include/clang/Checker/DomainSpecific/CocoaConventions.h
cfe/trunk/lib/Analysis/CocoaConventions.cpp
- copied, changed from r122036, cfe/trunk/lib/Checker/CocoaConventions.cpp
Removed:
cfe/trunk/include/clang/Checker/DomainSpecific/CocoaConventions.h
cfe/trunk/lib/Checker/CocoaConventions.cpp
Modified:
cfe/trunk/lib/Analysis/CMakeLists.txt
cfe/trunk/lib/Checker/CFRefCount.cpp
cfe/trunk/lib/Checker/CMakeLists.txt
Copied: cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h (from r122036, cfe/trunk/include/clang/Checker/DomainSpecific/CocoaConventions.h)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h?p2=cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h&p1=cfe/trunk/include/clang/Checker/DomainSpecific/CocoaConventions.h&r1=122036&r2=122040&rev=122040&view=diff
==============================================================================
--- cfe/trunk/include/clang/Checker/DomainSpecific/CocoaConventions.h (original)
+++ cfe/trunk/include/clang/Analysis/DomainSpecific/CocoaConventions.h Thu Dec 16 23:21:58 2010
@@ -11,8 +11,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_CHECKER_DS_COCOA
-#define LLVM_CLANG_CHECKER_DS_COCOA
+#ifndef LLVM_CLANG_ANALYSIS_DS_COCOA
+#define LLVM_CLANG_ANALYSIS_DS_COCOA
#include "clang/AST/Type.h"
Removed: cfe/trunk/include/clang/Checker/DomainSpecific/CocoaConventions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Checker/DomainSpecific/CocoaConventions.h?rev=122039&view=auto
==============================================================================
--- cfe/trunk/include/clang/Checker/DomainSpecific/CocoaConventions.h (original)
+++ cfe/trunk/include/clang/Checker/DomainSpecific/CocoaConventions.h (removed)
@@ -1,39 +0,0 @@
-//===- CocoaConventions.h - Special handling of Cocoa conventions -*- C++ -*--//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_CHECKER_DS_COCOA
-#define LLVM_CLANG_CHECKER_DS_COCOA
-
-#include "clang/AST/Type.h"
-
-namespace clang {
-namespace cocoa {
-
- enum NamingConvention { NoConvention, CreateRule, InitRule };
-
- NamingConvention deriveNamingConvention(Selector S);
-
- static inline bool followsFundamentalRule(Selector S) {
- return deriveNamingConvention(S) == CreateRule;
- }
-
- bool isRefType(QualType RetTy, llvm::StringRef Prefix,
- llvm::StringRef Name = llvm::StringRef());
-
- bool isCFObjectRef(QualType T);
-
- bool isCocoaObjectRef(QualType T);
-
-}}
-
-#endif
Modified: cfe/trunk/lib/Analysis/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CMakeLists.txt?rev=122040&r1=122039&r2=122040&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CMakeLists.txt (original)
+++ cfe/trunk/lib/Analysis/CMakeLists.txt Thu Dec 16 23:21:58 2010
@@ -6,6 +6,7 @@
AnalysisContext.cpp
CFG.cpp
CFGStmtMap.cpp
+ CocoaConventions.cpp
FormatString.cpp
LiveVariables.cpp
PrintfFormatString.cpp
Copied: cfe/trunk/lib/Analysis/CocoaConventions.cpp (from r122036, cfe/trunk/lib/Checker/CocoaConventions.cpp)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CocoaConventions.cpp?p2=cfe/trunk/lib/Analysis/CocoaConventions.cpp&p1=cfe/trunk/lib/Checker/CocoaConventions.cpp&r1=122036&r2=122040&rev=122040&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/CocoaConventions.cpp (original)
+++ cfe/trunk/lib/Analysis/CocoaConventions.cpp Thu Dec 16 23:21:58 2010
@@ -11,7 +11,7 @@
//
//===----------------------------------------------------------------------===//
-#include "clang/Checker/DomainSpecific/CocoaConventions.h"
+#include "clang/Analysis/DomainSpecific/CocoaConventions.h"
#include "clang/AST/Type.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
Modified: cfe/trunk/lib/Checker/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/CFRefCount.cpp?rev=122040&r1=122039&r2=122040&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Checker/CFRefCount.cpp Thu Dec 16 23:21:58 2010
@@ -19,7 +19,7 @@
#include "clang/Checker/BugReporter/BugType.h"
#include "clang/Checker/BugReporter/PathDiagnostic.h"
#include "clang/Checker/Checkers/LocalCheckers.h"
-#include "clang/Checker/DomainSpecific/CocoaConventions.h"
+#include "clang/Analysis/DomainSpecific/CocoaConventions.h"
#include "clang/Checker/PathSensitive/CheckerVisitor.h"
#include "clang/Checker/PathSensitive/GRExprEngineBuilders.h"
#include "clang/Checker/PathSensitive/GRStateTrait.h"
Modified: cfe/trunk/lib/Checker/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/CMakeLists.txt?rev=122040&r1=122039&r2=122040&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/CMakeLists.txt (original)
+++ cfe/trunk/lib/Checker/CMakeLists.txt Thu Dec 16 23:21:58 2010
@@ -30,7 +30,6 @@
Checker.cpp
CheckerHelpers.cpp
ChrootChecker.cpp
- CocoaConventions.cpp
DereferenceChecker.cpp
DivZeroChecker.cpp
Environment.cpp
Removed: cfe/trunk/lib/Checker/CocoaConventions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/CocoaConventions.cpp?rev=122039&view=auto
==============================================================================
--- cfe/trunk/lib/Checker/CocoaConventions.cpp (original)
+++ cfe/trunk/lib/Checker/CocoaConventions.cpp (removed)
@@ -1,172 +0,0 @@
-//===- CocoaConventions.h - Special handling of Cocoa conventions -*- C++ -*--//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Checker/DomainSpecific/CocoaConventions.h"
-#include "clang/AST/Type.h"
-#include "clang/AST/Decl.h"
-#include "clang/AST/DeclObjC.h"
-#include "llvm/ADT/StringExtras.h"
-
-using namespace clang;
-
-using llvm::StringRef;
-
-// The "fundamental rule" for naming conventions of methods:
-// (url broken into two lines)
-// http://developer.apple.com/documentation/Cocoa/Conceptual/
-// MemoryMgmt/Tasks/MemoryManagementRules.html
-//
-// "You take ownership of an object if you create it using a method whose name
-// begins with "alloc" or "new" or contains "copy" (for example, alloc,
-// newObject, or mutableCopy), or if you send it a retain message. You are
-// responsible for relinquishing ownership of objects you own using release
-// or autorelease. Any other time you receive an object, you must
-// not release it."
-//
-
-static bool isWordEnd(char ch, char prev, char next) {
- return ch == '\0'
- || (islower(prev) && isupper(ch)) // xxxC
- || (isupper(prev) && isupper(ch) && islower(next)) // XXCreate
- || !isalpha(ch);
-}
-
-static const char* parseWord(const char* s) {
- char ch = *s, prev = '\0';
- assert(ch != '\0');
- char next = *(s+1);
- while (!isWordEnd(ch, prev, next)) {
- prev = ch;
- ch = next;
- next = *((++s)+1);
- }
- return s;
-}
-
-cocoa::NamingConvention cocoa::deriveNamingConvention(Selector S) {
- IdentifierInfo *II = S.getIdentifierInfoForSlot(0);
-
- if (!II)
- return NoConvention;
-
- const char *s = II->getNameStart();
-
- // A method/function name may contain a prefix. We don't know it is there,
- // however, until we encounter the first '_'.
- while (*s != '\0') {
- // Skip '_', numbers, ':', etc.
- if (*s == '_' || !isalpha(*s)) {
- ++s;
- continue;
- }
- break;
- }
-
- // Parse the first word, and look for specific keywords.
- const char *wordEnd = parseWord(s);
- assert(wordEnd > s);
- unsigned len = wordEnd - s;
-
- switch (len) {
- default:
- return NoConvention;
- case 3:
- // Methods starting with 'new' follow the create rule.
- return (memcmp(s, "new", 3) == 0) ? CreateRule : NoConvention;
- case 4:
- // 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:
- 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;
- }
-}
-
-bool cocoa::isRefType(QualType RetTy, llvm::StringRef Prefix,
- llvm::StringRef Name) {
- // Recursively walk the typedef stack, allowing typedefs of reference types.
- while (TypedefType* TD = dyn_cast<TypedefType>(RetTy.getTypePtr())) {
- llvm::StringRef TDName = TD->getDecl()->getIdentifier()->getName();
- if (TDName.startswith(Prefix) && TDName.endswith("Ref"))
- return true;
-
- RetTy = TD->getDecl()->getUnderlyingType();
- }
-
- if (Name.empty())
- return false;
-
- // Is the type void*?
- const PointerType* PT = RetTy->getAs<PointerType>();
- if (!(PT->getPointeeType().getUnqualifiedType()->isVoidType()))
- return false;
-
- // Does the name start with the prefix?
- 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 cocoa::isCocoaObjectRef(QualType Ty) {
- if (!Ty->isObjCObjectPointerType())
- return false;
-
- const ObjCObjectPointerType *PT = Ty->getAs<ObjCObjectPointerType>();
-
- // Can be true for objects with the 'NSObject' attribute.
- if (!PT)
- return true;
-
- // We assume that id<..>, id, Class, and Class<..> all represent tracked
- // objects.
- if (PT->isObjCIdType() || PT->isObjCQualifiedIdType() ||
- PT->isObjCClassType() || PT->isObjCQualifiedClassType())
- return true;
-
- // Does the interface subclass NSObject?
- // FIXME: We can memoize here if this gets too expensive.
- const ObjCInterfaceDecl *ID = PT->getInterfaceDecl();
-
- // Assume that anything declared with a forward declaration and no
- // @interface subclasses NSObject.
- if (ID->isForwardDecl())
- return true;
-
- for ( ; ID ; ID = ID->getSuperClass())
- if (ID->getIdentifier()->getName() == "NSObject")
- return true;
-
- return false;
-}
More information about the cfe-commits
mailing list