Eliminate multiply of pointer type
[oota-llvm.git] / include / llvm / Analysis / DSGraphTraits.h
1 //===- DataStructureGraph.h - Provide graph classes --------------*- C++ -*--=//
2 //
3 // This file provides GraphTraits specializations for the DataStructure graph
4 // nodes, allowing datastructure graphs to be processed by generic graph
5 // algorithms.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_ANALYSIS_DATASTRUCTURE_GRAPH_H
10 #define LLVM_ANALYSIS_DATASTRUCTURE_GRAPH_H
11
12 #include "llvm/Analysis/DataStructure.h"
13 #include "Support/GraphTraits.h"
14 #include "Support/iterator"
15
16 class DSNodeIterator : public forward_iterator<DSNode, ptrdiff_t> {
17   friend class DSNode;
18   DSNode * const Node;
19   unsigned Link;
20   
21   typedef DSNodeIterator _Self;
22
23   DSNodeIterator(DSNode *N) : Node(N), Link(0) {   // begin iterator
24     unsigned NumLinks = Node->getNumLinks();
25     while (Link < NumLinks && Node->getLink(Link) == 0)
26       ++Link;
27   }
28   DSNodeIterator(DSNode *N, bool)       // Create end iterator
29     : Node(N), Link(N->getNumLinks()) {
30   }
31 public:
32
33   bool operator==(const _Self& x) const {
34     return Link == x.Link;
35   }
36   bool operator!=(const _Self& x) const { return !operator==(x); }
37   
38   pointer operator*() const {
39     return Node->getLink(Link);
40   }
41   pointer operator->() const { return operator*(); }
42   
43   _Self& operator++() {                // Preincrement
44     unsigned NumLinks = Node->getNumLinks();
45     do {
46       ++Link;
47     } while (Link < NumLinks && Node->getLink(Link) != 0);
48     return *this;
49   }
50   _Self operator++(int) { // Postincrement
51     _Self tmp = *this; ++*this; return tmp; 
52   }
53 };
54
55
56 template <> struct GraphTraits<DSNode*> {
57   typedef DSNode NodeType;
58   typedef DSNode::iterator ChildIteratorType;
59
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(); }
63 };
64
65 // Provide iterators for DSNode...
66 inline DSNode::iterator DSNode::begin() { return DSNodeIterator(this); }
67 inline DSNode::iterator DSNode::end()   { return DSNodeIterator(this, false); }
68
69 #endif