From: Anna Zaks Date: Tue, 18 Oct 2011 23:06:38 +0000 (+0000) Subject: [analyzer] Remove StmtNodeBuilder from CheckerContext X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3152b3cb5b6a2f797d0972c81a5eb3fd69c0d620;p=clang [analyzer] Remove StmtNodeBuilder from CheckerContext It now only depends on a generic NodeBuilder instead. As part of this change, make the generic node builder results finalized by default. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142452 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h index 1d0d716944..c2188454c9 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h @@ -24,7 +24,6 @@ namespace ento { class CheckerContext { ExplodedNodeSet &Dst; - StmtNodeBuilder &B; ExprEngine &Eng; ExplodedNode *Pred; const ProgramPoint Location; @@ -32,26 +31,25 @@ class CheckerContext { const unsigned size; // TODO: Use global context. NodeBuilderContext Ctx; - NodeBuilder NB; + NodeBuilder &NB; public: bool *respondsToCallback; public: CheckerContext(ExplodedNodeSet &dst, - StmtNodeBuilder &builder, + NodeBuilder &builder, ExprEngine &eng, ExplodedNode *pred, const ProgramPoint &loc, bool *respondsToCB = 0, const ProgramState *st = 0) : Dst(dst), - B(builder), Eng(eng), Pred(pred), Location(loc), ST(st), size(Dst.size()), Ctx(builder.C.Eng, builder.getBlock()), - NB(pred, Ctx), + NB(builder), respondsToCallback(respondsToCB) { assert(!(ST && ST != Pred->getState())); } diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h b/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h index 6e9f54fca7..7d7aa1417b 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h @@ -187,6 +187,8 @@ public: const NodeBuilderContext &C; protected: + /// Specifies if the builder results have been finalized. For example, if it + /// is set to false, autotransitions are yet to be generated. bool Finalized; /// \brief The frontier set - a set of nodes which need to be propagated after @@ -196,7 +198,8 @@ protected: BlockCounter getBlockCounter() const { return C.Eng.WList->getBlockCounter();} - bool checkResults() { + /// Checkes if the results are ready. + virtual bool checkResults() { if (!Finalized) return false; for (DeferredTy::iterator I=Deferred.begin(), E=Deferred.end(); I!=E; ++I) @@ -205,11 +208,8 @@ protected: return true; } - virtual void finalizeResults() { - if (!Finalized) { - Finalized = true; - } - } + /// Allow subclasses to finalize results before result_begin() is executed. + virtual void finalizeResults() {} ExplodedNode *generateNodeImpl(const ProgramPoint &PP, const ProgramState *State, @@ -217,15 +217,15 @@ protected: bool MarkAsSink = false); public: - NodeBuilder(ExplodedNode *N, NodeBuilderContext &Ctx) - : BuilderPred(N), C(Ctx), Finalized(false) { + NodeBuilder(ExplodedNode *N, NodeBuilderContext &Ctx, bool F = true) + : BuilderPred(N), C(Ctx), Finalized(F) { assert(!N->isSink()); Deferred.insert(N); } /// Create a new builder using the parent builder's context. - NodeBuilder(ExplodedNode *N, const NodeBuilder &ParentBldr) - : BuilderPred(N), C(ParentBldr.C), Finalized(false) { + NodeBuilder(ExplodedNode *N, const NodeBuilder &ParentBldr, bool F = true) + : BuilderPred(N), C(ParentBldr.C), Finalized(F) { assert(!N->isSink()); Deferred.insert(N); } @@ -383,6 +383,8 @@ class BranchNodeBuilder: public NodeBuilder { bool InFeasibleTrue; bool InFeasibleFalse; + /// Generate default branching transitions of none were generated or + /// suppressed. void finalizeResults() { if (Finalized) return; @@ -394,15 +396,15 @@ class BranchNodeBuilder: public NodeBuilder { public: BranchNodeBuilder(ExplodedNode *Pred, NodeBuilderContext &C, const CFGBlock *dstT, const CFGBlock *dstF) - : NodeBuilder(Pred, C), DstT(dstT), DstF(dstF), + : NodeBuilder(Pred, C, false), DstT(dstT), DstF(dstF), GeneratedTrue(false), GeneratedFalse(false), InFeasibleTrue(!DstT), InFeasibleFalse(!DstF) { } /// Create a new builder using the parent builder's context. BranchNodeBuilder(ExplodedNode *Pred, BranchNodeBuilder &ParentBldr) - : NodeBuilder(Pred, ParentBldr), DstT(ParentBldr.DstT), DstF(ParentBldr.DstF), - GeneratedTrue(false), GeneratedFalse(false), + : NodeBuilder(Pred, ParentBldr, false), DstT(ParentBldr.DstT), + DstF(ParentBldr.DstF), GeneratedTrue(false), GeneratedFalse(false), InFeasibleTrue(!DstT), InFeasibleFalse(!DstF) { } diff --git a/lib/StaticAnalyzer/Core/CheckerContext.cpp b/lib/StaticAnalyzer/Core/CheckerContext.cpp index e380165c2e..26479d0552 100644 --- a/lib/StaticAnalyzer/Core/CheckerContext.cpp +++ b/lib/StaticAnalyzer/Core/CheckerContext.cpp @@ -22,8 +22,4 @@ CheckerContext::~CheckerContext() { E = NB.results_end(); I != E; ++I) { Dst.Add(*I); } - - // Copy the results into the StmtNodeBuilder. - //TODO: This will be removed after we completely migrate NodeBuilder. - B.importNodesFromBuilder(NB); } diff --git a/lib/StaticAnalyzer/Core/CoreEngine.cpp b/lib/StaticAnalyzer/Core/CoreEngine.cpp index fda7bbdf4c..0a308670c0 100644 --- a/lib/StaticAnalyzer/Core/CoreEngine.cpp +++ b/lib/StaticAnalyzer/Core/CoreEngine.cpp @@ -489,9 +489,6 @@ ExplodedNode* NodeBuilder::generateNodeImpl(const ProgramPoint &Loc, const ProgramState *State, ExplodedNode *FromN, bool MarkAsSink) { - assert(Finalized == false && - "We cannot create new nodes after the results have been finalized."); - bool IsNew; ExplodedNode *N = C.Eng.G->getNode(Loc, State, &IsNew); N->addPredecessor(FromN, *C.Eng.G); @@ -570,6 +567,8 @@ ExplodedNode *StmtNodeBuilder::MakeNode(ExplodedNodeSet &Dst, ExplodedNode *BranchNodeBuilder::generateNode(const ProgramState *State, bool branch, ExplodedNode *NodePred) { + assert(Finalized == false && + "We cannot create new nodes after the results have been finalized."); // If the branch has been marked infeasible we should not generate a node. if (!isFeasible(branch))