mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-14 14:24:05 +00:00
Templatize graph traits and iterator to work with const and non-const clients
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4746 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -14,15 +14,16 @@
|
|||||||
#include "Support/iterator"
|
#include "Support/iterator"
|
||||||
#include "Support/STLExtras.h"
|
#include "Support/STLExtras.h"
|
||||||
|
|
||||||
|
template<typename NodeTy>
|
||||||
class DSNodeIterator : public forward_iterator<const DSNode, ptrdiff_t> {
|
class DSNodeIterator : public forward_iterator<const DSNode, ptrdiff_t> {
|
||||||
friend class DSNode;
|
friend class DSNode;
|
||||||
const DSNode * const Node;
|
NodeTy * const Node;
|
||||||
unsigned Offset;
|
unsigned Offset;
|
||||||
|
|
||||||
typedef DSNodeIterator _Self;
|
typedef DSNodeIterator<NodeTy> _Self;
|
||||||
|
|
||||||
DSNodeIterator(const DSNode *N) : Node(N), Offset(0) {} // begin iterator
|
DSNodeIterator(NodeTy *N) : Node(N), Offset(0) {} // begin iterator
|
||||||
DSNodeIterator(const DSNode *N, bool) // Create end iterator
|
DSNodeIterator(NodeTy *N, bool) // Create end iterator
|
||||||
: Node(N) {
|
: Node(N) {
|
||||||
Offset = (N->getSize()+((1 << DS::PointerShift)-1)) &
|
Offset = (N->getSize()+((1 << DS::PointerShift)-1)) &
|
||||||
~((1 << DS::PointerShift)-1);
|
~((1 << DS::PointerShift)-1);
|
||||||
@ -60,8 +61,18 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Provide iterators for DSNode...
|
// Provide iterators for DSNode...
|
||||||
inline DSNode::iterator DSNode::begin() const { return DSNodeIterator(this); }
|
inline DSNode::iterator DSNode::begin() {
|
||||||
inline DSNode::iterator DSNode::end() const { return DSNodeIterator(this, false); }
|
return DSNode::iterator(this);
|
||||||
|
}
|
||||||
|
inline DSNode::iterator DSNode::end() {
|
||||||
|
return DSNode::iterator(this, false);
|
||||||
|
}
|
||||||
|
inline DSNode::const_iterator DSNode::begin() const {
|
||||||
|
return DSNode::const_iterator(this);
|
||||||
|
}
|
||||||
|
inline DSNode::const_iterator DSNode::end() const {
|
||||||
|
return DSNode::const_iterator(this, false);
|
||||||
|
}
|
||||||
|
|
||||||
template <> struct GraphTraits<DSNode*> {
|
template <> struct GraphTraits<DSNode*> {
|
||||||
typedef DSNode NodeType;
|
typedef DSNode NodeType;
|
||||||
@ -72,6 +83,15 @@ template <> struct GraphTraits<DSNode*> {
|
|||||||
static ChildIteratorType child_end(NodeType *N) { return N->end(); }
|
static ChildIteratorType child_end(NodeType *N) { return N->end(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <> struct GraphTraits<const DSNode*> {
|
||||||
|
typedef const DSNode NodeType;
|
||||||
|
typedef DSNode::const_iterator ChildIteratorType;
|
||||||
|
|
||||||
|
static NodeType *getEntryNode(NodeType *N) { return N; }
|
||||||
|
static ChildIteratorType child_begin(NodeType *N) { return N->begin(); }
|
||||||
|
static ChildIteratorType child_end(NodeType *N) { return N->end(); }
|
||||||
|
};
|
||||||
|
|
||||||
static DSNode &dereference ( DSNode *N) { return *N; }
|
static DSNode &dereference ( DSNode *N) { return *N; }
|
||||||
static const DSNode &dereferenceC(const DSNode *N) { return *N; }
|
static const DSNode &dereferenceC(const DSNode *N) { return *N; }
|
||||||
|
|
||||||
@ -97,7 +117,7 @@ template <> struct GraphTraits<DSGraph*> {
|
|||||||
|
|
||||||
template <> struct GraphTraits<const DSGraph*> {
|
template <> struct GraphTraits<const DSGraph*> {
|
||||||
typedef const DSNode NodeType;
|
typedef const DSNode NodeType;
|
||||||
typedef DSNode::iterator ChildIteratorType;
|
typedef DSNode::const_iterator ChildIteratorType;
|
||||||
|
|
||||||
typedef std::pointer_to_unary_function<const DSNode *,const DSNode&> DerefFun;
|
typedef std::pointer_to_unary_function<const DSNode *,const DSNode&> DerefFun;
|
||||||
|
|
||||||
|
@ -14,15 +14,16 @@
|
|||||||
#include "Support/iterator"
|
#include "Support/iterator"
|
||||||
#include "Support/STLExtras.h"
|
#include "Support/STLExtras.h"
|
||||||
|
|
||||||
|
template<typename NodeTy>
|
||||||
class DSNodeIterator : public forward_iterator<const DSNode, ptrdiff_t> {
|
class DSNodeIterator : public forward_iterator<const DSNode, ptrdiff_t> {
|
||||||
friend class DSNode;
|
friend class DSNode;
|
||||||
const DSNode * const Node;
|
NodeTy * const Node;
|
||||||
unsigned Offset;
|
unsigned Offset;
|
||||||
|
|
||||||
typedef DSNodeIterator _Self;
|
typedef DSNodeIterator<NodeTy> _Self;
|
||||||
|
|
||||||
DSNodeIterator(const DSNode *N) : Node(N), Offset(0) {} // begin iterator
|
DSNodeIterator(NodeTy *N) : Node(N), Offset(0) {} // begin iterator
|
||||||
DSNodeIterator(const DSNode *N, bool) // Create end iterator
|
DSNodeIterator(NodeTy *N, bool) // Create end iterator
|
||||||
: Node(N) {
|
: Node(N) {
|
||||||
Offset = (N->getSize()+((1 << DS::PointerShift)-1)) &
|
Offset = (N->getSize()+((1 << DS::PointerShift)-1)) &
|
||||||
~((1 << DS::PointerShift)-1);
|
~((1 << DS::PointerShift)-1);
|
||||||
@ -60,8 +61,18 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Provide iterators for DSNode...
|
// Provide iterators for DSNode...
|
||||||
inline DSNode::iterator DSNode::begin() const { return DSNodeIterator(this); }
|
inline DSNode::iterator DSNode::begin() {
|
||||||
inline DSNode::iterator DSNode::end() const { return DSNodeIterator(this, false); }
|
return DSNode::iterator(this);
|
||||||
|
}
|
||||||
|
inline DSNode::iterator DSNode::end() {
|
||||||
|
return DSNode::iterator(this, false);
|
||||||
|
}
|
||||||
|
inline DSNode::const_iterator DSNode::begin() const {
|
||||||
|
return DSNode::const_iterator(this);
|
||||||
|
}
|
||||||
|
inline DSNode::const_iterator DSNode::end() const {
|
||||||
|
return DSNode::const_iterator(this, false);
|
||||||
|
}
|
||||||
|
|
||||||
template <> struct GraphTraits<DSNode*> {
|
template <> struct GraphTraits<DSNode*> {
|
||||||
typedef DSNode NodeType;
|
typedef DSNode NodeType;
|
||||||
@ -72,6 +83,15 @@ template <> struct GraphTraits<DSNode*> {
|
|||||||
static ChildIteratorType child_end(NodeType *N) { return N->end(); }
|
static ChildIteratorType child_end(NodeType *N) { return N->end(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <> struct GraphTraits<const DSNode*> {
|
||||||
|
typedef const DSNode NodeType;
|
||||||
|
typedef DSNode::const_iterator ChildIteratorType;
|
||||||
|
|
||||||
|
static NodeType *getEntryNode(NodeType *N) { return N; }
|
||||||
|
static ChildIteratorType child_begin(NodeType *N) { return N->begin(); }
|
||||||
|
static ChildIteratorType child_end(NodeType *N) { return N->end(); }
|
||||||
|
};
|
||||||
|
|
||||||
static DSNode &dereference ( DSNode *N) { return *N; }
|
static DSNode &dereference ( DSNode *N) { return *N; }
|
||||||
static const DSNode &dereferenceC(const DSNode *N) { return *N; }
|
static const DSNode &dereferenceC(const DSNode *N) { return *N; }
|
||||||
|
|
||||||
@ -97,7 +117,7 @@ template <> struct GraphTraits<DSGraph*> {
|
|||||||
|
|
||||||
template <> struct GraphTraits<const DSGraph*> {
|
template <> struct GraphTraits<const DSGraph*> {
|
||||||
typedef const DSNode NodeType;
|
typedef const DSNode NodeType;
|
||||||
typedef DSNode::iterator ChildIteratorType;
|
typedef DSNode::const_iterator ChildIteratorType;
|
||||||
|
|
||||||
typedef std::pointer_to_unary_function<const DSNode *,const DSNode&> DerefFun;
|
typedef std::pointer_to_unary_function<const DSNode *,const DSNode&> DerefFun;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user