LLVM API Documentation

SymbolTableListTraits.h

Go to the documentation of this file.
00001 //===-- llvm/SymbolTableListTraits.h - Traits for iplist --------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines a generic class that is used to implement the automatic
00011 // symbol table manipulation that occurs when you put (for example) a named
00012 // instruction into a basic block.
00013 //
00014 // The way that this is implemented is by using a special traits class with the
00015 // intrusive list that makes up the list of instructions in a basic block.  When
00016 // a new element is added to the list of instructions, the traits class is
00017 // notified, allowing the symbol table to be updated.
00018 //
00019 // This generic class implements the traits class.  It must be generic so that
00020 // it can work for all uses it, which include lists of instructions, basic
00021 // blocks, arguments, functions, global variables, etc...
00022 //
00023 //===----------------------------------------------------------------------===//
00024 
00025 #ifndef LLVM_SYMBOLTABLELISTTRAITS_H
00026 #define LLVM_SYMBOLTABLELISTTRAITS_H
00027 
00028 #include "llvm/ADT/ilist.h"
00029 
00030 namespace llvm {
00031 
00032 template<typename NodeTy> class ilist_iterator;
00033 template<typename NodeTy, typename Traits> class iplist;
00034 template<typename Ty> struct ilist_traits;
00035 
00036 // ValueSubClass  - The type of objects that I hold, e.g. Instruction.
00037 // ItemParentType - The type of object that owns the list, e.g. BasicBlock.
00038 // TraitBaseClass - The class this trait should inherit from, it should
00039 //                  inherit from ilist_traits<ValueSubClass>
00040 //
00041 template<typename ValueSubClass, typename ItemParentClass>
00042 class SymbolTableListTraits : public ilist_default_traits<ValueSubClass> {
00043   typedef ilist_traits<ValueSubClass> TraitsClass;
00044 public:
00045   SymbolTableListTraits() {}
00046 
00047   /// getListOwner - Return the object that owns this list.  If this is a list
00048   /// of instructions, it returns the BasicBlock that owns them.
00049   ItemParentClass *getListOwner() {
00050     return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(this)-
00051                                               TraitsClass::getListOffset());
00052   }
00053 
00054   void deleteNode(ValueSubClass *V) {
00055     delete V;
00056   }
00057 
00058   void addNodeToList(ValueSubClass *V);
00059   void removeNodeFromList(ValueSubClass *V);
00060   void transferNodesFromList(ilist_traits<ValueSubClass> &L2,
00061                              ilist_iterator<ValueSubClass> first,
00062                              ilist_iterator<ValueSubClass> last);
00063 //private:
00064   template<typename TPtr>
00065   void setSymTabObject(TPtr *, TPtr);
00066 };
00067 
00068 } // End llvm namespace
00069 
00070 #endif