-//===-- llvm/SymbolTableListTraits.h - Traits for iplist -------*- C++ -*--===//
+//===-- llvm/SymbolTableListTraits.h - Traits for iplist --------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
//
// This file defines a generic class that is used to implement the automatic
// symbol table manipulation that occurs when you put (for example) a named
#ifndef LLVM_SYMBOLTABLELISTTRAITS_H
#define LLVM_SYMBOLTABLELISTTRAITS_H
+namespace llvm {
+
template<typename NodeTy> class ilist_iterator;
template<typename NodeTy, typename Traits> class iplist;
template<typename Ty> struct ilist_traits;
-// ValueSubClass - The type of objects that I hold
-// ItemParentType - I call setParent() on all of my "ValueSubclass" items, and
-// this is the value that I pass in.
-// SymTabType - This is the class type, whose symtab I insert my
-// ValueSubClass items into. Most of the time it is
-// ItemParentType, but Instructions have item parents of BB's
-// but symtabtype's of a Function
+// ValueSubClass - The type of objects that I hold, e.g. Instruction.
+// ItemParentType - The type of object that owns the list, e.g. BasicBlock.
+// TraitBaseClass - The class this trait should inherit from, it should
+// inherit from ilist_traits<ValueSubClass>
//
-template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
- typename SubClass=ilist_traits<ValueSubClass> >
+template<typename ValueSubClass, typename ItemParentClass>
class SymbolTableListTraits {
- SymTabClass *SymTabObject;
- ItemParentClass *ItemParent;
+ typedef ilist_traits<ValueSubClass> TraitsClass;
public:
- SymbolTableListTraits() : SymTabObject(0), ItemParent(0) {}
-
- SymTabClass *getParent() { return SymTabObject; }
- const SymTabClass *getParent() const { return SymTabObject; }
+ SymbolTableListTraits() {}
+ /// getListOwner - Return the object that owns this list. If this is a list
+ /// of instructions, it returns the BasicBlock that owns them.
+ ItemParentClass *getListOwner() {
+ return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(this)-
+ TraitsClass::getListOffset());
+ }
static ValueSubClass *getPrev(ValueSubClass *V) { return V->getPrev(); }
static ValueSubClass *getNext(ValueSubClass *V) { return V->getNext(); }
static const ValueSubClass *getPrev(const ValueSubClass *V) {
void addNodeToList(ValueSubClass *V);
void removeNodeFromList(ValueSubClass *V);
- void transferNodesFromList(iplist<ValueSubClass,
+ void transferNodesFromList(iplist<ValueSubClass,
ilist_traits<ValueSubClass> > &L2,
ilist_iterator<ValueSubClass> first,
ilist_iterator<ValueSubClass> last);
-
//private:
- void setItemParent(ItemParentClass *IP) { ItemParent = IP; }//This is private!
- void setParent(SymTabClass *Parent); // This is private!
+ template<typename TPtr>
+ void setSymTabObject(TPtr *, TPtr);
};
+} // End llvm namespace
+
#endif