From 6e885d0dd52a181a74efb882025f840750c1df21 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Sun, 4 Jul 2004 12:14:17 +0000 Subject: [PATCH] - Changes for bug 122 - Remove Tabs - Add inserters needed since Value doesn't implement them any more - Move some functions here to avoid cyclic header file dependencies. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14618 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Type.cpp | 67 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index eefcee98d4e..f3810be0c2d 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/AbstractTypeUser.h" #include "llvm/DerivedTypes.h" #include "llvm/SymbolTable.h" #include "llvm/Constants.h" @@ -18,6 +19,7 @@ #include "Support/StringExtras.h" #include "Support/STLExtras.h" #include +#include using namespace llvm; // DEBUG_MERGE_TYPES - Enable this #define to see how and when derived types are @@ -42,8 +44,8 @@ static std::vector UIDMappings; static std::map ConcreteTypeDescriptions; static std::map AbstractTypeDescriptions; -Type::Type(const std::string &name, TypeID id) - : Value(Type::TypeTy, Value::TypeVal), RefCount(0), ForwardType(0) { +Type::Type( const std::string& name, TypeID id ) + : RefCount(0), ForwardType(0) { if (!name.empty()) ConcreteTypeDescriptions[this] = name; ID = id; @@ -57,7 +59,6 @@ void Type::setName(const std::string &Name, SymbolTable *ST) { if (!Name.empty()) ST->insert(Name, this); } - const Type *Type::getUniqueIDType(unsigned UID) { assert(UID < UIDMappings.size() && "Type::getPrimitiveType: UID out of range!"); @@ -78,7 +79,6 @@ const Type *Type::getPrimitiveType(TypeID IDNumber) { case LongTyID : return LongTy; case FloatTyID : return FloatTy; case DoubleTyID: return DoubleTy; - case TypeTyID : return TypeTy; case LabelTyID : return LabelTy; default: return 0; @@ -333,7 +333,7 @@ const Type *StructType::getTypeAtIndex(const Value *V) const { // type. // struct SignedIntType : public Type { - SignedIntType(const std::string &Name, TypeID id) : Type(Name, id) {} + SignedIntType(std::string name, TypeID id) : Type(name, id) {} // isSigned - Return whether a numeric type is signed. virtual bool isSigned() const { return 1; } @@ -345,7 +345,7 @@ struct SignedIntType : public Type { }; struct UnsignedIntType : public Type { - UnsignedIntType(const std::string &N, TypeID id) : Type(N, id) {} + UnsignedIntType(std::string name, TypeID id) : Type(name,id) {} // isUnsigned - Return whether a numeric type is signed. virtual bool isUnsigned() const { return 1; } @@ -357,13 +357,9 @@ struct UnsignedIntType : public Type { }; struct OtherType : public Type { - OtherType(const std::string &N, TypeID id) : Type(N, id) {} + OtherType(std:;string name, TypeID id) : Type(name,id) {} }; -static struct TypeType : public Type { - TypeType() : Type("type", TypeTyID) {} -} TheTypeTy; // Implement the type that is global. - //===----------------------------------------------------------------------===// // Static 'Type' data @@ -375,7 +371,7 @@ static SignedIntType TheSByteTy ("sbyte" , Type::SByteTyID); static UnsignedIntType TheUByteTy ("ubyte" , Type::UByteTyID); static SignedIntType TheShortTy ("short" , Type::ShortTyID); static UnsignedIntType TheUShortTy("ushort", Type::UShortTyID); -static SignedIntType TheIntTy ("int" , Type::IntTyID); +static SignedIntType TheIntTy ("int" , Type::IntTyID); static UnsignedIntType TheUIntTy ("uint" , Type::UIntTyID); static SignedIntType TheLongTy ("long" , Type::LongTyID); static UnsignedIntType TheULongTy ("ulong" , Type::ULongTyID); @@ -395,7 +391,6 @@ Type *Type::LongTy = &TheLongTy; Type *Type::ULongTy = &TheULongTy; Type *Type::FloatTy = &TheFloatTy; Type *Type::DoubleTy = &TheDoubleTy; -Type *Type::TypeTy = &TheTypeTy; Type *Type::LabelTy = &TheLabelTy; @@ -490,7 +485,7 @@ bool Type::isTypeAbstract() { // Scan all of the sub-types. If any of them are abstract, than so is this // one! - for (Type::subtype_iterator I = subtype_begin(), E = subtype_end(); + for (Type::subtype_iterator I = subtype_begin(), E = subtype_end(); I != E; ++I) if (const_cast(I->get())->isTypeAbstract()) { setAbstract(true); // Restore the abstract bit. @@ -516,7 +511,7 @@ bool Type::isTypeAbstract() { // that assumes that two graphs are the same until proven otherwise. // static bool TypesEqual(const Type *Ty, const Type *Ty2, - std::map &EqTypes) { + std::map &EqTypes) { if (Ty == Ty2) return true; if (Ty->getTypeID() != Ty2->getTypeID()) return false; if (isa(Ty)) @@ -582,8 +577,8 @@ static bool TypeHasCycleThrough(const Type *TargetTy, const Type *CurTy, return false; VisitedTypes.insert(VTI, CurTy); - for (Type::subtype_iterator I = CurTy->subtype_begin(), - E = CurTy->subtype_end(); I != E; ++I) + for (Type::subtype_iterator I = CurTy->subtype_begin(), + E = CurTy->subtype_end(); I != E; ++I) if (TypeHasCycleThrough(TargetTy, *I, VisitedTypes)) return true; return false; @@ -595,7 +590,7 @@ static bool TypeHasCycleThrough(const Type *TargetTy, const Type *CurTy, static bool TypeHasCycleThroughItself(const Type *Ty) { assert(Ty->isAbstract() && "This code assumes that Ty was abstract!"); std::set VisitedTypes; - for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end(); + for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end(); I != E; ++I) if (TypeHasCycleThrough(Ty, *I, VisitedTypes)) return true; @@ -1144,7 +1139,7 @@ void FunctionType::typeBecameConcrete(const DerivedType *AbsTy) { // concrete type. // void ArrayType::refineAbstractType(const DerivedType *OldType, - const Type *NewType) { + const Type *NewType) { ArrayTypes.finishRefinement(this, OldType, NewType); } @@ -1158,7 +1153,7 @@ void ArrayType::typeBecameConcrete(const DerivedType *AbsTy) { // concrete type. // void StructType::refineAbstractType(const DerivedType *OldType, - const Type *NewType) { + const Type *NewType) { StructTypes.finishRefinement(this, OldType, NewType); } @@ -1171,10 +1166,40 @@ void StructType::typeBecameConcrete(const DerivedType *AbsTy) { // concrete type. // void PointerType::refineAbstractType(const DerivedType *OldType, - const Type *NewType) { + const Type *NewType) { PointerTypes.finishRefinement(this, OldType, NewType); } void PointerType::typeBecameConcrete(const DerivedType *AbsTy) { refineAbstractType(AbsTy, AbsTy); } + +bool SequentialType::indexValid(const Value *V) const { + const Type *Ty = V->getType(); + switch (Ty->getTypeID()) { + case Type::IntTyID: + case Type::UIntTyID: + case Type::LongTyID: + case Type::ULongTyID: + return true; + default: + return false; + } +} + +namespace llvm { +std::ostream &operator<<(std::ostream &OS, const Type *T) { + if (T == 0) + OS << " value!\n"; + else + T->print(OS); + return OS; +} + +std::ostream &operator<<(std::ostream &OS, const Type &T) { + T.print(OS); + return OS; +} +} + +// vim: sw=2 -- 2.11.0