summaryrefslogtreecommitdiff
path: root/include/llvm/Constants.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2012-01-24 09:01:07 +0000
committerChris Lattner <sabre@nondot.org>2012-01-24 09:01:07 +0000
commit62339073127df4579905f551f61c132cf21d2aad (patch)
tree9fe0763ca88fdd7b369ec6437e2c04f64db5057c /include/llvm/Constants.h
parenta97a5eabe2a412d7cc078f94b7df7ee8ac840853 (diff)
downloadllvm-62339073127df4579905f551f61c132cf21d2aad.tar.gz
llvm-62339073127df4579905f551f61c132cf21d2aad.tar.bz2
llvm-62339073127df4579905f551f61c132cf21d2aad.tar.xz
Add various "string" methods to ConstantDataSequential, which have the
same semantics as ConstantArray's but much more efficient because they don't have to return std::string's. The ConstantArray methods will eventually be removed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148792 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Constants.h')
-rw-r--r--include/llvm/Constants.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index 958ebb88c7..21400e774d 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -371,6 +371,9 @@ public:
return reinterpret_cast<ArrayType*>(Value::getType());
}
+ // FIXME: String methods will eventually be removed.
+
+
/// isString - This method returns true if the array is an array of i8 and
/// the elements of the array are all ConstantInt's.
bool isString() const;
@@ -626,6 +629,30 @@ public:
/// byte.
uint64_t getElementByteSize() const;
+
+ /// isString - This method returns true if this is an array of i8.
+ bool isString() const;
+
+ /// isCString - This method returns true if the array "isString", ends with a
+ /// nul byte, and does not contains any other nul bytes.
+ bool isCString() const;
+
+ /// getAsString - If this array is isString(), then this method returns the
+ /// array as a StringRef. Otherwise, it asserts out.
+ ///
+ StringRef getAsString() const;
+
+ /// getAsCString - If this array is isCString(), then this method returns the
+ /// array (without the trailing null byte) as a StringRef. Otherwise, it
+ /// asserts out.
+ ///
+ StringRef getAsCString() const {
+ assert(isCString() && "Isn't a C string");
+ StringRef Str = getAsString();
+ return Str.substr(0, Str.size()-1);
+ }
+
+
virtual void destroyConstant();
/// Methods for support type inquiry through isa, cast, and dyn_cast: