00001 00016 //*************************************************************************** 00017 00018 //--------------------------------------------------------------------------- 00019 00020 #ifndef OA_DomTree_H 00021 #define OA_DomTree_H 00022 00023 //--------------------------------------------------------------------------- 00024 00025 #include <iostream> 00026 00027 // STL headers 00028 #include <set> 00029 #include <map> 00030 00031 // OpenAnalysis headers 00032 #include <OpenAnalysis/Utils/Tree.hpp> 00033 #include <OpenAnalysis/Utils/DGraph/DGraphInterface.hpp> 00034 00035 //--------------------------------------------------------------------------- 00036 00037 namespace OA { 00038 00039 //--------------------------------------------------------------------------- 00040 class DomTree : public Tree 00041 { 00042 public: 00043 class DomFrontIterator; 00044 00045 //------------------------------------------------------------------------- 00046 class Node : public Tree::Node { 00047 public: 00048 Node(OA_ptr<DGraph::NodeInterface> n) : Tree::Node() 00049 { graph_node_ptr = n; } 00050 ~Node() {} 00051 OA_ptr<DGraph::NodeInterface> getGraphNode() { return graph_node_ptr; } 00052 00053 OA_ptr<DomFrontIterator> getDomFrontIterator() { 00054 OA_ptr<DomFrontIterator> it; it = new DomFrontIterator(*this); 00055 return it; 00056 } 00057 00058 // included here to return subclass node type, avoids convert 00059 // calls in code that uses this 00060 OA_ptr<Node> parent () const { 00061 OA_ptr<Tree::Node> n = Tree::Node::parent(); 00062 if (n.ptrEqual(0)) { 00063 OA_ptr<Node> n; // convert() dies on NULL pointers! 00064 return n; 00065 } 00066 else { 00067 return n.convert<Node>(); 00068 } 00069 } 00070 00071 void dump(std::ostream& os); 00072 00073 private: 00074 typedef std::set<OA_ptr<Node> > DomFrontSet; 00075 00076 OA_ptr<DGraph::NodeInterface> graph_node_ptr; 00077 DomFrontSet dom_front; 00078 friend class DomTree; 00079 friend class DomTree::DomFrontIterator; 00080 }; 00081 00082 //------------------------------------------------------------------------- 00083 class DomFrontIterator : public Iterator { 00084 public: 00085 DomFrontIterator(Node& n) 00086 : Iterator(), mDomFrontSet(n.dom_front), mIter(mDomFrontSet.begin()) { } 00087 ~DomFrontIterator() { } 00088 00089 OA_ptr<Node> current() const { return *mIter; } 00090 void operator++() { ++mIter; } 00091 bool isValid() const { return (mIter != mDomFrontSet.end()); } 00092 void reset() { mIter = mDomFrontSet.begin(); } 00093 00094 private: 00095 std::set<OA_ptr<Node> >& mDomFrontSet; 00096 std::set<OA_ptr<Node> >::iterator mIter; 00097 }; 00098 //------------------------------------------------------------------------- 00099 00100 public: 00101 DomTree(OA_ptr<DGraph::DGraphInterface> graph); 00102 ~DomTree() {} 00103 00104 OA_ptr<Node> domtree_node(OA_ptr<DGraph::NodeInterface> n) 00105 { return dom_tree_node[n]; } 00106 void compute_dominance_frontiers(); 00107 void dump(std::ostream& os); 00108 00109 private: 00110 OA_ptr<DGraph::DGraphInterface> graph; 00111 std::map<OA_ptr<DGraph::NodeInterface>, OA_ptr<Node> > dom_tree_node; 00112 }; 00113 //--------------------------------------------------------------------------- 00114 00115 } // end of namespace OA 00116 00117 #endif
1.7.1