From: Ted Kremenek Date: Sun, 13 Jan 2008 04:56:13 +0000 (+0000) Subject: Created ExplodedGraph.cpp and moved most method implementations of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9eb49a40df510313132eef147419c5abefff23eb;p=clang Created ExplodedGraph.cpp and moved most method implementations of ExplodedNodeImpl::NodeGroup from being defined inline to being defined "out-of-line" in ExplodedGraph.cpp. This removes a dependence on including in ExplodedGraph.h, and will hopefully result in smaller generated code with negligible performance impact. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45928 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Analysis/ExplodedGraph.cpp b/Analysis/ExplodedGraph.cpp new file mode 100644 index 0000000000..4c9f026532 --- /dev/null +++ b/Analysis/ExplodedGraph.cpp @@ -0,0 +1,70 @@ +//=-- ExplodedGraph.cpp - Local, Path-Sens. "Exploded Graph" -*- C++ -*------=// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the template classes ExplodedNode and ExplodedGraph, +// which represent a path-sensitive, intra-procedural "exploded graph." +// +//===----------------------------------------------------------------------===// + +#include "clang/Analysis/PathSensitive/ExplodedGraph.h" +#include + +using namespace clang; + + +static inline std::vector& getVector(void* P) { + return *reinterpret_cast*>(P); +} + +void ExplodedNodeImpl::NodeGroup::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(getPtr()).push_back(N); +} + +bool ExplodedNodeImpl::NodeGroup::empty() const { + if (getKind() == Size1) + return getNode() ? false : true; + else + return getVector(getPtr()).empty(); +} + +unsigned ExplodedNodeImpl::NodeGroup::size() const { + if (getKind() == Size1) + return getNode() ? 1 : 0; + else + return getVector(getPtr()).size(); +} + +ExplodedNodeImpl** ExplodedNodeImpl::NodeGroup::begin() const { + if (getKind() == Size1) + return (ExplodedNodeImpl**) &P; + else + return const_cast(&*(getVector(getPtr()).begin())); +} + +ExplodedNodeImpl** ExplodedNodeImpl::NodeGroup::end() const { + if (getKind() == Size1) + return ((ExplodedNodeImpl**) &P)+1; + else + return const_cast(&*(getVector(getPtr()).rbegin())+1); +} + +ExplodedNodeImpl::NodeGroup::~NodeGroup() { + if (getKind() == SizeOther) delete &getVector(getPtr()); +} diff --git a/include/clang/Analysis/PathSensitive/ExplodedGraph.h b/include/clang/Analysis/PathSensitive/ExplodedGraph.h index 24bb1cb54f..fbd0a24415 100644 --- a/include/clang/Analysis/PathSensitive/ExplodedGraph.h +++ b/include/clang/Analysis/PathSensitive/ExplodedGraph.h @@ -39,68 +39,23 @@ protected: 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); - } + void* getPtr() const { return reinterpret_cast(P & ~Flags); } + ExplodedNodeImpl* getNode() const; public: NodeGroup() : P(0) {} - ~NodeGroup() { if (getKind() == SizeOther) delete &getVector(); } + ~NodeGroup(); - inline ExplodedNodeImpl** begin() const { - if (getKind() == Size1) - return (ExplodedNodeImpl**) &P; - else - return const_cast(&*(getVector().begin())); - } + inline ExplodedNodeImpl** begin() const; - inline ExplodedNodeImpl** end() const { - if (getKind() == Size1) - return ((ExplodedNodeImpl**) &P)+1; - else - return const_cast(&*(getVector().rbegin())+1); - } + inline ExplodedNodeImpl** end() const; - inline unsigned size() const { - if (getKind() == Size1) - return getNode() ? 1 : 0; - else - return getVector().size(); - } + inline unsigned size() const; - inline bool empty() const { - if (getKind() == Size1) - return getNode() ? false : true; - else - return getVector().empty(); - } + inline bool empty() const; - 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); - } + void addNode(ExplodedNodeImpl* N); };