1 //===- DataStructureGraph.h - Provide graph classes --------------*- C++ -*--=//
3 // This file provides GraphTraits specializations for the DataStructure graph
4 // nodes, allowing datastructure graphs to be processed by generic graph
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_ANALYSIS_DATASTRUCTURE_GRAPH_H
10 #define LLVM_ANALYSIS_DATASTRUCTURE_GRAPH_H
12 #include "llvm/Analysis/DataStructure.h"
13 #include "Support/GraphTraits.h"
14 #include "Support/iterator"
16 class DSNodeIterator : public forward_iterator<DSNode, ptrdiff_t> {
21 typedef DSNodeIterator _Self;
23 DSNodeIterator(DSNode *N) : Node(N), Link(0) { // begin iterator
24 unsigned NumLinks = Node->getNumLinks();
25 while (Link < NumLinks && Node->getLink(Link) == 0)
28 DSNodeIterator(DSNode *N, bool) // Create end iterator
29 : Node(N), Link(N->getNumLinks()) {
33 bool operator==(const _Self& x) const {
34 return Link == x.Link;
36 bool operator!=(const _Self& x) const { return !operator==(x); }
38 pointer operator*() const {
39 return Node->getLink(Link);
41 pointer operator->() const { return operator*(); }
43 _Self& operator++() { // Preincrement
44 unsigned NumLinks = Node->getNumLinks();
47 } while (Link < NumLinks && Node->getLink(Link) != 0);
50 _Self operator++(int) { // Postincrement
51 _Self tmp = *this; ++*this; return tmp;
56 template <> struct GraphTraits<DSNode*> {
57 typedef DSNode NodeType;
58 typedef DSNode::iterator ChildIteratorType;
60 static NodeType *getEntryNode(DSNode *N) { return N; }
61 static ChildIteratorType child_begin(NodeType *N) { return N->begin(); }
62 static ChildIteratorType child_end(NodeType *N) { return N->end(); }
65 // Provide iterators for DSNode...
66 inline DSNode::iterator DSNode::begin() { return DSNodeIterator(this); }
67 inline DSNode::iterator DSNode::end() { return DSNodeIterator(this, false); }