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_GC_FACTORY_LIST_TRAITS_H
     10 #define MCLD_GC_FACTORY_LIST_TRAITS_H
     11 #ifdef ENABLE_UNITTEST
     12 #include <gtest.h>
     13 #endif
     14 
     15 #include <llvm/ADT/ilist_node.h>
     16 #include <llvm/ADT/ilist.h>
     17 
     18 #include <assert.h>
     19 
     20 namespace mcld
     21 {
     22 
     23 /** \class GCFactoryListTraits
     24  *  \brief GCFactoryListTraits provides trait class for llvm::iplist when
     25  *  the nodes in the list is produced by GCFactory.
     26  */
     27 template<typename DataType>
     28 class GCFactoryListTraits : public llvm::ilist_default_traits<DataType> {
     29 private:
     30   class SentinelNode : public llvm::ilist_node<DataType> {
     31   public:
     32     SentinelNode() : llvm::ilist_node<DataType>() { }
     33   };
     34 
     35 public:
     36   // override the traits provided in llvm::ilist_sentinel_traits since we've
     37   // defined our own sentinel.
     38   DataType *createSentinel() const
     39   { return reinterpret_cast<DataType*>(&mSentinel); }
     40 
     41   static void destroySentinel(DataType*) { }
     42 
     43   DataType *provideInitialHead() const
     44   { return createSentinel(); }
     45 
     46   DataType *ensureHead(DataType*) const
     47   { return createSentinel(); }
     48 
     49   static void noteHead(DataType*, DataType*) { }
     50 
     51   // override the traits provided in llvm::ilist_node_traits since
     52   static DataType *createNode(const DataType &V) {
     53     assert(false && "Only GCFactory knows how to create a node.");
     54   }
     55   static void deleteNode(DataType *V) {
     56     // No action. GCFactory will handle it by itself.
     57   }
     58 
     59 private:
     60   mutable SentinelNode mSentinel;
     61 };
     62 
     63 } // namespace of mcld
     64 
     65 #endif
     66