clang-tidy: google-readability-casting (NFC)

This commit is contained in:
Peter Johnson
2020-12-28 11:04:20 -08:00
parent 32fa97d68d
commit c97c6dc065
17 changed files with 104 additions and 80 deletions

View File

@@ -2036,8 +2036,8 @@ struct LogMessage {
void CallJava(JNIEnv* env, jobject func, jmethodID mid) {
JLocal<jstring> file{env, MakeJString(env, m_file)};
JLocal<jstring> msg{env, MakeJString(env, m_msg)};
env->CallVoidMethod(func, mid, (jint)m_level, file.obj(), (jint)m_line,
msg.obj());
env->CallVoidMethod(func, mid, static_cast<jint>(m_level), file.obj(),
static_cast<jint>(m_line), msg.obj());
}
static const char* GetName() { return "CSLogger"; }

View File

@@ -234,9 +234,10 @@ jobject CreatePWMConfigDataResult(JNIEnv* env, int32_t maxPwm,
int32_t deadbandMinPwm, int32_t minPwm) {
static jmethodID constructor =
env->GetMethodID(pwmConfigDataResultCls, "<init>", "(IIIII)V");
return env->NewObject(pwmConfigDataResultCls, constructor, (jint)maxPwm,
(jint)deadbandMaxPwm, (jint)centerPwm,
(jint)deadbandMinPwm, (jint)minPwm);
return env->NewObject(
pwmConfigDataResultCls, constructor, static_cast<jint>(maxPwm),
static_cast<jint>(deadbandMaxPwm), static_cast<jint>(centerPwm),
static_cast<jint>(deadbandMinPwm), static_cast<jint>(minPwm));
}
void SetCanStatusObject(JNIEnv* env, jobject canStatus,
@@ -245,9 +246,11 @@ void SetCanStatusObject(JNIEnv* env, jobject canStatus,
uint32_t transmitErrorCount) {
static jmethodID func =
env->GetMethodID(canStatusCls, "setStatus", "(DIIII)V");
env->CallVoidMethod(canStatus, func, (jdouble)percentBusUtilization,
(jint)busOffCount, (jint)txFullCount,
(jint)receiveErrorCount, (jint)transmitErrorCount);
env->CallVoidMethod(
canStatus, func, static_cast<jdouble>(percentBusUtilization),
static_cast<jint>(busOffCount), static_cast<jint>(txFullCount),
static_cast<jint>(receiveErrorCount),
static_cast<jint>(transmitErrorCount));
}
void SetMatchInfoObject(JNIEnv* env, jobject matchStatus,
@@ -261,8 +264,9 @@ void SetMatchInfoObject(JNIEnv* env, jobject matchStatus,
MakeJString(env, wpi::StringRef{reinterpret_cast<const char*>(
matchInfo.gameSpecificMessage),
matchInfo.gameSpecificMessageSize}),
(jint)matchInfo.matchNumber, (jint)matchInfo.replayNumber,
(jint)matchInfo.matchType);
static_cast<jint>(matchInfo.matchNumber),
static_cast<jint>(matchInfo.replayNumber),
static_cast<jint>(matchInfo.matchType));
}
void SetAccumulatorResultObject(JNIEnv* env, jobject accumulatorResult,
@@ -270,15 +274,16 @@ void SetAccumulatorResultObject(JNIEnv* env, jobject accumulatorResult,
static jmethodID func =
env->GetMethodID(accumulatorResultCls, "set", "(JJ)V");
env->CallVoidMethod(accumulatorResult, func, (jlong)value, (jlong)count);
env->CallVoidMethod(accumulatorResult, func, static_cast<jlong>(value),
static_cast<jlong>(count));
}
jbyteArray SetCANDataObject(JNIEnv* env, jobject canData, int32_t length,
uint64_t timestamp) {
static jmethodID func = env->GetMethodID(canDataCls, "setData", "(IJ)[B");
jbyteArray retVal = static_cast<jbyteArray>(
env->CallObjectMethod(canData, func, (jint)length, (jlong)timestamp));
jbyteArray retVal = static_cast<jbyteArray>(env->CallObjectMethod(
canData, func, static_cast<jint>(length), static_cast<jlong>(timestamp)));
return retVal;
}
@@ -306,8 +311,8 @@ jobject CreateHALValue(JNIEnv* env, const HAL_Value& value) {
default:
break;
}
return env->CallStaticObjectMethod(halValueCls, fromNative, (jint)value.type,
value1, value2);
return env->CallStaticObjectMethod(
halValueCls, fromNative, static_cast<jint>(value.type), value1, value2);
}
JavaVM* GetJVM() {

View File

@@ -60,7 +60,7 @@ void BufferCallbackStore::performCallback(const char* name, uint8_t* buffer,
static_cast<size_t>(length)});
env->CallVoidMethod(m_call, sim::GetBufferCallback(), MakeJString(env, name),
toCallbackArr, (jint)length);
toCallbackArr, static_cast<jint>(length));
jbyte* fromCallbackArr = reinterpret_cast<jbyte*>(
env->GetPrimitiveArrayCritical(toCallbackArr, nullptr));

View File

@@ -55,8 +55,9 @@ void CallbackStore::performCallback(const char* name, const HAL_Value* value) {
}
env->CallVoidMethod(m_call, sim::GetNotifyCallback(), MakeJString(env, name),
(jint)value->type, (jlong)value->data.v_long,
(jdouble)value->data.v_double);
static_cast<jint>(value->type),
static_cast<jlong>(value->data.v_long),
static_cast<jdouble>(value->data.v_double));
if (env->ExceptionCheck()) {
env->ExceptionDescribe();

View File

@@ -61,7 +61,8 @@ void ConstBufferCallbackStore::performCallback(const char* name,
static_cast<size_t>(length)});
env->CallVoidMethod(m_call, sim::GetConstBufferCallback(),
MakeJString(env, name), toCallbackArr, (jint)length);
MakeJString(env, name), toCallbackArr,
static_cast<jint>(length));
if (env->ExceptionCheck()) {
env->ExceptionDescribe();

View File

@@ -55,7 +55,7 @@ jobject DeviceInfo::MakeJava(JNIEnv* env) const {
static jmethodID func =
env->GetMethodID(simDeviceInfoCls, "<init>", "(Ljava/lang/String;I)V");
return env->NewObject(simDeviceInfoCls, func, MakeJString(env, name),
(jint)handle);
static_cast<jint>(handle));
}
static std::pair<jlong, jdouble> ToValue12(const HAL_Value& value) {
@@ -88,8 +88,8 @@ jobject ValueInfo::MakeJava(JNIEnv* env) const {
env->GetMethodID(simValueInfoCls, "<init>", "(Ljava/lang/String;IIIJD)V");
auto [value1, value2] = ToValue12(value);
return env->NewObject(simValueInfoCls, func, MakeJString(env, name),
(jint)handle, (jint)direction, (jint)value.type, value1,
value2);
static_cast<jint>(handle), static_cast<jint>(direction),
static_cast<jint>(value.type), value1, value2);
}
namespace {
@@ -147,7 +147,7 @@ void DeviceCallbackStore::performCallback(const char* name,
}
env->CallVoidMethod(m_call, simDeviceCallbackCallback, MakeJString(env, name),
(jint)handle);
static_cast<jint>(handle));
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
@@ -183,13 +183,14 @@ void ValueCallbackStore::performCallback(const char* name,
auto [value1, value2] = ToValue12(value);
if (m_dirCallback) {
env->CallVoidMethod(m_call, simValueCallbackCallback,
MakeJString(env, name), (jint)handle, (jint)direction,
(jint)value.type, value1, value2);
MakeJString(env, name), static_cast<jint>(handle),
static_cast<jint>(direction),
static_cast<jint>(value.type), value1, value2);
} else {
env->CallVoidMethod(m_call, simValueCallbackCallback,
MakeJString(env, name), (jint)handle,
(jboolean)(direction == HAL_SimValueOutput),
(jint)value.type, value1, value2);
MakeJString(env, name), static_cast<jint>(handle),
static_cast<jboolean>(direction == HAL_SimValueOutput),
static_cast<jint>(value.type), value1, value2);
}
if (env->ExceptionCheck()) {

View File

@@ -61,7 +61,7 @@ int32_t SpiReadAutoReceiveBufferCallbackStore::performCallback(
jint ret = env->CallIntMethod(m_call, sim::GetBufferCallback(),
MakeJString(env, name), toCallbackArr,
(jint)numToRead);
static_cast<jint>(numToRead));
jint* fromCallbackArr = reinterpret_cast<jint*>(
env->GetPrimitiveArrayCritical(toCallbackArr, nullptr));

View File

@@ -192,10 +192,10 @@ static jobject MakeJObject(JNIEnv* env, const nt::Value& value) {
switch (value.type()) {
case NT_BOOLEAN:
return env->NewObject(booleanCls, booleanConstructor,
(jboolean)(value.GetBoolean() ? 1 : 0));
static_cast<jboolean>(value.GetBoolean() ? 1 : 0));
case NT_DOUBLE:
return env->NewObject(doubleCls, doubleConstructor,
(jdouble)value.GetDouble());
static_cast<jdouble>(value.GetDouble()));
case NT_STRING:
return MakeJString(env, value.GetString());
case NT_RAW:
@@ -217,11 +217,13 @@ static jobject MakeJValue(JNIEnv* env, const nt::Value* value) {
static jmethodID constructor =
env->GetMethodID(valueCls, "<init>", "(ILjava/lang/Object;J)V");
if (!value) {
return env->NewObject(valueCls, constructor, (jint)NT_UNASSIGNED, nullptr,
(jlong)0);
return env->NewObject(valueCls, constructor,
static_cast<jint>(NT_UNASSIGNED), nullptr,
static_cast<jlong>(0));
}
return env->NewObject(valueCls, constructor, (jint)value->type(),
MakeJObject(env, *value), (jlong)value->time());
return env->NewObject(valueCls, constructor, static_cast<jint>(value->type()),
MakeJObject(env, *value),
static_cast<jlong>(value->time()));
}
static jobject MakeJObject(JNIEnv* env, const nt::ConnectionInfo& info) {
@@ -231,8 +233,9 @@ static jobject MakeJObject(JNIEnv* env, const nt::ConnectionInfo& info) {
JLocal<jstring> remote_id{env, MakeJString(env, info.remote_id)};
JLocal<jstring> remote_ip{env, MakeJString(env, info.remote_ip)};
return env->NewObject(connectionInfoCls, constructor, remote_id.obj(),
remote_ip.obj(), (jint)info.remote_port,
(jlong)info.last_update, (jint)info.protocol_version);
remote_ip.obj(), static_cast<jint>(info.remote_port),
static_cast<jlong>(info.last_update),
static_cast<jint>(info.protocol_version));
}
static jobject MakeJObject(JNIEnv* env, jobject inst,
@@ -243,8 +246,9 @@ static jobject MakeJObject(JNIEnv* env, jobject inst,
"networktables/ConnectionInfo;)V");
JLocal<jobject> conn{env, MakeJObject(env, notification.conn)};
return env->NewObject(connectionNotificationCls, constructor, inst,
(jint)notification.listener,
(jboolean)notification.connected, conn.obj());
static_cast<jint>(notification.listener),
static_cast<jboolean>(notification.connected),
conn.obj());
}
static jobject MakeJObject(JNIEnv* env, jobject inst,
@@ -254,9 +258,10 @@ static jobject MakeJObject(JNIEnv* env, jobject inst,
"(Ledu/wpi/first/networktables/"
"NetworkTableInstance;ILjava/lang/String;IIJ)V");
JLocal<jstring> name{env, MakeJString(env, info.name)};
return env->NewObject(entryInfoCls, constructor, inst, (jint)info.entry,
name.obj(), (jint)info.type, (jint)info.flags,
(jlong)info.last_change);
return env->NewObject(
entryInfoCls, constructor, inst, static_cast<jint>(info.entry),
name.obj(), static_cast<jint>(info.type), static_cast<jint>(info.flags),
static_cast<jlong>(info.last_change));
}
static jobject MakeJObject(JNIEnv* env, jobject inst,
@@ -268,8 +273,9 @@ static jobject MakeJObject(JNIEnv* env, jobject inst,
JLocal<jstring> name{env, MakeJString(env, notification.name)};
JLocal<jobject> value{env, MakeJValue(env, notification.value.get())};
return env->NewObject(entryNotificationCls, constructor, inst,
(jint)notification.listener, (jint)notification.entry,
name.obj(), value.obj(), (jint)notification.flags);
static_cast<jint>(notification.listener),
static_cast<jint>(notification.entry), name.obj(),
value.obj(), static_cast<jint>(notification.flags));
}
static jobject MakeJObject(JNIEnv* env, jobject inst,
@@ -280,9 +286,10 @@ static jobject MakeJObject(JNIEnv* env, jobject inst,
"String;ILjava/lang/String;)V");
JLocal<jstring> filename{env, MakeJString(env, msg.filename)};
JLocal<jstring> message{env, MakeJString(env, msg.message)};
return env->NewObject(logMessageCls, constructor, inst, (jint)msg.logger,
(jint)msg.level, filename.obj(), (jint)msg.line,
message.obj());
return env->NewObject(logMessageCls, constructor, inst,
static_cast<jint>(msg.logger),
static_cast<jint>(msg.level), filename.obj(),
static_cast<jint>(msg.line), message.obj());
}
static jobject MakeJObject(JNIEnv* env, jobject inst,
@@ -295,9 +302,9 @@ static jobject MakeJObject(JNIEnv* env, jobject inst,
JLocal<jstring> name{env, MakeJString(env, answer.name)};
JLocal<jbyteArray> params{env, MakeJByteArray(env, answer.params)};
JLocal<jobject> conn{env, MakeJObject(env, answer.conn)};
return env->NewObject(rpcAnswerCls, constructor, inst, (jint)answer.entry,
(jint)answer.call, name.obj(), params.obj(),
conn.obj());
return env->NewObject(
rpcAnswerCls, constructor, inst, static_cast<jint>(answer.entry),
static_cast<jint>(answer.call), name.obj(), params.obj(), conn.obj());
}
static jobjectArray MakeJObject(JNIEnv* env, jobject inst,

View File

@@ -95,7 +95,8 @@ void HALSimWSProviderJoystick::OnNetValueChanged(const wpi::json& json) {
if ((it = json.find(">axes")) != json.end()) {
HAL_JoystickAxes axes{};
axes.count =
std::min(it.value().size(), (wpi::json::size_type)HAL_kMaxJoystickAxes);
std::min(it.value().size(),
static_cast<wpi::json::size_type>(HAL_kMaxJoystickAxes));
for (int i = 0; i < axes.count; i++) {
axes.axes[i] = it.value()[i];
}
@@ -105,7 +106,8 @@ void HALSimWSProviderJoystick::OnNetValueChanged(const wpi::json& json) {
if ((it = json.find(">buttons")) != json.end()) {
HAL_JoystickButtons buttons{};
buttons.count = std::min(it.value().size(), (wpi::json::size_type)32);
buttons.count =
std::min(it.value().size(), static_cast<wpi::json::size_type>(32));
for (int i = 0; i < buttons.count; i++) {
if (it.value()[i]) {
buttons.buttons |= 1 << (i - 1);
@@ -118,7 +120,8 @@ void HALSimWSProviderJoystick::OnNetValueChanged(const wpi::json& json) {
if ((it = json.find(">povs")) != json.end()) {
HAL_JoystickPOVs povs{};
povs.count =
std::min(it.value().size(), (wpi::json::size_type)HAL_kMaxJoystickPOVs);
std::min(it.value().size(),
static_cast<wpi::json::size_type>(HAL_kMaxJoystickPOVs));
for (int i = 0; i < povs.count; i++) {
povs.povs[i] = it.value()[i];
}

View File

@@ -28,7 +28,7 @@ void BuiltInAccelerometer::SetRange(Range range) {
}
HAL_SetAccelerometerActive(false);
HAL_SetAccelerometerRange((HAL_AccelerometerRange)range);
HAL_SetAccelerometerRange(static_cast<HAL_AccelerometerRange>(range));
HAL_SetAccelerometerActive(true);
}

View File

@@ -20,7 +20,8 @@ using namespace frc;
Counter::Counter(Mode mode) {
int32_t status = 0;
m_counter = HAL_InitializeCounter((HAL_Counter_Mode)mode, &m_index, &status);
m_counter = HAL_InitializeCounter(static_cast<HAL_Counter_Mode>(mode),
&m_index, &status);
wpi_setHALError(status);
SetMaxPeriod(0.5);
@@ -129,10 +130,10 @@ void Counter::SetUpSource(std::shared_ptr<DigitalSource> source) {
CloneError(*m_upSource);
} else {
int32_t status = 0;
HAL_SetCounterUpSource(
m_counter, source->GetPortHandleForRouting(),
(HAL_AnalogTriggerType)source->GetAnalogTriggerTypeForRouting(),
&status);
HAL_SetCounterUpSource(m_counter, source->GetPortHandleForRouting(),
static_cast<HAL_AnalogTriggerType>(
source->GetAnalogTriggerTypeForRouting()),
&status);
wpi_setHALError(status);
}
}
@@ -208,10 +209,10 @@ void Counter::SetDownSource(std::shared_ptr<DigitalSource> source) {
CloneError(*m_downSource);
} else {
int32_t status = 0;
HAL_SetCounterDownSource(
m_counter, source->GetPortHandleForRouting(),
(HAL_AnalogTriggerType)source->GetAnalogTriggerTypeForRouting(),
&status);
HAL_SetCounterDownSource(m_counter, source->GetPortHandleForRouting(),
static_cast<HAL_AnalogTriggerType>(
source->GetAnalogTriggerTypeForRouting()),
&status);
wpi_setHALError(status);
}
}

View File

@@ -62,7 +62,7 @@ HAL_Handle DigitalInput::GetPortHandleForRouting() const {
}
AnalogTriggerType DigitalInput::GetAnalogTriggerTypeForRouting() const {
return (AnalogTriggerType)0;
return static_cast<AnalogTriggerType>(0);
}
bool DigitalInput::IsAnalogTrigger() const {

View File

@@ -77,7 +77,7 @@ HAL_Handle DigitalOutput::GetPortHandleForRouting() const {
}
AnalogTriggerType DigitalOutput::GetAnalogTriggerTypeForRouting() const {
return (AnalogTriggerType)0;
return static_cast<AnalogTriggerType>(0);
}
bool DigitalOutput::IsAnalogTrigger() const {

View File

@@ -237,10 +237,11 @@ void Encoder::SetIndexSource(int channel, Encoder::IndexingType type) {
void Encoder::SetIndexSource(const DigitalSource& source,
Encoder::IndexingType type) {
int32_t status = 0;
HAL_SetEncoderIndexSource(
m_encoder, source.GetPortHandleForRouting(),
(HAL_AnalogTriggerType)source.GetAnalogTriggerTypeForRouting(),
(HAL_EncoderIndexingType)type, &status);
HAL_SetEncoderIndexSource(m_encoder, source.GetPortHandleForRouting(),
static_cast<HAL_AnalogTriggerType>(
source.GetAnalogTriggerTypeForRouting()),
static_cast<HAL_EncoderIndexingType>(type),
&status);
wpi_setHALError(status);
}
@@ -277,10 +278,13 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) {
int32_t status = 0;
m_encoder = HAL_InitializeEncoder(
m_aSource->GetPortHandleForRouting(),
(HAL_AnalogTriggerType)m_aSource->GetAnalogTriggerTypeForRouting(),
static_cast<HAL_AnalogTriggerType>(
m_aSource->GetAnalogTriggerTypeForRouting()),
m_bSource->GetPortHandleForRouting(),
(HAL_AnalogTriggerType)m_bSource->GetAnalogTriggerTypeForRouting(),
reverseDirection, (HAL_EncoderEncodingType)encodingType, &status);
static_cast<HAL_AnalogTriggerType>(
m_bSource->GetAnalogTriggerTypeForRouting()),
reverseDirection, static_cast<HAL_EncoderEncodingType>(encodingType),
&status);
wpi_setHALError(status);
HAL_Report(HALUsageReporting::kResourceType_Encoder, GetFPGAIndex() + 1,

View File

@@ -283,10 +283,10 @@ void SPI::StartAutoRate(double period) {
void SPI::StartAutoTrigger(DigitalSource& source, bool rising, bool falling) {
int32_t status = 0;
HAL_StartSPIAutoTrigger(
m_port, source.GetPortHandleForRouting(),
(HAL_AnalogTriggerType)source.GetAnalogTriggerTypeForRouting(), rising,
falling, &status);
HAL_StartSPIAutoTrigger(m_port, source.GetPortHandleForRouting(),
static_cast<HAL_AnalogTriggerType>(
source.GetAnalogTriggerTypeForRouting()),
rising, falling, &status);
wpi_setHALError(status);
}

View File

@@ -190,7 +190,7 @@ std::unique_ptr<NetworkStream> TCPAcceptor::accept() {
socklen_t len = sizeof(address);
#endif
std::memset(&address, 0, sizeof(address));
int sd = ::accept(m_lsd, (struct sockaddr*)&address, &len);
int sd = ::accept(m_lsd, reinterpret_cast<struct sockaddr*>(&address), &len);
if (sd < 0) {
if (!m_shutdown) {
WPI_ERROR(m_logger, "accept() on port "

View File

@@ -108,7 +108,8 @@ std::unique_ptr<NetworkStream> TCPConnector::connect(const char* server,
WPI_ERROR(logger, "could not create socket");
return nullptr;
}
if (::connect(sd, (struct sockaddr*)&address, sizeof(address)) != 0) {
if (::connect(sd, reinterpret_cast<struct sockaddr*>(&address),
sizeof(address)) != 0) {
WPI_ERROR(logger, "connect() to " << server << " port " << port
<< " failed: " << SocketStrerror());
#ifdef _WIN32
@@ -152,8 +153,8 @@ std::unique_ptr<NetworkStream> TCPConnector::connect(const char* server,
#endif
// Connect with time limit
if ((result = ::connect(sd, (struct sockaddr*)&address, sizeof(address))) <
0) {
if ((result = ::connect(sd, reinterpret_cast<struct sockaddr*>(&address),
sizeof(address))) < 0) {
int my_errno = SocketErrno();
#ifdef _WIN32
if (my_errno == WSAEWOULDBLOCK || my_errno == WSAEINPROGRESS) {