Made the following changes:
authorChris Lattner <sabre@nondot.org>
Sat, 14 Jul 2001 06:07:58 +0000 (06:07 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 14 Jul 2001 06:07:58 +0000 (06:07 +0000)
* ValueHolder became a 3 argument template.  This allows for BasicBlock to
  use the value holder arg as a typesafe parent pointer.
* SymTabValue no longer inherits from Value
* Method does not inherit from only SymTabValue.  Now it inherits from both
  STV & Value.
* Module does not inherit from only SymTabValue.  Now it inherits from both
  STV & Value.
* Updated the SymTabValue.h file to reference SymTabValue instead of STDef
  in several places
* Added isArraySelector & isStructSelector to GetElementPtr instruction

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177 91177308-0d34-0410-b5e6-96231b3b80d8

12 files changed:
include/llvm/BasicBlock.h
include/llvm/ConstPoolVals.h
include/llvm/ConstantPool.h
include/llvm/Function.h
include/llvm/Instruction.h
include/llvm/Module.h
include/llvm/SymTabValue.h
include/llvm/Value.h
include/llvm/ValueHolder.h
include/llvm/iMemory.h
include/llvm/iOther.h
lib/VMCore/ValueHolderImpl.h

index 402b1fd0875e430672cbda1f180f309a90d0d018..c0922d6290596228da14e93b62460df18d522b22 100644 (file)
@@ -32,11 +32,11 @@ class TerminatorInst;
 
 class BasicBlock : public Value {       // Basic blocks are data objects also
 public:
-  typedef ValueHolder<Instruction, BasicBlock> InstListType;
+  typedef ValueHolder<Instruction, BasicBlock, Method> InstListType;
 private :
   InstListType InstList;
 
-  friend class ValueHolder<BasicBlock,Method>;
+  friend class ValueHolder<BasicBlock,Method,Method>;
   void setParent(Method *parent);
 
 public:
@@ -57,8 +57,8 @@ public:
   // Specialize setName to take care of symbol table majik
   virtual void setName(const string &name);
 
-  const Method *getParent() const { return (const Method*)InstList.getParent();}
-        Method *getParent()       { return (Method*)InstList.getParent(); }
+  const Method *getParent() const { return InstList.getParent(); }
+        Method *getParent()       { return InstList.getParent(); }
 
   // getTerminator() - If this is a well formed basic block, then this returns
   // a pointer to the terminator instruction.  If it is not, then you get a null
index 47941eb82ee84451805b431d8c2c8a21de3f0f43..ff7baf5b404826a543d560c344928c0027b7f942 100644 (file)
@@ -23,7 +23,7 @@ class StructType;
 class ConstPoolVal : public User {
   SymTabValue *Parent;
 
-  friend class ValueHolder<ConstPoolVal, SymTabValue>;
+  friend class ValueHolder<ConstPoolVal, SymTabValue, SymTabValue>;
   inline void setParent(SymTabValue *parent) { 
     Parent = parent;
   }
@@ -50,6 +50,8 @@ public:
 
   inline const SymTabValue *getParent() const { return Parent; }
   inline       SymTabValue *getParent()       { return Parent; }
+  inline const     Value *getParentV() const { return Parent->getSTVParent(); }
+  inline           Value *getParentV()       { return Parent->getSTVParent(); }
 };
 
 
index 7c8e255790c6cdb0bd4408c5b477b07f9d84ec6c..ad4d64ac5b7128f5c887654fbba21c490ecbbb98 100644 (file)
 
 #include <vector>
 #include "llvm/ValueHolder.h"
-
-class ConstPoolVal;
 class SymTabValue;
+class ConstPoolVal;
 class Type;
+class Value;
 
 class ConstantPool {
 public:
-  typedef ValueHolder<ConstPoolVal, SymTabValue> PlaneType;
+  typedef ValueHolder<ConstPoolVal, SymTabValue, SymTabValue> PlaneType;
 private:
   typedef vector<PlaneType*> PlanesType;
   PlanesType Planes;
@@ -30,6 +30,8 @@ public:
 
   inline       SymTabValue *getParent()       { return Parent; }
   inline const SymTabValue *getParent() const { return Parent; }
+  const Value *getParentV() const;
+        Value *getParentV()      ;
 
   void setParent(SymTabValue *STV);
 
index b7aa855b2c2aad89fc241cfad6cc71c52d2cf663..349dd61a84692303c4e05f445aed6ba52477babd 100644 (file)
@@ -21,10 +21,10 @@ class MethodArgument;
 class MethodType;
 class Module;
 
-class Method : public SymTabValue {
+class Method : public Value, public SymTabValue {
 public:
-  typedef ValueHolder<MethodArgument, Method> ArgumentListType;
-  typedef ValueHolder<BasicBlock    , Method> BasicBlocksType;
+  typedef ValueHolder<MethodArgument, Method, Method> ArgumentListType;
+  typedef ValueHolder<BasicBlock    , Method, Method> BasicBlocksType;
 
   // BasicBlock iterators...
   typedef BasicBlocksType::iterator iterator;
@@ -40,7 +40,7 @@ private:
 
   Module *Parent;                  // The module that contains this method
 
-  friend class ValueHolder<Method,Module>;
+  friend class ValueHolder<Method,Module, Module>;
   void setParent(Module *parent);
 
 public:
index 25be14fbd21969ce1011ffe3116d7b5f6b1b5768..6b6d31a15c026a76c198d6619f583b20022fbf5e 100644 (file)
@@ -18,7 +18,7 @@ class Instruction : public User {
   BasicBlock *Parent;
   unsigned iType;      // InstructionType
 
-  friend class ValueHolder<Instruction,BasicBlock>;
+  friend class ValueHolder<Instruction,BasicBlock,Method>;
   inline void setParent(BasicBlock *P) { Parent = P; }
 
 public:
index d02b3a050eacd7b65d0eff75d8c8d3b8b4913f68..740a8879b65daf0dc37609696098f0b2eb4ad28c 100644 (file)
@@ -8,12 +8,13 @@
 #ifndef LLVM_MODULE_H
 #define LLVM_MODULE_H
 
+#include "llvm/Value.h"
 #include "llvm/SymTabValue.h"
 class Method;
 
-class Module : public SymTabValue {
+class Module : public Value, public SymTabValue {
 public:
-  typedef ValueHolder<Method, Module> MethodListType;
+  typedef ValueHolder<Method, Module, Module> MethodListType;
 
   // Method iterators...
   typedef MethodListType::iterator iterator;
index 556d5c7a0718d9f4841409719c976e0f842d5e81..f86218d198b55affb3fdc5ce8d03e0838641c0be 100644 (file)
@@ -1,31 +1,35 @@
-//===-- llvm/SymTabDef.h - Implement SymbolTable Defs ------------*- C++ -*--=//
+//===-- llvm/SymTabValue.h - Implement SymbolTable Values --------*- C++ -*--=//
 //
-// This subclass of Def implements a def that has a symbol table for keeping
-// track of children.  This is used by the DefHolder template class...
+// This subclass of Value implements a def that has a symbol table for keeping
+// track of children.  This is used by the ValueHolder template class...
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_SYMTABDEF_H
-#define LLVM_SYMTABDEF_H
+#ifndef LLVM_SYMTAB_VALUE_H
+#define LLVM_SYMTAB_VALUE_H
 
-#include "llvm/Value.h"               // Get the definition of Value
 #include "llvm/ConstantPool.h"
 
 class SymbolTable;
 class ConstPoolVal;
+class Value;
 
-class SymTabValue : public Value {
+class SymTabValue {
 public:
   typedef ConstantPool ConstantPoolType;
 private:
   SymbolTable *SymTab, *ParentSymTab;
   ConstantPool ConstPool;   // The constant pool
+  Value *ValueParent;
 
 protected:
   void setParentSymTab(SymbolTable *ST);
 public:
-  SymTabValue(const Type *Ty, ValueTy dty, const string &name = "");
-  ~SymTabValue();    // Implemented in Def.cpp
+  SymTabValue(Value *Parent);
+  ~SymTabValue();    // Implemented in Value.cpp
+
+  inline       Value *getSTVParent()       { return ValueParent; }
+  inline const Value *getSTVParent() const { return ValueParent; }
 
   // hasSymbolTable() - Returns true if there is a symbol table allocated to
   // this object AND if there is at least one name in it!
@@ -45,7 +49,7 @@ public:
   // the method does not already have a symtab, one is created.  Use this if
   // you intend to put something into the symbol table for the method.
   //
-  SymbolTable *getSymbolTableSure();  // Implemented in Def.cpp
+  SymbolTable *getSymbolTableSure();  // Implemented in Value.cpp
 };
 
 #endif
index 43373321c70fcf31df35557686ff738736dfe4c3..07a61a60188c21b70425abea4c2f58d4d0ae7889 100644 (file)
@@ -19,7 +19,8 @@ class Instruction;
 class BasicBlock;
 class Method;
 class Module;
-template<class ValueSubclass, class ItemParentType> class ValueHolder;
+template<class ValueSubclass, class ItemParentType, class SymTabType> 
+  class ValueHolder;
 
 //===----------------------------------------------------------------------===//
 //                                 Value Class
index 18f6e3f40b9caf38e5fb4afa2abbae802b810c7f..09aa49d05777bfd9bceb2d3878b796192767465c 100644 (file)
 #define LLVM_VALUEHOLDER_H
 
 #include <vector>
-class SymTabValue;
 
-// ItemParentType ItemParent - I call setParent() on all of my 
-// "ValueSubclass" items, and this is the value that I pass in.
+// 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 (which should be derived from
+//                  SymTabValue), 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 Method
 //
-template<class ValueSubclass, class ItemParentType> 
+template<class ValueSubclass, class ItemParentType, class SymTabType
 class ValueHolder {
   // TODO: Should I use a deque instead of a vector?
   vector<ValueSubclass*> ValueList;
 
   ItemParentType *ItemParent;
-  SymTabValue *Parent;
+  SymTabType *Parent;
 
   ValueHolder(const ValueHolder &V);   // DO NOT IMPLEMENT
 public:
-  inline ValueHolder(ItemParentType *IP, SymTabValue *parent = 0) { 
+  inline ValueHolder(ItemParentType *IP, SymTabType *parent = 0) { 
     assert(IP && "Item parent may not be null!");
     ItemParent = IP;
     Parent = 0;
@@ -41,9 +46,9 @@ public:
     assert(Parent == 0 && "Should have been unlinked from method!");
   }
 
-  inline const SymTabValue *getParent() const { return Parent; }
-  inline SymTabValue *getParent() { return Parent; }
-  void setParent(SymTabValue *Parent);  // Defined in ValueHolderImpl.h
+  inline const SymTabType *getParent() const { return Parent; }
+  inline SymTabType *getParent() { return Parent; }
+  void setParent(SymTabType *Parent);  // Defined in ValueHolderImpl.h
 
   inline unsigned size() const { return ValueList.size(); }
   inline bool empty()    const { return ValueList.empty(); }
index fe045d72667356f9bb1d676eace3e7c2593906b9..92d6a6c80d4a99f5ec8497ce0ee1dfada80c4523 100644 (file)
@@ -178,6 +178,9 @@ public:
                    const string &Name = "");
   virtual Instruction *clone() const { return new GetElementPtrInst(*this); }
   virtual const char *getOpcodeName() const { return "getelementptr"; }  
+
+  inline bool isArraySelector() const { return !isStructSelector(); }
+  bool isStructSelector() const;
 };
 
 #endif // LLVM_IMEMORY_H
index ce5aa9306203029a31ed7803b460a370ffb096b2..e522e1453d25b513efd11d190121505d14725933 100644 (file)
@@ -87,7 +87,7 @@ public:
 class MethodArgument : public Value {  // Defined in the InstrType.cpp file
   Method *Parent;
 
-  friend class ValueHolder<MethodArgument,Method>;
+  friend class ValueHolder<MethodArgument,Method,Method>;
   inline void setParent(Method *parent) { Parent = parent; }
 
 public:
index f19d71f502606e1426ff5202684df2978560e9da..c59f9f2dafa0f7247ae0e8850103e3527292e1b7 100644 (file)
@@ -13,8 +13,9 @@
 #include "llvm/SymbolTable.h"
 #include <algorithm>
 
-template<class ValueSubclass, class ItemParentType>
-void ValueHolder<ValueSubclass,ItemParentType>::setParent(SymTabValue *P) { 
+template<class ValueSubclass, class ItemParentType, class SymTabType>
+void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
+::setParent(SymTabType *P) { 
   if (Parent) {     // Remove all of the items from the old symbol table..
     SymbolTable *SymTab = Parent->getSymbolTable();
     for (iterator I = begin(); I != end(); ++I)
@@ -31,8 +32,9 @@ void ValueHolder<ValueSubclass,ItemParentType>::setParent(SymTabValue *P) {
 }
 
 
-template<class ValueSubclass, class ItemParentType>
-void ValueHolder<ValueSubclass,ItemParentType>::remove(ValueSubclass *D) {
+template<class ValueSubclass, class ItemParentType, class SymTabType>
+void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
+::remove(ValueSubclass *D) {
   iterator I(find(begin(), end(), D));
   assert(I != end() && "Value not in ValueHolder!!");
   remove(I);
@@ -42,8 +44,9 @@ void ValueHolder<ValueSubclass,ItemParentType>::remove(ValueSubclass *D) {
 // specified by the iterator, and leaves the iterator pointing to the element
 // that used to follow the element deleted.
 //
-template<class ValueSubclass, class ItemParentType>
-ValueSubclass *ValueHolder<ValueSubclass,ItemParentType>::remove(iterator &DI) {
+template<class ValueSubclass, class ItemParentType, class SymTabType>
+ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType>
+::remove(iterator &DI) {
   assert(DI != ValueList.end() && 
          "Trying to remove the end of the def list!!!");
   
@@ -59,8 +62,9 @@ ValueSubclass *ValueHolder<ValueSubclass,ItemParentType>::remove(iterator &DI) {
   return i;
 }
 
-template<class ValueSubclass, class ItemParentType>
-ValueSubclass *ValueHolder<ValueSubclass,ItemParentType>::pop_back() {
+template<class ValueSubclass, class ItemParentType, class SymTabType>
+ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType>
+::pop_back() {
   assert(!ValueList.empty() && "Can't pop_back an empty valuelist!");
   ValueSubclass *i = ValueList.back();
   ValueList.pop_back();
@@ -74,8 +78,8 @@ ValueSubclass *ValueHolder<ValueSubclass,ItemParentType>::pop_back() {
 }
 
 
-template<class ValueSubclass, class ItemParentType>
-ValueSubclass *ValueHolder<ValueSubclass,ItemParentType>
+template<class ValueSubclass, class ItemParentType, class SymTabType>
+ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType>
 ::remove(const iterator &DI) {
   assert(DI != ValueList.end() && 
          "Trying to remove the end of the def list!!!");
@@ -92,8 +96,9 @@ ValueSubclass *ValueHolder<ValueSubclass,ItemParentType>
   return i;
 }
 
-template<class ValueSubclass, class ItemParentType>
-void ValueHolder<ValueSubclass,ItemParentType>::push_front(ValueSubclass *Inst) {
+template<class ValueSubclass, class ItemParentType, class SymTabType>
+void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
+::push_front(ValueSubclass *Inst) {
   assert(Inst->getParent() == 0 && "Value already has parent!");
   Inst->setParent(ItemParent);
 
@@ -104,8 +109,9 @@ void ValueHolder<ValueSubclass,ItemParentType>::push_front(ValueSubclass *Inst)
     Parent->getSymbolTableSure()->insert(Inst);
 }
 
-template<class ValueSubclass, class ItemParentType>
-void ValueHolder<ValueSubclass,ItemParentType>::push_back(ValueSubclass *Inst) {
+template<class ValueSubclass, class ItemParentType, class SymTabType>
+void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
+::push_back(ValueSubclass *Inst) {
   assert(Inst->getParent() == 0 && "Value already has parent!");
   Inst->setParent(ItemParent);
 
@@ -119,10 +125,10 @@ void ValueHolder<ValueSubclass,ItemParentType>::push_back(ValueSubclass *Inst) {
 // indicated iterator position, and returns an interator to the newly inserted
 // value.
 //
-template<class ValueSubclass, class ItemParentType>
-ValueHolder<ValueSubclass,ItemParentType>::iterator
-ValueHolder<ValueSubclass,ItemParentType>::insert(iterator Pos,
-                                                          ValueSubclass *Inst){
+template<class ValueSubclass, class ItemParentType, class SymTabType>
+ValueHolder<ValueSubclass,ItemParentType,SymTabType>::iterator
+ValueHolder<ValueSubclass,ItemParentType,SymTabType>
+::insert(iterator Pos, ValueSubclass *Inst) {
   assert(Inst->getParent() == 0 && "Value already has parent!");
   Inst->setParent(ItemParent);