Add two methods which have been needed for a long time: Type::get(Un)signedVersion
authorChris Lattner <sabre@nondot.org>
Fri, 26 Mar 2004 21:43:22 +0000 (21:43 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 26 Mar 2004 21:43:22 +0000 (21:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12522 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Type.h
lib/VMCore/Type.cpp

index 960af949b1204bb3152d4f8c55ecbe9d6576c5ca..e1fef6c882aa11bcc7319c7e1ac411bc3296b8a6 100644 (file)
@@ -212,9 +212,18 @@ public:
   ///
   unsigned getPrimitiveSize() const;
 
+  /// getUnsignedVersion - If this is an integer type, return the unsigned
+  /// variant of this type.  For example int -> uint.
+  const Type *getUnsignedVersion() const;
+
+  /// getSignedVersion - If this is an integer type, return the signed variant
+  /// of this type.  For example uint -> int.
+  const Type *getSignedVersion() const;
+
   /// getForwaredType - Return the type that this type has been resolved to if
   /// it has been resolved to anything.  This is used to implement the
-  /// union-find algorithm for type resolution.
+  /// union-find algorithm for type resolution, and shouldn't be used by general
+  /// purpose clients.
   const Type *getForwardedType() const {
     if (!ForwardType) return 0;
     return getForwardedTypeInternal();
index 1d265e1dd20ee2da4c0d763aade3fe0d17a7cad2..5b19cb01d0231cadb9db04c89b851023358d3a43 100644 (file)
@@ -113,6 +113,41 @@ bool Type::isLosslesslyConvertibleTo(const Type *Ty) const {
   }
 }
 
+/// getUnsignedVersion - If this is an integer type, return the unsigned
+/// variant of this type.  For example int -> uint.
+const Type *Type::getUnsignedVersion() const {
+  switch (getPrimitiveID()) {
+  default:
+    assert(isInteger()&&"Type::getUnsignedVersion is only valid for integers!");
+  case Type::UByteTyID:   
+  case Type::SByteTyID:   return Type::UByteTy;
+  case Type::UShortTyID:  
+  case Type::ShortTyID:   return Type::UShortTy;
+  case Type::UIntTyID:    
+  case Type::IntTyID:     return Type::UIntTy;
+  case Type::ULongTyID:   
+  case Type::LongTyID:    return Type::ULongTy;
+  }
+}
+
+/// getSignedVersion - If this is an integer type, return the signed variant
+/// of this type.  For example uint -> int.
+const Type *Type::getSignedVersion() const {
+  switch (getPrimitiveID()) {
+  default:
+    assert(isInteger() && "Type::getSignedVersion is only valid for integers!");
+  case Type::UByteTyID:   
+  case Type::SByteTyID:   return Type::SByteTy;
+  case Type::UShortTyID:  
+  case Type::ShortTyID:   return Type::ShortTy;
+  case Type::UIntTyID:    
+  case Type::IntTyID:     return Type::IntTy;
+  case Type::ULongTyID:   
+  case Type::LongTyID:    return Type::LongTy;
+  }
+}
+
+
 // getPrimitiveSize - Return the basic size of this type if it is a primitive
 // type.  These are fixed by LLVM and are not target dependent.  This will
 // return zero if the type does not have a size or is not a primitive type.