]> granicus.if.org Git - clang/commitdiff
Simplify GRIndirectGotoNodeBuilder.
authorTed Kremenek <kremenek@apple.com>
Wed, 13 Feb 2008 17:27:37 +0000 (17:27 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 13 Feb 2008 17:27:37 +0000 (17:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47068 91177308-0d34-0410-b5e6-96231b3b80d8

Analysis/GRConstants.cpp
Analysis/GREngine.cpp
include/clang/Analysis/PathSensitive/GREngine.h

index c2395512c59e416a0b1f6e4227ae0996a9445543..dad8b08cf3a10b40624ad85469f006c92f431f3d 100644 (file)
@@ -449,10 +449,8 @@ void GRConstants::ProcessIndirectGoto(IndirectGotoNodeBuilder& builder) {
     LabelStmt* L = cast<lval::GotoLabel>(V).getLabel();
     
     for (iterator I=builder.begin(), E=builder.end(); I != E; ++I) {
-      IndirectGotoNodeBuilder::Destination D = *I;
-      
-      if (D.getLabel() == L) {
-        builder.generateNode(D, St);
+      if (I.getLabel() == L) {
+        builder.generateNode(I, St);
         return;
       }
     }
@@ -463,7 +461,7 @@ void GRConstants::ProcessIndirectGoto(IndirectGotoNodeBuilder& builder) {
 
   if (isa<lval::ConcreteInt>(V) || isa<UninitializedVal>(V)) {
     // Dispatch to the first target and mark it as a sink.
-    NodeTy* N = builder.generateNode(*builder.begin(), St, true);
+    NodeTy* N = builder.generateNode(builder.begin(), St, true);
     UninitBranches.insert(N);
     return;
   }
@@ -473,7 +471,7 @@ void GRConstants::ProcessIndirectGoto(IndirectGotoNodeBuilder& builder) {
   assert (isa<UnknownVal>(V));
   
   for (iterator I=builder.begin(), E=builder.end(); I != E; ++I)
-    builder.generateNode(*I, St);
+    builder.generateNode(I, St);
 }
 
 void GRConstants::VisitLogicalExpr(BinaryOperator* B, NodeTy* Pred,
index 3d46fa35fe3c71f2d1a604d6f2159665df184b20..a15bcb5ba966b2bc44fa009127ac8e42ec6332e3 100644 (file)
@@ -361,32 +361,15 @@ GRBranchNodeBuilderImpl::~GRBranchNodeBuilderImpl() {
     if (!(*I)->isSink()) Eng.WList->Enqueue(*I);
 }
 
-GRIndirectGotoNodeBuilderImpl::Destination
-GRIndirectGotoNodeBuilderImpl::Iterator::operator*() {
-  CFGBlock* B = *I;
-  assert (!B->empty());      
-  LabelStmt* L = cast<LabelStmt>(B->getLabel());
-  return Destination(L, *I);
-}
-
-GRIndirectGotoNodeBuilderImpl::Iterator
-GRIndirectGotoNodeBuilderImpl::begin() {
-  return Iterator(DispatchBlock.succ_begin());
-}
-
-GRIndirectGotoNodeBuilderImpl::Iterator
-GRIndirectGotoNodeBuilderImpl::end() {
-  return Iterator(DispatchBlock.succ_end());
-}
 
 ExplodedNodeImpl*
-GRIndirectGotoNodeBuilderImpl::generateNodeImpl(const Destination& D,
+GRIndirectGotoNodeBuilderImpl::generateNodeImpl(const Iterator& I,
                                                 void* St,
                                                 bool isSink) {
   bool IsNew;
   
   ExplodedNodeImpl* Succ =
-    Eng.G->getNodeImpl(BlockEdge(Eng.getCFG(), Src, D.getBlock(), true),
+    Eng.G->getNodeImpl(BlockEdge(Eng.getCFG(), Src, I.getBlock(), true),
                        St, &IsNew);
               
   Succ->addPredecessor(Pred);
index 4e1f2095cb5aed6212453051ed81bc5ed367fb99..bceb1b85944fa04c33dee96da15151b46533c6bb 100644 (file)
 #ifndef LLVM_CLANG_ANALYSIS_GRENGINE
 #define LLVM_CLANG_ANALYSIS_GRENGINE
 
+#include "clang/AST/Stmt.h"
 #include "clang/Analysis/PathSensitive/ExplodedGraph.h"
 #include "clang/Analysis/PathSensitive/GRWorkList.h"
 #include "clang/Analysis/PathSensitive/GRBlockCounter.h"
 #include "llvm/ADT/OwningPtr.h"
 
+
 namespace clang {
   
 class GRStmtNodeBuilderImpl;
@@ -27,7 +29,16 @@ class GRBranchNodeBuilderImpl;
 class GRIndirectGotoNodeBuilderImpl;
 class GRWorkList;
 class LabelStmt;
-  
+
+//===----------------------------------------------------------------------===//
+/// GREngineImpl - Implements the core logic of the graph-reachability analysis.
+///   It traverses the CFG and generates the ExplodedGraph. Program "states"
+///   are treated as opaque void pointers.  The template class GREngine
+///   (which subclasses GREngineImpl) provides the matching component
+///   to the engine that knows the actual types for states.  Note that this
+///   engine only dispatches to transfer functions as the statement and
+///   block-level.  The analyses themselves must implement any transfer
+///   function logic and the sub-expression level (if any).
 class GREngineImpl {
 protected:
   friend class GRStmtNodeBuilderImpl;
@@ -262,20 +273,7 @@ public:
                                 GREngineImpl* eng)
   : Eng(*eng), Src(src), DispatchBlock(*dispatch), E(e), Pred(pred) {}
   
-  class Iterator;
-  
-  class Destination {
-    LabelStmt* L;
-    CFGBlock* B;
 
-    friend class Iterator;
-    Destination(LabelStmt* l, CFGBlock* b) : L(l), B(b) {}
-    
-  public:    
-    CFGBlock*  getBlock() const { return B; }
-    LabelStmt* getLabel() const { return L; }
-  };
-  
   class Iterator {
     CFGBlock::succ_iterator I;
     
@@ -286,13 +284,19 @@ public:
     Iterator& operator++() { ++I; return *this; }
     bool operator!=(const Iterator& X) const { return I != X.I; }
     
-    Destination operator*();
+    LabelStmt* getLabel() const {
+      return llvm::cast<LabelStmt>((*I)->getLabel());
+    }
+    
+    CFGBlock*  getBlock() const {
+      return *I;
+    }
   };
   
-  Iterator begin();
-  Iterator end();
+  Iterator begin() { return Iterator(DispatchBlock.succ_begin()); }
+  Iterator end() { return Iterator(DispatchBlock.succ_end()); }
   
-  ExplodedNodeImpl* generateNodeImpl(const Destination& D, void* State,
+  ExplodedNodeImpl* generateNodeImpl(const Iterator& I, void* State,
                                      bool isSink);
   
   inline Expr* getTarget() const { return E; }
@@ -312,18 +316,15 @@ public:
   GRIndirectGotoNodeBuilder(GRIndirectGotoNodeBuilderImpl& nb) : NB(nb) {}
   
   typedef GRIndirectGotoNodeBuilderImpl::Iterator     iterator;
-  typedef GRIndirectGotoNodeBuilderImpl::Destination  Destination;
 
   inline iterator begin() { return NB.begin(); }
   inline iterator end() { return NB.end(); }
   
   inline Expr* getTarget() const { return NB.getTarget(); }
   
-  inline NodeTy* generateNode(const Destination& D, StateTy St,
-                              bool isSink = false) {
-    
+  inline NodeTy* generateNode(const iterator& I, StateTy St, bool isSink=false){    
     void *state = GRTrait<StateTy>::toPtr(St);        
-    return static_cast<NodeTy*>(NB.generateNodeImpl(D, state, isSink));
+    return static_cast<NodeTy*>(NB.generateNodeImpl(I, state, isSink));
   }
   
   inline StateTy getState() const {