LLVM API Documentation
00001 //===-- llvm/SymbolTableListTraits.h - Traits for iplist --------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source 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 namespace llvm { 00029 00030 template<typename NodeTy> class ilist_iterator; 00031 template<typename NodeTy, typename Traits> class iplist; 00032 template<typename Ty> struct ilist_traits; 00033 00034 // ValueSubClass - The type of objects that I hold 00035 // ItemParentType - I call setParent() on all of my "ValueSubclass" items, and 00036 // this is the value that I pass in. 00037 // SymTabType - This is the class type, whose symtab I insert my 00038 // ValueSubClass items into. Most of the time it is 00039 // ItemParentType, but Instructions have item parents of BB's 00040 // but symtabtype's of a Function 00041 // 00042 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, 00043 typename SubClass=ilist_traits<ValueSubClass> > 00044 class SymbolTableListTraits { 00045 SymTabClass *SymTabObject; 00046 ItemParentClass *ItemParent; 00047 public: 00048 SymbolTableListTraits() : SymTabObject(0), ItemParent(0) {} 00049 00050 SymTabClass *getParent() { return SymTabObject; } 00051 const SymTabClass *getParent() const { return SymTabObject; } 00052 00053 static ValueSubClass *getPrev(ValueSubClass *V) { return V->getPrev(); } 00054 static ValueSubClass *getNext(ValueSubClass *V) { return V->getNext(); } 00055 static const ValueSubClass *getPrev(const ValueSubClass *V) { 00056 return V->getPrev(); 00057 } 00058 static const ValueSubClass *getNext(const ValueSubClass *V) { 00059 return V->getNext(); 00060 } 00061 00062 static void setPrev(ValueSubClass *V, ValueSubClass *P) { V->setPrev(P); } 00063 static void setNext(ValueSubClass *V, ValueSubClass *N) { V->setNext(N); } 00064 00065 void addNodeToList(ValueSubClass *V); 00066 void removeNodeFromList(ValueSubClass *V); 00067 void transferNodesFromList(iplist<ValueSubClass, 00068 ilist_traits<ValueSubClass> > &L2, 00069 ilist_iterator<ValueSubClass> first, 00070 ilist_iterator<ValueSubClass> last); 00071 00072 //private: 00073 void setItemParent(ItemParentClass *IP) { ItemParent = IP; }//This is private! 00074 void setParent(SymTabClass *Parent); // This is private! 00075 }; 00076 00077 } // End llvm namespace 00078 00079 #endif