Enable log macros to work with no args (#4475)

This is enabled by the C++20 __VA_OPT__ feature.
Uses of "{}" format string were updated.
Some warning suppressions were required for older clang versions.
Also improve codegen of wpi::Logger::Log(), frc::ReportError(), and frc::MakeError();
these generate better and less redundant code if they use fmt::string_view for the
format string instead of templating on it.
This commit is contained in:
Tyler Veness
2022-10-19 10:49:27 -07:00
committed by GitHub
parent 878cc8defb
commit 1fc098e696
70 changed files with 373 additions and 338 deletions

View File

@@ -22,7 +22,7 @@ Counter::Counter(Mode mode) {
int32_t status = 0;
m_counter = HAL_InitializeCounter(static_cast<HAL_Counter_Mode>(mode),
&m_index, &status);
FRC_CheckErrorStatus(status, "{}", "InitializeCounter");
FRC_CheckErrorStatus(status, "InitializeCounter");
SetMaxPeriod(0.5_s);
@@ -64,7 +64,7 @@ Counter::Counter(EncodingType encodingType,
std::shared_ptr<DigitalSource> downSource, bool inverted)
: Counter(kExternalDirection) {
if (encodingType != k1X && encodingType != k2X) {
throw FRC_MakeError(err::ParameterOutOfRange, "{}",
throw FRC_MakeError(err::ParameterOutOfRange,
"Counter only supports 1X and 2X quadrature decoding");
}
SetUpSource(upSource);
@@ -79,7 +79,7 @@ Counter::Counter(EncodingType encodingType,
HAL_SetCounterAverageSize(m_counter, 2, &status);
}
FRC_CheckErrorStatus(status, "{}", "Counter constructor");
FRC_CheckErrorStatus(status, "Counter constructor");
SetDownSourceEdge(inverted, true);
}
@@ -92,7 +92,7 @@ Counter::~Counter() {
int32_t status = 0;
HAL_FreeCounter(m_counter, &status);
FRC_ReportError(status, "{}", "Counter destructor");
FRC_ReportError(status, "Counter destructor");
}
void Counter::SetUpSource(int channel) {
@@ -124,7 +124,7 @@ void Counter::SetUpSource(std::shared_ptr<DigitalSource> source) {
static_cast<HAL_AnalogTriggerType>(
source->GetAnalogTriggerTypeForRouting()),
&status);
FRC_CheckErrorStatus(status, "{}", "SetUpSource");
FRC_CheckErrorStatus(status, "SetUpSource");
}
void Counter::SetUpSource(DigitalSource& source) {
@@ -135,19 +135,19 @@ void Counter::SetUpSource(DigitalSource& source) {
void Counter::SetUpSourceEdge(bool risingEdge, bool fallingEdge) {
if (m_upSource == nullptr) {
throw FRC_MakeError(
err::NullParameter, "{}",
err::NullParameter,
"Must set non-nullptr UpSource before setting UpSourceEdge");
}
int32_t status = 0;
HAL_SetCounterUpSourceEdge(m_counter, risingEdge, fallingEdge, &status);
FRC_CheckErrorStatus(status, "{}", "SetUpSourceEdge");
FRC_CheckErrorStatus(status, "SetUpSourceEdge");
}
void Counter::ClearUpSource() {
m_upSource.reset();
int32_t status = 0;
HAL_ClearCounterUpSource(m_counter, &status);
FRC_CheckErrorStatus(status, "{}", "ClearUpSource");
FRC_CheckErrorStatus(status, "ClearUpSource");
}
void Counter::SetDownSource(int channel) {
@@ -184,37 +184,37 @@ void Counter::SetDownSource(std::shared_ptr<DigitalSource> source) {
static_cast<HAL_AnalogTriggerType>(
source->GetAnalogTriggerTypeForRouting()),
&status);
FRC_CheckErrorStatus(status, "{}", "SetDownSource");
FRC_CheckErrorStatus(status, "SetDownSource");
}
void Counter::SetDownSourceEdge(bool risingEdge, bool fallingEdge) {
if (m_downSource == nullptr) {
throw FRC_MakeError(
err::NullParameter, "{}",
err::NullParameter,
"Must set non-nullptr DownSource before setting DownSourceEdge");
}
int32_t status = 0;
HAL_SetCounterDownSourceEdge(m_counter, risingEdge, fallingEdge, &status);
FRC_CheckErrorStatus(status, "{}", "SetDownSourceEdge");
FRC_CheckErrorStatus(status, "SetDownSourceEdge");
}
void Counter::ClearDownSource() {
m_downSource.reset();
int32_t status = 0;
HAL_ClearCounterDownSource(m_counter, &status);
FRC_CheckErrorStatus(status, "{}", "ClearDownSource");
FRC_CheckErrorStatus(status, "ClearDownSource");
}
void Counter::SetUpDownCounterMode() {
int32_t status = 0;
HAL_SetCounterUpDownMode(m_counter, &status);
FRC_CheckErrorStatus(status, "{}", "SetUpDownCounterMode");
FRC_CheckErrorStatus(status, "SetUpDownCounterMode");
}
void Counter::SetExternalDirectionMode() {
int32_t status = 0;
HAL_SetCounterExternalDirectionMode(m_counter, &status);
FRC_CheckErrorStatus(status, "{}", "SetExternalDirectionMode");
FRC_CheckErrorStatus(status, "SetExternalDirectionMode");
}
void Counter::SetSemiPeriodMode(bool highSemiPeriod) {
@@ -227,7 +227,7 @@ void Counter::SetSemiPeriodMode(bool highSemiPeriod) {
void Counter::SetPulseLengthMode(double threshold) {
int32_t status = 0;
HAL_SetCounterPulseLengthMode(m_counter, threshold, &status);
FRC_CheckErrorStatus(status, "{}", "SetPulseLengthMode");
FRC_CheckErrorStatus(status, "SetPulseLengthMode");
}
void Counter::SetReverseDirection(bool reverseDirection) {
@@ -252,7 +252,7 @@ void Counter::SetSamplesToAverage(int samplesToAverage) {
int Counter::GetSamplesToAverage() const {
int32_t status = 0;
int samples = HAL_GetCounterSamplesToAverage(m_counter, &status);
FRC_CheckErrorStatus(status, "{}", "GetSamplesToAverage");
FRC_CheckErrorStatus(status, "GetSamplesToAverage");
return samples;
}
@@ -263,46 +263,46 @@ int Counter::GetFPGAIndex() const {
int Counter::Get() const {
int32_t status = 0;
int value = HAL_GetCounter(m_counter, &status);
FRC_CheckErrorStatus(status, "{}", "Get");
FRC_CheckErrorStatus(status, "Get");
return value;
}
void Counter::Reset() {
int32_t status = 0;
HAL_ResetCounter(m_counter, &status);
FRC_CheckErrorStatus(status, "{}", "Reset");
FRC_CheckErrorStatus(status, "Reset");
}
units::second_t Counter::GetPeriod() const {
int32_t status = 0;
double value = HAL_GetCounterPeriod(m_counter, &status);
FRC_CheckErrorStatus(status, "{}", "GetPeriod");
FRC_CheckErrorStatus(status, "GetPeriod");
return units::second_t{value};
}
void Counter::SetMaxPeriod(units::second_t maxPeriod) {
int32_t status = 0;
HAL_SetCounterMaxPeriod(m_counter, maxPeriod.value(), &status);
FRC_CheckErrorStatus(status, "{}", "SetMaxPeriod");
FRC_CheckErrorStatus(status, "SetMaxPeriod");
}
void Counter::SetUpdateWhenEmpty(bool enabled) {
int32_t status = 0;
HAL_SetCounterUpdateWhenEmpty(m_counter, enabled, &status);
FRC_CheckErrorStatus(status, "{}", "SetUpdateWhenEmpty");
FRC_CheckErrorStatus(status, "SetUpdateWhenEmpty");
}
bool Counter::GetStopped() const {
int32_t status = 0;
bool value = HAL_GetCounterStopped(m_counter, &status);
FRC_CheckErrorStatus(status, "{}", "GetStopped");
FRC_CheckErrorStatus(status, "GetStopped");
return value;
}
bool Counter::GetDirection() const {
int32_t status = 0;
bool value = HAL_GetCounterDirection(m_counter, &status);
FRC_CheckErrorStatus(status, "{}", "GetDirection");
FRC_CheckErrorStatus(status, "GetDirection");
return value;
}