diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-01-13 04:20:10 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-01-13 04:20:10 +0000 |
commit | 4c4cb527a44037d076da82ad9d12b4e655e64dbb (patch) | |
tree | de821da8515356b771dc44e2cb18678389456166 /include/clang/Analysis/PathSensitive/ExplodedGraph.h | |
parent | 37d887c6c8e3c653fc581183d012a646d1653f57 (diff) |
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
Diffstat (limited to 'include/clang/Analysis/PathSensitive/ExplodedGraph.h')
-rw-r--r-- | include/clang/Analysis/PathSensitive/ExplodedGraph.h | 151 |
1 files changed, 72 insertions, 79 deletions
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<ExplodedNodeImpl*>& getVector() { - assert (getKind() == SizeOther); - return *reinterpret_cast<std::vector<ExplodedNodeImpl*>*>(P & ~Flags); - } - const std::vector<ExplodedNodeImpl*>& getVector() const { - assert (getKind() == SizeOther); - return *reinterpret_cast<std::vector<ExplodedNodeImpl*>*>(P & ~Flags); - } - - ExplodedNodeImpl* getNode() const { - assert (getKind() == Size1); - return reinterpret_cast<ExplodedNodeImpl*>(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<ExplodedNodeImpl**>(&*(getVector().begin())); - } - - inline ExplodedNodeImpl** end() const { - if (getKind() == Size1) - return ((ExplodedNodeImpl**) &P)+1; - else - return const_cast<ExplodedNodeImpl**>(&*(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<ExplodedNodeImpl*>* V = new std::vector<ExplodedNodeImpl*>(); - V->push_back(NOld); - V->push_back(N); - P = reinterpret_cast<uintptr_t>(V) & SizeOther; - } - else - P = reinterpret_cast<uintptr_t>(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<ExplodedNodeImpl*>& getVector() { + assert (getKind() == SizeOther); + return *reinterpret_cast<std::vector<ExplodedNodeImpl*>*>(P & ~Flags); + } + const std::vector<ExplodedNodeImpl*>& getVector() const { + assert (getKind() == SizeOther); + return *reinterpret_cast<std::vector<ExplodedNodeImpl*>*>(P & ~Flags); + } + + ExplodedNodeImpl* getNode() const { + assert (getKind() == Size1); + return reinterpret_cast<ExplodedNodeImpl*>(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<ExplodedNodeImpl**>(&*(getVector().begin())); + } + + inline ExplodedNodeImpl** end() const { + if (getKind() == Size1) + return ((ExplodedNodeImpl**) &P)+1; + else + return const_cast<ExplodedNodeImpl**>(&*(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<ExplodedNodeImpl*>* V = new std::vector<ExplodedNodeImpl*>(); + V->push_back(NOld); + V->push_back(N); + P = reinterpret_cast<uintptr_t>(V) & SizeOther; + } + else + P = reinterpret_cast<uintptr_t>(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) |