X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSymbolTableListTraits.h;h=91a4eb99ff0d368c489c7b0d9ff50829b93bf08a;hb=d8c5ec6aece5732c766bd7d773ff75976d364168;hp=969c03fc55029cc63ebbfa3be432a52edc5f23c1;hpb=9769ab22265b313171d201b5928688524a01bd87;p=oota-llvm.git diff --git a/include/llvm/SymbolTableListTraits.h b/include/llvm/SymbolTableListTraits.h index 969c03fc550..91a4eb99ff0 100644 --- a/include/llvm/SymbolTableListTraits.h +++ b/include/llvm/SymbolTableListTraits.h @@ -2,8 +2,8 @@ // // 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 is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -25,53 +25,53 @@ #ifndef LLVM_SYMBOLTABLELISTTRAITS_H #define LLVM_SYMBOLTABLELISTTRAITS_H -namespace llvm { +#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) {} - - SymTabClass *getParent() { return SymTabObject; } - const SymTabClass *getParent() const { return SymTabObject; } + SymbolTableListTraits() {} - 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