X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSymbolTableListTraits.h;h=91a4eb99ff0d368c489c7b0d9ff50829b93bf08a;hb=9da42434301d77f4f1ebf976943f836ec34c18da;hp=633fe6d821f83c6a8d1455d8bfae1b575d3dafc1;hpb=48486893f46d2e12e926682a3ecb908716bc66c4;p=oota-llvm.git diff --git a/include/llvm/SymbolTableListTraits.h b/include/llvm/SymbolTableListTraits.h index 633fe6d821f..91a4eb99ff0 100644 --- a/include/llvm/SymbolTableListTraits.h +++ b/include/llvm/SymbolTableListTraits.h @@ -1,5 +1,12 @@ //===-- llvm/SymbolTableListTraits.h - Traits for iplist --------*- C++ -*-===// // +// The LLVM Compiler Infrastructure +// +// This file 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 // instruction into a basic block. @@ -18,51 +25,55 @@ #ifndef LLVM_SYMBOLTABLELISTTRAITS_H #define LLVM_SYMBOLTABLELISTTRAITS_H +#include "llvm/ADT/ilist.h" + +namespace llvm { +class ValueSymbolTable; + template class ilist_iterator; template class iplist; template 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. +// ItemParentClass - The type of object that owns the list, e.g. BasicBlock. // -template > -class SymbolTableListTraits { - SymTabClass *SymTabObject; - ItemParentClass *ItemParent; +template +class SymbolTableListTraits : public ilist_default_traits { + typedef ilist_traits TraitsClass; public: - SymbolTableListTraits() : SymTabObject(0), ItemParent(0) {} + SymbolTableListTraits() {} - SymTabClass *getParent() { return SymTabObject; } - const SymTabClass *getParent() const { return SymTabObject; } - - static ValueSubClass *getPrev(ValueSubClass *V) { return V->getPrev(); } - static ValueSubClass *getNext(ValueSubClass *V) { return V->getNext(); } - static const ValueSubClass *getPrev(const ValueSubClass *V) { - return V->getPrev(); + /// getListOwner - Return the object that owns this list. If this is a list + /// of instructions, it returns the BasicBlock that owns them. + ItemParentClass *getListOwner() { + typedef iplist ItemParentClass::*Sublist; + size_t Offset(size_t(&((ItemParentClass*)0->*ItemParentClass:: + getSublistAccess(static_cast(0))))); + iplist* Anchor(static_cast*>(this)); + return reinterpret_cast(reinterpret_cast(Anchor)- + Offset); } - static const ValueSubClass *getNext(const ValueSubClass *V) { - return V->getNext(); + + static iplist &getList(ItemParentClass *Par) { + return Par->*(Par->getSublistAccess((ValueSubClass*)0)); } - static void setPrev(ValueSubClass *V, ValueSubClass *P) { V->setPrev(P); } - static void setNext(ValueSubClass *V, ValueSubClass *N) { V->setNext(N); } + static ValueSymbolTable *getSymTab(ItemParentClass *Par) { + return Par ? toPtr(Par->getValueSymbolTable()) : 0; + } void addNodeToList(ValueSubClass *V); void removeNodeFromList(ValueSubClass *V); - void transferNodesFromList(iplist > &L2, + void transferNodesFromList(ilist_traits &L2, ilist_iterator first, ilist_iterator last); - //private: - void setItemParent(ItemParentClass *IP) { ItemParent = IP; }//This is private! - void setParent(SymTabClass *Parent); // This is private! + template + void setSymTabObject(TPtr *, TPtr); + static ValueSymbolTable *toPtr(ValueSymbolTable *P) { return P; } + static ValueSymbolTable *toPtr(ValueSymbolTable &R) { return &R; } }; +} // End llvm namespace + #endif