mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
ADT: Use typedefs for ilist_base and ilist_node_base, NFC
This is a prep commit to minimize changes in a follow-up that is adding a template parameter to ilist_node_base and ilist_base. llvm-svn: 281141
This commit is contained in:
parent
62efe46df3
commit
8080a7d548
@ -19,18 +19,20 @@ namespace llvm {
|
||||
|
||||
/// Implementations of list algorithms using ilist_node_base.
|
||||
class ilist_base {
|
||||
typedef ilist_node_base node_base_type;
|
||||
|
||||
public:
|
||||
static void insertBeforeImpl(ilist_node_base &Next, ilist_node_base &N) {
|
||||
ilist_node_base &Prev = *Next.getPrev();
|
||||
static void insertBeforeImpl(node_base_type &Next, node_base_type &N) {
|
||||
node_base_type &Prev = *Next.getPrev();
|
||||
N.setNext(&Next);
|
||||
N.setPrev(&Prev);
|
||||
Prev.setNext(&N);
|
||||
Next.setPrev(&N);
|
||||
}
|
||||
|
||||
static void removeImpl(ilist_node_base &N) {
|
||||
ilist_node_base *Prev = N.getPrev();
|
||||
ilist_node_base *Next = N.getNext();
|
||||
static void removeImpl(node_base_type &N) {
|
||||
node_base_type *Prev = N.getPrev();
|
||||
node_base_type *Next = N.getNext();
|
||||
Next->setPrev(Prev);
|
||||
Prev->setNext(Next);
|
||||
|
||||
@ -39,9 +41,9 @@ public:
|
||||
N.setNext(nullptr);
|
||||
}
|
||||
|
||||
static void removeRangeImpl(ilist_node_base &First, ilist_node_base &Last) {
|
||||
ilist_node_base *Prev = First.getPrev();
|
||||
ilist_node_base *Final = Last.getPrev();
|
||||
static void removeRangeImpl(node_base_type &First, node_base_type &Last) {
|
||||
node_base_type *Prev = First.getPrev();
|
||||
node_base_type *Final = Last.getPrev();
|
||||
Last.setPrev(Prev);
|
||||
Prev->setNext(&Last);
|
||||
|
||||
@ -50,8 +52,8 @@ public:
|
||||
Final->setNext(nullptr);
|
||||
}
|
||||
|
||||
static void transferBeforeImpl(ilist_node_base &Next, ilist_node_base &First,
|
||||
ilist_node_base &Last) {
|
||||
static void transferBeforeImpl(node_base_type &Next, node_base_type &First,
|
||||
node_base_type &Last) {
|
||||
if (&Next == &Last || &First == &Last)
|
||||
return;
|
||||
|
||||
@ -60,14 +62,14 @@ public:
|
||||
// Check for the most common mistake.
|
||||
"Insertion point can't be one of the transferred nodes");
|
||||
|
||||
ilist_node_base &Final = *Last.getPrev();
|
||||
node_base_type &Final = *Last.getPrev();
|
||||
|
||||
// Detach from old list/position.
|
||||
First.getPrev()->setNext(&Last);
|
||||
Last.setPrev(First.getPrev());
|
||||
|
||||
// Splice [First, Final] into its new list/position.
|
||||
ilist_node_base &Prev = *Next.getPrev();
|
||||
node_base_type &Prev = *Next.getPrev();
|
||||
Final.setNext(&Next);
|
||||
First.setPrev(&Prev);
|
||||
Prev.setNext(&First);
|
||||
|
@ -47,6 +47,7 @@ namespace llvm {
|
||||
/// because the extra semantic is otherwise non-obvious. They are equivalent
|
||||
/// to calling \a std::for_each() on the range to be discarded.
|
||||
template <typename T> class simple_ilist : ilist_base, ilist_node_access {
|
||||
typedef ilist_base list_base_type;
|
||||
ilist_sentinel<T> Sentinel;
|
||||
|
||||
public:
|
||||
@ -120,7 +121,7 @@ public:
|
||||
|
||||
/// Insert a node by reference; never copies.
|
||||
iterator insert(iterator I, reference Node) {
|
||||
ilist_base::insertBefore(*I.getNodePtr(), *this->getNodePtr(&Node));
|
||||
list_base_type::insertBefore(*I.getNodePtr(), *this->getNodePtr(&Node));
|
||||
return iterator(&Node);
|
||||
}
|
||||
|
||||
@ -135,7 +136,7 @@ public:
|
||||
///
|
||||
/// \see \a erase() for removing by iterator.
|
||||
/// \see \a removeAndDispose() if the node should be deleted.
|
||||
void remove(reference N) { ilist_base::remove(*this->getNodePtr(&N)); }
|
||||
void remove(reference N) { list_base_type::remove(*this->getNodePtr(&N)); }
|
||||
|
||||
/// Remove a node by reference and dispose of it.
|
||||
template <class Disposer>
|
||||
@ -158,7 +159,7 @@ public:
|
||||
///
|
||||
/// \see \a eraseAndDispose() if the nodes should be deleted.
|
||||
iterator erase(iterator First, iterator Last) {
|
||||
ilist_base::removeRange(*First.getNodePtr(), *Last.getNodePtr());
|
||||
list_base_type::removeRange(*First.getNodePtr(), *Last.getNodePtr());
|
||||
return Last;
|
||||
}
|
||||
|
||||
@ -201,8 +202,8 @@ public:
|
||||
|
||||
/// Splice in a range of nodes from another list.
|
||||
void splice(iterator I, simple_ilist &, iterator First, iterator Last) {
|
||||
ilist_base::transferBefore(*I.getNodePtr(), *First.getNodePtr(),
|
||||
*Last.getNodePtr());
|
||||
list_base_type::transferBefore(*I.getNodePtr(), *First.getNodePtr(),
|
||||
*Last.getNodePtr());
|
||||
}
|
||||
|
||||
/// Merge in another list.
|
||||
|
@ -14,21 +14,24 @@ using namespace llvm;
|
||||
|
||||
namespace {
|
||||
|
||||
typedef ilist_base list_base_type;
|
||||
typedef ilist_node_base node_base_type;
|
||||
|
||||
TEST(IListBaseTest, insertBeforeImpl) {
|
||||
ilist_node_base S, A, B;
|
||||
node_base_type S, A, B;
|
||||
// [S] <-> [S]
|
||||
S.setPrev(&S);
|
||||
S.setNext(&S);
|
||||
|
||||
// [S] <-> A <-> [S]
|
||||
ilist_base::insertBeforeImpl(S, A);
|
||||
list_base_type::insertBeforeImpl(S, A);
|
||||
EXPECT_EQ(&A, S.getPrev());
|
||||
EXPECT_EQ(&S, A.getPrev());
|
||||
EXPECT_EQ(&A, S.getNext());
|
||||
EXPECT_EQ(&S, A.getNext());
|
||||
|
||||
// [S] <-> A <-> B <-> [S]
|
||||
ilist_base::insertBeforeImpl(S, B);
|
||||
list_base_type::insertBeforeImpl(S, B);
|
||||
EXPECT_EQ(&B, S.getPrev());
|
||||
EXPECT_EQ(&A, B.getPrev());
|
||||
EXPECT_EQ(&S, A.getPrev());
|
||||
@ -38,16 +41,16 @@ TEST(IListBaseTest, insertBeforeImpl) {
|
||||
}
|
||||
|
||||
TEST(IListBaseTest, removeImpl) {
|
||||
ilist_node_base S, A, B;
|
||||
node_base_type S, A, B;
|
||||
|
||||
// [S] <-> A <-> B <-> [S]
|
||||
S.setPrev(&S);
|
||||
S.setNext(&S);
|
||||
ilist_base::insertBeforeImpl(S, A);
|
||||
ilist_base::insertBeforeImpl(S, B);
|
||||
list_base_type::insertBeforeImpl(S, A);
|
||||
list_base_type::insertBeforeImpl(S, B);
|
||||
|
||||
// [S] <-> B <-> [S]
|
||||
ilist_base::removeImpl(A);
|
||||
list_base_type::removeImpl(A);
|
||||
EXPECT_EQ(&B, S.getPrev());
|
||||
EXPECT_EQ(&S, B.getPrev());
|
||||
EXPECT_EQ(&B, S.getNext());
|
||||
@ -56,7 +59,7 @@ TEST(IListBaseTest, removeImpl) {
|
||||
EXPECT_EQ(nullptr, A.getNext());
|
||||
|
||||
// [S] <-> [S]
|
||||
ilist_base::removeImpl(B);
|
||||
list_base_type::removeImpl(B);
|
||||
EXPECT_EQ(&S, S.getPrev());
|
||||
EXPECT_EQ(&S, S.getNext());
|
||||
EXPECT_EQ(nullptr, B.getPrev());
|
||||
@ -64,18 +67,18 @@ TEST(IListBaseTest, removeImpl) {
|
||||
}
|
||||
|
||||
TEST(IListBaseTest, removeRangeImpl) {
|
||||
ilist_node_base S, A, B, C, D;
|
||||
node_base_type S, A, B, C, D;
|
||||
|
||||
// [S] <-> A <-> B <-> C <-> D <-> [S]
|
||||
S.setPrev(&S);
|
||||
S.setNext(&S);
|
||||
ilist_base::insertBeforeImpl(S, A);
|
||||
ilist_base::insertBeforeImpl(S, B);
|
||||
ilist_base::insertBeforeImpl(S, C);
|
||||
ilist_base::insertBeforeImpl(S, D);
|
||||
list_base_type::insertBeforeImpl(S, A);
|
||||
list_base_type::insertBeforeImpl(S, B);
|
||||
list_base_type::insertBeforeImpl(S, C);
|
||||
list_base_type::insertBeforeImpl(S, D);
|
||||
|
||||
// [S] <-> A <-> D <-> [S]
|
||||
ilist_base::removeRangeImpl(B, D);
|
||||
list_base_type::removeRangeImpl(B, D);
|
||||
EXPECT_EQ(&D, S.getPrev());
|
||||
EXPECT_EQ(&A, D.getPrev());
|
||||
EXPECT_EQ(&S, A.getPrev());
|
||||
@ -87,16 +90,16 @@ TEST(IListBaseTest, removeRangeImpl) {
|
||||
}
|
||||
|
||||
TEST(IListBaseTest, removeRangeImplAllButSentinel) {
|
||||
ilist_node_base S, A, B;
|
||||
node_base_type S, A, B;
|
||||
|
||||
// [S] <-> A <-> B <-> [S]
|
||||
S.setPrev(&S);
|
||||
S.setNext(&S);
|
||||
ilist_base::insertBeforeImpl(S, A);
|
||||
ilist_base::insertBeforeImpl(S, B);
|
||||
list_base_type::insertBeforeImpl(S, A);
|
||||
list_base_type::insertBeforeImpl(S, B);
|
||||
|
||||
// [S] <-> [S]
|
||||
ilist_base::removeRangeImpl(A, S);
|
||||
list_base_type::removeRangeImpl(A, S);
|
||||
EXPECT_EQ(&S, S.getPrev());
|
||||
EXPECT_EQ(&S, S.getNext());
|
||||
EXPECT_EQ(nullptr, A.getPrev());
|
||||
@ -104,23 +107,23 @@ TEST(IListBaseTest, removeRangeImplAllButSentinel) {
|
||||
}
|
||||
|
||||
TEST(IListBaseTest, transferBeforeImpl) {
|
||||
ilist_node_base S1, S2, A, B, C, D, E;
|
||||
node_base_type S1, S2, A, B, C, D, E;
|
||||
|
||||
// [S1] <-> A <-> B <-> C <-> [S1]
|
||||
S1.setPrev(&S1);
|
||||
S1.setNext(&S1);
|
||||
ilist_base::insertBeforeImpl(S1, A);
|
||||
ilist_base::insertBeforeImpl(S1, B);
|
||||
ilist_base::insertBeforeImpl(S1, C);
|
||||
list_base_type::insertBeforeImpl(S1, A);
|
||||
list_base_type::insertBeforeImpl(S1, B);
|
||||
list_base_type::insertBeforeImpl(S1, C);
|
||||
|
||||
// [S2] <-> D <-> E <-> [S2]
|
||||
S2.setPrev(&S2);
|
||||
S2.setNext(&S2);
|
||||
ilist_base::insertBeforeImpl(S2, D);
|
||||
ilist_base::insertBeforeImpl(S2, E);
|
||||
list_base_type::insertBeforeImpl(S2, D);
|
||||
list_base_type::insertBeforeImpl(S2, E);
|
||||
|
||||
// [S1] <-> C <-> [S1]
|
||||
ilist_base::transferBeforeImpl(D, A, C);
|
||||
list_base_type::transferBeforeImpl(D, A, C);
|
||||
EXPECT_EQ(&C, S1.getPrev());
|
||||
EXPECT_EQ(&S1, C.getPrev());
|
||||
EXPECT_EQ(&C, S1.getNext());
|
||||
|
Loading…
Reference in New Issue
Block a user