Added LLVM header notice.
[oota-llvm.git] / include / llvm / SymbolTableListTraits.h
1 //===-- llvm/SymbolTableListTraits.h - Traits for iplist --------*- C++ -*-===//
2 //
3 // This file defines a generic class that is used to implement the automatic
4 // symbol table manipulation that occurs when you put (for example) a named
5 // instruction into a basic block.
6 //
7 // The way that this is implemented is by using a special traits class with the
8 // intrusive list that makes up the list of instructions in a basic block.  When
9 // a new element is added to the list of instructions, the traits class is
10 // notified, allowing the symbol table to be updated.
11 //
12 // This generic class implements the traits class.  It must be generic so that
13 // it can work for all uses it, which include lists of instructions, basic
14 // blocks, arguments, functions, global variables, etc...
15 //
16 //===----------------------------------------------------------------------===//
17
18 #ifndef LLVM_SYMBOLTABLELISTTRAITS_H
19 #define LLVM_SYMBOLTABLELISTTRAITS_H
20
21 template<typename NodeTy> class ilist_iterator;
22 template<typename NodeTy, typename Traits> class iplist;
23 template<typename Ty> struct ilist_traits;
24
25 // ValueSubClass  - The type of objects that I hold
26 // ItemParentType - I call setParent() on all of my "ValueSubclass" items, and
27 //                  this is the value that I pass in.
28 // SymTabType     - This is the class type, whose symtab I insert my
29 //                  ValueSubClass items into.  Most of the time it is
30 //                  ItemParentType, but Instructions have item parents of BB's
31 //                  but symtabtype's of a Function
32 //
33 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
34          typename SubClass=ilist_traits<ValueSubClass> >
35 class SymbolTableListTraits {
36   SymTabClass     *SymTabObject;
37   ItemParentClass *ItemParent;
38 public:
39   SymbolTableListTraits() : SymTabObject(0), ItemParent(0) {}
40
41         SymTabClass *getParent()       { return SymTabObject; }
42   const SymTabClass *getParent() const { return SymTabObject; }
43
44   static ValueSubClass *getPrev(ValueSubClass *V) { return V->getPrev(); }
45   static ValueSubClass *getNext(ValueSubClass *V) { return V->getNext(); }
46   static const ValueSubClass *getPrev(const ValueSubClass *V) {
47     return V->getPrev();
48   }
49   static const ValueSubClass *getNext(const ValueSubClass *V) {
50     return V->getNext();
51   }
52
53   static void setPrev(ValueSubClass *V, ValueSubClass *P) { V->setPrev(P); }
54   static void setNext(ValueSubClass *V, ValueSubClass *N) { V->setNext(N); }
55
56   void addNodeToList(ValueSubClass *V);
57   void removeNodeFromList(ValueSubClass *V);
58   void transferNodesFromList(iplist<ValueSubClass, 
59                              ilist_traits<ValueSubClass> > &L2,
60                              ilist_iterator<ValueSubClass> first,
61                              ilist_iterator<ValueSubClass> last);
62
63 //private:
64   void setItemParent(ItemParentClass *IP) { ItemParent = IP; }//This is private!
65   void setParent(SymTabClass *Parent);  // This is private!
66 };
67
68 #endif