mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-29 10:25:12 +00:00
ADT: Add ilist_node::get{Prev,Next}Node, which return the adjacent node or null.
- This provides a convenient alternative to using something llvm::prior or manual iterator access, for example:: if (T *Prev = foo->getPrevNode()) ... instead of:: iterator it(foo); if (it != begin()) { --it; ... } - Chris, please review. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103647 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -49,6 +49,56 @@ class ilist_node : private ilist_half_node<NodeTy> {
|
||||
void setNext(NodeTy *N) { Next = N; }
|
||||
protected:
|
||||
ilist_node() : Next(0) {}
|
||||
|
||||
public:
|
||||
/// @name Adjacent Node Accessors
|
||||
/// @{
|
||||
|
||||
/// \brief Get the previous node, or 0 for the list head.
|
||||
NodeTy *getPrevNode() {
|
||||
NodeTy *Prev = this->getPrev();
|
||||
|
||||
// Check for sentinel.
|
||||
if (!Prev->getNext())
|
||||
return 0;
|
||||
|
||||
return Prev;
|
||||
}
|
||||
|
||||
/// \brief Get the previous node, or 0 for the list head.
|
||||
const NodeTy *getPrevNode() const {
|
||||
NodeTy *Prev = this->getPrev();
|
||||
|
||||
// Check for sentinel.
|
||||
if (!Prev->getNext())
|
||||
return 0;
|
||||
|
||||
return Prev;
|
||||
}
|
||||
|
||||
/// \brief Get the next node, or 0 for the list tail.
|
||||
NodeTy *getNextNode() {
|
||||
NodeTy *Next = getNext();
|
||||
|
||||
// Check for sentinel.
|
||||
if (!Next->getNext())
|
||||
return 0;
|
||||
|
||||
return Next;
|
||||
}
|
||||
|
||||
/// \brief Get the next node, or 0 for the list tail.
|
||||
const NodeTy *getNextNode() const {
|
||||
NodeTy *Next = getNext();
|
||||
|
||||
// Check for sentinel.
|
||||
if (!Next->getNext())
|
||||
return 0;
|
||||
|
||||
return Next;
|
||||
}
|
||||
|
||||
/// @}
|
||||
};
|
||||
|
||||
} // End llvm namespace
|
||||
|
Reference in New Issue
Block a user