* Change Constant::getNullConstant to Constant::getNullValue
[oota-llvm.git] / lib / VMCore / Constants.cpp
index b2335bc9444a0cd90e84223bd884a443a580a605..8bf1d9cc199ad6cb51730b344b12ff84ca7733e0 100644 (file)
@@ -34,7 +34,7 @@ void Constant::setName(const std::string &Name, SymbolTable *ST) {
 }
 
 // Static constructor to create a '0' constant of arbitrary type...
-Constant *Constant::getNullConstant(const Type *Ty) {
+Constant *Constant::getNullValue(const Type *Ty) {
   switch (Ty->getPrimitiveID()) {
   case Type::BoolTyID:   return ConstantBool::get(false);
   case Type::SByteTyID:
@@ -141,134 +141,6 @@ ConstantPointerRef::ConstantPointerRef(GlobalValue *GV)
 
 
 
-//===----------------------------------------------------------------------===//
-//                          getStrValue implementations
-
-std::string ConstantBool::getStrValue() const {
-  return Val ? "true" : "false";
-}
-
-std::string ConstantSInt::getStrValue() const {
-  return itostr(Val.Signed);
-}
-
-std::string ConstantUInt::getStrValue() const {
-  return utostr(Val.Unsigned);
-}
-
-// ConstantFP::getStrValue - We would like to output the FP constant value in
-// exponential notation, but we cannot do this if doing so will lose precision.
-// Check here to make sure that we only output it in exponential format if we
-// can parse the value back and get the same value.
-//
-std::string ConstantFP::getStrValue() const {
-  std::string StrVal = ftostr(Val);
-
-  // Check to make sure that the stringized number is not some string like "Inf"
-  // or NaN, that atof will accept, but the lexer will not.  Check that the
-  // string matches the "[-+]?[0-9]" regex.
-  //
-  if ((StrVal[0] >= '0' && StrVal[0] <= '9') ||
-      ((StrVal[0] == '-' || StrVal[0] == '+') &&
-       (StrVal[0] >= '0' && StrVal[0] <= '9'))) {
-    double TestVal = atof(StrVal.c_str());  // Reparse stringized version!
-    if (TestVal == Val)
-      return StrVal;
-  }
-
-  // Otherwise we could not reparse it to exactly the same value, so we must
-  // output the string in hexadecimal format!
-  //
-  // Behave nicely in the face of C TBAA rules... see:
-  // http://www.nullstone.com/htmls/category/aliastyp.htm
-  //
-  char *Ptr = (char*)&Val;
-  assert(sizeof(double) == sizeof(uint64_t) && sizeof(double) == 8 &&
-         "assuming that double is 64 bits!");
-  return "0x"+utohexstr(*(uint64_t*)Ptr);
-}
-
-std::string ConstantArray::getStrValue() const {
-  std::string Result;
-  
-  // As a special case, print the array as a string if it is an array of
-  // ubytes or an array of sbytes with positive values.
-  // 
-  const Type *ETy = getType()->getElementType();
-  bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy);
-
-  if (ETy == Type::SByteTy) {
-    for (unsigned i = 0; i < Operands.size(); ++i)
-      if (ETy == Type::SByteTy &&
-          cast<ConstantSInt>(Operands[i])->getValue() < 0) {
-        isString = false;
-        break;
-      }
-  }
-
-  if (isString) {
-    Result = "c\"";
-    for (unsigned i = 0; i < Operands.size(); ++i) {
-      unsigned char C = (ETy == Type::SByteTy) ?
-        (unsigned char)cast<ConstantSInt>(Operands[i])->getValue() :
-        (unsigned char)cast<ConstantUInt>(Operands[i])->getValue();
-
-      if (isprint(C)) {
-        Result += C;
-      } else {
-        Result += '\\';
-        Result += ( C/16  < 10) ? ( C/16 +'0') : ( C/16 -10+'A');
-        Result += ((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A');
-      }
-    }
-    Result += "\"";
-
-  } else {
-    Result = "[";
-    if (Operands.size()) {
-      Result += " " + Operands[0]->getType()->getDescription() + 
-               " " + cast<Constant>(Operands[0])->getStrValue();
-      for (unsigned i = 1; i < Operands.size(); i++)
-        Result += ", " + Operands[i]->getType()->getDescription() + 
-                  " " + cast<Constant>(Operands[i])->getStrValue();
-    }
-    Result += " ]";
-  }
-  
-  return Result;
-}
-
-std::string ConstantStruct::getStrValue() const {
-  std::string Result = "{";
-  if (Operands.size()) {
-    Result += " " + Operands[0]->getType()->getDescription() + 
-             " " + cast<Constant>(Operands[0])->getStrValue();
-    for (unsigned i = 1; i < Operands.size(); i++)
-      Result += ", " + Operands[i]->getType()->getDescription() + 
-               " " + cast<Constant>(Operands[i])->getStrValue();
-  }
-
-  return Result + " }";
-}
-
-std::string ConstantPointerNull::getStrValue() const {
-  return "null";
-}
-
-std::string ConstantPointerRef::getStrValue() const {
-  const GlobalValue *V = getValue();
-  if (V->hasName()) return "%" + V->getName();
-
-  // FIXME: This is a gross hack.
-  SlotCalculator *Table = new SlotCalculator(V->getParent(), true);
-  int Slot = Table->getValSlot(V);
-  delete Table;
-
-  if (Slot >= 0) return std::string(" %") + itostr(Slot);
-  else return "<pointer reference badref>";
-}
-
-
 //===----------------------------------------------------------------------===//
 //                           classof implementations
 
@@ -352,38 +224,6 @@ bool ConstantFP::isValueValidForType(const Type *Ty, double Val) {
   }
 };
 
-//===----------------------------------------------------------------------===//
-//                      Hash Function Implementations
-#if 0
-unsigned ConstantSInt::hash(const Type *Ty, int64_t V) {
-  return unsigned(Ty->getPrimitiveID() ^ V);
-}
-
-unsigned ConstantUInt::hash(const Type *Ty, uint64_t V) {
-  return unsigned(Ty->getPrimitiveID() ^ V);
-}
-
-unsigned ConstantFP::hash(const Type *Ty, double V) {
-  return Ty->getPrimitiveID() ^ unsigned(V);
-}
-
-unsigned ConstantArray::hash(const ArrayType *Ty,
-                             const std::vector<Constant*> &V) {
-  unsigned Result = (Ty->getUniqueID() << 5) ^ (Ty->getUniqueID() * 7);
-  for (unsigned i = 0; i < V.size(); ++i)
-    Result ^= V[i]->getHash() << (i & 7);
-  return Result;
-}
-
-unsigned ConstantStruct::hash(const StructType *Ty,
-                              const std::vector<Constant*> &V) {
-  unsigned Result = (Ty->getUniqueID() << 5) ^ (Ty->getUniqueID() * 7);
-  for (unsigned i = 0; i < V.size(); ++i)
-    Result ^= V[i]->getHash() << (i & 7);
-  return Result;
-}
-#endif
-
 //===----------------------------------------------------------------------===//
 //                      Factory Function Implementation