diff --git a/wpilibc/athena/include/DriverStation.h b/wpilibc/athena/include/DriverStation.h index 54637ad86b..c8ca104a11 100644 --- a/wpilibc/athena/include/DriverStation.h +++ b/wpilibc/athena/include/DriverStation.h @@ -32,11 +32,10 @@ class DriverStation : public SensorBase, public RobotStateInterface { virtual ~DriverStation(); static DriverStation& GetInstance(); - static void ReportError(std::string error); - static void ReportWarning(std::string error); - static void ReportError(bool is_error, int code, const std::string& error, - const std::string& location, - const std::string& stack); + static void ReportError(llvm::StringRef error); + static void ReportWarning(llvm::StringRef error); + static void ReportError(bool is_error, int code, llvm::StringRef error, + llvm::StringRef location, llvm::StringRef stack); static const int kJoystickPorts = 6; diff --git a/wpilibc/athena/src/DriverStation.cpp b/wpilibc/athena/src/DriverStation.cpp index 03af035da3..8378dea515 100644 --- a/wpilibc/athena/src/DriverStation.cpp +++ b/wpilibc/athena/src/DriverStation.cpp @@ -17,6 +17,7 @@ #include "Timer.h" #include "Utility.h" #include "WPIErrors.h" +#include "llvm/SmallString.h" using namespace frc; @@ -44,8 +45,9 @@ DriverStation& DriverStation::GetInstance() { * * The error is also printed to the program console. */ -void DriverStation::ReportError(std::string error) { - HAL_SendError(1, 1, 0, error.c_str(), "", "", 1); +void DriverStation::ReportError(llvm::StringRef error) { + llvm::SmallString<128> temp; + HAL_SendError(1, 1, 0, error.c_str(temp), "", "", 1); } /** @@ -53,8 +55,9 @@ void DriverStation::ReportError(std::string error) { * * The warning is also printed to the program console. */ -void DriverStation::ReportWarning(std::string error) { - HAL_SendError(0, 1, 0, error.c_str(), "", "", 1); +void DriverStation::ReportWarning(llvm::StringRef error) { + llvm::SmallString<128> temp; + HAL_SendError(0, 1, 0, error.c_str(temp), "", "", 1); } /** @@ -63,11 +66,13 @@ void DriverStation::ReportWarning(std::string error) { * The error is also printed to the program console. */ void DriverStation::ReportError(bool is_error, int32_t code, - const std::string& error, - const std::string& location, - const std::string& stack) { - HAL_SendError(is_error, code, 0, error.c_str(), location.c_str(), - stack.c_str(), 1); + llvm::StringRef error, llvm::StringRef location, + llvm::StringRef stack) { + llvm::SmallString<128> errorTemp; + llvm::SmallString<128> locationTemp; + llvm::SmallString<128> stackTemp; + HAL_SendError(is_error, code, 0, error.c_str(errorTemp), + location.c_str(locationTemp), stack.c_str(stackTemp), 1); } /** diff --git a/wpilibc/athena/src/Preferences.cpp b/wpilibc/athena/src/Preferences.cpp index 5813770800..e47835b664 100644 --- a/wpilibc/athena/src/Preferences.cpp +++ b/wpilibc/athena/src/Preferences.cpp @@ -11,11 +11,12 @@ #include "HAL/HAL.h" #include "WPIErrors.h" +#include "llvm/StringRef.h" using namespace frc; /** The Preferences table name */ -static const char* kTableName = "Preferences"; +static llvm::StringRef kTableName{"Preferences"}; void Preferences::Listener::ValueChanged(ITable* source, llvm::StringRef key, std::shared_ptr value, diff --git a/wpilibc/athena/src/Utility.cpp b/wpilibc/athena/src/Utility.cpp index 37e52334ce..de27907808 100644 --- a/wpilibc/athena/src/Utility.cpp +++ b/wpilibc/athena/src/Utility.cpp @@ -17,6 +17,7 @@ #include "ErrorBase.h" #include "HAL/HAL.h" +#include "llvm/SmallString.h" using namespace frc; @@ -26,13 +27,14 @@ using namespace frc; * The users don't call this, but instead use the wpi_assert macros in * Utility.h. */ -bool wpi_assert_impl(bool conditionValue, const char* conditionText, - const char* message, const char* fileName, int lineNumber, - const char* funcName) { +bool wpi_assert_impl(bool conditionValue, llvm::StringRef conditionText, + llvm::StringRef message, llvm::StringRef fileName, + int lineNumber, llvm::StringRef funcName) { if (!conditionValue) { std::stringstream locStream; locStream << funcName << " ["; - locStream << basename(fileName) << ":" << lineNumber << "]"; + llvm::SmallString<128> fileTemp; + locStream << basename(fileName.c_str(fileTemp)) << ":" << lineNumber << "]"; std::stringstream errorStream; @@ -60,13 +62,15 @@ bool wpi_assert_impl(bool conditionValue, const char* conditionText, * This should not be called directly; it should only be used by * wpi_assertEqual_impl and wpi_assertNotEqual_impl. */ -void wpi_assertEqual_common_impl(const char* valueA, const char* valueB, - const char* equalityType, const char* message, - const char* fileName, int lineNumber, - const char* funcName) { +void wpi_assertEqual_common_impl(llvm::StringRef valueA, llvm::StringRef valueB, + llvm::StringRef equalityType, + llvm::StringRef message, + llvm::StringRef fileName, int lineNumber, + llvm::StringRef funcName) { std::stringstream locStream; locStream << funcName << " ["; - locStream << basename(fileName) << ":" << lineNumber << "]"; + llvm::SmallString<128> fileTemp; + locStream << basename(fileName.c_str(fileTemp)) << ":" << lineNumber << "]"; std::stringstream errorStream; @@ -94,10 +98,10 @@ void wpi_assertEqual_common_impl(const char* valueA, const char* valueB, * The users don't call this, but instead use the wpi_assertEqual macros in * Utility.h. */ -bool wpi_assertEqual_impl(int valueA, int valueB, const char* valueAString, - const char* valueBString, const char* message, - const char* fileName, int lineNumber, - const char* funcName) { +bool wpi_assertEqual_impl(int valueA, int valueB, llvm::StringRef valueAString, + llvm::StringRef valueBString, llvm::StringRef message, + llvm::StringRef fileName, int lineNumber, + llvm::StringRef funcName) { if (!(valueA == valueB)) { wpi_assertEqual_common_impl(valueAString, valueBString, "==", message, fileName, lineNumber, funcName); @@ -112,10 +116,11 @@ bool wpi_assertEqual_impl(int valueA, int valueB, const char* valueAString, * The users don't call this, but instead use the wpi_assertNotEqual macros in * Utility.h. */ -bool wpi_assertNotEqual_impl(int valueA, int valueB, const char* valueAString, - const char* valueBString, const char* message, - const char* fileName, int lineNumber, - const char* funcName) { +bool wpi_assertNotEqual_impl(int valueA, int valueB, + llvm::StringRef valueAString, + llvm::StringRef valueBString, + llvm::StringRef message, llvm::StringRef fileName, + int lineNumber, llvm::StringRef funcName) { if (!(valueA != valueB)) { wpi_assertEqual_common_impl(valueAString, valueBString, "!=", message, fileName, lineNumber, funcName); diff --git a/wpilibc/shared/include/Utility.h b/wpilibc/shared/include/Utility.h index ab47c1d4aa..6e58b56578 100644 --- a/wpilibc/shared/include/Utility.h +++ b/wpilibc/shared/include/Utility.h @@ -15,6 +15,8 @@ #include +#include "llvm/StringRef.h" + #define wpi_assert(condition) \ wpi_assert_impl(condition, #condition, "", __FILE__, __LINE__, __FUNCTION__) #define wpi_assertWithMessage(condition, message) \ @@ -32,17 +34,18 @@ wpi_assertNotEqual_impl(a, b, #a, #b, message, __FILE__, __LINE__, \ __FUNCTION__) -bool wpi_assert_impl(bool conditionValue, const char* conditionText, - const char* message, const char* fileName, int lineNumber, - const char* funcName); -bool wpi_assertEqual_impl(int valueA, int valueB, const char* valueAString, - const char* valueBString, const char* message, - const char* fileName, int lineNumber, - const char* funcName); -bool wpi_assertNotEqual_impl(int valueA, int valueB, const char* valueAString, - const char* valueBString, const char* message, - const char* fileName, int lineNumber, - const char* funcName); +bool wpi_assert_impl(bool conditionValue, llvm::StringRef conditionText, + llvm::StringRef message, llvm::StringRef fileName, + int lineNumber, llvm::StringRef funcName); +bool wpi_assertEqual_impl(int valueA, int valueB, llvm::StringRef valueAString, + llvm::StringRef valueBString, llvm::StringRef message, + llvm::StringRef fileName, int lineNumber, + llvm::StringRef funcName); +bool wpi_assertNotEqual_impl(int valueA, int valueB, + llvm::StringRef valueAString, + llvm::StringRef valueBString, + llvm::StringRef message, llvm::StringRef fileName, + int lineNumber, llvm::StringRef funcName); void wpi_suspendOnAssertEnabled(bool enabled); diff --git a/wpilibc/sim/include/DriverStation.h b/wpilibc/sim/include/DriverStation.h index 8d9818f4b2..f0dec6856a 100644 --- a/wpilibc/sim/include/DriverStation.h +++ b/wpilibc/sim/include/DriverStation.h @@ -15,6 +15,7 @@ #include "RobotState.h" #include "SensorBase.h" +#include "llvm/StringRef.h" #include "simulation/gz_msgs/msgs.h" #ifdef _WIN32 @@ -38,11 +39,10 @@ class DriverStation : public SensorBase, public RobotStateInterface { virtual ~DriverStation() = default; static DriverStation& GetInstance(); - static void ReportError(std::string error); - static void ReportWarning(std::string error); - static void ReportError(bool is_error, int code, const std::string& error, - const std::string& location, - const std::string& stack); + static void ReportError(llvm::StringRef error); + static void ReportWarning(llvm::StringRef error); + static void ReportError(bool is_error, int code, llvm::StringRef error, + llvm::StringRef location, llvm::StringRef stack); static const int kBatteryChannel = 7; static const int kJoystickPorts = 4; diff --git a/wpilibc/sim/src/DriverStation.cpp b/wpilibc/sim/src/DriverStation.cpp index e974b6eb9d..6d04933e03 100644 --- a/wpilibc/sim/src/DriverStation.cpp +++ b/wpilibc/sim/src/DriverStation.cpp @@ -330,7 +330,7 @@ double DriverStation::GetMatchTime() const { * Report an error to the DriverStation messages window. * The error is also printed to the program console. */ -void DriverStation::ReportError(std::string error) { +void DriverStation::ReportError(llvm::StringRef error) { std::cout << error << std::endl; } @@ -338,7 +338,7 @@ void DriverStation::ReportError(std::string error) { * Report a warning to the DriverStation messages window. * The warning is also printed to the program console. */ -void DriverStation::ReportWarning(std::string error) { +void DriverStation::ReportWarning(llvm::StringRef error) { std::cout << error << std::endl; } @@ -346,10 +346,9 @@ void DriverStation::ReportWarning(std::string error) { * Report an error to the DriverStation messages window. * The error is also printed to the program console. */ -void DriverStation::ReportError(bool is_error, int code, - const std::string& error, - const std::string& location, - const std::string& stack) { +void DriverStation::ReportError(bool is_error, int code, llvm::StringRef error, + llvm::StringRef location, + llvm::StringRef stack) { if (!location.empty()) std::cout << (is_error ? "Error" : "Warning") << " at " << location << ": "; std::cout << error << std::endl; diff --git a/wpilibc/sim/src/Utility.cpp b/wpilibc/sim/src/Utility.cpp index da97cc5231..8f7d1003f0 100644 --- a/wpilibc/sim/src/Utility.cpp +++ b/wpilibc/sim/src/Utility.cpp @@ -18,6 +18,7 @@ #include #include "Timer.h" +#include "llvm/SmallString.h" #include "simulation/simTime.h" using namespace frc; @@ -56,15 +57,17 @@ static void wpi_handleTracing() { * The users don't call this, but instead use the wpi_assert macros in * Utility.h. */ -bool wpi_assert_impl(bool conditionValue, const char* conditionText, - const char* message, const char* fileName, int lineNumber, - const char* funcName) { +bool wpi_assert_impl(bool conditionValue, llvm::StringRef conditionText, + llvm::StringRef message, llvm::StringRef fileName, + int lineNumber, llvm::StringRef funcName) { if (!conditionValue) { std::stringstream errorStream; errorStream << "Assertion \"" << conditionText << "\" "; errorStream << "on line " << lineNumber << " "; - errorStream << "of " << basename(fileName) << " "; + + llvm::SmallString<128> fileTemp; + errorStream << "of " << basename(fileName.c_str(fileTemp)) << " "; if (message[0] != '\0') { errorStream << "failed: " << message << std::endl; @@ -86,10 +89,10 @@ bool wpi_assert_impl(bool conditionValue, const char* conditionText, * wpi_assertEqual_impl and wpi_assertNotEqual_impl. */ void wpi_assertEqual_common_impl(int valueA, int valueB, - const std::string& equalityType, - const std::string& message, - const std::string& fileName, int lineNumber, - const std::string& funcName) { + llvm::StringRef equalityType, + llvm::StringRef message, + llvm::StringRef fileName, int lineNumber, + llvm::StringRef funcName) { // Error string buffer std::stringstream error; @@ -118,9 +121,9 @@ void wpi_assertEqual_common_impl(int valueA, int valueB, * The users don't call this, but instead use the wpi_assertEqual macros in * Utility.h. */ -bool wpi_assertEqual_impl(int valueA, int valueB, const std::string& message, - const std::string& fileName, int lineNumber, - const std::string& funcName) { +bool wpi_assertEqual_impl(int valueA, int valueB, llvm::StringRef message, + llvm::StringRef fileName, int lineNumber, + llvm::StringRef funcName) { if (!(valueA == valueB)) { wpi_assertEqual_common_impl(valueA, valueB, "!=", message, fileName, lineNumber, funcName); @@ -135,9 +138,9 @@ bool wpi_assertEqual_impl(int valueA, int valueB, const std::string& message, * The users don't call this, but instead use the wpi_assertNotEqual macros in * Utility.h. */ -bool wpi_assertNotEqual_impl(int valueA, int valueB, const std::string& message, - const std::string& fileName, int lineNumber, - const std::string& funcName) { +bool wpi_assertNotEqual_impl(int valueA, int valueB, llvm::StringRef message, + llvm::StringRef fileName, int lineNumber, + llvm::StringRef funcName) { if (!(valueA != valueB)) { wpi_assertEqual_common_impl(valueA, valueB, "==", message, fileName, lineNumber, funcName);