Remove extranous #include
[oota-llvm.git] / include / llvm / SymbolTable.h
index a53608f1d955b01fa963fb463f9e60cb2ae30596..e425e88d0d214fb543a41efbd186d81010d12ffc 100644 (file)
 #define LLVM_SYMBOL_TABLE_H
 
 #include "llvm/Value.h"
-#include <vector>
 #include <map>
 
-class Value;
+#ifndef NDEBUG             // Only for assertions
+#include "llvm/Type.h"
+#include "llvm/ConstantVals.h"
+#endif
+
 class Type;
 
-// TODO: Change this back to vector<map<const string, Value *> >
-// Make the vector be a data member, and base it on UniqueID's
-// That should be much more efficient!
-//
 class SymbolTable : public AbstractTypeUser,
-                   public map<const Type *, map<const string, Value *> > {
-  typedef map<const string, Value *> VarMap;
-  typedef map<const Type *, VarMap> super;
+                   public std::map<const Type *, 
+                                    std::map<const std::string, Value *> > {
+public:
+  typedef std::map<const std::string, Value *> VarMap;
+  typedef std::map<const Type *, VarMap> super;
+private:
 
   SymbolTable *ParentSymTab;
 
@@ -41,42 +43,43 @@ public:
   typedef VarMap::iterator type_iterator;
   typedef VarMap::const_iterator type_const_iterator;
 
-  inline SymbolTable(SymbolTable *P = 0) { ParentSymTab = P; }
+  inline SymbolTable(SymbolTable *P = 0) {
+    ParentSymTab = P;
+    InternallyInconsistent = false;
+  }
   ~SymbolTable();
 
   SymbolTable *getParentSymTab() { return ParentSymTab; }
 
   // lookup - Returns null on failure...
-  Value *lookup(const Type *Ty, const string &name);
-
-  // find - returns end(Ty->getIDNumber()) on failure...
-  type_iterator type_find(const Type *Ty, const string &name);
-  type_iterator type_find(const Value *D);
+  Value *lookup(const Type *Ty, const std::string &name);
 
   // insert - Add named definition to the symbol table...
   inline void insert(Value *N) {
     assert(N->hasName() && "Value must be named to go into symbol table!");
-    insertEntry(N->getName(), N);
+    insertEntry(N->getName(), N->getType(), N);
   }
 
   // insert - Insert a constant or type into the symbol table with the specified
   // name...  There can be a many to one mapping between names and
   // (constant/type)s.
   //
-  inline void insert(const string &Name, Value *V) {
-    assert((V->isType() || V->isConstant()) &&
+  inline void insert(const std::string &Name, Value *V) {
+    assert((isa<Type>(V) || isa<Constant>(V)) &&
           "Can only insert types and constants here!");
-    insertEntry(Name, V);
+    insertEntry(Name, V->getType(), V);
   }
 
   void remove(Value *N);
-  Value *type_remove(const type_iterator &It);
+  Value *type_remove(const type_iterator &It) {
+    return removeEntry(find(It->second->getType()), It);
+  }
 
   // getUniqueName - Given a base name, return a string that is either equal to
   // it (or derived from it) that does not already occur in the symbol table for
   // the specified type.
   //
-  string getUniqueName(const Type *Ty, const string &BaseName);
+  std::string getUniqueName(const Type *Ty, const std::string &BaseName);
 
   inline unsigned type_size(const Type *TypeID) const {
     return find(TypeID)->second.size();
@@ -99,11 +102,31 @@ public:
     return find(TypeID)->second.end(); 
   }
 
+  void dump() const;  // Debug method, print out symbol table
+
 private:
+  // InternallyInconsistent - There are times when the symbol table is
+  // internally inconsistent with the rest of the program.  In this one case, a
+  // value exists with a Name, and it's not in the symbol table.  When we call
+  // V->setName(""), it tries to remove itself from the symbol table and dies.
+  // We know this is happening, and so if the flag InternallyInconsistent is
+  // set, removal from the symbol table is a noop.
+  //
+  bool InternallyInconsistent;
+
+  inline super::value_type operator[](const Type *Ty) {
+    assert(0 && "Should not use this operator to access symbol table!");
+    return super::value_type();
+  }
+
   // insertEntry - Insert a value into the symbol table with the specified
   // name...
   //
-  void insertEntry(const string &Name, Value *V);
+  void insertEntry(const std::string &Name, const Type *Ty, Value *V);
+
+  // removeEntry - Remove a value from the symbol table...
+  //
+  Value *removeEntry(iterator Plane, type_iterator Entry);
 
   // This function is called when one of the types in the type plane are refined
   virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);