00001 /* 00002 * See the dyninst/COPYRIGHT file for copyright information. 00003 * 00004 * We provide the Paradyn Tools (below described as "Paradyn") 00005 * on an AS IS basis, and do not warrant its validity or performance. 00006 * We reserve the right to update, modify, or discontinue this 00007 * software at any time. We shall have no obligation to supply such 00008 * updates or modifications or any other form of support to you. 00009 * 00010 * By your use of Paradyn, you understand and agree that we (or any 00011 * other person or entity with proprietary rights in Paradyn) are 00012 * under no obligation to provide either maintenance services, 00013 * update services, notices of latent defects, or correction of 00014 * defects for Paradyn. 00015 * 00016 * This library is free software; you can redistribute it and/or 00017 * modify it under the terms of the GNU Lesser General Public 00018 * License as published by the Free Software Foundation; either 00019 * version 2.1 of the License, or (at your option) any later version. 00020 * 00021 * This library is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00024 * Lesser General Public License for more details. 00025 * 00026 * You should have received a copy of the GNU Lesser General Public 00027 * License along with this library; if not, write to the Free Software 00028 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00029 */ 00030 00031 #if !defined(NODE_H) 00032 #define NODE_H 00033 00034 #include <set> 00035 #include <string> 00036 #include "Annotatable.h" 00037 00038 #include "dyntypes.h" 00039 #include "boost/shared_ptr.hpp" 00040 00041 #if defined(_MSC_VER) 00042 #pragma warning(disable:4251) 00043 #endif 00044 00045 class BPatch_function; 00046 class BPatch_basicBlock; 00047 00048 namespace Dyninst { 00049 00050 class Edge; 00051 class Graph; 00052 class NodeIterator; 00053 class EdgeIterator; 00054 00055 class COMMON_EXPORT Node { 00056 friend class Edge; 00057 friend class Graph; 00058 00059 typedef boost::shared_ptr<Edge> EdgePtr; 00060 typedef boost::shared_ptr<Graph> GraphPtr; 00061 typedef std::set<EdgePtr> EdgeSet; 00062 00063 public: 00064 typedef boost::shared_ptr<Node> Ptr; 00065 00066 void ins(EdgeIterator &begin, EdgeIterator &end); 00067 void outs(EdgeIterator &begin, EdgeIterator &end); 00068 00069 void ins(NodeIterator &begin, NodeIterator &end); 00070 void outs(NodeIterator &begin, NodeIterator &end); 00071 00072 bool hasInEdges(); 00073 bool hasOutEdges(); 00074 00075 void deleteInEdge(EdgeIterator e); 00076 void deleteOutEdge(EdgeIterator e); 00077 00078 void forwardClosure(NodeIterator &begin, NodeIterator &end); 00079 void backwardClosure(NodeIterator &begin, NodeIterator &end); 00080 00081 GraphPtr forwardSubgraph(); 00082 GraphPtr backwardSubgraph(); 00083 00084 virtual Address addr() const { return INVALID_ADDR; } 00085 00086 virtual std::string format() const = 0; 00087 00088 virtual Node::Ptr copy() = 0; 00089 00090 virtual bool isVirtual() const = 0; 00091 00092 virtual ~Node() {}; 00093 00094 // DOT output methods... 00095 virtual std::string DOTshape() const; 00096 virtual std::string DOTrank() const; 00097 virtual std::string DOTname() const; 00098 virtual bool DOTinclude() const { return true; } 00099 00100 protected: 00101 Node() {}; 00102 00103 EdgeSet ins_; 00104 EdgeSet outs_; 00105 00106 void addInEdge(const EdgePtr in); 00107 void addOutEdge(const EdgePtr out); 00108 00109 static const Address INVALID_ADDR; 00110 }; 00111 00112 class COMMON_EXPORT PhysicalNode : public Node { 00113 public: 00114 typedef boost::shared_ptr<PhysicalNode> Ptr; 00115 00116 static Node::Ptr createNode(Address addr); 00117 00118 virtual Address addr() const { return addr_; } 00119 00120 virtual std::string format() const; 00121 00122 virtual bool isVirtual() const { return false; } 00123 00124 virtual ~PhysicalNode() {}; 00125 00126 virtual Node::Ptr copy(); 00127 00128 protected: 00129 PhysicalNode(Address addr) : addr_(addr) {}; 00130 00131 Address addr_; 00132 }; 00133 00134 class COMMON_EXPORT VirtualNode : public Node { 00135 friend class Edge; 00136 friend class Graph; 00137 00138 public: 00139 typedef boost::shared_ptr<VirtualNode> Ptr; 00140 00141 static Node::Ptr createNode(); 00142 static Node::Ptr createNode(std::string name); 00143 00144 virtual std::string format() const; 00145 virtual Node::Ptr copy(); 00146 00147 virtual bool isVirtual() const { return true; } 00148 00149 virtual ~VirtualNode() {}; 00150 00151 VirtualNode(std::string name) : name_(name) {}; 00152 VirtualNode() : name_(defaultName) {}; 00153 00154 static std::string defaultName; 00155 00156 // DOT output methods... 00157 virtual std::string DOTshape() const; 00158 private: 00159 std::string name_; 00160 }; 00161 00162 class NodeIteratorImpl; 00163 00164 class COMMON_EXPORT NodeIterator { 00165 friend class Node; 00166 friend class Graph; 00167 friend class Edge; 00168 00169 public: 00170 00171 NodeIterator &operator++(); 00172 NodeIterator operator++(int); 00173 00174 NodeIterator &operator--(); 00175 NodeIterator operator--(int); 00176 00177 Node::Ptr operator*() const; 00178 00179 bool operator==(const NodeIterator &rhs) const; 00180 bool operator!=(const NodeIterator &rhs) const; 00181 00182 NodeIterator &operator=(const NodeIterator &rhs); 00183 00184 00185 // For code such as: 00186 // NodeIterator begin, end; 00187 // graph->entryNodes(begin, end); 00188 NodeIterator(); 00189 00190 // Main constructor 00191 // The iter parameter becomes owned by the iterator and will be destroyed 00192 // when the iterator is destroyed. 00193 NodeIterator(NodeIteratorImpl *iter); 00194 00195 // Aaaand let's _really_ not forget the copy constructor 00196 NodeIterator(const NodeIterator &rhs); 00197 00198 ~NodeIterator(); 00199 00200 protected: 00201 00202 // We hide the internal iteration behavior behind a pointer. 00203 // This allows us to override (yay for virtual functions). 00204 NodeIteratorImpl *iter_; 00205 00206 NodeIteratorImpl *copy() const; 00207 00208 }; 00209 00210 } 00211 #endif
1.6.1