forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADT: Explode include/llvm/ADT/{ilist,ilist_node}.h, NFC
I'm working on a lower-level intrusive list that can be used stand-alone, and splitting the files up a bit will make the code easier to organize. Explode the ilist headers in advance to improve blame lists in the future. - Move ilist_node_base from ilist_node.h to ilist_node_base.h. - Move ilist_base from ilist.h to ilist_base.h. - Move ilist_iterator from ilist.h to ilist_iterator.h. - Move ilist_node_access from ilist.h to ilist_node.h to support ilist_iterator. - Update unit tests to #include smaller headers. - Clang-format the moved things. I noticed in transit that there is a simplify_type specialization for ilist_iterator. Since there is no longer an implicit conversion from ilist<T>::iterator to T*, this doesn't make sense (effectively it's a form of implicit conversion). For now I've added a FIXME. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280047 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
1 parent
ff612bc
commit e86c615
Showing
7 changed files
with
330 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//===- llvm/ADT/ilist_base.h - Intrusive List Base ---------------*- C++ -*-==// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_ADT_ILIST_BASE_H | ||
#define LLVM_ADT_ILIST_BASE_H | ||
|
||
#include "llvm/ADT/ilist_node_base.h" | ||
#include <cassert> | ||
#include <cstddef> | ||
#include <type_traits> | ||
|
||
namespace llvm { | ||
|
||
/// Implementations of list algorithms using ilist_node_base. | ||
class ilist_base { | ||
public: | ||
static void insertBeforeImpl(ilist_node_base &Next, ilist_node_base &N) { | ||
ilist_node_base &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(); | ||
Next->setPrev(Prev); | ||
Prev->setNext(Next); | ||
|
||
// Not strictly necessary, but helps catch a class of bugs. | ||
N.setPrev(nullptr); | ||
N.setNext(nullptr); | ||
} | ||
|
||
static void transferBeforeImpl(ilist_node_base &Next, ilist_node_base &First, | ||
ilist_node_base &Last) { | ||
assert(&Next != &Last && "Should be checked by callers"); | ||
assert(&First != &Last && "Should be checked by callers"); | ||
// Position cannot be contained in the range to be transferred. | ||
assert(&Next != &First && | ||
// Check for the most common mistake. | ||
"Insertion point can't be one of the transferred nodes"); | ||
|
||
ilist_node_base &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(); | ||
Final.setNext(&Next); | ||
First.setPrev(&Prev); | ||
Prev.setNext(&First); | ||
Next.setPrev(&Final); | ||
} | ||
|
||
template <class T> static void insertBefore(T &Next, T &N) { | ||
insertBeforeImpl(Next, N); | ||
} | ||
|
||
template <class T> static void remove(T &N) { removeImpl(N); } | ||
|
||
template <class T> static void transferBefore(T &Next, T &First, T &Last) { | ||
transferBeforeImpl(Next, First, Last); | ||
} | ||
}; | ||
|
||
} // end namespace llvm | ||
|
||
#endif // LLVM_ADT_ILIST_BASE_H |
Oops, something went wrong.