Rename ConstPoolVal -> Constant
[oota-llvm.git] / lib / VMCore / SymbolTable.cpp
index 7a6854c240a8afd34cb47a2b417fcd03f9418c46..dd6329fc97ff2487fdaf5f45ae52445a3648f0fb 100644 (file)
@@ -6,10 +6,10 @@
 
 #include "llvm/SymbolTable.h"
 #include "llvm/InstrTypes.h"
-#include "llvm/Support/StringExtras.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
+#include "Support/StringExtras.h"
 
 #define DEBUG_SYMBOL_TABLE 0
 #define DEBUG_ABSTYPE 0
@@ -25,11 +25,15 @@ SymbolTable::~SymbolTable() {
        cast<DerivedType>(Ty)->removeAbstractTypeUser(this);
     }
   }
+
+ // TODO: FIXME: BIG ONE: This doesn't unreference abstract types for the planes
+ // that could still have entries!
+
 #ifndef NDEBUG   // Only do this in -g mode...
   bool LeftoverValues = true;
   for (iterator i = begin(); i != end(); ++i) {
     for (type_iterator I = i->second.begin(); I != i->second.end(); ++I)
-      if (!isa<ConstPoolVal>(I->second) && !isa<Type>(I->second)) {
+      if (!isa<Constant>(I->second) && !isa<Type>(I->second)) {
        cerr << "Value still in symbol table! Type = '"
             << i->first->getDescription() << "' Name = '" << I->first << "'\n";
        LeftoverValues = false;
@@ -129,9 +133,14 @@ Value *SymbolTable::removeEntry(iterator Plane, type_iterator Entry) {
 // name...
 //
 void SymbolTable::insertEntry(const string &Name, const Type *VTy, Value *V) {
-  // TODO: The typeverifier should catch this when its implemented
-  assert(lookup(VTy, Name) == 0 && 
-        "SymbolTable::insertEntry - Name already in symbol table!");
+  // Check to see if there is a naming conflict.  If so, rename this value!
+  if (lookup(VTy, Name)) {
+    string UniqueName = getUniqueName(VTy, Name);
+    InternallyInconsistent = true;
+    V->setName(UniqueName, this);
+    InternallyInconsistent = false;
+    return;
+  }
 
 #if DEBUG_SYMBOL_TABLE
   cerr << this << " Inserting definition: " << Name << ": " 
@@ -173,27 +182,27 @@ void SymbolTable::insertEntry(const string &Name, const Type *VTy, Value *V) {
 // This function is called when one of the types in the type plane are refined
 void SymbolTable::refineAbstractType(const DerivedType *OldType,
                                     const Type *NewType) {
-  if (OldType == NewType) return;  // Noop, don't waste time dinking around
-
-  // Get a handle to the new type plane...
-  iterator NewTypeIt = find(NewType);
-  if (NewTypeIt == super::end()) {      // If no plane exists, add one
-    NewTypeIt = super::insert(make_pair(NewType, VarMap())).first;
+  if (OldType == NewType && OldType->isAbstract())
+    return;  // Noop, don't waste time dinking around
 
-    if (NewType->isAbstract()) {
-      cast<DerivedType>(NewType)->addAbstractTypeUser(this);
+  // Search to see if we have any values of the type oldtype.  If so, we need to
+  // move them into the newtype plane...
+  iterator TPI = find(OldType);
+  if (OldType != NewType && TPI != end()) {
+    // Get a handle to the new type plane...
+    iterator NewTypeIt = find(NewType);
+    if (NewTypeIt == super::end()) {      // If no plane exists, add one
+      NewTypeIt = super::insert(make_pair(NewType, VarMap())).first;
+      
+      if (NewType->isAbstract()) {
+        cast<DerivedType>(NewType)->addAbstractTypeUser(this);
 #if DEBUG_ABSTYPE
-      cerr << "refined to abstype: " << NewType->getDescription() <<endl;
+        cerr << "[Added] refined to abstype: "<<NewType->getDescription()<<endl;
 #endif
     }
   }
 
-  VarMap &NewPlane = NewTypeIt->second;
-
-  // Search to see if we have any values of the type oldtype.  If so, we need to
-  // move them into the newtype plane...
-  iterator TPI = find(OldType);
-  if (TPI != end()) {
+    VarMap &NewPlane = NewTypeIt->second;
     VarMap &OldPlane = TPI->second;
     while (!OldPlane.empty()) {
       pair<const string, Value*> V = *OldPlane.begin();
@@ -256,6 +265,12 @@ void SymbolTable::refineAbstractType(const DerivedType *OldType,
 
     // Remove the plane that is no longer used
     erase(TPI);
+  } else if (TPI != end()) {
+    assert(OldType == NewType);
+#if DEBUG_ABSTYPE
+    cerr << "Removing SELF type " << OldType->getDescription() << endl;
+#endif
+    OldType->removeAbstractTypeUser(this);
   }
 
   TPI = find(Type::TypeTy);