1fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman//==-- llvm/ADT/ilist_node.h - Intrusive Linked List Helper ------*- C++ -*-==// 23a54b3dc87a581c203b18050b4f787b4ca28a12cMisha Brukman// 3fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman// The LLVM Compiler Infrastructure 4fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman// 5fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman// This file is distributed under the University of Illinois Open Source 6fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman// License. See LICENSE.TXT for details. 73a54b3dc87a581c203b18050b4f787b4ca28a12cMisha Brukman// 8fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman//===----------------------------------------------------------------------===// 9fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman// 10fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman// This file defines the ilist_node class template, which is a convenient 11fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman// base class for creating classes that can be used with ilists. 12fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman// 13fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman//===----------------------------------------------------------------------===// 14fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 15674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#ifndef LLVM_ADT_ILISTNODE_H 16674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#define LLVM_ADT_ILISTNODE_H 17fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 18fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmannamespace llvm { 19fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 20fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmantemplate<typename NodeTy> 212600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greifstruct ilist_traits; 22fd7a918e5890a6c0611ab6b3fca7001d16593844Gabor Greif 232600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greif/// ilist_half_node - Base class that provides prev services for sentinels. 242600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greif/// 25fd7a918e5890a6c0611ab6b3fca7001d16593844Gabor Greiftemplate<typename NodeTy> 262600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greifclass ilist_half_node { 272600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greif friend struct ilist_traits<NodeTy>; 282600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greif NodeTy *Prev; 292600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greifprotected: 302600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greif NodeTy *getPrev() { return Prev; } 312600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greif const NodeTy *getPrev() const { return Prev; } 322600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greif void setPrev(NodeTy *P) { Prev = P; } 332600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greif ilist_half_node() : Prev(0) {} 342600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greif}; 352600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greif 362600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greiftemplate<typename NodeTy> 372600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greifstruct ilist_nextprev_traits; 380a0e68a7eac0513505aff3079e2d5d6864e51895Gabor Greif 39fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman/// ilist_node - Base class that provides next/prev services for nodes 40fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman/// that use ilist_nextprev_traits or ilist_default_traits. 41fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman/// 42fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmantemplate<typename NodeTy> 4359bf4fcc0680e75b408579064d1205a132361196Duncan Sandsclass ilist_node : private ilist_half_node<NodeTy> { 44fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman friend struct ilist_nextprev_traits<NodeTy>; 45a05764c4fb1ff4fc6013dcfd71fc83fb25cdcd27Gabor Greif friend struct ilist_traits<NodeTy>; 462600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greif NodeTy *Next; 47fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman NodeTy *getNext() { return Next; } 48fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman const NodeTy *getNext() const { return Next; } 49fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman void setNext(NodeTy *N) { Next = N; } 50fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanprotected: 512600ca8b3f3602d0904289eeed3d26f3d7aad2aeGabor Greif ilist_node() : Next(0) {} 52aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 53aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbarpublic: 54aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar /// @name Adjacent Node Accessors 55aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar /// @{ 56aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 57aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar /// \brief Get the previous node, or 0 for the list head. 58aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar NodeTy *getPrevNode() { 59aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar NodeTy *Prev = this->getPrev(); 60aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 61aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar // Check for sentinel. 62aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar if (!Prev->getNext()) 63aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar return 0; 64aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 65aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar return Prev; 66aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar } 67aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 68aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar /// \brief Get the previous node, or 0 for the list head. 69aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar const NodeTy *getPrevNode() const { 70f1fd2288f36b58b8979761ba09e2a398c6afd110Daniel Dunbar const NodeTy *Prev = this->getPrev(); 71aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 72aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar // Check for sentinel. 73aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar if (!Prev->getNext()) 74aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar return 0; 75aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 76aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar return Prev; 77aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar } 78aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 79aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar /// \brief Get the next node, or 0 for the list tail. 80aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar NodeTy *getNextNode() { 81aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar NodeTy *Next = getNext(); 82aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 83aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar // Check for sentinel. 84aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar if (!Next->getNext()) 85aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar return 0; 86aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 87aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar return Next; 88aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar } 89aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 90aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar /// \brief Get the next node, or 0 for the list tail. 91aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar const NodeTy *getNextNode() const { 92f1fd2288f36b58b8979761ba09e2a398c6afd110Daniel Dunbar const NodeTy *Next = getNext(); 93aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 94aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar // Check for sentinel. 95aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar if (!Next->getNext()) 96aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar return 0; 97aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 98aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar return Next; 99aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar } 100aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar 101aa81380353a27d9d216cafdd88df08a5eef43b74Daniel Dunbar /// @} 102fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman}; 103fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 104fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman} // End llvm namespace 105fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 106fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman#endif 107