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

@@ -16,11 +16,11 @@
#include <utility>
#include <vector>
#include <llvm/raw_ostream.h>
#include <support/SafeThread.h>
#include <support/UidVector.h>
#include <support/condition_variable.h>
#include <support/mutex.h>
#include <wpi/SafeThread.h>
#include <wpi/UidVector.h>
#include <wpi/condition_variable.h>
#include <wpi/mutex.h>
#include <wpi/raw_ostream.h>
namespace nt {

View File

@@ -10,12 +10,13 @@
#include <algorithm>
#include <iterator>
#include <wpi/TCPAcceptor.h>
#include <wpi/TCPConnector.h>
#include "IConnectionNotifier.h"
#include "IStorage.h"
#include "Log.h"
#include "NetworkConnection.h"
#include "tcpsockets/TCPAcceptor.h"
#include "tcpsockets/TCPConnector.h"
using namespace nt;
@@ -37,13 +38,13 @@ void Dispatcher::SetServer(const char* server_name, unsigned int port) {
void Dispatcher::SetServer(
ArrayRef<std::pair<StringRef, unsigned int>> servers) {
llvm::SmallVector<std::pair<std::string, int>, 16> servers_copy;
wpi::SmallVector<std::pair<std::string, int>, 16> servers_copy;
for (const auto& server : servers)
servers_copy.emplace_back(std::string{server.first},
static_cast<int>(server.second));
SetConnector([=]() -> std::unique_ptr<wpi::NetworkStream> {
llvm::SmallVector<std::pair<const char*, int>, 16> servers_copy2;
wpi::SmallVector<std::pair<const char*, int>, 16> servers_copy2;
for (const auto& server : servers_copy)
servers_copy2.emplace_back(server.first.c_str(), server.second);
return wpi::TCPConnector::connect_parallel(servers_copy2, m_logger, 1);
@@ -54,9 +55,9 @@ void Dispatcher::SetServerTeam(unsigned int team, unsigned int port) {
std::pair<StringRef, unsigned int> servers[5];
// 10.te.am.2
llvm::SmallString<32> fixed;
wpi::SmallString<32> fixed;
{
llvm::raw_svector_ostream oss{fixed};
wpi::raw_svector_ostream oss{fixed};
oss << "10." << static_cast<int>(team / 100) << '.'
<< static_cast<int>(team % 100) << ".2";
servers[0] = std::make_pair(oss.str(), port);
@@ -66,25 +67,25 @@ void Dispatcher::SetServerTeam(unsigned int team, unsigned int port) {
servers[1] = std::make_pair("172.22.11.2", port);
// roboRIO-<team>-FRC.local
llvm::SmallString<32> mdns;
wpi::SmallString<32> mdns;
{
llvm::raw_svector_ostream oss{mdns};
wpi::raw_svector_ostream oss{mdns};
oss << "roboRIO-" << team << "-FRC.local";
servers[2] = std::make_pair(oss.str(), port);
}
// roboRIO-<team>-FRC.lan
llvm::SmallString<32> mdns_lan;
wpi::SmallString<32> mdns_lan;
{
llvm::raw_svector_ostream oss{mdns_lan};
wpi::raw_svector_ostream oss{mdns_lan};
oss << "roboRIO-" << team << "-FRC.lan";
servers[3] = std::make_pair(oss.str(), port);
}
// roboRIO-<team>-FRC.frc-field.local
llvm::SmallString<64> field_local;
wpi::SmallString<64> field_local;
{
llvm::raw_svector_ostream oss{field_local};
wpi::raw_svector_ostream oss{field_local};
oss << "roboRIO-" << team << "-FRC.frc-field.local";
servers[4] = std::make_pair(oss.str(), port);
}
@@ -463,7 +464,7 @@ void DispatcherBase::ClientThreadMain() {
bool DispatcherBase::ClientHandshake(
NetworkConnection& conn, std::function<std::shared_ptr<Message>()> get_msg,
std::function<void(llvm::ArrayRef<std::shared_ptr<Message>>)> send_msgs) {
std::function<void(wpi::ArrayRef<std::shared_ptr<Message>>)> send_msgs) {
// get identity
std::string self_id;
{
@@ -543,7 +544,7 @@ bool DispatcherBase::ClientHandshake(
bool DispatcherBase::ServerHandshake(
NetworkConnection& conn, std::function<std::shared_ptr<Message>()> get_msg,
std::function<void(llvm::ArrayRef<std::shared_ptr<Message>>)> send_msgs) {
std::function<void(wpi::ArrayRef<std::shared_ptr<Message>>)> send_msgs) {
// Wait for the client to send us a hello.
auto msg = get_msg();
if (!msg) {

View File

@@ -17,10 +17,10 @@
#include <utility>
#include <vector>
#include <llvm/StringRef.h>
#include <llvm/Twine.h>
#include <support/condition_variable.h>
#include <support/mutex.h>
#include <wpi/StringRef.h>
#include <wpi/Twine.h>
#include <wpi/condition_variable.h>
#include <wpi/mutex.h>
#include "IDispatcher.h"
#include "INetworkConnection.h"
@@ -81,11 +81,11 @@ class DispatcherBase : public IDispatcher {
bool ClientHandshake(
NetworkConnection& conn,
std::function<std::shared_ptr<Message>()> get_msg,
std::function<void(llvm::ArrayRef<std::shared_ptr<Message>>)> send_msgs);
std::function<void(wpi::ArrayRef<std::shared_ptr<Message>>)> send_msgs);
bool ServerHandshake(
NetworkConnection& conn,
std::function<std::shared_ptr<Message>()> get_msg,
std::function<void(llvm::ArrayRef<std::shared_ptr<Message>>)> send_msgs);
std::function<void(wpi::ArrayRef<std::shared_ptr<Message>>)> send_msgs);
void ClientReconnect(unsigned int proto_rev = 0x0300);

View File

@@ -7,13 +7,13 @@
#include "DsClient.h"
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include <support/raw_socket_istream.h>
#include <wpi/SmallString.h>
#include <wpi/TCPConnector.h>
#include <wpi/raw_ostream.h>
#include <wpi/raw_socket_istream.h>
#include "Dispatcher.h"
#include "Log.h"
#include "tcpsockets/TCPConnector.h"
using namespace nt;
@@ -80,7 +80,7 @@ void DsClient::Thread::Main() {
while (m_active && !is.has_error()) {
// Read JSON "{...}". This is very limited, does not handle quoted "}" or
// nested {}, but is sufficient for this purpose.
llvm::SmallString<128> json;
wpi::SmallString<128> json;
char ch;
// Throw away characters until {
@@ -112,10 +112,10 @@ void DsClient::Thread::Main() {
// Look for "robotIP":12345, and get 12345 portion
size_t pos = json.find("\"robotIP\"");
if (pos == llvm::StringRef::npos) continue; // could not find?
if (pos == wpi::StringRef::npos) continue; // could not find?
pos += 9;
pos = json.find(':', pos);
if (pos == llvm::StringRef::npos) continue; // could not find?
if (pos == wpi::StringRef::npos) continue; // could not find?
size_t endpos = json.find_first_not_of("0123456789", pos + 1);
DEBUG3("found robotIP=" << json.slice(pos + 1, endpos));
@@ -136,7 +136,7 @@ void DsClient::Thread::Main() {
// Convert number into dotted quad
json.clear();
llvm::raw_svector_ostream os{json};
wpi::raw_svector_ostream os{json};
os << ((ip >> 24) & 0xff) << "." << ((ip >> 16) & 0xff) << "."
<< ((ip >> 8) & 0xff) << "." << (ip & 0xff);
INFO("client: DS overriding server IP to " << os.str());

View File

@@ -8,7 +8,7 @@
#ifndef NTCORE_DSCLIENT_H_
#define NTCORE_DSCLIENT_H_
#include <support/SafeThread.h>
#include <wpi/SafeThread.h>
#include "Log.h"

View File

@@ -41,7 +41,7 @@ bool impl::EntryNotifierThread::Matches(const EntryListenerData& listener,
// must match local id or prefix
if (listener.entry != 0 && data.entry != listener.entry) return false;
if (listener.entry == 0 &&
!llvm::StringRef(data.name).startswith(listener.prefix))
!wpi::StringRef(data.name).startswith(listener.prefix))
return false;
return true;
@@ -62,7 +62,7 @@ unsigned int EntryNotifier::Add(
}
unsigned int EntryNotifier::AddPolled(unsigned int poller_uid,
llvm::StringRef prefix,
wpi::StringRef prefix,
unsigned int flags) {
if ((flags & NT_NOTIFY_LOCAL) != 0) m_local_notifiers = true;
return DoAdd(poller_uid, prefix, flags);

View File

@@ -86,10 +86,10 @@ class EntryNotifier
bool local_notifiers() const override;
unsigned int Add(std::function<void(const EntryNotification& event)> callback,
llvm::StringRef prefix, unsigned int flags) override;
wpi::StringRef prefix, unsigned int flags) override;
unsigned int Add(std::function<void(const EntryNotification& event)> callback,
unsigned int local_id, unsigned int flags) override;
unsigned int AddPolled(unsigned int poller_uid, llvm::StringRef prefix,
unsigned int AddPolled(unsigned int poller_uid, wpi::StringRef prefix,
unsigned int flags) override;
unsigned int AddPolled(unsigned int poller_uid, unsigned int local_id,
unsigned int flags) override;

View File

@@ -25,12 +25,12 @@ class IEntryNotifier {
virtual unsigned int Add(
std::function<void(const EntryNotification& event)> callback,
llvm::StringRef prefix, unsigned int flags) = 0;
wpi::StringRef prefix, unsigned int flags) = 0;
virtual unsigned int Add(
std::function<void(const EntryNotification& event)> callback,
unsigned int local_id, unsigned int flags) = 0;
virtual unsigned int AddPolled(unsigned int poller_uid,
llvm::StringRef prefix,
wpi::StringRef prefix,
unsigned int flags) = 0;
virtual unsigned int AddPolled(unsigned int poller_uid, unsigned int local_id,
unsigned int flags) = 0;

View File

@@ -12,8 +12,8 @@
#include <memory>
#include <vector>
#include <llvm/ArrayRef.h>
#include <llvm/Twine.h>
#include <wpi/ArrayRef.h>
#include <wpi/Twine.h>
#include "Message.h"
#include "ntcore_cpp.h"
@@ -48,7 +48,7 @@ class IStorage {
INetworkConnection& conn,
std::vector<std::shared_ptr<Message>>* msgs) = 0;
virtual void ApplyInitialAssignments(
INetworkConnection& conn, llvm::ArrayRef<std::shared_ptr<Message>> msgs,
INetworkConnection& conn, wpi::ArrayRef<std::shared_ptr<Message>> msgs,
bool new_server, std::vector<std::shared_ptr<Message>>* out_msgs) = 0;
// Filename-based save/load functions. Used both by periodic saves and

View File

@@ -11,8 +11,8 @@
#include <atomic>
#include <memory>
#include <support/UidVector.h>
#include <support/mutex.h>
#include <wpi/UidVector.h>
#include <wpi/mutex.h>
#include "ConnectionNotifier.h"
#include "Dispatcher.h"

View File

@@ -8,7 +8,7 @@
#ifndef NTCORE_LOG_H_
#define NTCORE_LOG_H_
#include <support/Logger.h>
#include <wpi/Logger.h>
#define LOG(level, x) WPI_LOG(m_logger, level, x)

View File

@@ -7,24 +7,24 @@
#include "LoggerImpl.h"
#include <llvm/Path.h>
#include <llvm/SmallString.h>
#include <llvm/StringRef.h>
#include <llvm/raw_ostream.h>
#include <wpi/Path.h>
#include <wpi/SmallString.h>
#include <wpi/StringRef.h>
#include <wpi/raw_ostream.h>
using namespace nt;
static void DefaultLogger(unsigned int level, const char* file,
unsigned int line, const char* msg) {
llvm::SmallString<128> buf;
llvm::raw_svector_ostream oss(buf);
wpi::SmallString<128> buf;
wpi::raw_svector_ostream oss(buf);
if (level == 20) {
oss << "NT: " << msg << '\n';
llvm::errs() << oss.str();
wpi::errs() << oss.str();
return;
}
llvm::StringRef levelmsg;
wpi::StringRef levelmsg;
if (level >= 50)
levelmsg = "CRITICAL: ";
else if (level >= 40)
@@ -34,7 +34,7 @@ static void DefaultLogger(unsigned int level, const char* file,
else
return;
oss << "NT: " << levelmsg << msg << " (" << file << ':' << line << ")\n";
llvm::errs() << oss.str();
wpi::errs() << oss.str();
}
LoggerImpl::LoggerImpl(int inst) : m_inst(inst) {}
@@ -67,7 +67,7 @@ unsigned int LoggerImpl::GetMinLevel() {
void LoggerImpl::Log(unsigned int level, const char* file, unsigned int line,
const char* msg) {
// this is safe because it's null terminated and always the end
const char* filename = llvm::sys::path::filename(file).data();
const char* filename = wpi::sys::path::filename(file).data();
{
auto thr = GetThread();
if (!thr || thr->m_listeners.empty())

View File

@@ -126,7 +126,7 @@ std::shared_ptr<Message> Message::Read(WireDecoder& decoder,
if (!decoder.ReadUleb128(&size)) return nullptr;
const char* params;
if (!decoder.Read(&params, size)) return nullptr;
msg->m_str = llvm::StringRef(params, size);
msg->m_str = wpi::StringRef(params, size);
break;
}
case kRpcResponse: {
@@ -140,7 +140,7 @@ std::shared_ptr<Message> Message::Read(WireDecoder& decoder,
if (!decoder.ReadUleb128(&size)) return nullptr;
const char* results;
if (!decoder.Read(&results, size)) return nullptr;
msg->m_str = llvm::StringRef(results, size);
msg->m_str = wpi::StringRef(results, size);
break;
}
default:
@@ -151,21 +151,21 @@ std::shared_ptr<Message> Message::Read(WireDecoder& decoder,
return msg;
}
std::shared_ptr<Message> Message::ClientHello(llvm::StringRef self_id) {
std::shared_ptr<Message> Message::ClientHello(wpi::StringRef self_id) {
auto msg = std::make_shared<Message>(kClientHello, private_init());
msg->m_str = self_id;
return msg;
}
std::shared_ptr<Message> Message::ServerHello(unsigned int flags,
llvm::StringRef self_id) {
wpi::StringRef self_id) {
auto msg = std::make_shared<Message>(kServerHello, private_init());
msg->m_str = self_id;
msg->m_flags = flags;
return msg;
}
std::shared_ptr<Message> Message::EntryAssign(llvm::StringRef name,
std::shared_ptr<Message> Message::EntryAssign(wpi::StringRef name,
unsigned int id,
unsigned int seq_num,
std::shared_ptr<Value> value,
@@ -204,7 +204,7 @@ std::shared_ptr<Message> Message::EntryDelete(unsigned int id) {
}
std::shared_ptr<Message> Message::ExecuteRpc(unsigned int id, unsigned int uid,
llvm::StringRef params) {
wpi::StringRef params) {
auto msg = std::make_shared<Message>(kExecuteRpc, private_init());
msg->m_str = params;
msg->m_id = id;
@@ -213,7 +213,7 @@ std::shared_ptr<Message> Message::ExecuteRpc(unsigned int id, unsigned int uid,
}
std::shared_ptr<Message> Message::RpcResponse(unsigned int id, unsigned int uid,
llvm::StringRef result) {
wpi::StringRef result) {
auto msg = std::make_shared<Message>(kRpcResponse, private_init());
msg->m_str = result;
msg->m_id = id;

View File

@@ -50,7 +50,7 @@ class Message {
// Message data accessors. Callers are responsible for knowing what data is
// actually provided for a particular message.
llvm::StringRef str() const { return m_str; }
wpi::StringRef str() const { return m_str; }
std::shared_ptr<Value> value() const { return m_value; }
unsigned int id() const { return m_id; }
unsigned int flags() const { return m_flags; }
@@ -79,10 +79,10 @@ class Message {
}
// Create messages with data
static std::shared_ptr<Message> ClientHello(llvm::StringRef self_id);
static std::shared_ptr<Message> ClientHello(wpi::StringRef self_id);
static std::shared_ptr<Message> ServerHello(unsigned int flags,
llvm::StringRef self_id);
static std::shared_ptr<Message> EntryAssign(llvm::StringRef name,
wpi::StringRef self_id);
static std::shared_ptr<Message> EntryAssign(wpi::StringRef name,
unsigned int id,
unsigned int seq_num,
std::shared_ptr<Value> value,
@@ -94,9 +94,9 @@ class Message {
unsigned int flags);
static std::shared_ptr<Message> EntryDelete(unsigned int id);
static std::shared_ptr<Message> ExecuteRpc(unsigned int id, unsigned int uid,
llvm::StringRef params);
wpi::StringRef params);
static std::shared_ptr<Message> RpcResponse(unsigned int id, unsigned int uid,
llvm::StringRef result);
wpi::StringRef result);
Message(const Message&) = delete;
Message& operator=(const Message&) = delete;

View File

@@ -7,14 +7,14 @@
#include "NetworkConnection.h"
#include <support/raw_socket_istream.h>
#include <support/timestamp.h>
#include <wpi/NetworkStream.h>
#include <wpi/raw_socket_istream.h>
#include <wpi/timestamp.h>
#include "IConnectionNotifier.h"
#include "Log.h"
#include "WireDecoder.h"
#include "WireEncoder.h"
#include "tcpsockets/NetworkStream.h"
using namespace nt;
@@ -143,7 +143,7 @@ void NetworkConnection::ReadThreadMain() {
DEBUG("error reading in handshake: " << decoder.error());
return msg;
},
[&](llvm::ArrayRef<std::shared_ptr<Message>> msgs) {
[&](wpi::ArrayRef<std::shared_ptr<Message>> msgs) {
m_outgoing.emplace(msgs);
})) {
set_state(kDead);

View File

@@ -18,9 +18,9 @@
#include <utility>
#include <vector>
#include <support/ConcurrentQueue.h>
#include <support/condition_variable.h>
#include <support/mutex.h>
#include <wpi/ConcurrentQueue.h>
#include <wpi/condition_variable.h>
#include <wpi/mutex.h>
#include "INetworkConnection.h"
#include "Message.h"
@@ -40,7 +40,7 @@ class NetworkConnection : public INetworkConnection {
typedef std::function<bool(
NetworkConnection& conn,
std::function<std::shared_ptr<Message>()> get_msg,
std::function<void(llvm::ArrayRef<std::shared_ptr<Message>>)> send_msgs)>
std::function<void(wpi::ArrayRef<std::shared_ptr<Message>>)> send_msgs)>
HandshakeFunc;
typedef std::function<void(std::shared_ptr<Message> msg,
NetworkConnection* conn)>

View File

@@ -36,7 +36,7 @@ void RpcServer::ProcessRpc(unsigned int local_id, unsigned int call_uid,
}
void RpcServer::PostRpcResponse(unsigned int local_id, unsigned int call_uid,
llvm::StringRef result) {
wpi::StringRef result) {
auto thr = GetThread();
auto i = thr->m_response_map.find(impl::RpcIdPair{local_id, call_uid});
if (i == thr->m_response_map.end()) {

View File

@@ -10,8 +10,8 @@
#include <utility>
#include <llvm/DenseMap.h>
#include <support/mutex.h>
#include <wpi/DenseMap.h>
#include <wpi/mutex.h>
#include "CallbackManager.h"
#include "Handle.h"
@@ -75,7 +75,7 @@ class RpcServerThread
int m_inst;
wpi::Logger& m_logger;
llvm::DenseMap<RpcIdPair, IRpcServer::SendResponseFunc> m_response_map;
wpi::DenseMap<RpcIdPair, IRpcServer::SendResponseFunc> m_response_map;
};
} // namespace impl
@@ -100,7 +100,7 @@ class RpcServer : public IRpcServer,
unsigned int rpc_uid) override;
void PostRpcResponse(unsigned int local_id, unsigned int call_uid,
llvm::StringRef result);
wpi::StringRef result);
private:
int m_inst;

View File

@@ -7,7 +7,7 @@
#include "Storage.h"
#include <support/timestamp.h>
#include <wpi/timestamp.h>
#include "Handle.h"
#include "IDispatcher.h"
@@ -386,7 +386,7 @@ void Storage::GetInitialAssignments(
}
void Storage::ApplyInitialAssignments(
INetworkConnection& conn, llvm::ArrayRef<std::shared_ptr<Message>> msgs,
INetworkConnection& conn, wpi::ArrayRef<std::shared_ptr<Message>> msgs,
bool new_server, std::vector<std::shared_ptr<Message>>* out_msgs) {
std::unique_lock<wpi::mutex> lock(m_mutex);
if (m_server) return; // should not do this on server
@@ -758,7 +758,7 @@ void Storage::DeleteAllEntries() {
}
Storage::Entry* Storage::GetOrNew(const Twine& name) {
llvm::SmallString<128> nameBuf;
wpi::SmallString<128> nameBuf;
StringRef nameStr = name.toStringRef(nameBuf);
auto& entry = m_entries[nameStr];
if (!entry) {
@@ -779,7 +779,7 @@ unsigned int Storage::GetEntry(const Twine& name) {
std::vector<unsigned int> Storage::GetEntries(const Twine& prefix,
unsigned int types) {
llvm::SmallString<128> prefixBuf;
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
std::lock_guard<wpi::mutex> lock(m_mutex);
std::vector<unsigned int> ids;
@@ -837,7 +837,7 @@ uint64_t Storage::GetEntryLastChange(unsigned int local_id) const {
std::vector<EntryInfo> Storage::GetEntryInfo(int inst, const Twine& prefix,
unsigned int types) {
llvm::SmallString<128> prefixBuf;
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
std::lock_guard<wpi::mutex> lock(m_mutex);
std::vector<EntryInfo> infos;
@@ -861,7 +861,7 @@ unsigned int Storage::AddListener(
const Twine& prefix,
std::function<void(const EntryNotification& event)> callback,
unsigned int flags) const {
llvm::SmallString<128> prefixBuf;
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
std::lock_guard<wpi::mutex> lock(m_mutex);
unsigned int uid = m_notifier.Add(callback, prefixStr, flags);
@@ -898,7 +898,7 @@ unsigned int Storage::AddListener(
unsigned int Storage::AddPolledListener(unsigned int poller,
const Twine& prefix,
unsigned int flags) const {
llvm::SmallString<128> prefixBuf;
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
std::lock_guard<wpi::mutex> lock(m_mutex);
unsigned int uid = m_notifier.AddPolled(poller, prefixStr, flags);
@@ -965,7 +965,7 @@ bool Storage::GetEntries(
const Twine& prefix,
std::vector<std::pair<std::string, std::shared_ptr<Value>>>* entries)
const {
llvm::SmallString<128> prefixBuf;
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
// copy values out of storage as quickly as possible so lock isn't held
{

View File

@@ -18,24 +18,21 @@
#include <utility>
#include <vector>
#include <llvm/DenseMap.h>
#include <llvm/SmallSet.h>
#include <llvm/StringMap.h>
#include <support/condition_variable.h>
#include <support/mutex.h>
#include <wpi/DenseMap.h>
#include <wpi/SmallSet.h>
#include <wpi/StringMap.h>
#include <wpi/condition_variable.h>
#include <wpi/mutex.h>
#include "IStorage.h"
#include "Message.h"
#include "SequenceNumber.h"
#include "ntcore_cpp.h"
namespace llvm {
class raw_ostream;
} // namespace llvm
namespace wpi {
class Logger;
class raw_istream;
class raw_ostream;
} // namespace wpi
namespace nt {
@@ -72,7 +69,7 @@ class Storage : public IStorage {
INetworkConnection& conn,
std::vector<std::shared_ptr<Message>>* msgs) override;
void ApplyInitialAssignments(
INetworkConnection& conn, llvm::ArrayRef<std::shared_ptr<Message>> msgs,
INetworkConnection& conn, wpi::ArrayRef<std::shared_ptr<Message>> msgs,
bool new_server,
std::vector<std::shared_ptr<Message>>* out_msgs) override;
@@ -142,11 +139,11 @@ class Storage : public IStorage {
// Stream-based save/load functions (exposed for testing purposes). These
// implement the guts of the filename-based functions.
void SavePersistent(llvm::raw_ostream& os, bool periodic) const;
void SavePersistent(wpi::raw_ostream& os, bool periodic) const;
bool LoadEntries(wpi::raw_istream& is, const Twine& prefix, bool persistent,
std::function<void(size_t line, const char* msg)> warn);
void SaveEntries(llvm::raw_ostream& os, const Twine& prefix) const;
void SaveEntries(wpi::raw_ostream& os, const Twine& prefix) const;
// RPC configuration needs to come through here as RPC definitions are
// actually special Storage value types.
@@ -161,7 +158,7 @@ class Storage : public IStorage {
private:
// Data for each table entry.
struct Entry {
explicit Entry(llvm::StringRef name_) : name(name_) {}
explicit Entry(wpi::StringRef name_) : name(name_) {}
bool IsPersistent() const { return (flags & NT_PERSISTENT) != 0; }
// We redundantly store the name so that it's available when accessing the
@@ -195,12 +192,12 @@ class Storage : public IStorage {
unsigned int rpc_call_uid{0};
};
typedef llvm::StringMap<Entry*> EntriesMap;
typedef wpi::StringMap<Entry*> EntriesMap;
typedef std::vector<Entry*> IdMap;
typedef std::vector<std::unique_ptr<Entry>> LocalMap;
typedef std::pair<unsigned int, unsigned int> RpcIdPair;
typedef llvm::DenseMap<RpcIdPair, std::string> RpcResultMap;
typedef llvm::SmallSet<RpcIdPair, 12> RpcBlockingCallSet;
typedef wpi::DenseMap<RpcIdPair, std::string> RpcResultMap;
typedef wpi::SmallSet<RpcIdPair, 12> RpcBlockingCallSet;
mutable wpi::mutex m_mutex;
EntriesMap m_entries;

View File

@@ -8,10 +8,10 @@
#include <cctype>
#include <string>
#include <llvm/SmallString.h>
#include <llvm/StringExtras.h>
#include <support/Base64.h>
#include <support/raw_istream.h>
#include <wpi/Base64.h>
#include <wpi/SmallString.h>
#include <wpi/StringExtras.h>
#include <wpi/raw_istream.h>
#include "IDispatcher.h"
#include "IEntryNotifier.h"
@@ -35,7 +35,7 @@ class LoadPersistentImpl {
bool ReadLine();
bool ReadHeader();
NT_Type ReadType();
llvm::StringRef ReadName(llvm::SmallVectorImpl<char>& buf);
wpi::StringRef ReadName(wpi::SmallVectorImpl<char>& buf);
std::shared_ptr<Value> ReadValue(NT_Type type);
std::shared_ptr<Value> ReadBooleanValue();
std::shared_ptr<Value> ReadDoubleValue();
@@ -52,8 +52,8 @@ class LoadPersistentImpl {
wpi::raw_istream& m_is;
WarnFunc m_warn;
llvm::StringRef m_line;
llvm::SmallString<128> m_line_buf;
wpi::StringRef m_line;
wpi::SmallString<128> m_line_buf;
size_t m_line_num = 0;
std::vector<int> m_buf_boolean_array;
@@ -71,11 +71,11 @@ class LoadPersistentImpl {
* Returns a pair containing the extracted token (if any) and the remaining
* tail string.
*/
static std::pair<llvm::StringRef, llvm::StringRef> ReadStringToken(
llvm::StringRef source) {
static std::pair<wpi::StringRef, wpi::StringRef> ReadStringToken(
wpi::StringRef source) {
// Match opening quote
if (source.empty() || source.front() != '"')
return std::make_pair(llvm::StringRef(), source);
return std::make_pair(wpi::StringRef(), source);
// Scan for ending double quote, checking for escaped as we go.
size_t size = source.size();
@@ -98,8 +98,8 @@ static int fromxdigit(char ch) {
return ch - '0';
}
static llvm::StringRef UnescapeString(llvm::StringRef source,
llvm::SmallVectorImpl<char>& buf) {
static wpi::StringRef UnescapeString(wpi::StringRef source,
wpi::SmallVectorImpl<char>& buf) {
assert(source.size() >= 2 && source.front() == '"' && source.back() == '"');
buf.clear();
buf.reserve(source.size() - 2);
@@ -137,7 +137,7 @@ static llvm::StringRef UnescapeString(llvm::StringRef source,
break;
}
}
return llvm::StringRef{buf.data(), buf.size()};
return wpi::StringRef{buf.data(), buf.size()};
}
bool LoadPersistentImpl::Load(StringRef prefix, std::vector<Entry>* entries) {
@@ -152,8 +152,8 @@ bool LoadPersistentImpl::Load(StringRef prefix, std::vector<Entry>* entries) {
}
// name
llvm::SmallString<128> buf;
llvm::StringRef name = ReadName(buf);
wpi::SmallString<128> buf;
wpi::StringRef name = ReadName(buf);
if (name.empty() || !name.startswith(prefix)) continue;
// =
@@ -194,7 +194,7 @@ bool LoadPersistentImpl::ReadHeader() {
}
NT_Type LoadPersistentImpl::ReadType() {
llvm::StringRef tok;
wpi::StringRef tok;
std::tie(tok, m_line) = m_line.split(' ');
if (tok == "boolean") {
return NT_BOOLEAN;
@@ -205,7 +205,7 @@ NT_Type LoadPersistentImpl::ReadType() {
} else if (tok == "raw") {
return NT_RAW;
} else if (tok == "array") {
llvm::StringRef array_tok;
wpi::StringRef array_tok;
std::tie(array_tok, m_line) = m_line.split(' ');
if (array_tok == "boolean")
return NT_BOOLEAN_ARRAY;
@@ -217,16 +217,16 @@ NT_Type LoadPersistentImpl::ReadType() {
return NT_UNASSIGNED;
}
llvm::StringRef LoadPersistentImpl::ReadName(llvm::SmallVectorImpl<char>& buf) {
llvm::StringRef tok;
wpi::StringRef LoadPersistentImpl::ReadName(wpi::SmallVectorImpl<char>& buf) {
wpi::StringRef tok;
std::tie(tok, m_line) = ReadStringToken(m_line);
if (tok.empty()) {
Warn("missing name");
return llvm::StringRef{};
return wpi::StringRef{};
}
if (tok.back() != '"') {
Warn("unterminated name string");
return llvm::StringRef{};
return wpi::StringRef{};
}
return UnescapeString(tok, buf);
}
@@ -262,7 +262,7 @@ std::shared_ptr<Value> LoadPersistentImpl::ReadBooleanValue() {
std::shared_ptr<Value> LoadPersistentImpl::ReadDoubleValue() {
// need to convert to null-terminated string for std::strtod()
llvm::SmallString<64> buf;
wpi::SmallString<64> buf;
char* end;
double v = std::strtod(m_line.c_str(buf), &end);
if (*end != '\0') {
@@ -273,7 +273,7 @@ std::shared_ptr<Value> LoadPersistentImpl::ReadDoubleValue() {
}
std::shared_ptr<Value> LoadPersistentImpl::ReadStringValue() {
llvm::StringRef tok;
wpi::StringRef tok;
std::tie(tok, m_line) = ReadStringToken(m_line);
if (tok.empty()) {
Warn("missing string value");
@@ -283,12 +283,12 @@ std::shared_ptr<Value> LoadPersistentImpl::ReadStringValue() {
Warn("unterminated string value");
return nullptr;
}
llvm::SmallString<128> buf;
wpi::SmallString<128> buf;
return Value::MakeString(UnescapeString(tok, buf));
}
std::shared_ptr<Value> LoadPersistentImpl::ReadRawValue() {
llvm::SmallString<128> buf;
wpi::SmallString<128> buf;
size_t nr;
return Value::MakeRaw(wpi::Base64Decode(m_line, &nr, buf));
}
@@ -296,7 +296,7 @@ std::shared_ptr<Value> LoadPersistentImpl::ReadRawValue() {
std::shared_ptr<Value> LoadPersistentImpl::ReadBooleanArrayValue() {
m_buf_boolean_array.clear();
while (!m_line.empty()) {
llvm::StringRef tok;
wpi::StringRef tok;
std::tie(tok, m_line) = m_line.split(',');
tok = tok.trim(" \t");
if (tok == "true") {
@@ -314,11 +314,11 @@ std::shared_ptr<Value> LoadPersistentImpl::ReadBooleanArrayValue() {
std::shared_ptr<Value> LoadPersistentImpl::ReadDoubleArrayValue() {
m_buf_double_array.clear();
while (!m_line.empty()) {
llvm::StringRef tok;
wpi::StringRef tok;
std::tie(tok, m_line) = m_line.split(',');
tok = tok.trim(" \t");
// need to convert to null-terminated string for std::strtod()
llvm::SmallString<64> buf;
wpi::SmallString<64> buf;
char* end;
double v = std::strtod(tok.c_str(buf), &end);
if (*end != '\0') {
@@ -334,7 +334,7 @@ std::shared_ptr<Value> LoadPersistentImpl::ReadDoubleArrayValue() {
std::shared_ptr<Value> LoadPersistentImpl::ReadStringArrayValue() {
m_buf_string_array.clear();
while (!m_line.empty()) {
llvm::StringRef tok;
wpi::StringRef tok;
std::tie(tok, m_line) = ReadStringToken(m_line);
if (tok.empty()) {
Warn("missing string value");
@@ -345,7 +345,7 @@ std::shared_ptr<Value> LoadPersistentImpl::ReadStringArrayValue() {
return nullptr;
}
llvm::SmallString<128> buf;
wpi::SmallString<128> buf;
m_buf_string_array.push_back(UnescapeString(tok, buf));
m_line = m_line.ltrim(" \t");
@@ -363,7 +363,7 @@ std::shared_ptr<Value> LoadPersistentImpl::ReadStringArrayValue() {
bool Storage::LoadEntries(
wpi::raw_istream& is, const Twine& prefix, bool persistent,
std::function<void(size_t line, const char* msg)> warn) {
llvm::SmallString<128> prefixBuf;
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
// entries to add

View File

@@ -8,11 +8,11 @@
#include <cctype>
#include <string>
#include <llvm/Format.h>
#include <llvm/SmallString.h>
#include <llvm/StringExtras.h>
#include <llvm/raw_ostream.h>
#include <support/Base64.h>
#include <wpi/Base64.h>
#include <wpi/Format.h>
#include <wpi/SmallString.h>
#include <wpi/StringExtras.h>
#include <wpi/raw_ostream.h>
#include "Log.h"
#include "Storage.h"
@@ -25,25 +25,25 @@ class SavePersistentImpl {
public:
typedef std::pair<std::string, std::shared_ptr<Value>> Entry;
explicit SavePersistentImpl(llvm::raw_ostream& os) : m_os(os) {}
explicit SavePersistentImpl(wpi::raw_ostream& os) : m_os(os) {}
void Save(llvm::ArrayRef<Entry> entries);
void Save(wpi::ArrayRef<Entry> entries);
private:
void WriteString(llvm::StringRef str);
void WriteString(wpi::StringRef str);
void WriteHeader();
void WriteEntries(llvm::ArrayRef<Entry> entries);
void WriteEntry(llvm::StringRef name, const Value& value);
void WriteEntries(wpi::ArrayRef<Entry> entries);
void WriteEntry(wpi::StringRef name, const Value& value);
bool WriteType(NT_Type type);
void WriteValue(const Value& value);
llvm::raw_ostream& m_os;
wpi::raw_ostream& m_os;
};
} // namespace
/* Escapes and writes a string, including start and end double quotes */
void SavePersistentImpl::WriteString(llvm::StringRef str) {
void SavePersistentImpl::WriteString(wpi::StringRef str) {
m_os << '"';
for (auto c : str) {
switch (c) {
@@ -67,14 +67,14 @@ void SavePersistentImpl::WriteString(llvm::StringRef str) {
// Write out the escaped representation.
m_os << "\\x";
m_os << llvm::hexdigit((c >> 4) & 0xF);
m_os << llvm::hexdigit((c >> 0) & 0xF);
m_os << wpi::hexdigit((c >> 4) & 0xF);
m_os << wpi::hexdigit((c >> 0) & 0xF);
}
}
m_os << '"';
}
void SavePersistentImpl::Save(llvm::ArrayRef<Entry> entries) {
void SavePersistentImpl::Save(wpi::ArrayRef<Entry> entries) {
WriteHeader();
WriteEntries(entries);
}
@@ -83,14 +83,14 @@ void SavePersistentImpl::WriteHeader() {
m_os << "[NetworkTables Storage 3.0]\n";
}
void SavePersistentImpl::WriteEntries(llvm::ArrayRef<Entry> entries) {
void SavePersistentImpl::WriteEntries(wpi::ArrayRef<Entry> entries) {
for (auto& i : entries) {
if (!i.second) continue;
WriteEntry(i.first, *i.second);
}
}
void SavePersistentImpl::WriteEntry(llvm::StringRef name, const Value& value) {
void SavePersistentImpl::WriteEntry(wpi::StringRef name, const Value& value) {
if (!WriteType(value.type())) return; // type
WriteString(name); // name
m_os << '='; // '='
@@ -133,7 +133,7 @@ void SavePersistentImpl::WriteValue(const Value& value) {
m_os << (value.GetBoolean() ? "true" : "false");
break;
case NT_DOUBLE:
m_os << llvm::format("%g", value.GetDouble());
m_os << wpi::format("%g", value.GetDouble());
break;
case NT_STRING:
WriteString(value.GetString());
@@ -156,7 +156,7 @@ void SavePersistentImpl::WriteValue(const Value& value) {
for (auto elem : value.GetDoubleArray()) {
if (!first) m_os << ',';
first = false;
m_os << llvm::format("%g", elem);
m_os << wpi::format("%g", elem);
}
break;
}
@@ -174,7 +174,7 @@ void SavePersistentImpl::WriteValue(const Value& value) {
}
}
void Storage::SavePersistent(llvm::raw_ostream& os, bool periodic) const {
void Storage::SavePersistent(wpi::raw_ostream& os, bool periodic) const {
std::vector<SavePersistentImpl::Entry> entries;
if (!GetPersistentEntries(periodic, &entries)) return;
SavePersistentImpl(os).Save(entries);
@@ -182,11 +182,11 @@ void Storage::SavePersistent(llvm::raw_ostream& os, bool periodic) const {
const char* Storage::SavePersistent(const Twine& filename,
bool periodic) const {
llvm::SmallString<128> fn;
wpi::SmallString<128> fn;
filename.toVector(fn);
llvm::SmallString<128> tmp = fn;
wpi::SmallString<128> tmp = fn;
tmp += ".tmp";
llvm::SmallString<128> bak = fn;
wpi::SmallString<128> bak = fn;
bak += ".bak";
// Get entries before creating file
@@ -197,7 +197,7 @@ const char* Storage::SavePersistent(const Twine& filename,
// start by writing to temporary file
std::error_code ec;
llvm::raw_fd_ostream os(tmp, ec, llvm::sys::fs::F_Text);
wpi::raw_fd_ostream os(tmp, ec, wpi::sys::fs::F_Text);
if (ec.value() != 0) {
err = "could not open file";
goto done;
@@ -226,7 +226,7 @@ done:
return err;
}
void Storage::SaveEntries(llvm::raw_ostream& os, const Twine& prefix) const {
void Storage::SaveEntries(wpi::raw_ostream& os, const Twine& prefix) const {
std::vector<SavePersistentImpl::Entry> entries;
if (!GetEntries(prefix, &entries)) return;
SavePersistentImpl(os).Save(entries);
@@ -234,11 +234,11 @@ void Storage::SaveEntries(llvm::raw_ostream& os, const Twine& prefix) const {
const char* Storage::SaveEntries(const Twine& filename,
const Twine& prefix) const {
llvm::SmallString<128> fn;
wpi::SmallString<128> fn;
filename.toVector(fn);
llvm::SmallString<128> tmp = fn;
wpi::SmallString<128> tmp = fn;
tmp += ".tmp";
llvm::SmallString<128> bak = fn;
wpi::SmallString<128> bak = fn;
bak += ".bak";
// Get entries before creating file
@@ -247,7 +247,7 @@ const char* Storage::SaveEntries(const Twine& filename,
// start by writing to temporary file
std::error_code ec;
llvm::raw_fd_ostream os(tmp, ec, llvm::sys::fs::F_Text);
wpi::raw_fd_ostream os(tmp, ec, wpi::sys::fs::F_Text);
if (ec.value() != 0) {
return "could not open file";
}

View File

@@ -7,7 +7,7 @@
#include <stdint.h>
#include <support/timestamp.h>
#include <wpi/timestamp.h>
#include "Value_internal.h"
#include "networktables/NetworkTableValue.h"
@@ -42,7 +42,7 @@ Value::~Value() {
delete[] m_val.data.arr_string.arr;
}
std::shared_ptr<Value> Value::MakeBooleanArray(llvm::ArrayRef<int> value,
std::shared_ptr<Value> Value::MakeBooleanArray(wpi::ArrayRef<int> value,
uint64_t time) {
auto val = std::make_shared<Value>(NT_BOOLEAN_ARRAY, time, private_init());
val->m_val.data.arr_boolean.arr = new int[value.size()];
@@ -51,7 +51,7 @@ std::shared_ptr<Value> Value::MakeBooleanArray(llvm::ArrayRef<int> value,
return val;
}
std::shared_ptr<Value> Value::MakeDoubleArray(llvm::ArrayRef<double> value,
std::shared_ptr<Value> Value::MakeDoubleArray(wpi::ArrayRef<double> value,
uint64_t time) {
auto val = std::make_shared<Value>(NT_DOUBLE_ARRAY, time, private_init());
val->m_val.data.arr_double.arr = new double[value.size()];
@@ -60,7 +60,7 @@ std::shared_ptr<Value> Value::MakeDoubleArray(llvm::ArrayRef<double> value,
return val;
}
std::shared_ptr<Value> Value::MakeStringArray(llvm::ArrayRef<std::string> value,
std::shared_ptr<Value> Value::MakeStringArray(wpi::ArrayRef<std::string> value,
uint64_t time) {
auto val = std::make_shared<Value>(NT_STRING_ARRAY, time, private_init());
val->m_string_array = value;
@@ -142,7 +142,7 @@ void nt::ConvertToC(const Value& in, NT_Value* out) {
out->type = in.type();
}
void nt::ConvertToC(llvm::StringRef in, NT_String* out) {
void nt::ConvertToC(wpi::StringRef in, NT_String* out) {
out->len = in.size();
out->str = static_cast<char*>(std::malloc(in.size() + 1));
std::memcpy(out->str, in.data(), in.size());
@@ -164,10 +164,10 @@ std::shared_ptr<Value> nt::ConvertFromC(const NT_Value& value) {
case NT_RPC:
return Value::MakeRpc(ConvertFromC(value.data.v_raw));
case NT_BOOLEAN_ARRAY:
return Value::MakeBooleanArray(llvm::ArrayRef<int>(
return Value::MakeBooleanArray(wpi::ArrayRef<int>(
value.data.arr_boolean.arr, value.data.arr_boolean.size));
case NT_DOUBLE_ARRAY:
return Value::MakeDoubleArray(llvm::ArrayRef<double>(
return Value::MakeDoubleArray(wpi::ArrayRef<double>(
value.data.arr_double.arr, value.data.arr_double.size));
case NT_STRING_ARRAY: {
std::vector<std::string> v;

View File

@@ -11,7 +11,7 @@
#include <memory>
#include <string>
#include <llvm/StringRef.h>
#include <wpi/StringRef.h>
#include "ntcore_c.h"
@@ -21,9 +21,9 @@ class Value;
void ConvertToC(const Value& in, NT_Value* out);
std::shared_ptr<Value> ConvertFromC(const NT_Value& value);
void ConvertToC(llvm::StringRef in, NT_String* out);
inline llvm::StringRef ConvertFromC(const NT_String& str) {
return llvm::StringRef(str.str, str.len);
void ConvertToC(wpi::StringRef in, NT_String* out);
inline wpi::StringRef ConvertFromC(const NT_String& str) {
return wpi::StringRef(str.str, str.len);
}
} // namespace nt

View File

@@ -13,8 +13,8 @@
#include <cstdlib>
#include <cstring>
#include <llvm/MathExtras.h>
#include <support/leb128.h>
#include <wpi/MathExtras.h>
#include <wpi/leb128.h>
using namespace nt;
@@ -43,7 +43,7 @@ static double ReadDouble(const char*& buf) {
val <<= 8;
val |= (*reinterpret_cast<const unsigned char*>(buf)) & 0xff;
++buf;
return llvm::BitsToDouble(val);
return wpi::BitsToDouble(val);
}
WireDecoder::WireDecoder(wpi::raw_istream& is, unsigned int proto_rev,
@@ -202,6 +202,6 @@ bool WireDecoder::ReadString(std::string* str) {
}
const char* buf;
if (!Read(&buf, len)) return false;
*str = llvm::StringRef(buf, len);
*str = wpi::StringRef(buf, len);
return true;
}

View File

@@ -14,8 +14,8 @@
#include <memory>
#include <string>
#include <support/leb128.h>
#include <support/raw_istream.h>
#include <wpi/leb128.h>
#include <wpi/raw_istream.h>
#include "Log.h"
#include "networktables/NetworkTableValue.h"

View File

@@ -13,8 +13,8 @@
#include <cstdlib>
#include <cstring>
#include <llvm/MathExtras.h>
#include <support/leb128.h>
#include <wpi/MathExtras.h>
#include <wpi/leb128.h>
using namespace nt;
@@ -25,7 +25,7 @@ WireEncoder::WireEncoder(unsigned int proto_rev) {
void WireEncoder::WriteDouble(double val) {
// The highest performance way to do this, albeit non-portable.
uint64_t v = llvm::DoubleToBits(val);
uint64_t v = wpi::DoubleToBits(val);
m_data.append(
{static_cast<char>((v >> 56) & 0xff), static_cast<char>((v >> 48) & 0xff),
static_cast<char>((v >> 40) & 0xff), static_cast<char>((v >> 32) & 0xff),
@@ -175,7 +175,7 @@ void WireEncoder::WriteValue(const Value& value) {
}
}
size_t WireEncoder::GetStringSize(llvm::StringRef str) const {
size_t WireEncoder::GetStringSize(wpi::StringRef str) const {
if (m_proto_rev < 0x0300u) {
size_t len = str.size();
if (len > 0xffff) len = 0xffff; // Limited to 64K length; truncate
@@ -184,7 +184,7 @@ size_t WireEncoder::GetStringSize(llvm::StringRef str) const {
return wpi::SizeUleb128(str.size()) + str.size();
}
void WireEncoder::WriteString(llvm::StringRef str) {
void WireEncoder::WriteString(wpi::StringRef str) {
// length
size_t len = str.size();
if (m_proto_rev < 0x0300u) {

View File

@@ -13,8 +13,8 @@
#include <cassert>
#include <cstddef>
#include <llvm/SmallVector.h>
#include <llvm/StringRef.h>
#include <wpi/SmallVector.h>
#include <wpi/StringRef.h>
#include "networktables/NetworkTableValue.h"
@@ -52,8 +52,8 @@ class WireEncoder {
/* Returns number of bytes written to memory buffer. */
size_t size() const { return m_data.size(); }
llvm::StringRef ToStringRef() const {
return llvm::StringRef(m_data.data(), m_data.size());
wpi::StringRef ToStringRef() const {
return wpi::StringRef(m_data.data(), m_data.size());
}
/* Writes a single byte. */
@@ -83,7 +83,7 @@ class WireEncoder {
void WriteType(NT_Type type);
void WriteValue(const Value& value);
void WriteString(llvm::StringRef str);
void WriteString(wpi::StringRef str);
/* Utility function to get the written size of a value (without actually
* writing it).
@@ -93,7 +93,7 @@ class WireEncoder {
/* Utility function to get the written size of a string (without actually
* writing it).
*/
size_t GetStringSize(llvm::StringRef str) const;
size_t GetStringSize(wpi::StringRef str) const;
protected:
/* The protocol revision. E.g. 0x0200 for version 2.0. */
@@ -103,7 +103,7 @@ class WireEncoder {
const char* m_error;
private:
llvm::SmallVector<char, 256> m_data;
wpi::SmallVector<char, 256> m_data;
};
} // namespace nt

View File

@@ -3,10 +3,10 @@
#include "edu_wpi_first_networktables_NetworkTablesJNI.h"
#include "ntcore.h"
#include "support/jni_util.h"
#include "llvm/ConvertUTF.h"
#include "llvm/SmallString.h"
#include "llvm/raw_ostream.h"
#include "wpi/ConvertUTF.h"
#include "wpi/SmallString.h"
#include "wpi/jni_util.h"
#include "wpi/raw_ostream.h"
using namespace wpi::java;
@@ -141,7 +141,7 @@ std::shared_ptr<nt::Value> FromJavaBooleanArray(JNIEnv* env, jbooleanArray jarr,
jlong time) {
CriticalJBooleanArrayRef ref{env, jarr};
if (!ref) return nullptr;
llvm::ArrayRef<jboolean> elements{ref};
wpi::ArrayRef<jboolean> elements{ref};
size_t len = elements.size();
std::vector<int> arr;
arr.reserve(len);
@@ -286,7 +286,7 @@ static jobject MakeJObject(JNIEnv *env, jobject inst,
}
static jobjectArray MakeJObject(JNIEnv *env, jobject inst,
llvm::ArrayRef<nt::ConnectionNotification> arr) {
wpi::ArrayRef<nt::ConnectionNotification> arr) {
jobjectArray jarr = env->NewObjectArray(arr.size(), connectionNotificationCls, nullptr);
if (!jarr) return nullptr;
for (size_t i = 0; i < arr.size(); ++i) {
@@ -297,7 +297,7 @@ static jobjectArray MakeJObject(JNIEnv *env, jobject inst,
}
static jobjectArray MakeJObject(JNIEnv *env, jobject inst,
llvm::ArrayRef<nt::EntryNotification> arr) {
wpi::ArrayRef<nt::EntryNotification> arr) {
jobjectArray jarr = env->NewObjectArray(arr.size(), entryNotificationCls, nullptr);
if (!jarr) return nullptr;
for (size_t i = 0; i < arr.size(); ++i) {
@@ -308,7 +308,7 @@ static jobjectArray MakeJObject(JNIEnv *env, jobject inst,
}
static jobjectArray MakeJObject(JNIEnv *env, jobject inst,
llvm::ArrayRef<nt::LogMessage> arr) {
wpi::ArrayRef<nt::LogMessage> arr) {
jobjectArray jarr = env->NewObjectArray(arr.size(), logMessageCls, nullptr);
if (!jarr) return nullptr;
for (size_t i = 0; i < arr.size(); ++i) {
@@ -319,7 +319,7 @@ static jobjectArray MakeJObject(JNIEnv *env, jobject inst,
}
static jobjectArray MakeJObject(JNIEnv *env, jobject inst,
llvm::ArrayRef<nt::RpcAnswer> arr) {
wpi::ArrayRef<nt::RpcAnswer> arr) {
jobjectArray jarr = env->NewObjectArray(arr.size(), rpcAnswerCls, nullptr);
if (!jarr) return nullptr;
for (size_t i = 0; i < arr.size(); ++i) {
@@ -1593,8 +1593,8 @@ JNIEXPORT jobjectArray JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI
std::vector<std::string> warns;
const char* err = nt::LoadPersistent(inst, JStringRef{env, filename}.str(),
[&](size_t line, const char* msg) {
llvm::SmallString<128> warn;
llvm::raw_svector_ostream oss(warn);
wpi::SmallString<128> warn;
wpi::raw_svector_ostream oss(warn);
oss << line << ": " << msg;
warns.emplace_back(oss.str());
});
@@ -1646,8 +1646,8 @@ JNIEXPORT jobjectArray JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI
const char* err = nt::LoadEntries(inst, JStringRef{env, filename}.str(),
JStringRef{env, prefix}.str(),
[&](size_t line, const char* msg) {
llvm::SmallString<128> warn;
llvm::raw_svector_ostream oss(warn);
wpi::SmallString<128> warn;
wpi::raw_svector_ostream oss(warn);
oss << line << ": " << msg;
warns.emplace_back(oss.str());
});

View File

@@ -9,9 +9,9 @@
#include <algorithm>
#include <llvm/SmallString.h>
#include <llvm/StringMap.h>
#include <llvm/raw_ostream.h>
#include <wpi/SmallString.h>
#include <wpi/StringMap.h>
#include <wpi/raw_ostream.h>
#include "networktables/NetworkTableInstance.h"
#include "ntcore.h"
@@ -38,19 +38,19 @@ StringRef NetworkTable::BasenameKey(StringRef key) {
std::string NetworkTable::NormalizeKey(const Twine& key,
bool withLeadingSlash) {
llvm::SmallString<128> buf;
wpi::SmallString<128> buf;
return NormalizeKey(key, buf, withLeadingSlash);
}
StringRef NetworkTable::NormalizeKey(const Twine& key,
llvm::SmallVectorImpl<char>& buf,
wpi::SmallVectorImpl<char>& buf,
bool withLeadingSlash) {
buf.clear();
if (withLeadingSlash) buf.push_back(PATH_SEPARATOR_CHAR);
// for each path element, add it with a slash following
llvm::SmallString<128> keyBuf;
wpi::SmallString<128> keyBuf;
StringRef keyStr = key.toStringRef(keyBuf);
llvm::SmallVector<StringRef, 16> parts;
wpi::SmallVector<StringRef, 16> parts;
keyStr.split(parts, PATH_SEPARATOR_CHAR, -1, false);
for (auto i = parts.begin(); i != parts.end(); ++i) {
buf.append(i->begin(), i->end());
@@ -65,10 +65,10 @@ std::vector<std::string> NetworkTable::GetHierarchy(const Twine& key) {
std::vector<std::string> hierarchy;
hierarchy.emplace_back(1, PATH_SEPARATOR_CHAR);
// for each path element, add it to the end of what we built previously
llvm::SmallString<128> keyBuf;
wpi::SmallString<128> keyBuf;
StringRef keyStr = key.toStringRef(keyBuf);
llvm::SmallString<128> path;
llvm::SmallVector<StringRef, 16> parts;
wpi::SmallString<128> path;
wpi::SmallVector<StringRef, 16> parts;
keyStr.split(parts, PATH_SEPARATOR_CHAR, -1, false);
if (!parts.empty()) {
for (auto i = parts.begin(); i != parts.end(); ++i) {
@@ -121,7 +121,7 @@ void NetworkTable::SetTeam(int team) {
void NetworkTable::SetIPAddress(StringRef address) {
auto inst = NetworkTableInstance::GetDefault();
llvm::SmallString<32> addr_copy{address};
wpi::SmallString<32> addr_copy{address};
inst.SetServer(addr_copy.c_str(), s_port);
// Stop the DS client if we're explicitly connecting to localhost
@@ -133,7 +133,7 @@ void NetworkTable::SetIPAddress(StringRef address) {
void NetworkTable::SetIPAddress(ArrayRef<std::string> addresses) {
auto inst = NetworkTableInstance::GetDefault();
llvm::SmallVector<StringRef, 8> servers;
wpi::SmallVector<StringRef, 8> servers;
for (const auto& ip_address : addresses) servers.emplace_back(ip_address);
inst.SetServer(servers, s_port);
@@ -201,7 +201,7 @@ NetworkTableInstance NetworkTable::GetInstance() const {
}
NetworkTableEntry NetworkTable::GetEntry(const Twine& key) const {
llvm::SmallString<128> keyBuf;
wpi::SmallString<128> keyBuf;
StringRef keyStr = key.toStringRef(keyBuf);
std::lock_guard<wpi::mutex> lock(m_mutex);
NT_Entry& entry = m_entries[keyStr];
@@ -257,7 +257,7 @@ void NetworkTable::AddTableListener(ITableListener* listener,
void NetworkTable::AddTableListenerEx(ITableListener* listener,
unsigned int flags) {
std::lock_guard<wpi::mutex> lock(m_mutex);
llvm::SmallString<128> path(m_path);
wpi::SmallString<128> path(m_path);
path += PATH_SEPARATOR_CHAR;
size_t prefix_len = path.size();
NT_EntryListener id = nt::AddEntryListener(
@@ -304,7 +304,7 @@ void NetworkTable::AddSubTableListener(ITableListener* listener,
// The lambda needs to be copyable, but StringMap is not, so use
// a shared_ptr to it.
auto notified_tables = std::make_shared<llvm::StringMap<char>>();
auto notified_tables = std::make_shared<wpi::StringMap<char>>();
unsigned int flags = NT_NOTIFY_NEW | NT_NOTIFY_IMMEDIATE;
if (localNotify) flags |= NT_NOTIFY_LOCAL;

View File

@@ -7,7 +7,7 @@
#include "networktables/NetworkTableInstance.h"
#include <llvm/SmallString.h>
#include <wpi/SmallString.h>
using namespace nt;
@@ -31,7 +31,7 @@ std::shared_ptr<NetworkTable> NetworkTableInstance::GetTable(
void NetworkTableInstance::StartClient(ArrayRef<StringRef> servers,
unsigned int port) {
llvm::SmallVector<std::pair<StringRef, unsigned int>, 8> server_ports;
wpi::SmallVector<std::pair<StringRef, unsigned int>, 8> server_ports;
for (const auto& server : servers)
server_ports.emplace_back(std::make_pair(server, port));
StartClient(server_ports);
@@ -39,7 +39,7 @@ void NetworkTableInstance::StartClient(ArrayRef<StringRef> servers,
void NetworkTableInstance::SetServer(ArrayRef<StringRef> servers,
unsigned int port) {
llvm::SmallVector<std::pair<StringRef, unsigned int>, 8> server_ports;
wpi::SmallVector<std::pair<StringRef, unsigned int>, 8> server_ports;
for (const auto& server : servers)
server_ports.emplace_back(std::make_pair(server, port));
SetServer(server_ports);

View File

@@ -10,7 +10,7 @@
#include <cassert>
#include <cstdlib>
#include <support/timestamp.h>
#include <wpi/timestamp.h>
#include "Value_internal.h"
#include "ntcore.h"
@@ -19,7 +19,7 @@ using namespace nt;
// Conversion helpers
static void ConvertToC(llvm::StringRef in, char** out) {
static void ConvertToC(wpi::StringRef in, char** out) {
*out = static_cast<char*>(std::malloc(in.size() + 1));
std::memmove(*out, in.data(), in.size());
(*out)[in.size()] = '\0';
@@ -915,11 +915,11 @@ NT_Bool NT_SetEntryBooleanArray(NT_Entry entry, uint64_t time,
NT_Bool force) {
if (force != 0) {
nt::SetEntryTypeValue(
entry, Value::MakeBooleanArray(llvm::makeArrayRef(arr, size), time));
entry, Value::MakeBooleanArray(wpi::makeArrayRef(arr, size), time));
return 1;
} else {
return nt::SetEntryValue(
entry, Value::MakeBooleanArray(llvm::makeArrayRef(arr, size), time));
entry, Value::MakeBooleanArray(wpi::makeArrayRef(arr, size), time));
}
}
@@ -927,11 +927,11 @@ NT_Bool NT_SetEntryDoubleArray(NT_Entry entry, uint64_t time, const double* arr,
size_t size, NT_Bool force) {
if (force != 0) {
nt::SetEntryTypeValue(
entry, Value::MakeDoubleArray(llvm::makeArrayRef(arr, size), time));
entry, Value::MakeDoubleArray(wpi::makeArrayRef(arr, size), time));
return 1;
} else {
return nt::SetEntryValue(
entry, Value::MakeDoubleArray(llvm::makeArrayRef(arr, size), time));
entry, Value::MakeDoubleArray(wpi::makeArrayRef(arr, size), time));
}
}
@@ -1061,7 +1061,7 @@ NT_Bool NT_SetDefaultEntryBooleanArray(NT_Entry entry, uint64_t time,
size_t default_size) {
return nt::SetDefaultEntryValue(
entry, Value::MakeBooleanArray(
llvm::makeArrayRef(default_value, default_size), time));
wpi::makeArrayRef(default_value, default_size), time));
}
NT_Bool NT_SetDefaultEntryDoubleArray(NT_Entry entry, uint64_t time,
@@ -1069,7 +1069,7 @@ NT_Bool NT_SetDefaultEntryDoubleArray(NT_Entry entry, uint64_t time,
size_t default_size) {
return nt::SetDefaultEntryValue(
entry, Value::MakeDoubleArray(
llvm::makeArrayRef(default_value, default_size), time));
wpi::makeArrayRef(default_value, default_size), time));
}
NT_Bool NT_SetDefaultEntryStringArray(NT_Entry entry, uint64_t time,

View File

@@ -11,7 +11,7 @@
#include <cstdio>
#include <cstdlib>
#include <support/timestamp.h>
#include <wpi/timestamp.h>
#include "Handle.h"
#include "InstanceImpl.h"

View File

@@ -13,7 +13,7 @@ extern "C" {
struct NT_String* NT_GetStringForTesting(const char* string, int* struct_size) {
struct NT_String* str =
static_cast<NT_String*>(std::calloc(1, sizeof(NT_String)));
nt::ConvertToC(llvm::StringRef(string), str);
nt::ConvertToC(wpi::StringRef(string), str);
*struct_size = sizeof(NT_String);
return str;
}
@@ -25,7 +25,7 @@ struct NT_EntryInfo* NT_GetEntryInfoForTesting(const char* name,
int* struct_size) {
struct NT_EntryInfo* entry_info =
static_cast<NT_EntryInfo*>(std::calloc(1, sizeof(NT_EntryInfo)));
nt::ConvertToC(llvm::StringRef(name), &entry_info->name);
nt::ConvertToC(wpi::StringRef(name), &entry_info->name);
entry_info->type = type;
entry_info->flags = flags;
entry_info->last_change = last_change;
@@ -43,8 +43,8 @@ struct NT_ConnectionInfo* NT_GetConnectionInfoForTesting(
uint64_t last_update, unsigned int protocol_version, int* struct_size) {
struct NT_ConnectionInfo* conn_info = static_cast<NT_ConnectionInfo*>(
std::calloc(1, sizeof(NT_ConnectionInfo)));
nt::ConvertToC(llvm::StringRef(remote_id), &conn_info->remote_id);
nt::ConvertToC(llvm::StringRef(remote_ip), &conn_info->remote_ip);
nt::ConvertToC(wpi::StringRef(remote_id), &conn_info->remote_id);
nt::ConvertToC(wpi::StringRef(remote_ip), &conn_info->remote_ip);
conn_info->remote_port = remote_port;
conn_info->last_update = last_update;
conn_info->protocol_version = protocol_version;
@@ -87,7 +87,7 @@ struct NT_Value* NT_GetValueStringForTesting(uint64_t last_change,
static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
value->type = NT_STRING;
value->last_change = last_change;
nt::ConvertToC(llvm::StringRef(str), &value->data.v_string);
nt::ConvertToC(wpi::StringRef(str), &value->data.v_string);
*struct_size = sizeof(NT_Value);
return value;
}
@@ -98,7 +98,7 @@ struct NT_Value* NT_GetValueRawForTesting(uint64_t last_change, const char* raw,
static_cast<NT_Value*>(std::calloc(1, sizeof(NT_Value)));
value->type = NT_RAW;
value->last_change = last_change;
nt::ConvertToC(llvm::StringRef(raw, raw_len), &value->data.v_string);
nt::ConvertToC(wpi::StringRef(raw, raw_len), &value->data.v_string);
*struct_size = sizeof(NT_Value);
return value;
}
@@ -165,7 +165,7 @@ static void CopyNtValue(const struct NT_Value* copy_from,
static void CopyNtString(const struct NT_String* copy_from,
struct NT_String* copy_to) {
nt::ConvertToC(llvm::StringRef(copy_from->str, copy_from->len), copy_to);
nt::ConvertToC(wpi::StringRef(copy_from->str, copy_from->len), copy_to);
}
struct NT_RpcParamDef* NT_GetRpcParamDefForTesting(const char* name,
@@ -173,7 +173,7 @@ struct NT_RpcParamDef* NT_GetRpcParamDefForTesting(const char* name,
int* struct_size) {
struct NT_RpcParamDef* def =
static_cast<NT_RpcParamDef*>(std::calloc(1, sizeof(NT_RpcParamDef)));
nt::ConvertToC(llvm::StringRef(name), &def->name);
nt::ConvertToC(wpi::StringRef(name), &def->name);
CopyNtValue(val, &def->def_value);
*struct_size = sizeof(NT_RpcParamDef);
return def;
@@ -190,7 +190,7 @@ struct NT_RpcResultDef* NT_GetRpcResultsDefForTesting(const char* name,
int* struct_size) {
struct NT_RpcResultDef* def =
static_cast<NT_RpcResultDef*>(std::calloc(1, sizeof(NT_RpcResultDef)));
nt::ConvertToC(llvm::StringRef(name), &def->name);
nt::ConvertToC(wpi::StringRef(name), &def->name);
def->type = type;
*struct_size = sizeof(NT_RpcResultDef);
return def;
@@ -208,7 +208,7 @@ struct NT_RpcDefinition* NT_GetRpcDefinitionForTesting(
struct NT_RpcDefinition* def =
static_cast<NT_RpcDefinition*>(std::calloc(1, sizeof(NT_RpcDefinition)));
def->version = version;
nt::ConvertToC(llvm::StringRef(name), &def->name);
nt::ConvertToC(wpi::StringRef(name), &def->name);
def->num_params = num_params;
def->params = static_cast<NT_RpcParamDef*>(
std::malloc(num_params * sizeof(NT_RpcParamDef)));
@@ -235,8 +235,8 @@ struct NT_RpcAnswer* NT_GetRpcAnswerForTesting(
static_cast<NT_RpcAnswer*>(std::calloc(1, sizeof(NT_RpcAnswer)));
info->entry = rpc_id;
info->call = call_uid;
nt::ConvertToC(llvm::StringRef(name), &info->name);
nt::ConvertToC(llvm::StringRef(params, params_len), &info->params);
nt::ConvertToC(wpi::StringRef(name), &info->name);
nt::ConvertToC(wpi::StringRef(params, params_len), &info->params);
*struct_size = sizeof(NT_RpcAnswer);
return info;
}

View File

@@ -9,7 +9,7 @@
#include "ntcore_c.h"
void ITableListener::ValueChangedEx(ITable* source, llvm::StringRef key,
void ITableListener::ValueChangedEx(ITable* source, wpi::StringRef key,
std::shared_ptr<nt::Value> value,
unsigned int flags) {
ValueChanged(source, key, value, (flags & NT_NOTIFY_NEW) != 0);