Move entirety of llvm namespace to wpi namespace.

During shared library loading, a different libLLVM can be pulled in, causing
llvm symbols from dependent libraries to resolve to that library instead of
this one. This has been seen in the wild with the Mesa OpenGL implementation
in JavaFX applications (see wpilibsuite/shuffleboard#361).

This is clearly a very breaking change. For some level of backwards
compatibility, a namespace alias from llvm to wpi is performed in the "llvm"
headers.  Unfortunately, forward declarations of llvm classes will still break,
but compilers seem to generate clear error messages in those cases
("namespace alias 'llvm' not allowed here, assuming 'wpi'").

This change also moves all the wpiutil headers to a single "wpi" subdirectory
from the previously split "llvm", "support", "tcpsockets", and "udpsockets".
Shim headers will be added for backwards compatibility in a later commit.
This commit is contained in:
Peter Johnson
2018-04-29 23:33:19 -07:00
parent 93859eb84f
commit f84018af5f
377 changed files with 2747 additions and 2742 deletions

View File

@@ -735,7 +735,7 @@ TEST(CborFloatTest, Number)
TEST(CborFloatTest, HalfInfinity)
{
json j = json::from_cbor(llvm::StringRef("\xf9\x7c\x00", 3));
json j = json::from_cbor(wpi::StringRef("\xf9\x7c\x00", 3));
json::number_float_t d = j;
EXPECT_FALSE(std::isfinite(d));
EXPECT_EQ(j.dump(), "null");
@@ -1138,31 +1138,31 @@ TEST(CborErrorTest, TooShortByteVector)
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor("\x19"), json::parse_error,
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor(llvm::StringRef("\x19\x00", 2)), json::parse_error,
EXPECT_THROW_MSG(json::from_cbor(wpi::StringRef("\x19\x00", 2)), json::parse_error,
"[json.exception.parse_error.110] parse error at 3: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor("\x1a"), json::parse_error,
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor(llvm::StringRef("\x1a\x00", 2)), json::parse_error,
EXPECT_THROW_MSG(json::from_cbor(wpi::StringRef("\x1a\x00", 2)), json::parse_error,
"[json.exception.parse_error.110] parse error at 3: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor(llvm::StringRef("\x1a\x00\x00", 3)), json::parse_error,
EXPECT_THROW_MSG(json::from_cbor(wpi::StringRef("\x1a\x00\x00", 3)), json::parse_error,
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor(llvm::StringRef("\x1a\x00\x00\x00", 4)), json::parse_error,
EXPECT_THROW_MSG(json::from_cbor(wpi::StringRef("\x1a\x00\x00\x00", 4)), json::parse_error,
"[json.exception.parse_error.110] parse error at 5: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor("\x1b"), json::parse_error,
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor(llvm::StringRef("\x1b\x00", 2)), json::parse_error,
EXPECT_THROW_MSG(json::from_cbor(wpi::StringRef("\x1b\x00", 2)), json::parse_error,
"[json.exception.parse_error.110] parse error at 3: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor(llvm::StringRef("\x1b\x00\x00", 3)), json::parse_error,
EXPECT_THROW_MSG(json::from_cbor(wpi::StringRef("\x1b\x00\x00", 3)), json::parse_error,
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor(llvm::StringRef("\x1b\x00\x00\x00", 4)), json::parse_error,
EXPECT_THROW_MSG(json::from_cbor(wpi::StringRef("\x1b\x00\x00\x00", 4)), json::parse_error,
"[json.exception.parse_error.110] parse error at 5: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor(llvm::StringRef("\x1b\x00\x00\x00\x00", 5)), json::parse_error,
EXPECT_THROW_MSG(json::from_cbor(wpi::StringRef("\x1b\x00\x00\x00\x00", 5)), json::parse_error,
"[json.exception.parse_error.110] parse error at 6: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor(llvm::StringRef("\x1b\x00\x00\x00\x00\x00", 6)), json::parse_error,
EXPECT_THROW_MSG(json::from_cbor(wpi::StringRef("\x1b\x00\x00\x00\x00\x00", 6)), json::parse_error,
"[json.exception.parse_error.110] parse error at 7: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor(llvm::StringRef("\x1b\x00\x00\x00\x00\x00\x00", 7)), json::parse_error,
EXPECT_THROW_MSG(json::from_cbor(wpi::StringRef("\x1b\x00\x00\x00\x00\x00\x00", 7)), json::parse_error,
"[json.exception.parse_error.110] parse error at 8: unexpected end of input");
EXPECT_THROW_MSG(json::from_cbor(llvm::StringRef("\x1b\x00\x00\x00\x00\x00\x00\x00", 8)), json::parse_error,
EXPECT_THROW_MSG(json::from_cbor(wpi::StringRef("\x1b\x00\x00\x00\x00\x00\x00\x00", 8)), json::parse_error,
"[json.exception.parse_error.110] parse error at 9: unexpected end of input");
}
@@ -1547,7 +1547,7 @@ TEST(CborFirstBytesTest, Unsupported)
try
{
json::from_cbor(llvm::StringRef(&byte, 1));
json::from_cbor(wpi::StringRef(&byte, 1));
}
catch (const json::parse_error& e)
{
@@ -1571,7 +1571,7 @@ TEST(CborFirstBytesTest, Unsupported)
namespace {
struct CborRoundtripTestParam {
const char* plain;
llvm::StringRef encoded;
wpi::StringRef encoded;
bool test_encode;
};
} // anonymous namespace
@@ -1589,7 +1589,7 @@ TEST_P(CborRoundtripTest, Case)
}
static const CborRoundtripTestParam rfc7049_appendix_a_numbers[] = {
{"0", llvm::StringRef("\x00", 1), true},
{"0", wpi::StringRef("\x00", 1), true},
{"1", "\x01", true},
{"10", "\x0a", true},
{"23", "\x17", true},
@@ -1597,38 +1597,38 @@ static const CborRoundtripTestParam rfc7049_appendix_a_numbers[] = {
{"25", "\x18\x19", true},
{"100", "\x18\x64", true},
{"1000", "\x19\x03\xe8", true},
{"1000000", llvm::StringRef("\x1a\x00\x0f\x42\x40", 5), true},
{"1000000000000", llvm::StringRef("\x1b\x00\x00\x00\xe8\xd4\xa5\x10\x00", 9), true},
{"1000000", wpi::StringRef("\x1a\x00\x0f\x42\x40", 5), true},
{"1000000000000", wpi::StringRef("\x1b\x00\x00\x00\xe8\xd4\xa5\x10\x00", 9), true},
{"18446744073709551615", "\x1b\xff\xff\xff\xff\xff\xff\xff\xff", true},
// positive bignum is not supported
//{"18446744073709551616", llvm::StringRef("\xc2\x49\x01\x00\x00\x00\x00\x00\x00\x00\x00", 11), true},
//{"18446744073709551616", wpi::StringRef("\xc2\x49\x01\x00\x00\x00\x00\x00\x00\x00\x00", 11), true},
//{"-18446744073709551616", "\x3b\xff\xff\xff\xff\xff\xff\xff\xff", true},
// negative bignum is not supported
//{"-18446744073709551617", llvm::StringRef("\xc3\x49\x01\x00\x00\x00\x00\x00\x00\x00\x00", 11), true},
//{"-18446744073709551617", wpi::StringRef("\xc3\x49\x01\x00\x00\x00\x00\x00\x00\x00\x00", 11), true},
{"-1", "\x20", true},
{"-10", "\x29", true},
{"-100", "\x38\x63", true},
{"-1000", "\x39\x03\xe7", true},
// half-precision float
{"0.0", llvm::StringRef("\xf9\x00\x00", 3), false},
{"0.0", wpi::StringRef("\xf9\x00\x00", 3), false},
// half-precision float
{"-0.0", llvm::StringRef("\xf9\x80\x00", 3), false},
{"-0.0", wpi::StringRef("\xf9\x80\x00", 3), false},
// half-precision float
{"1.0", llvm::StringRef("\xf9\x3c\x00", 3), false},
{"1.0", wpi::StringRef("\xf9\x3c\x00", 3), false},
{"1.1", "\xfb\x3f\xf1\x99\x99\x99\x99\x99\x9a", true},
// half-precision float
{"1.5", llvm::StringRef("\xf9\x3e\x00", 3), false},
{"1.5", wpi::StringRef("\xf9\x3e\x00", 3), false},
// half-precision float
{"65504.0", "\xf9\x7b\xff", false},
{"100000.0", llvm::StringRef("\xfa\x47\xc3\x50\x00", 5), false},
{"100000.0", wpi::StringRef("\xfa\x47\xc3\x50\x00", 5), false},
{"3.4028234663852886e+38", "\xfa\x7f\x7f\xff\xff", false},
{"1.0e+300", llvm::StringRef("\xfb\x7e\x37\xe4\x3c\x88\x00\x75\x9c", 9), true},
{"1.0e+300", wpi::StringRef("\xfb\x7e\x37\xe4\x3c\x88\x00\x75\x9c", 9), true},
// half-precision float
{"5.960464477539063e-8", llvm::StringRef("\xf9\x00\x01", 3), false},
{"5.960464477539063e-8", wpi::StringRef("\xf9\x00\x01", 3), false},
// half-precision float
{"0.00006103515625", llvm::StringRef("\xf9\x04\x00", 3), false},
{"0.00006103515625", wpi::StringRef("\xf9\x04\x00", 3), false},
// half-precision float
{"-4.0", llvm::StringRef("\xf9\xc4\x00", 3), false},
{"-4.0", wpi::StringRef("\xf9\xc4\x00", 3), false},
{"-4.1", "\xfb\xc0\x10\x66\x66\x66\x66\x66\x66", true},
};

View File

@@ -34,11 +34,10 @@ SOFTWARE.
#include "gtest/gtest.h"
#include "llvm/SmallString.h"
#include "wpi/SmallString.h"
#include "unit-json.h"
#include "support/json_serializer.h"
#include "json_serializer.h"
using wpi::json;
@@ -68,11 +67,11 @@ class JsonStringEscapeTest
: public ::testing::TestWithParam<std::pair<const char*, const char*>> {};
TEST_P(JsonStringEscapeTest, Case)
{
llvm::SmallString<32> buf;
llvm::raw_svector_ostream ss(buf);
wpi::SmallString<32> buf;
wpi::raw_svector_ostream ss(buf);
json::serializer s(ss);
s.dump_escaped(GetParam().first);
EXPECT_EQ(ss.str(), llvm::StringRef(GetParam().second));
EXPECT_EQ(ss.str(), wpi::StringRef(GetParam().second));
}
static const std::pair<const char*, const char*> string_escape_cases[] = {

View File

@@ -35,7 +35,7 @@ SOFTWARE.
#include "gtest/gtest.h"
#include "unit-json.h"
#include "support/raw_istream.h"
#include "wpi/raw_istream.h"
using wpi::json;
#include <valarray>

View File

@@ -8,7 +8,7 @@
#include <ostream>
#include "support/json.h"
#include "wpi/json.h"
namespace wpi {

View File

@@ -1008,31 +1008,31 @@ TEST(MessagePackErrorTest, TooShortByteVector)
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack("\xcd"), json::parse_error,
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack(llvm::StringRef("\xcd\x00", 2)), json::parse_error,
EXPECT_THROW_MSG(json::from_msgpack(wpi::StringRef("\xcd\x00", 2)), json::parse_error,
"[json.exception.parse_error.110] parse error at 3: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack("\xce"), json::parse_error,
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack(llvm::StringRef("\xce\x00", 2)), json::parse_error,
EXPECT_THROW_MSG(json::from_msgpack(wpi::StringRef("\xce\x00", 2)), json::parse_error,
"[json.exception.parse_error.110] parse error at 3: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack(llvm::StringRef("\xce\x00\x00", 3)), json::parse_error,
EXPECT_THROW_MSG(json::from_msgpack(wpi::StringRef("\xce\x00\x00", 3)), json::parse_error,
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack(llvm::StringRef("\xce\x00\x00\x00", 4)), json::parse_error,
EXPECT_THROW_MSG(json::from_msgpack(wpi::StringRef("\xce\x00\x00\x00", 4)), json::parse_error,
"[json.exception.parse_error.110] parse error at 5: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack("\xcf"), json::parse_error,
"[json.exception.parse_error.110] parse error at 2: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack(llvm::StringRef("\xcf\x00", 2)), json::parse_error,
EXPECT_THROW_MSG(json::from_msgpack(wpi::StringRef("\xcf\x00", 2)), json::parse_error,
"[json.exception.parse_error.110] parse error at 3: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack(llvm::StringRef("\xcf\x00\x00", 3)), json::parse_error,
EXPECT_THROW_MSG(json::from_msgpack(wpi::StringRef("\xcf\x00\x00", 3)), json::parse_error,
"[json.exception.parse_error.110] parse error at 4: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack(llvm::StringRef("\xcf\x00\x00\x00", 4)), json::parse_error,
EXPECT_THROW_MSG(json::from_msgpack(wpi::StringRef("\xcf\x00\x00\x00", 4)), json::parse_error,
"[json.exception.parse_error.110] parse error at 5: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack(llvm::StringRef("\xcf\x00\x00\x00\x00", 5)), json::parse_error,
EXPECT_THROW_MSG(json::from_msgpack(wpi::StringRef("\xcf\x00\x00\x00\x00", 5)), json::parse_error,
"[json.exception.parse_error.110] parse error at 6: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack(llvm::StringRef("\xcf\x00\x00\x00\x00\x00", 6)), json::parse_error,
EXPECT_THROW_MSG(json::from_msgpack(wpi::StringRef("\xcf\x00\x00\x00\x00\x00", 6)), json::parse_error,
"[json.exception.parse_error.110] parse error at 7: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack(llvm::StringRef("\xcf\x00\x00\x00\x00\x00\x00", 7)), json::parse_error,
EXPECT_THROW_MSG(json::from_msgpack(wpi::StringRef("\xcf\x00\x00\x00\x00\x00\x00", 7)), json::parse_error,
"[json.exception.parse_error.110] parse error at 8: unexpected end of input");
EXPECT_THROW_MSG(json::from_msgpack(llvm::StringRef("\xcf\x00\x00\x00\x00\x00\x00\x00", 8)), json::parse_error,
EXPECT_THROW_MSG(json::from_msgpack(wpi::StringRef("\xcf\x00\x00\x00\x00\x00\x00\x00", 8)), json::parse_error,
"[json.exception.parse_error.110] parse error at 9: unexpected end of input");
}

View File

@@ -124,14 +124,14 @@ TEST(JsonReadmeTest, FromToString)
// explicit conversion to string
std::string s;
llvm::raw_string_ostream os(s);
wpi::raw_string_ostream os(s);
j.dump(os); // {\"happy\":true,\"pi\":3.141}
EXPECT_EQ(os.str(), "{\"happy\":true,\"pi\":3.141}");
// serialization with pretty printing
// pass in the amount of spaces to indent
std::string s2;
llvm::raw_string_ostream os2(s2);
wpi::raw_string_ostream os2(s2);
j2.dump(os2, 4);
EXPECT_EQ(os2.str(), "{\n \"happy\": true,\n \"pi\": 3.141\n}");
// {
@@ -149,7 +149,7 @@ TEST(JsonReadmeTest, Basic2)
j.push_back(true);
std::string s;
llvm::raw_string_ostream os(s);
wpi::raw_string_ostream os(s);
// iterate the array
for (json::iterator it = j.begin(); it != j.end(); ++it)
@@ -198,7 +198,7 @@ TEST(JsonReadmeTest, OtherContainer)
{
std::vector<int> c_vector {1, 2, 3, 4};
json j_vec(c_vector);
json j_vec2(llvm::makeArrayRef(c_vector));
json j_vec2(wpi::makeArrayRef(c_vector));
// [1, 2, 3, 4]
std::deque<float> c_deque {1.2f, 2.3f, 3.4f, 5.6f};

View File

@@ -37,8 +37,8 @@ SOFTWARE.
#include "unit-json.h"
using wpi::json;
#include "llvm/Format.h"
#include "llvm/StringExtras.h"
#include "wpi/Format.h"
#include "wpi/StringExtras.h"
#include <fstream>
@@ -90,18 +90,18 @@ using wpi::json;
error:
auto result = ::testing::AssertionFailure();
result << basemsg << " with {" << llvm::utohexstr(byte1);
result << basemsg << " with {" << wpi::utohexstr(byte1);
if (byte2 != -1)
{
result << ',' << llvm::utohexstr(byte2);
result << ',' << wpi::utohexstr(byte2);
}
if (byte3 != -1)
{
result << ',' << llvm::utohexstr(byte3);
result << ',' << wpi::utohexstr(byte3);
}
if (byte4 != -1)
{
result << ',' << llvm::utohexstr(byte4);
result << ',' << wpi::utohexstr(byte4);
}
result << '}';
return result;
@@ -919,8 +919,8 @@ static std::string codepoint_to_unicode(std::size_t cp)
// by four hexadecimal digits that encode the character's code
// point
std::string s;
llvm::raw_string_ostream ss(s);
ss << "\\u" << llvm::format_hex_no_prefix(cp, 4);
wpi::raw_string_ostream ss(s);
ss << "\\u" << wpi::format_hex_no_prefix(cp, 4);
ss.flush();
return s;
}