1 //===- GCFactoryListTraits.h ----------------------------------------------===// 2 // 3 // The MCLinker Project 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #ifndef MCLD_SUPPORT_GCFACTORYLISTTRAITS_H_ 10 #define MCLD_SUPPORT_GCFACTORYLISTTRAITS_H_ 11 12 #include <llvm/ADT/ilist.h> 13 #include <llvm/ADT/ilist_node.h> 14 15 #include <assert.h> 16 17 namespace mcld { 18 19 /** \class GCFactoryListTraits 20 * \brief GCFactoryListTraits provides trait class for llvm::iplist when 21 * the nodes in the list is produced by GCFactory. 22 */ 23 template <typename DataType> 24 class GCFactoryListTraits : public llvm::ilist_default_traits<DataType> { 25 private: 26 class SentinelNode : public DataType { 27 public: SentinelNode()28 SentinelNode() {} 29 }; 30 31 public: 32 // override the traits provided in llvm::ilist_sentinel_traits since we've 33 // defined our own sentinel. createSentinel()34 DataType* createSentinel() const { 35 return reinterpret_cast<DataType*>(&mSentinel); 36 } 37 destroySentinel(DataType * pData)38 static void destroySentinel(DataType* pData) {} 39 provideInitialHead()40 DataType* provideInitialHead() const { return createSentinel(); } 41 ensureHead(DataType * pData)42 DataType* ensureHead(DataType* pData) const { return createSentinel(); } 43 noteHead(DataType * pNew,DataType * pSentinel)44 static void noteHead(DataType* pNew, DataType* pSentinel) {} 45 46 // override the traits provided in llvm::ilist_node_traits since createNode(const DataType & V)47 static DataType* createNode(const DataType& V) { 48 assert(false && "Only GCFactory knows how to create a node."); 49 } deleteNode(DataType * V)50 static void deleteNode(DataType* V) { 51 // No action. GCFactory will handle it by itself. 52 } 53 54 private: 55 mutable SentinelNode mSentinel; 56 }; 57 58 } // namespace mcld 59 60 #endif // MCLD_SUPPORT_GCFACTORYLISTTRAITS_H_ 61