Convert more code to use new style casts
Eliminate old style casts from value.h


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@696 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp
index 67cfff7..aaecedd 100644
--- a/lib/Bytecode/Reader/ConstantReader.cpp
+++ b/lib/Bytecode/Reader/ConstantReader.cpp
@@ -241,8 +241,8 @@
       unsigned Slot;
       if (read_vbr(Buf, EndBuf, Slot)) return failure(true);
       Value *V = getValue(AT->getElementType(), Slot, false);
-      if (!V || !V->isConstant()) return failure(true);
-      Elements.push_back((ConstPoolVal*)V);
+      if (!V || !isa<ConstPoolVal>(V)) return failure(true);
+      Elements.push_back(cast<ConstPoolVal>(V));
     }
     V = ConstPoolArray::get(AT, Elements);
     break;
@@ -257,9 +257,9 @@
       unsigned Slot;
       if (read_vbr(Buf, EndBuf, Slot)) return failure(true);
       Value *V = getValue(ET[i], Slot, false);
-      if (!V || !V->isConstant())
+      if (!V || !isa<ConstPoolVal>(V))
 	return failure(true);
-      Elements.push_back((ConstPoolVal*)V);      
+      Elements.push_back(cast<ConstPoolVal>(V));      
     }
 
     V = ConstPoolStruct::get(ST, Elements);
diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp
index 8c3e08f..300c409 100644
--- a/lib/Bytecode/Reader/InstructionReader.cpp
+++ b/lib/Bytecode/Reader/InstructionReader.cpp
@@ -266,25 +266,25 @@
     case 0: cerr << "Invalid load encountered!\n"; return failure(true);
     case 1: break;
     case 2: V = getValue(Type::UByteTy, Raw.Arg2);
-            if (!V->isConstant()) return failure(true);
-            Idx.push_back(V->castConstant());
+            if (!isa<ConstPoolVal>(V)) return failure(true);
+            Idx.push_back(cast<ConstPoolVal>(V));
             break;
     case 3: V = getValue(Type::UByteTy, Raw.Arg2);
-            if (!V->isConstant()) return failure(true);
-            Idx.push_back(V->castConstant());
+            if (!isa<ConstPoolVal>(V)) return failure(true);
+            Idx.push_back(cast<ConstPoolVal>(V));
 	    V = getValue(Type::UByteTy, Raw.Arg3);
-            if (!V->isConstant()) return failure(true);
-            Idx.push_back(V->castConstant());
+            if (!isa<ConstPoolVal>(V)) return failure(true);
+            Idx.push_back(cast<ConstPoolVal>(V));
             break;
     default:
       V = getValue(Type::UByteTy, Raw.Arg2);
-      if (!V->isConstant()) return failure(true);
-      Idx.push_back(V->castConstant());
+      if (!isa<ConstPoolVal>(V)) return failure(true);
+      Idx.push_back(cast<ConstPoolVal>(V));
       vector<unsigned> &args = *Raw.VarArgs;
       for (unsigned i = 0, E = args.size(); i != E; ++i) {
 	V = getValue(Type::UByteTy, args[i]);
-	if (!V->isConstant()) return failure(true);
-	Idx.push_back(V->castConstant());
+	if (!isa<ConstPoolVal>(V)) return failure(true);
+	Idx.push_back(cast<ConstPoolVal>(V));
       }
       delete Raw.VarArgs; 
       break;
@@ -304,15 +304,15 @@
     case 1: cerr << "Invalid store encountered!\n"; return failure(true);
     case 2: break;
     case 3: V = getValue(Type::UByteTy, Raw.Arg3);
-            if (!V->isConstant()) return failure(true);
-            Idx.push_back(V->castConstant());
+            if (!isa<ConstPoolVal>(V)) return failure(true);
+            Idx.push_back(cast<ConstPoolVal>(V));
             break;
     default:
       vector<unsigned> &args = *Raw.VarArgs;
       for (unsigned i = 0, E = args.size(); i != E; ++i) {
 	V = getValue(Type::UByteTy, args[i]);
-	if (!V->isConstant()) return failure(true);
-	Idx.push_back(V->castConstant());
+	if (!isa<ConstPoolVal>(V)) return failure(true);
+	Idx.push_back(cast<ConstPoolVal>(V));
       }
       delete Raw.VarArgs; 
       break;
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index b7904bb..0e48830 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -206,7 +206,7 @@
 	return failure(true);
       }
       BCR_TRACE(4, "Map: '" << Name << "' to #" << slot << ":" << D;
-		if (!D->isInstruction()) cerr << endl);
+		if (!isa<Instruction>(D)) cerr << endl);
 
       D->setName(Name, ST);
     }
@@ -291,7 +291,7 @@
 
   Value *MethPHolder = getValue(MTy, MethSlot, false);
   assert(MethPHolder && "Something is broken no placeholder found!");
-  assert(MethPHolder->isMethod() && "Not a method?");
+  assert(isa<Method>(MethPHolder) && "Not a method?");
 
   unsigned type;  // Type slot
   assert(!getTypeSlot(MTy, type) && "How can meth type not exist?");
@@ -359,7 +359,7 @@
   if (read_vbr(Buf, End, MethSignature)) return failure(true);
   while (MethSignature != Type::VoidTyID) { // List is terminated by Void
     const Type *Ty = getType(MethSignature);
-    if (!Ty || !Ty->isMethodType()) { 
+    if (!Ty || !isa<MethodType>(Ty)) { 
       cerr << "Method not meth type!  Ty = " << Ty << endl;
       return failure(true); 
     }
diff --git a/lib/Bytecode/Reader/ReaderInternals.h b/lib/Bytecode/Reader/ReaderInternals.h
index ed4f1a4..cf5a43e 100644
--- a/lib/Bytecode/Reader/ReaderInternals.h
+++ b/lib/Bytecode/Reader/ReaderInternals.h
@@ -129,8 +129,7 @@
 
 struct MethPlaceHolderHelper : public Method {
   MethPlaceHolderHelper(const Type *Ty) 
-    : Method((const MethodType*)Ty) {
-    assert(Ty->isMethodType() && "Method placeholders must be method types!");
+    : Method(cast<const MethodType>(Ty)) {
   }
 };
 
diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp
index d0f37fb..38980e5 100644
--- a/lib/Bytecode/Writer/SlotCalculator.cpp
+++ b/lib/Bytecode/Writer/SlotCalculator.cpp
@@ -106,7 +106,7 @@
   for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I)
     for (SymbolTable::type_const_iterator TI = I->second.begin(), 
 	   TE = I->second.end(); TI != TE; ++TI)
-      if (TI->second->isConstant())
+      if (isa<ConstPoolVal>(TI->second))
 	insertValue(TI->second);
 }
 
@@ -223,7 +223,7 @@
 
 
 int SlotCalculator::insertValue(const Value *D) {
-  if (D->isConstant() || D->isGlobal()) {
+  if (isa<ConstPoolVal>(D) || isa<GlobalVariable>(D)) {
     const User *U = (const User *)D;
     // This makes sure that if a constant has uses (for example an array
     // of const ints), that they are inserted also.  Same for global variable
diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp
index 94cbcec..5df2fda 100644
--- a/lib/Bytecode/Writer/Writer.cpp
+++ b/lib/Bytecode/Writer/Writer.cpp
@@ -79,7 +79,7 @@
       ValNo = Type::FirstDerivedTyID; // Start emitting at the derived types...
     
     // Scan through and ignore method arguments...
-    for (; ValNo < Plane.size() && Plane[ValNo]->isMethodArgument(); ValNo++)
+    for (; ValNo < Plane.size() && isa<MethodArgument>(Plane[ValNo]); ValNo++)
       /*empty*/;
 
     unsigned NC = ValNo;              // Number of constants
@@ -103,7 +103,7 @@
 
     for (unsigned i = ValNo; i < ValNo+NC; ++i) {
       const Value *V = Plane[i];
-      if (const ConstPoolVal *CPV = V->castConstant()) {
+      if (const ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(V)) {
 	//cerr << "Serializing value: <" << V->getType() << ">: " 
 	//     << ((const ConstPoolVal*)V)->getStrValue() << ":" 
 	//     << Out.size() << "\n";
@@ -127,7 +127,7 @@
 
     // Fields: bit0 = isConstant, bit1 = hasInitializer, bit2+ = slot#
     unsigned oSlot = ((unsigned)Slot << 2) | (GV->hasInitializer() << 1) | 
-                        GV->isConstant();
+                        isa<ConstPoolVal>(GV);
     output_vbr(oSlot, Out);
 
     // If we have an initialized, output it now.