From: Ted Kremenek Date: Sun, 13 Jan 2008 04:20:10 +0000 (+0000) Subject: Moved 'ExplodedNodeGroup' into class 'ExplodedNode' as the nested class X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c4cb527a44037d076da82ad9d12b4e655e64dbb;p=clang Moved 'ExplodedNodeGroup' into class 'ExplodedNode' as the nested class 'NodeGroup.' git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45927 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/PathSensitive/ExplodedGraph.h b/include/clang/Analysis/PathSensitive/ExplodedGraph.h index b9d45f0fd5..24bb1cb54f 100644 --- a/include/clang/Analysis/PathSensitive/ExplodedGraph.h +++ b/include/clang/Analysis/PathSensitive/ExplodedGraph.h @@ -29,88 +29,81 @@ namespace clang { class GREngineImpl; class ExplodedNodeImpl; - -/// ExplodedNodeGroup - A utility class used to represent the set of successor -/// and predecessor nodes of a node. Most nodes will have only 1 successor -/// and 1 predecessor, so class allows us to store such unit sets of nodes -/// using a single pointer without allocating an entire vector. For -/// larger sets of nodes, we dynamically allocate a vector. This class -/// will likely be revised in the future to further improve performance and -/// to reduce memory footprint. -class ExplodedNodeGroup { - enum { Size1 = 0x0, SizeOther = 0x1, Flags = 0x1 }; - uintptr_t P; - - unsigned getKind() const { return P & Flags; } - - std::vector& getVector() { - assert (getKind() == SizeOther); - return *reinterpret_cast*>(P & ~Flags); - } - const std::vector& getVector() const { - assert (getKind() == SizeOther); - return *reinterpret_cast*>(P & ~Flags); - } - - ExplodedNodeImpl* getNode() const { - assert (getKind() == Size1); - return reinterpret_cast(P); - } - -public: - ExplodedNodeGroup() : P(0) {} - - ~ExplodedNodeGroup() { if (getKind() == SizeOther) delete &getVector(); } - - inline ExplodedNodeImpl** begin() const { - if (getKind() == Size1) - return (ExplodedNodeImpl**) &P; - else - return const_cast(&*(getVector().begin())); - } - - inline ExplodedNodeImpl** end() const { - if (getKind() == Size1) - return ((ExplodedNodeImpl**) &P)+1; - else - return const_cast(&*(getVector().rbegin())+1); - } - - inline unsigned size() const { - if (getKind() == Size1) - return getNode() ? 1 : 0; - else - return getVector().size(); - } - - inline bool empty() const { - if (getKind() == Size1) - return getNode() ? false : true; - else - return getVector().empty(); - } - - inline void addNode(ExplodedNodeImpl* N) { - if (getKind() == Size1) { - if (ExplodedNodeImpl* NOld = getNode()) { - std::vector* V = new std::vector(); - V->push_back(NOld); - V->push_back(N); - P = reinterpret_cast(V) & SizeOther; - } - else - P = reinterpret_cast(N); - } - else - getVector().push_back(N); - } -}; -/// ExplodedNodeImpl - class ExplodedNodeImpl : public llvm::FoldingSetNode { protected: friend class ExplodedGraphImpl; + class NodeGroup { + enum { Size1 = 0x0, SizeOther = 0x1, Flags = 0x1 }; + uintptr_t P; + + unsigned getKind() const { return P & Flags; } + + std::vector& getVector() { + assert (getKind() == SizeOther); + return *reinterpret_cast*>(P & ~Flags); + } + const std::vector& getVector() const { + assert (getKind() == SizeOther); + return *reinterpret_cast*>(P & ~Flags); + } + + ExplodedNodeImpl* getNode() const { + assert (getKind() == Size1); + return reinterpret_cast(P); + } + + public: + NodeGroup() : P(0) {} + + ~NodeGroup() { if (getKind() == SizeOther) delete &getVector(); } + + inline ExplodedNodeImpl** begin() const { + if (getKind() == Size1) + return (ExplodedNodeImpl**) &P; + else + return const_cast(&*(getVector().begin())); + } + + inline ExplodedNodeImpl** end() const { + if (getKind() == Size1) + return ((ExplodedNodeImpl**) &P)+1; + else + return const_cast(&*(getVector().rbegin())+1); + } + + inline unsigned size() const { + if (getKind() == Size1) + return getNode() ? 1 : 0; + else + return getVector().size(); + } + + inline bool empty() const { + if (getKind() == Size1) + return getNode() ? false : true; + else + return getVector().empty(); + } + + inline void addNode(ExplodedNodeImpl* N) { + if (getKind() == Size1) { + if (ExplodedNodeImpl* NOld = getNode()) { + std::vector* V = new std::vector(); + V->push_back(NOld); + V->push_back(N); + P = reinterpret_cast(V) & SizeOther; + } + else + P = reinterpret_cast(N); + } + else + getVector().push_back(N); + } + }; + + /// Location - The program location (within a function body) associated /// with this node. const ProgramPoint Location; @@ -121,10 +114,10 @@ protected: void* State; /// Preds - The predecessors of this node. - ExplodedNodeGroup Preds; + NodeGroup Preds; /// Succs - The successors of this node. - ExplodedNodeGroup Succs; + NodeGroup Succs; /// Construct a ExplodedNodeImpl with the provided location and state. explicit ExplodedNodeImpl(const ProgramPoint& loc, void* state)