Make a provision to encode inline location in a variable. This will enable dwarf...
[oota-llvm.git] / include / llvm / SymbolTableListTraits.h
index 911d1ce19dda09278d0cbddfc4a6e08ae98816c3..91a4eb99ff0d368c489c7b0d9ff50829b93bf08a 100644 (file)
 #include "llvm/ADT/ilist.h"
 
 namespace llvm {
-
+class ValueSymbolTable;
+  
 template<typename NodeTy> class ilist_iterator;
 template<typename NodeTy, typename Traits> class iplist;
 template<typename Ty> struct ilist_traits;
 
-// ValueSubClass  - The type of objects that I hold, e.g. Instruction.
-// ItemParentType - The type of object that owns the list, e.g. BasicBlock.
-// TraitBaseClass - The class this trait should inherit from, it should
-//                  inherit from ilist_traits<ValueSubClass>
+// ValueSubClass   - The type of objects that I hold, e.g. Instruction.
+// ItemParentClass - The type of object that owns the list, e.g. BasicBlock.
 //
 template<typename ValueSubClass, typename ItemParentClass>
 class SymbolTableListTraits : public ilist_default_traits<ValueSubClass> {
@@ -47,12 +46,20 @@ public:
   /// getListOwner - Return the object that owns this list.  If this is a list
   /// of instructions, it returns the BasicBlock that owns them.
   ItemParentClass *getListOwner() {
-    return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(this)-
-                                              TraitsClass::getListOffset());
+    typedef iplist<ValueSubClass> ItemParentClass::*Sublist;
+    size_t Offset(size_t(&((ItemParentClass*)0->*ItemParentClass::
+                           getSublistAccess(static_cast<ValueSubClass*>(0)))));
+    iplist<ValueSubClass>* Anchor(static_cast<iplist<ValueSubClass>*>(this));
+    return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(Anchor)-
+                                              Offset);
+  }
+
+  static iplist<ValueSubClass> &getList(ItemParentClass *Par) {
+    return Par->*(Par->getSublistAccess((ValueSubClass*)0));
   }
 
-  void deleteNode(ValueSubClass *V) {
-    delete V;
+  static ValueSymbolTable *getSymTab(ItemParentClass *Par) {
+    return Par ? toPtr(Par->getValueSymbolTable()) : 0;
   }
 
   void addNodeToList(ValueSubClass *V);
@@ -63,6 +70,8 @@ public:
 //private:
   template<typename TPtr>
   void setSymTabObject(TPtr *, TPtr);
+  static ValueSymbolTable *toPtr(ValueSymbolTable *P) { return P; }
+  static ValueSymbolTable *toPtr(ValueSymbolTable &R) { return &R; }
 };
 
 } // End llvm namespace