]> granicus.if.org Git - clang/commitdiff
Remove 'AnalysisContext::setDecl()', as we the Decl associated with an
authorTed Kremenek <kremenek@apple.com>
Fri, 21 Aug 2009 23:58:43 +0000 (23:58 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 21 Aug 2009 23:58:43 +0000 (23:58 +0000)
AnalysisContext should never change. Along the way, propagate some constness
around.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79701 91177308-0d34-0410-b5e6-96231b3b80d8

13 files changed:
include/clang/Analysis/LocalCheckers.h
include/clang/Analysis/PathSensitive/AnalysisContext.h
include/clang/Analysis/PathSensitive/AnalysisManager.h
include/clang/Analysis/PathSensitive/ExplodedGraph.h
include/clang/Analysis/PathSensitive/GRCoreEngine.h
include/clang/Analysis/PathSensitive/GRExprEngine.h
lib/Analysis/AnalysisContext.cpp
lib/Analysis/AnalysisManager.cpp
lib/Analysis/CheckObjCDealloc.cpp
lib/Analysis/CheckObjCInstMethSignature.cpp
lib/Analysis/CheckObjCUnusedIVars.cpp
lib/Analysis/CheckSecuritySyntaxOnly.cpp
lib/Analysis/GRExprEngine.cpp

index 2322f5ebb7a4f6633c55f37a6080029bceeba2e7..c6d53e60ef62bed3e5ceaa97278514e3a0598843 100644 (file)
@@ -40,15 +40,17 @@ void CheckUninitializedValues(CFG& cfg, ASTContext& Ctx, Diagnostic& Diags,
 GRTransferFuncs* MakeCFRefCountTF(ASTContext& Ctx, bool GCEnabled,
                                   const LangOptions& lopts); 
   
-void CheckObjCDealloc(ObjCImplementationDecl* D, const LangOptions& L,
+void CheckObjCDealloc(const ObjCImplementationDecl* D, const LangOptions& L,
                       BugReporter& BR);
   
-void CheckObjCInstMethSignature(ObjCImplementationDecl* ID, BugReporter& BR);
-void CheckObjCUnusedIvar(ObjCImplementationDecl* D, BugReporter& BR);
+void CheckObjCInstMethSignature(const ObjCImplementationDecl *ID,
+                                BugReporter& BR);
+
+void CheckObjCUnusedIvar(const ObjCImplementationDecl *D, BugReporter& BR);
   
 void RegisterAppleChecks(GRExprEngine& Eng, const Decl &D);
   
-void CheckSecuritySyntaxOnly(Decl *D, BugReporter &BR);
+void CheckSecuritySyntaxOnly(const Decl *D, BugReporter &BR);
 
   
 } // end namespace clang
index db281fec58ed7752daffac521175378aec897dd7..e69b4f529fe63ac56c7ea27bd07a10dde3b090a2 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/FoldingSet.h"
-#include <map>
+#include "llvm/ADT/DenseMap.h"
 
 namespace clang {
 
@@ -31,8 +31,7 @@ class ImplicitParamDecl;
 /// AnalysisContext contains the context data for the function or method under
 /// analysis.
 class AnalysisContext {
-  Decl *D;
-  Stmt *Body;
+  const Decl *D;
 
   // AnalysisContext owns the following data.
   CFG *cfg;
@@ -40,11 +39,10 @@ class AnalysisContext {
   ParentMap *PM;
 
 public:
-  AnalysisContext() : D(0), Body(0), cfg(0), liveness(0), PM(0) {}
+  AnalysisContext(const Decl *d) : D(d), cfg(0), liveness(0), PM(0) {}
   ~AnalysisContext();
 
-  void setDecl(Decl* d) { D = d; }
-  Decl *getDecl() { return D; }
+  const Decl *getDecl() { return D; }
   Stmt *getBody();
   CFG *getCFG();
   ParentMap &getParentMap();
@@ -56,12 +54,12 @@ public:
 };
 
 class AnalysisContextManager {
-  std::map<Decl*, AnalysisContext> Contexts;
-
+  typedef llvm::DenseMap<const Decl*, AnalysisContext*> ContextMap;
+  ContextMap Contexts;
 public:
-  typedef std::map<Decl*, AnalysisContext>::iterator iterator;
-
-  AnalysisContext *getContext(Decl *D);
+  ~AnalysisContextManager();
+  
+  AnalysisContext *getContext(const Decl *D);
 };
 
 class LocationContext : public llvm::FoldingSetNode {
index deff4818ce79d7b2db0e5e8f970e3422da99b769..78d77b58a192863e1e6ee452309be7468e41a78a 100644 (file)
@@ -83,7 +83,7 @@ public:
     DisplayedFunction = false;
   }
     
-  Decl *getCodeDecl() const { 
+  const Decl *getCodeDecl() const { 
     assert (AScope == ScopeDecl);
     return EntryContext->getDecl();
   }
index 1a25565c2942264cd28dd264297f8374e03d2e18..79df895d6c6cdfc8e79da389c1405175a93ac637 100644 (file)
@@ -226,9 +226,10 @@ protected:
   /// cfg - The CFG associated with this analysis graph.
   CFG& cfg;
   
+  // FIXME: Remove.
   /// CodeDecl - The declaration containing the code being analyzed.  This
   ///  can be a FunctionDecl or and ObjCMethodDecl.
-  Decl& CodeDecl;
+  const Decl& CodeDecl;
   
   /// Ctx - The ASTContext used to "interpret" CodeDecl.
   ASTContext& Ctx;
@@ -261,7 +262,7 @@ public:
     return V;
   }
 
-  ExplodedGraph(CFG& c, Decl& cd, ASTContext& ctx)
+  ExplodedGraph(CFG& c, const Decl &cd, ASTContext& ctx)
     : cfg(c), CodeDecl(cd), Ctx(ctx), NumNodes(0) {}
 
   virtual ~ExplodedGraph() {}
@@ -310,7 +311,7 @@ public:
   CFG& getCFG() { return cfg; }
   ASTContext& getContext() { return Ctx; }
 
-  Decl& getCodeDecl() { return CodeDecl; }
+  // FIXME: Remove.
   const Decl& getCodeDecl() const { return CodeDecl; }
 
   const FunctionDecl* getFunctionDecl() const {
index 8d93963e75189d0f940685af3fa269d60bc7d122..ee7a095748fbcbd1c8e543f280bc87631158a237 100644 (file)
@@ -98,7 +98,8 @@ private:
 public:
   /// Construct a GRCoreEngine object to analyze the provided CFG using
   ///  a DFS exploration of the exploded graph.
-  GRCoreEngine(CFG& cfg, Decl& cd, ASTContext& ctx, GRSubEngine& subengine)
+  GRCoreEngine(CFG& cfg, const Decl &cd, ASTContext& ctx,
+               GRSubEngine& subengine)
     : SubEngine(subengine), G(new ExplodedGraph(cfg, cd, ctx)), 
       WList(GRWorkList::MakeBFS()),
       BCounterFactory(G->getAllocator()) {}
@@ -106,7 +107,7 @@ public:
   /// Construct a GRCoreEngine object to analyze the provided CFG and to
   ///  use the provided worklist object to execute the worklist algorithm.
   ///  The GRCoreEngine object assumes ownership of 'wlist'.
-  GRCoreEngine(CFG& cfg, Decl& cd, ASTContext& ctx, GRWorkList* wlist,
+  GRCoreEngine(CFG& cfg, const Decl &cd, ASTContext& ctx, GRWorkList* wlist,
                GRSubEngine& subengine)
     : SubEngine(subengine), G(new ExplodedGraph(cfg, cd, ctx)), WList(wlist),
       BCounterFactory(G->getAllocator()) {}
index a651f95b90f28fd5e4cb5c9384be14945dea7c0e..6ca8cf4b7fb87b7e40868d573729e3f07343a269 100644 (file)
@@ -202,7 +202,7 @@ public:
   ErrorNodes ExplicitOOBMemAccesses;
   
 public:
-  GRExprEngine(CFG& cfg, Decl& CD, ASTContext& Ctx, LiveVariables& L,
+  GRExprEngine(CFG& cfg, const Decl &CD, ASTContext& Ctx, LiveVariables& L,
                AnalysisManager &mgr,
                bool purgeDead, bool eagerlyAssume = true,
                StoreManagerCreator SMC = CreateBasicStoreManager,
index ef47ece70ed2d712b0ca6fe0b66340448e2f609f..da671d62f13792895f9887984173fbe94da72507 100644 (file)
@@ -28,10 +28,15 @@ AnalysisContext::~AnalysisContext() {
   delete PM;
 }
 
+AnalysisContextManager::~AnalysisContextManager() {
+  for (ContextMap::iterator I = Contexts.begin(), E = Contexts.end(); I!=E; ++I)
+    delete I->second;
+}
+
 Stmt *AnalysisContext::getBody() {
-  if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
+  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
     return FD->getBody();
-  else if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
+  else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
     return MD->getBody();
 
   llvm::llvm_unreachable("unknown code decl");
@@ -70,14 +75,12 @@ LiveVariables *AnalysisContext::getLiveVariables() {
   return liveness;
 }
 
-AnalysisContext *AnalysisContextManager::getContext(Decl *D) {
-  iterator I = Contexts.find(D);
-  if (I != Contexts.end())
-    return &(I->second);
-
-  AnalysisContext &Ctx = Contexts[D];
-  Ctx.setDecl(D);
-  return &Ctx;
+AnalysisContext *AnalysisContextManager::getContext(const Decl *D) {
+  AnalysisContext *&AC = Contexts[D];
+  if (!AC)
+    AC = new AnalysisContext(D);
+  
+  return AC;
 }
 
 void LocationContext::Profile(llvm::FoldingSetNodeID &ID, ContextKind k,
index 125c00bfee65c7c5e2da148ad08f2083a3cd9574..f29cd7857595e919634294f38473716d6c48011b 100644 (file)
@@ -27,7 +27,7 @@ void AnalysisManager::DisplayFunction() {
   // FIXME: Is getCodeDecl() always a named decl?
   if (isa<FunctionDecl>(getCodeDecl()) ||
       isa<ObjCMethodDecl>(getCodeDecl())) {
-    NamedDecl *ND = cast<NamedDecl>(getCodeDecl());
+    const NamedDecl *ND = cast<NamedDecl>(getCodeDecl());
     SourceManager &SM = getContext().getSourceManager();
     llvm::cerr << "ANALYZE: "
                << SM.getPresumedLoc(ND->getLocation()).getFilename()
index 7e6023a1f5afe6a5e2ffb72f80802193ab4325d5..3392fcfdc3add12f5f1cee361f6fa3e10629afb0 100644 (file)
@@ -87,13 +87,13 @@ static bool scan_ivar_release(Stmt* S, ObjCIvarDecl* ID,
   return false;
 }
 
-void clang::CheckObjCDealloc(ObjCImplementationDecl* D,
+void clang::CheckObjCDealloc(const ObjCImplementationDecl* D,
                              const LangOptions& LOpts, BugReporter& BR) {
 
   assert (LOpts.getGCMode() != LangOptions::GCOnly);
   
   ASTContext& Ctx = BR.getContext();
-  ObjCInterfaceDecl* ID = D->getClassInterface();
+  const ObjCInterfaceDecl* ID = D->getClassInterface();
     
   // Does the class contain any ivars that are pointers (or id<...>)?
   // If not, skip the check entirely.
index c208a7c323e5127e75931c8e7f1b1df8a2a0a1b1..aae1e1da3b83bfbbb4e9973980aeda0062f0b57e 100644 (file)
@@ -36,10 +36,10 @@ static bool AreTypesCompatible(QualType Derived, QualType Ancestor,
   return C.typesAreCompatible(Derived, Ancestor);
 }
 
-static void CompareReturnTypes(ObjCMethodDecl* MethDerived,
-                               ObjCMethodDecl* MethAncestor,
-                               BugReporter& BR, ASTContext& Ctx,
-                               ObjCImplementationDecl* ID) {
+static void CompareReturnTypes(const ObjCMethodDecl *MethDerived,
+                               const ObjCMethodDecl *MethAncestor,
+                               BugReporter &BR, ASTContext &Ctx,
+                               const ObjCImplementationDecl *ID) {
     
   QualType ResDerived  = MethDerived->getResultType();
   QualType ResAncestor = MethAncestor->getResultType(); 
@@ -69,11 +69,11 @@ static void CompareReturnTypes(ObjCMethodDecl* MethDerived,
   }
 }
 
-void clang::CheckObjCInstMethSignature(ObjCImplementationDecl* ID,
+void clang::CheckObjCInstMethSignature(const ObjCImplementationDecl* ID,
                                        BugReporter& BR) {
   
-  ObjCInterfaceDecl* D = ID->getClassInterface();
-  ObjCInterfaceDecl* C = D->getSuperClass();
+  const ObjCInterfaceDecl* D = ID->getClassInterface();
+  const ObjCInterfaceDecl* C = D->getSuperClass();
 
   if (!C)
     return;
index 3a69e00499d400c1b62ba24ad207a537c1f6164f..75470972f3bb1a39a08502759e2198aac47e53bf 100644 (file)
@@ -62,7 +62,8 @@ static void Scan(IvarUsageMap& M, const ObjCPropertyImplDecl* D) {
     I->second = Used;
 }
 
-void clang::CheckObjCUnusedIvar(ObjCImplementationDecl* D, BugReporter& BR) {
+void clang::CheckObjCUnusedIvar(const ObjCImplementationDecl *D,
+                                BugReporter &BR) {
 
   const ObjCInterfaceDecl* ID = D->getClassInterface();
   IvarUsageMap M;
index 17fc6d7c32ed911a26299fd246e0b83ee8ae1df6..96c42f8ba01c666f32ce9e42c05b9dcff8db8bda 100644 (file)
@@ -229,7 +229,7 @@ void WalkAST::CheckCall_gets(const CallExpr *CE, const FunctionDecl *FD) {
 // Entry point for check.
 //===----------------------------------------------------------------------===//
 
-void clang::CheckSecuritySyntaxOnly(Decl *D, BugReporter &BR) {  
+void clang::CheckSecuritySyntaxOnly(const Decl *D, BugReporter &BR) {  
   WalkAST walker(BR);
   walker.Visit(D->getBody());  
 }
index a8d34071e6cd8067b5f1afdc2ee7c4ff5487208f..f4711a15203c5e1e7d4ab96a43fd8f45403d90d8 100644 (file)
@@ -148,8 +148,8 @@ static inline Selector GetNullarySelector(const char* name, ASTContext& Ctx) {
 }
 
 
-GRExprEngine::GRExprEngine(CFG& cfg, Decl& CD, ASTContext& Ctx,
-                           LiveVariablesL, AnalysisManager &mgr,
+GRExprEngine::GRExprEngine(CFG &cfg, const Decl &CD, ASTContext &Ctx,
+                           LiveVariables &L, AnalysisManager &mgr,
                            bool purgeDead, bool eagerlyAssume,
                            StoreManagerCreator SMC,
                            ConstraintManagerCreator CMC)