diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-01-29 22:56:11 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-01-29 22:56:11 +0000 |
commit | 7d7fe6d539b3bdb1701835223cca306c325614a7 (patch) | |
tree | 1565e4a64e8b616997ec90beb3d5c9db1ae5ae53 /include/clang | |
parent | f4b7a6940070f04d7845ac55f0d1e300a8bee0d9 (diff) |
Added boilerplate logic in GREngine for processing branches.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46532 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/Analysis/PathSensitive/ExplodedGraph.h | 3 | ||||
-rw-r--r-- | include/clang/Analysis/PathSensitive/GREngine.h | 63 |
2 files changed, 59 insertions, 7 deletions
diff --git a/include/clang/Analysis/PathSensitive/ExplodedGraph.h b/include/clang/Analysis/PathSensitive/ExplodedGraph.h index a7f6c3c005..dc96c1c5a4 100644 --- a/include/clang/Analysis/PathSensitive/ExplodedGraph.h +++ b/include/clang/Analysis/PathSensitive/ExplodedGraph.h @@ -29,6 +29,7 @@ namespace clang { class GREngineImpl; class ExplodedNodeImpl; class GRStmtNodeBuilderImpl; +class GRBranchNodeBuilderImpl; class CFG; class ASTContext; class FunctionDecl; @@ -39,6 +40,7 @@ protected: friend class ExplodedGraphImpl; friend class GREngineImpl; friend class GRStmtNodeBuilderImpl; + friend class GRBranchNodeBuilderImpl; class NodeGroup { enum { Size1 = 0x0, SizeOther = 0x1, Infeasible = 0x2, Flags = 0x3 }; @@ -193,6 +195,7 @@ class ExplodedGraphImpl { protected: friend class GREngineImpl; friend class GRStmtNodeBuilderImpl; + friend class GRBranchNodeBuilderImpl; // Type definitions. typedef llvm::DenseMap<ProgramPoint,void*> EdgeNodeSetMap; diff --git a/include/clang/Analysis/PathSensitive/GREngine.h b/include/clang/Analysis/PathSensitive/GREngine.h index e783d8e7d0..c3a9e209b8 100644 --- a/include/clang/Analysis/PathSensitive/GREngine.h +++ b/include/clang/Analysis/PathSensitive/GREngine.h @@ -22,11 +22,13 @@ namespace clang { class GRStmtNodeBuilderImpl; +class GRBranchNodeBuilderImpl; class GRWorkList; class GREngineImpl { protected: friend class GRStmtNodeBuilderImpl; + friend class GRBranchNodeBuilderImpl; typedef llvm::DenseMap<Stmt*,Stmt*> ParentMapTy; @@ -59,13 +61,17 @@ protected: void HandleBlockExit(CFGBlock* B, ExplodedNodeImpl* Pred); void HandlePostStmt(const PostStmt& S, CFGBlock* B, unsigned StmtIdx, ExplodedNodeImpl *Pred); - + + void HandleBranch(Stmt* Cond, Stmt* Term, CFGBlock* B, + ExplodedNodeImpl* Pred); + virtual void* ProcessEOP(CFGBlock* Blk, void* State) = 0; - virtual void ProcessStmt(Stmt* S, GRStmtNodeBuilderImpl& Builder) = 0; + virtual void ProcessStmt(Stmt* S, GRStmtNodeBuilderImpl& Builder) = 0; + + virtual void ProcessBranch(Stmt* Condition, Stmt* Terminator, + GRBranchNodeBuilderImpl& Builder) = 0; - virtual void ProcessTerminator(Stmt* Terminator, CFGBlock* B, - ExplodedNodeImpl* Pred) = 0; private: GREngineImpl(const GREngineImpl&); // Do not implement. @@ -154,6 +160,47 @@ public: } }; +class GRBranchNodeBuilderImpl { + GREngineImpl& Eng; + CFGBlock* Src; + CFGBlock* DstT; + CFGBlock* DstF; + ExplodedNodeImpl* Pred; + +public: + GRBranchNodeBuilderImpl(CFGBlock* src, CFGBlock* dstT, CFGBlock* dstF, + ExplodedNodeImpl* pred, GREngineImpl* e) + : Eng(*e), Src(src), DstT(dstT), DstF(dstF), Pred(pred) {} + + ~GRBranchNodeBuilderImpl() {} + + const ExplodedGraphImpl& getGraph() const { return *Eng.G; } + + void generateNodeImpl(void* State, bool branch); +}; + +template<typename CHECKER> +class GRBranchNodeBuilder { + typedef CHECKER CheckerTy; + typedef typename CheckerTy::StateTy StateTy; + typedef ExplodedGraph<CheckerTy> GraphTy; + typedef typename GraphTy::NodeTy NodeTy; + + GRBranchNodeBuilderImpl& NB; + +public: + GRBranchNodeBuilder(GRBranchNodeBuilderImpl& nb) : NB(nb) {} + + const GraphTy& getGraph() const { + return static_cast<const GraphTy&>(NB.getGraph()); + } + + void generateNode(StateTy State, bool branch) { + void *state = GRTrait<StateTy>::toPtr(State); + NB.generateNodeImpl(state, branch); + } +}; + template<typename CHECKER> class GREngine : public GREngineImpl { @@ -182,9 +229,11 @@ protected: Checker->ProcessStmt(S, Builder); } - virtual void ProcessTerminator(Stmt* Terminator, CFGBlock* B, - ExplodedNodeImpl* Pred) { - // FIXME: Dispatch. + + virtual void ProcessBranch(Stmt* Condition, Stmt* Terminator, + GRBranchNodeBuilderImpl& BuilderImpl) { + GRBranchNodeBuilder<CHECKER> Builder(BuilderImpl); + Checker->ProcessBranch(Condition, Terminator, Builder); } |