1 //===-- llvm/SymbolTableListTraits.h - Traits for iplist -------*- C++ -*--===//
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.
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.
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...
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_SYMBOLTABLELISTTRAITS_H
19 #define LLVM_SYMBOLTABLELISTTRAITS_H
21 template<typename NodeTy> class ilist_iterator;
22 template<typename NodeTy, typename Traits> class iplist;
23 template<typename Ty> struct ilist_traits;
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
33 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
34 typename SubClass=ilist_traits<ValueSubClass> >
35 class SymbolTableListTraits {
36 SymTabClass *SymTabObject;
37 ItemParentClass *ItemParent;
39 SymbolTableListTraits() : SymTabObject(0), ItemParent(0) {}
41 SymTabClass *getParent() { return SymTabObject; }
42 const SymTabClass *getParent() const { return SymTabObject; }
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) {
49 static const ValueSubClass *getNext(const ValueSubClass *V) {
53 static void setPrev(ValueSubClass *V, ValueSubClass *P) { V->setPrev(P); }
54 static void setNext(ValueSubClass *V, ValueSubClass *N) { V->setNext(N); }
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);
64 void setItemParent(ItemParentClass *IP) { ItemParent = IP; }//This is private!
65 void setParent(SymTabClass *Parent); // This is private!