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