Home | History | Annotate | Download | only in Support
      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_node.h>
     13 #include <llvm/ADT/ilist.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 {
     26 private:
     27   class SentinelNode : public DataType
     28   {
     29   public:
     30     SentinelNode() { }
     31   };
     32 
     33 public:
     34   // override the traits provided in llvm::ilist_sentinel_traits since we've
     35   // defined our own sentinel.
     36   DataType *createSentinel() const
     37   { return reinterpret_cast<DataType*>(&mSentinel); }
     38 
     39   static void destroySentinel(DataType*) { }
     40 
     41   DataType *provideInitialHead() const
     42   { return createSentinel(); }
     43 
     44   DataType *ensureHead(DataType*) const
     45   { return createSentinel(); }
     46 
     47   static void noteHead(DataType*, DataType*) { }
     48 
     49   // override the traits provided in llvm::ilist_node_traits since
     50   static DataType *createNode(const DataType &V) {
     51     assert(false && "Only GCFactory knows how to create a node.");
     52   }
     53   static void deleteNode(DataType *V) {
     54     // No action. GCFactory will handle it by itself.
     55   }
     56 
     57 private:
     58   mutable SentinelNode mSentinel;
     59 };
     60 
     61 } // namespace of mcld
     62 
     63 #endif
     64