aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Analysis/DataStructureGraph.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-03-31 07:11:20 +0000
committerChris Lattner <sabre@nondot.org>2002-03-31 07:11:20 +0000
commit41deedf32fca64f806e4ba812bc364cfa1671fc4 (patch)
treeb133cab6f2efe39aa324e5d31e2859229f6420e2 /include/llvm/Analysis/DataStructureGraph.h
parentf7cedec1f2c6a8b054e54f98922d5d295d086cff (diff)
* Allow access to DSNode iterator as DSNode::iterator/begin/end
* Add debugging "dump" method to DSNode * Fix bugs in DSNode iterator git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2060 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Analysis/DataStructureGraph.h')
-rw-r--r--include/llvm/Analysis/DataStructureGraph.h29
1 files changed, 18 insertions, 11 deletions
diff --git a/include/llvm/Analysis/DataStructureGraph.h b/include/llvm/Analysis/DataStructureGraph.h
index 6798969750..3b6ff744c7 100644
--- a/include/llvm/Analysis/DataStructureGraph.h
+++ b/include/llvm/Analysis/DataStructureGraph.h
@@ -11,19 +11,24 @@
#include "Support/GraphTraits.h"
#include "llvm/Analysis/DataStructure.h"
-#include "llvm/Value.h" // FIXME: Move cast/dyn_cast out to Support
class DSNodeIterator : public std::forward_iterator<DSNode, ptrdiff_t> {
+ friend class DSNode;
DSNode * const Node;
unsigned Link;
unsigned LinkIdx;
typedef DSNodeIterator _Self;
-public:
- DSNodeIterator(DSNode *N) : Node(N), Link(0), LinkIdx(0) {} // begin iterator
+
+ DSNodeIterator(DSNode *N) : Node(N), Link(0), LinkIdx(0) { // begin iterator
+ unsigned NumLinks = Node->getNumOutgoingLinks();
+ while (Link < NumLinks && Node->getOutgoingLink(Link).empty())
+ ++Link;
+ }
DSNodeIterator(DSNode *N, bool) // Create end iterator
: Node(N), Link(N->getNumOutgoingLinks()), LinkIdx(0) {
}
+public:
bool operator==(const _Self& x) const {
return Link == x.Link && LinkIdx == x.LinkIdx;
@@ -39,7 +44,10 @@ public:
if (LinkIdx < Node->getOutgoingLink(Link).size()-1)
++LinkIdx;
else {
- ++Link;
+ unsigned NumLinks = Node->getNumOutgoingLinks();
+ do {
+ ++Link;
+ } while (Link < NumLinks && Node->getOutgoingLink(Link).empty());
LinkIdx = 0;
}
return *this;
@@ -52,16 +60,15 @@ public:
template <> struct GraphTraits<DSNode*> {
typedef DSNode NodeType;
- typedef DSNodeIterator ChildIteratorType;
+ typedef DSNode::iterator ChildIteratorType;
static NodeType *getEntryNode(DSNode *N) { return N; }
- static ChildIteratorType child_begin(NodeType *N) {
- return DSNodeIterator(N);
- }
- static ChildIteratorType child_end(NodeType *N) {
- return DSNodeIterator(N, true);
- }
+ static ChildIteratorType child_begin(NodeType *N) { return N->begin(); }
+ static ChildIteratorType child_end(NodeType *N) { return N->end(); }
};
+// Provide iterators for DSNode...
+inline DSNode::iterator DSNode::begin() { return DSNodeIterator(this); }
+inline DSNode::iterator DSNode::end() { return DSNodeIterator(this, false); }
#endif