[cfe-commits] r47921 - in /cfe/trunk/include/clang/Analysis/PathSensitive: ExplodedGraph.h GRCoreEngine.h GRExprEngine.h ValueState.h

Ted Kremenek kremenek at apple.com
Tue Mar 4 16:11:33 PST 2008


Author: kremenek
Date: Tue Mar  4 18:11:33 2008
New Revision: 47921

URL: http://llvm.org/viewvc/llvm-project?rev=47921&view=rev
Log:
Cleaned up typedefs involving StateTy so that we always use "StateTy*" instead of StateTy.
This is conceptually much cleaner, as it shows that the state is always a pointer.
It also makes it easier to marshall these values around across the internal APIs
of the path-sensitive engine.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h
    cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h
    cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
    cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h?rev=47921&r1=47920&r2=47921&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h Tue Mar  4 18:11:33 2008
@@ -114,15 +114,6 @@
   }
   
 public:
-  // This method is only defined so that we can cast a
-  // void* to FoldingSet<ExplodedNodeImpl> so that we can iterate
-  // over the vertices of EdgeNodeSetMap in ExplodeGraphImpl.
-  // The actual profiling of vertices will be done in the derived
-  // class, ExplodedNode<>.  Nodes will NEVER be INSERTED into the
-  // FoldingSet using this Profile method (since it doesn't do anything).
-  inline void Profile(llvm::FoldingSetNodeID& ID) const {
-    assert (false && "Needs to be implemented in derived class.");
-  }
   
   /// getLocation - Returns the edge associated with the given node.
   const ProgramPoint& getLocation() const { return Location; }
@@ -139,11 +130,8 @@
 
 template <typename StateTy>
 struct GRTrait {
-  static inline void* toPtr(StateTy S) {
-    return reinterpret_cast<void*>(S);
-  }  
-  static inline StateTy toState(void* P) {
-    return reinterpret_cast<StateTy>(P);
+  static inline void Profile(llvm::FoldingSetNodeID& ID, const StateTy* St) {
+    St->Profile(ID);
   }
 };
 
@@ -153,19 +141,19 @@
 public:
   /// Construct a ExplodedNodeImpl with the given node ID, program edge,
   ///  and state.
-  explicit ExplodedNode(const ProgramPoint& loc, StateTy state)
-  : ExplodedNodeImpl(loc, GRTrait<StateTy>::toPtr(state)) {}
+  explicit ExplodedNode(const ProgramPoint& loc, StateTy* St)
+    : ExplodedNodeImpl(loc, St) {}
   
   /// getState - Returns the state associated with the node.  
-  inline StateTy getState() const {
-    return GRTrait<StateTy>::toState(State);
+  inline StateTy* getState() const {
+    return static_cast<StateTy*>(State);
   }
   
   // Profiling (for FoldingSet).
   
   static inline void Profile(llvm::FoldingSetNodeID& ID,
                              const ProgramPoint& Loc,
-                             StateTy state) {
+                             StateTy* state) {
     ID.Add(Loc);
     GRTrait<StateTy>::Profile(ID, state);
   }
@@ -293,7 +281,7 @@
 protected:
   virtual ExplodedNodeImpl*
   getNodeImpl(const ProgramPoint& L, void* State, bool* IsNew) {
-    return getNode(L, GRTrait<StateTy>::toState(State), IsNew);
+    return getNode(L, static_cast<StateTy*>(State), IsNew);
   }
     
 public:
@@ -309,7 +297,7 @@
   ///  where the 'Location' is a ProgramPoint in the CFG.  If no node for
   ///  this pair exists, it is created.  IsNew is set to true if
   ///  the node was freshly created.
-  NodeTy* getNode(const ProgramPoint& L, StateTy State, bool* IsNew = NULL) {
+  NodeTy* getNode(const ProgramPoint& L, StateTy* State, bool* IsNew = NULL) {
     
     // Profile 'State' to determine if we already have an existing node.
     llvm::FoldingSetNodeID profile;    

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h?rev=47921&r1=47920&r2=47921&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h Tue Mar  4 18:11:33 2008
@@ -168,18 +168,16 @@
     return static_cast<NodeTy*>(NB.getLastNode());
   }
   
-  NodeTy* generateNode(Stmt* S, StateTy State, NodeTy* Pred) {
-    void *state = GRTrait<StateTy>::toPtr(State);        
-    return static_cast<NodeTy*>(NB.generateNodeImpl(S, state, Pred));
+  NodeTy* generateNode(Stmt* S, StateTy* St, NodeTy* Pred) {
+    return static_cast<NodeTy*>(NB.generateNodeImpl(S, St, Pred));
   }
   
-  NodeTy* generateNode(Stmt* S, StateTy State) {
-    void *state = GRTrait<StateTy>::toPtr(State);
-    return static_cast<NodeTy*>(NB.generateNodeImpl(S, state));    
+  NodeTy* generateNode(Stmt* S, StateTy* St) {
+    return static_cast<NodeTy*>(NB.generateNodeImpl(S, St));    
   }
   
-  NodeTy* Nodify(ExplodedNodeSet<NodeTy> Dst, Stmt* S,
-                 NodeTy* Pred, StateTy St) {
+  NodeTy* Nodify(ExplodedNodeSet<NodeTy>& Dst, Stmt* S,
+                 NodeTy* Pred, StateTy* St) {
     
     // If the state hasn't changed, don't generate a new node.
     if (St == Pred->getState()) {
@@ -251,13 +249,12 @@
     return static_cast<NodeTy*>(NB.getPredecessor());
   }
   
-  StateTy getState() const {
+  StateTy* getState() const {
     return getPredecessor()->getState();
   }
 
-  inline NodeTy* generateNode(StateTy State, bool branch) {
-    void *state = GRTrait<StateTy>::toPtr(State);        
-    return static_cast<NodeTy*>(NB.generateNodeImpl(state, branch));
+  inline NodeTy* generateNode(StateTy* St, bool branch) {
+    return static_cast<NodeTy*>(NB.generateNodeImpl(St, branch));
   }
   
   GRBlockCounter getBlockCounter() const {
@@ -334,13 +331,12 @@
   
   inline Expr* getTarget() const { return NB.getTarget(); }
   
-  inline NodeTy* generateNode(const iterator& I, StateTy St, bool isSink=false){    
-    void *state = GRTrait<StateTy>::toPtr(St);        
-    return static_cast<NodeTy*>(NB.generateNodeImpl(I, state, isSink));
+  inline NodeTy* generateNode(const iterator& I, StateTy* St, bool isSink=false){    
+    return static_cast<NodeTy*>(NB.generateNodeImpl(I, St, isSink));
   }
   
-  inline StateTy getState() const {
-    return GRTrait<StateTy>::toState(NB.getState());
+  inline StateTy* getState() const {
+    return static_cast<StateTy*>(NB.getState());
   }    
 };
   
@@ -402,18 +398,16 @@
   
   inline Expr* getCondition() const { return NB.getCondition(); }
   
-  inline NodeTy* generateCaseStmtNode(const iterator& I, StateTy St) {
-    void *state = GRTrait<StateTy>::toPtr(St);        
-    return static_cast<NodeTy*>(NB.generateCaseStmtNodeImpl(I, state));
+  inline NodeTy* generateCaseStmtNode(const iterator& I, StateTy* St) {
+    return static_cast<NodeTy*>(NB.generateCaseStmtNodeImpl(I, St));
   }
   
-  inline NodeTy* generateDefaultCaseNode(StateTy St, bool isSink = false) {    
-    void *state = GRTrait<StateTy>::toPtr(St);        
-    return static_cast<NodeTy*>(NB.generateDefaultCaseNodeImpl(state, isSink));
+  inline NodeTy* generateDefaultCaseNode(StateTy* St, bool isSink = false) {    
+    return static_cast<NodeTy*>(NB.generateDefaultCaseNodeImpl(St, isSink));
   }
   
-  inline StateTy getState() const {
-    return GRTrait<StateTy>::toState(NB.getState());
+  inline StateTy* getState() const {
+    return static_cast<StateTy*>(NB.getState());
   }    
 };
 
@@ -432,7 +426,7 @@
   CheckerTy* Checker;  
   
   virtual void* getInitialState() {
-    return GRTrait<StateTy>::toPtr(getCheckerState().getInitialState());
+    return getCheckerState().getInitialState();
   }
   
   virtual void* ProcessEOP(CFGBlock* Blk, void* State) {
@@ -448,7 +442,7 @@
   virtual bool ProcessBlockEntrance(CFGBlock* Blk, void* State,
                                     GRBlockCounter BC) {    
     return Checker->ProcessBlockEntrance(Blk,
-                                         GRTrait<StateTy>::toState(State), BC);
+                                         static_cast<StateTy*>(State), BC);
   }
 
   virtual void ProcessBranch(Expr* Condition, Stmt* Terminator,

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h?rev=47921&r1=47920&r2=47921&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h Tue Mar  4 18:11:33 2008
@@ -22,7 +22,7 @@
 class GRExprEngine {
   
 public:
-  typedef ValueState*                 StateTy;
+  typedef ValueState                  StateTy;
   typedef ExplodedGraph<GRExprEngine> GraphTy;
   typedef GraphTy::NodeTy             NodeTy;
   

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h?rev=47921&r1=47920&r2=47921&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h Tue Mar  4 18:11:33 2008
@@ -93,7 +93,7 @@
   
   /// Profile - Profile the contents of a ValueState object for use
   ///  in a FoldingSet.
-  static void Profile(llvm::FoldingSetNodeID& ID, ValueState* V) {
+  static void Profile(llvm::FoldingSetNodeID& ID, const ValueState* V) {
     V->SubExprBindings.Profile(ID);
     V->BlockExprBindings.Profile(ID);
     V->VarBindings.Profile(ID);
@@ -103,7 +103,7 @@
 
   /// Profile - Used to profile the contents of this object for inclusion
   ///  in a FoldingSet.
-  void Profile(llvm::FoldingSetNodeID& ID) {
+  void Profile(llvm::FoldingSetNodeID& ID) const {
     Profile(ID, this);
   }
   





More information about the cfe-commits mailing list