GCFactoryListTraits.h revision 37b74a387bb3993387029859c2d9d051c41c724e
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 17namespace 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 */ 23template <typename DataType> 24class GCFactoryListTraits : public llvm::ilist_default_traits<DataType> { 25 private: 26 class SentinelNode : public DataType { 27 public: 28 SentinelNode() {} 29 }; 30 31 public: 32 // override the traits provided in llvm::ilist_sentinel_traits since we've 33 // defined our own sentinel. 34 DataType* createSentinel() const { 35 return reinterpret_cast<DataType*>(&mSentinel); 36 } 37 38 static void destroySentinel(DataType* pData) {} 39 40 DataType* provideInitialHead() const { return createSentinel(); } 41 42 DataType* ensureHead(DataType* pData) const { return createSentinel(); } 43 44 static void noteHead(DataType* pNew, DataType* pSentinel) {} 45 46 // override the traits provided in llvm::ilist_node_traits since 47 static DataType* createNode(const DataType& V) { 48 assert(false && "Only GCFactory knows how to create a node."); 49 } 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