Add support for casting operators
[oota-llvm.git] / lib / VMCore / Value.cpp
index 79d8e0a46205f292cf839e122648b1fb04137120..48f9347f962e6394ef8c0593973066cbd4e435ba 100644 (file)
@@ -43,6 +43,7 @@ Value::~Value() {
 
 void Value::replaceAllUsesWith(Value *D) {
   assert(D && "Value::replaceAllUsesWith(<null>) is invalid!");
+  assert(D != this && "V->replaceAllUsesWith(V) is NOT valid!");
   while (!Uses.empty()) {
     User *Use = Uses.front();
 #ifndef NDEBUG
@@ -88,14 +89,13 @@ User::User(const Type *Ty, ValueTy vty, const string &name)
 void User::replaceUsesOfWith(Value *From, Value *To) {
   if (From == To) return;   // Duh what?
 
-  for (unsigned OpNum = 0; Value *D = getOperand(OpNum); ++OpNum) {   
-    if (D == From) {  // Okay, this operand is pointing to our fake def.
+  for (unsigned i = 0, E = getNumOperands(); i != E; ++i)
+    if (getOperand(i) == From) {  // Is This operand is pointing to oldval?
       // The side effects of this setOperand call include linking to
       // "To", adding "this" to the uses list of To, and
       // most importantly, removing "this" from the use list of "From".
-      setOperand(OpNum, To); // Fix it now...
+      setOperand(i, To); // Fix it now...
     }
-  }
 }
 
 
@@ -106,10 +106,10 @@ void User::replaceUsesOfWith(Value *From, Value *To) {
 // Instantiate Templates - This ugliness is the price we have to pay
 // for having a ValueHolderImpl.h file seperate from ValueHolder.h!  :(
 //
-template class ValueHolder<ConstPoolVal, SymTabValue>;
+template class ValueHolder<ConstPoolVal, SymTabValue, SymTabValue>;
 
-SymTabValue::SymTabValue(const Type *Ty, ValueTy dty, const string &name = "") 
-  : Value(Ty, dty, name), ConstPool(this) { 
+SymTabValue::SymTabValue(Value *p) : ConstPool(this), ValueParent(p) { 
+  assert(ValueParent && "SymTavValue without parent!?!");
   ParentSymTab = SymTab = 0;
 }