mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-25 12:50:00 +00:00
Roll back the ConstStringRef change for now
There are a couple of interesting things here that we want to check over (particularly the expecting asserts in StringRef) and get right for general use in ADT so hold back on this one. For clang we have a workable templated solution to use in the meanwhile. This reverts commit r200187. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200194 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
72e501f0be
commit
650e286dcf
@ -10,8 +10,6 @@
|
||||
#ifndef LLVM_ADT_STRINGREF_H
|
||||
#define LLVM_ADT_STRINGREF_H
|
||||
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/type_traits.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
@ -72,7 +70,7 @@ namespace llvm {
|
||||
/// @{
|
||||
|
||||
/// Construct an empty string ref.
|
||||
/*implicit*/ LLVM_CONSTEXPR StringRef() : Data(0), Length(0) {}
|
||||
/*implicit*/ StringRef() : Data(0), Length(0) {}
|
||||
|
||||
/// Construct a string ref from a cstring.
|
||||
/*implicit*/ StringRef(const char *Str)
|
||||
@ -82,8 +80,11 @@ namespace llvm {
|
||||
}
|
||||
|
||||
/// Construct a string ref from a pointer and length.
|
||||
/*implicit*/ LLVM_CONSTEXPR StringRef(const char *data, size_t length)
|
||||
: Data(data), Length((llvm_expect(data || length == 0), length)) {}
|
||||
/*implicit*/ StringRef(const char *data, size_t length)
|
||||
: Data(data), Length(length) {
|
||||
assert((data || length == 0) &&
|
||||
"StringRef cannot be built from a NULL argument with non-null length");
|
||||
}
|
||||
|
||||
/// Construct a string ref from an std::string.
|
||||
/*implicit*/ StringRef(const std::string &Str)
|
||||
@ -103,20 +104,24 @@ namespace llvm {
|
||||
|
||||
/// data - Get a pointer to the start of the string (which may not be null
|
||||
/// terminated).
|
||||
LLVM_CONSTEXPR const char *data() const { return Data; }
|
||||
const char *data() const { return Data; }
|
||||
|
||||
/// empty - Check if the string is empty.
|
||||
LLVM_CONSTEXPR bool empty() const { return Length == 0; }
|
||||
bool empty() const { return Length == 0; }
|
||||
|
||||
/// size - Get the string size.
|
||||
LLVM_CONSTEXPR size_t size() const { return Length; }
|
||||
size_t size() const { return Length; }
|
||||
|
||||
/// front - Get the first character in the string.
|
||||
LLVM_CONSTEXPR char front() const { return llvm_expect(!empty()), Data[0]; }
|
||||
char front() const {
|
||||
assert(!empty());
|
||||
return Data[0];
|
||||
}
|
||||
|
||||
/// back - Get the last character in the string.
|
||||
LLVM_CONSTEXPR char back() const {
|
||||
return llvm_expect(!empty()), Data[Length - 1];
|
||||
char back() const {
|
||||
assert(!empty());
|
||||
return Data[Length-1];
|
||||
}
|
||||
|
||||
/// equals - Check for string equality, this is more efficient than
|
||||
@ -182,8 +187,9 @@ namespace llvm {
|
||||
/// @name Operator Overloads
|
||||
/// @{
|
||||
|
||||
LLVM_CONSTEXPR char operator[](size_t Index) const {
|
||||
return llvm_expect(Index < Length), Data[Index];
|
||||
char operator[](size_t Index) const {
|
||||
assert(Index < Length && "Invalid index!");
|
||||
return Data[Index];
|
||||
}
|
||||
|
||||
/// @}
|
||||
@ -541,20 +547,6 @@ namespace llvm {
|
||||
|
||||
/// @}
|
||||
|
||||
/// ConstStringRef - A \c StringRef carrying the additional stipulation that
|
||||
/// the referenced string is a compile-time constant.
|
||||
///
|
||||
/// Use this to specify function parameters that require fixed inputs such
|
||||
/// as debug and diagnostic messages or format strings.
|
||||
class ConstStringRef : public StringRef {
|
||||
public:
|
||||
/*implicit*/ LLVM_CONSTEXPR ConstStringRef() : StringRef() {}
|
||||
|
||||
template <size_t N>
|
||||
/*implicit*/ LLVM_CONSTEXPR ConstStringRef(const char (&data)[N])
|
||||
: StringRef(data, (llvm_expect(N > 0 && data[N - 1] == '\0'), N - 1)) {}
|
||||
};
|
||||
|
||||
/// \brief Compute a hash_code for a StringRef.
|
||||
hash_code hash_value(StringRef S);
|
||||
|
||||
|
@ -15,11 +15,11 @@
|
||||
#ifndef LLVM_SUPPORT_ERRORHANDLING_H
|
||||
#define LLVM_SUPPORT_ERRORHANDLING_H
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include <string>
|
||||
|
||||
namespace llvm {
|
||||
class StringRef;
|
||||
class Twine;
|
||||
|
||||
/// An error handler callback.
|
||||
@ -78,7 +78,7 @@ namespace llvm {
|
||||
bool gen_crash_diag = true);
|
||||
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const std::string &reason,
|
||||
bool gen_crash_diag = true);
|
||||
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const StringRef &reason,
|
||||
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(StringRef reason,
|
||||
bool gen_crash_diag = true);
|
||||
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const Twine &reason,
|
||||
bool gen_crash_diag = true);
|
||||
@ -108,14 +108,4 @@ namespace llvm {
|
||||
#define llvm_unreachable(msg) ::llvm::llvm_unreachable_internal()
|
||||
#endif
|
||||
|
||||
/// An assert macro that's usable in constexprs and that becomes an optimizer
|
||||
/// hint in NDEBUG builds.
|
||||
///
|
||||
/// Unlike \c assert() the \param test expression may be evaluated in optimized
|
||||
/// builds and so should be simple, accurate and never have side effects.
|
||||
#define llvm_expect(test) (void)(!!(test) ? 0 : (llvm_unreachable(#test), 0))
|
||||
|
||||
// TODO: Update other headers to explicitly include StringRef.h and drop this.
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
#endif
|
||||
|
@ -58,7 +58,7 @@ void llvm::report_fatal_error(const std::string &Reason, bool GenCrashDiag) {
|
||||
report_fatal_error(Twine(Reason), GenCrashDiag);
|
||||
}
|
||||
|
||||
void llvm::report_fatal_error(const StringRef &Reason, bool GenCrashDiag) {
|
||||
void llvm::report_fatal_error(StringRef Reason, bool GenCrashDiag) {
|
||||
report_fatal_error(Twine(Reason), GenCrashDiag);
|
||||
}
|
||||
|
||||
|
@ -531,22 +531,4 @@ TEST(StringRefTest, joinStrings) {
|
||||
EXPECT_TRUE(v2_join3);
|
||||
}
|
||||
|
||||
static void fn_stringref(StringRef str) {
|
||||
EXPECT_TRUE(str == "hello");
|
||||
}
|
||||
static void fn_conststringref(ConstStringRef str) {
|
||||
fn_stringref(str);
|
||||
}
|
||||
|
||||
TEST(StringRefTest, constStringRef) {
|
||||
LLVM_CONSTEXPR ConstStringRef csr("hello");
|
||||
#if __has_feature(cxx_constexpr) || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
LLVM_STATIC_ASSERT(csr[0] != csr[1], "");
|
||||
LLVM_STATIC_ASSERT(csr[2] == csr[3], "");
|
||||
LLVM_STATIC_ASSERT(csr.size() == 5, "");
|
||||
#endif
|
||||
llvm_expect(csr[2] == csr[3]);
|
||||
fn_conststringref(csr);
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
|
Loading…
Reference in New Issue
Block a user