From 96d72241de8a0d83511139d3d31b7e15cb9e763c Mon Sep 17 00:00:00 2001 From: Larry Ruckman Date: Wed, 16 Oct 2024 11:10:08 -0700 Subject: [PATCH] resolving c++ linter Using C-style cast. Use static_cast(...) instead [readability/casting] [4] --- src/rogue/Logging.cpp | 2 +- src/rogue/interfaces/memory/Block.cpp | 12 +++++---- src/rogue/interfaces/memory/Variable.cpp | 8 +++--- src/rogue/interfaces/stream/Buffer.cpp | 10 +++---- src/rogue/interfaces/stream/Frame.cpp | 2 +- src/rogue/interfaces/stream/FrameIterator.cpp | 2 +- src/rogue/interfaces/stream/RateDrop.cpp | 6 ++--- .../protocols/packetizer/ControllerV2.cpp | 16 ++++++------ src/rogue/protocols/rssi/Controller.cpp | 2 +- src/rogue/protocols/rssi/Header.cpp | 26 +++++++++---------- src/rogue/protocols/xilinx/JtagDriver.cpp | 6 ++--- 11 files changed, 47 insertions(+), 45 deletions(-) diff --git a/src/rogue/Logging.cpp b/src/rogue/Logging.cpp index 26b4dfd64..d9f95c5a0 100644 --- a/src/rogue/Logging.cpp +++ b/src/rogue/Logging.cpp @@ -159,7 +159,7 @@ void rogue::Logging::logThreadId() { #elif defined(__APPLE__) && defined(__MACH__) uint64_t tid64; pthread_threadid_np(NULL, &tid64); - tid = (uint32_t)tid64; + tid = static_cast(tid64); #else tid = 0; #endif diff --git a/src/rogue/interfaces/memory/Block.cpp b/src/rogue/interfaces/memory/Block.cpp index 2c7f323a4..bebcaff5f 100644 --- a/src/rogue/interfaces/memory/Block.cpp +++ b/src/rogue/interfaces/memory/Block.cpp @@ -575,7 +575,7 @@ void rim::Block::addVariables(std::vector variables) { x = 0; while (rem > 0) { - ss << "0x" << std::setfill('0') << std::hex << std::setw(2) << (uint32_t)(verifyMask_[x]) << " "; + ss << "0x" << std::setfill('0') << std::hex << std::setw(2) << static_cast(verifyMask_[x]) << " "; x++; rem--; if (rem == 0 || x % 10 == 0) { @@ -1013,7 +1013,7 @@ bp::object rim::Block::getUIntPy(rim::Variable* var, int32_t index) { PyArrayObject* arr = reinterpret_cast(obj); uint32_t* dst = reinterpret_cast(PyArray_DATA(arr)); - for (x = 0; x < var->numValues_; x++) dst[x] = (uint32_t)getUInt(var, x); + for (x = 0; x < var->numValues_; x++) dst[x] = static_cast(getUInt(var, x)); } boost::python::handle<> handle(obj); ret = bp::object(handle); @@ -1178,7 +1178,7 @@ bp::object rim::Block::getIntPy(rim::Variable* var, int32_t index) { PyArrayObject* arr = reinterpret_cast(obj); int32_t* dst = reinterpret_cast(PyArray_DATA(arr)); - for (x = 0; x < var->numValues_; x++) dst[x] = (int32_t)getInt(var, x); + for (x = 0; x < var->numValues_; x++) dst[x] = static_cast(getInt(var, x)); } boost::python::handle<> handle(obj); ret = bp::object(handle); @@ -1217,7 +1217,9 @@ int64_t rim::Block::getInt(rim::Variable* var, int32_t index) { getBytes(reinterpret_cast(&tmp), var, index); if (var->valueBits_ != 64) { - if (tmp >= (uint64_t)pow(2, var->valueBits_ - 1)) tmp -= (uint64_t)pow(2, var->valueBits_); + if (tmp >= static_cast(pow(2, var->valueBits_ - 1))) { + tmp -= static_cast(pow(2, var->valueBits_)); + } } return tmp; } @@ -1870,7 +1872,7 @@ void rim::Block::setFixed(const double& val, rim::Variable* var, int32_t index) var->maxValue_)); // Convert - int64_t fPoint = (int64_t)round(val * pow(2, var->binPoint_)); + int64_t fPoint = static_cast(round(val * pow(2, var->binPoint_))); // Check for positive edge case uint64_t mask = 1 << (var->valueBits_ - 1); if (val > 0 && ((fPoint & mask) != 0)) { diff --git a/src/rogue/interfaces/memory/Variable.cpp b/src/rogue/interfaces/memory/Variable.cpp index b6be4d008..ae2779b26 100644 --- a/src/rogue/interfaces/memory/Variable.cpp +++ b/src/rogue/interfaces/memory/Variable.cpp @@ -705,7 +705,7 @@ std::string rim::Variable::getDumpValue(bool read) { else index = 0; - while (index < (int32_t)numValues_) { + while (index < static_cast(numValues_)) { ret << " "; switch (modelId_) { @@ -713,7 +713,7 @@ std::string rim::Variable::getDumpValue(bool read) { (block_->*getByteArray_)(byteData, this, index); ret << "0x"; for (x = 0; x < valueBytes_; x++) - ret << std::setfill('0') << std::setw(2) << std::hex << (uint32_t)byteData[x]; + ret << std::setfill('0') << std::setw(2) << std::hex << static_cast(byteData[x]); break; case rim::UInt: @@ -721,7 +721,7 @@ std::string rim::Variable::getDumpValue(bool read) { (block_->*getByteArray_)(byteData, this, index); ret << "0x"; for (x = 0; x < valueBytes_; x++) - ret << std::setfill('0') << std::setw(2) << std::hex << (uint32_t)byteData[x]; + ret << std::setfill('0') << std::setw(2) << std::hex << static_cast(byteData[x]); } else { ret << (block_->*getUInt_)(this, index); } @@ -732,7 +732,7 @@ std::string rim::Variable::getDumpValue(bool read) { (block_->*getByteArray_)(byteData, this, index); ret << "0x"; for (x = 0; x < valueBytes_; x++) - ret << std::setfill('0') << std::setw(2) << std::hex << (uint32_t)byteData[x]; + ret << std::setfill('0') << std::setw(2) << std::hex << static_cast(byteData[x]); } else { ret << (block_->*getInt_)(this, index); } diff --git a/src/rogue/interfaces/stream/Buffer.cpp b/src/rogue/interfaces/stream/Buffer.cpp index 169614a75..6f6f32a3a 100644 --- a/src/rogue/interfaces/stream/Buffer.cpp +++ b/src/rogue/interfaces/stream/Buffer.cpp @@ -78,14 +78,14 @@ void ris::Buffer::setMeta(uint32_t meta) { //! Adjust header by passed value void ris::Buffer::adjustHeader(int32_t value) { // Decreasing header size - if (value < 0 && (uint32_t)abs(value) > headRoom_) + if (value < 0 && static_cast(abs(value)) > headRoom_) throw(rogue::GeneralError::create("Buffer::adjustHeader", "Attempt to reduce header with size %" PRIu32 " by %" PRIi32, headRoom_, value)); // Increasing header size - if (value > 0 && (uint32_t)value > (rawSize_ - (headRoom_ + tailRoom_))) + if (value > 0 && static_cast(value) > (rawSize_ - (headRoom_ + tailRoom_))) throw(rogue::GeneralError::create("Buffer::adjustHeader", "Attempt to increase header by %" PRIi32 " in buffer with size %" PRIu32, value, @@ -112,14 +112,14 @@ void ris::Buffer::zeroHeader() { //! Adjust tail by passed value void ris::Buffer::adjustTail(int32_t value) { // Decreasing tail size - if (value < 0 && (uint32_t)abs(value) > tailRoom_) + if (value < 0 && static_cast(abs(value)) > tailRoom_) throw(rogue::GeneralError::create("Buffer::adjustTail", "Attempt to reduce tail with size %" PRIu32 " by %" PRIi32, tailRoom_, value)); // Increasing tail size - if (value > 0 && (uint32_t)value > (rawSize_ - (headRoom_ + tailRoom_))) + if (value > 0 && static_cast(value) > (rawSize_ - (headRoom_ + tailRoom_))) throw(rogue::GeneralError::create("Buffer::adjustTail", "Attempt to increase header by %" PRIi32 " in buffer with size %" PRIu32, value, @@ -227,7 +227,7 @@ void ris::Buffer::minPayload(uint32_t size) { //! Adjust payload size void ris::Buffer::adjustPayload(int32_t value) { - if (value < 0 && (uint32_t)abs(value) > getPayload()) + if (value < 0 && static_cast(abs(value)) > getPayload()) throw(rogue::GeneralError::create("Buffer::adjustPayload", "Attempt to decrease payload by %" PRIi32 " in buffer with size %" PRIu32, value, diff --git a/src/rogue/interfaces/stream/Frame.cpp b/src/rogue/interfaces/stream/Frame.cpp index 5c8315f3a..f59994e6e 100644 --- a/src/rogue/interfaces/stream/Frame.cpp +++ b/src/rogue/interfaces/stream/Frame.cpp @@ -220,7 +220,7 @@ void ris::Frame::minPayload(uint32_t size) { void ris::Frame::adjustPayload(int32_t value) { uint32_t size = getPayload(); - if (value < 0 && (uint32_t)abs(value) > size) + if (value < 0 && static_cast(abs(value)) > size) throw(rogue::GeneralError::create("Frame::adjustPayload", "Attempt to reduce payload by %" PRIi32 " in frame with size %" PRIu32, value, diff --git a/src/rogue/interfaces/stream/FrameIterator.cpp b/src/rogue/interfaces/stream/FrameIterator.cpp index bfc345178..abf860461 100644 --- a/src/rogue/interfaces/stream/FrameIterator.cpp +++ b/src/rogue/interfaces/stream/FrameIterator.cpp @@ -156,7 +156,7 @@ uint8_t* ris::FrameIterator::ptr() const { //! De-reference by index uint8_t ris::FrameIterator::operator[](const uint32_t offset) const { ris::FrameIterator ret(*this); - ret.increment((int32_t)offset); + ret.increment(static_cast(offset)); return *ret; } diff --git a/src/rogue/interfaces/stream/RateDrop.cpp b/src/rogue/interfaces/stream/RateDrop.cpp index 77be40bf3..19bed311f 100644 --- a/src/rogue/interfaces/stream/RateDrop.cpp +++ b/src/rogue/interfaces/stream/RateDrop.cpp @@ -58,12 +58,12 @@ ris::RateDrop::RateDrop(bool period, double value) : ris::Master(), ris::Slave() if ((!period) || value == 0) { periodFlag_ = false; - dropCount_ = (uint32_t)value; - dropTarget_ = (uint32_t)value; + dropCount_ = static_cast(value); + dropTarget_ = static_cast(value); } else { periodFlag_ = true; - per = (uint32_t)(value * 1e6); + per = static_cast(value * 1e6); div_t divResult = div(per, 1000000); timePeriod_.tv_sec = divResult.quot; diff --git a/src/rogue/protocols/packetizer/ControllerV2.cpp b/src/rogue/protocols/packetizer/ControllerV2.cpp index 87fd38462..b5ea3f1f1 100644 --- a/src/rogue/protocols/packetizer/ControllerV2.cpp +++ b/src/rogue/protocols/packetizer/ControllerV2.cpp @@ -118,21 +118,21 @@ void rpp::ControllerV2::transportRx(ris::FramePtr frame) { tmpId = data[3]; // Header word 1 - tmpCount = uint32_t(data[4]) << 0; - tmpCount |= uint32_t(data[5]) << 8; + tmpCount = static_cast(data[4]) << 0; + tmpCount |= static_cast(data[5]) << 8; tmpSof = ((data[7] & 0x80) ? true : false); // SOF (PACKETIZER2_HDR_SOF_BIT_C = 63) // Tail word 0 tmpLuser = data[size - 8]; tmpEof = ((data[size - 7] & 0x1) ? true : false); - last = uint32_t(data[size - 6]); + last = static_cast(data[size - 6]); if (enIbCrc_) { // Tail word 1 - tmpCrc = uint32_t(data[size - 1]) << 0; - tmpCrc |= uint32_t(data[size - 2]) << 8; - tmpCrc |= uint32_t(data[size - 3]) << 16; - tmpCrc |= uint32_t(data[size - 4]) << 24; + tmpCrc = static_cast(data[size - 1]) << 0; + tmpCrc |= static_cast(data[size - 2]) << 8; + tmpCrc |= static_cast(data[size - 3]) << 16; + tmpCrc |= static_cast(data[size - 4]) << 24; // Compute CRC if (tmpSof) @@ -179,7 +179,7 @@ void rpp::ControllerV2::transportRx(ris::FramePtr frame) { // Shorten message by removing tail and adjusting for last value // Do this before adjusting tail reservation - buff->adjustPayload(-8 + ((int32_t)last - 8)); + buff->adjustPayload(-8 + (static_cast(last) - 8)); // Add 8 bytes to headroom and tail reservation buff->adjustHeader(8); diff --git a/src/rogue/protocols/rssi/Controller.cpp b/src/rogue/protocols/rssi/Controller.cpp index 0230e3cd5..1e9ea10c4 100644 --- a/src/rogue/protocols/rssi/Controller.cpp +++ b/src/rogue/protocols/rssi/Controller.cpp @@ -702,7 +702,7 @@ void rpr::Controller::convTime(struct timeval& tme, uint32_t rssiTime) { float units = std::pow(10, -TimeoutUnit); float value = units * static_cast(rssiTime); - uint32_t usec = (uint32_t)(value / 1e-6); + uint32_t usec = static_cast(value / 1e-6); div_t divResult = div(usec, 1000000); tme.tv_sec = divResult.quot; diff --git a/src/rogue/protocols/rssi/Header.cpp b/src/rogue/protocols/rssi/Header.cpp index 71c022ead..a453e9cbe 100644 --- a/src/rogue/protocols/rssi/Header.cpp +++ b/src/rogue/protocols/rssi/Header.cpp @@ -233,7 +233,7 @@ std::string rpr::Header::dump() { ret << " Raw Header : "; for (x = 0; x < data[1]; x++) { - ret << "0x" << std::hex << std::setw(2) << std::setfill('0') << (uint32_t)data[x] << " "; + ret << "0x" << std::hex << std::setw(2) << std::setfill('0') << static_cast(data[x]) << " "; if ((x % 8) == 7 && (x + 1) != data[1]) ret << std::endl << " "; } ret << std::endl; @@ -243,22 +243,22 @@ std::string rpr::Header::dump() { ret << " Rst : " << std::dec << rst << std::endl; ret << " Nul : " << std::dec << nul << std::endl; ret << " Busy : " << std::dec << busy << std::endl; - ret << " Sequence : " << std::dec << (uint32_t)sequence << std::endl; - ret << " Acknowledge : " << std::dec << (uint32_t)acknowledge << std::endl; + ret << " Sequence : " << std::dec << static_cast(sequence) << std::endl; + ret << " Acknowledge : " << std::dec << static_cast(acknowledge) << std::endl; if (!syn) return (ret.str()); - ret << " Version : " << std::dec << (uint32_t)version << std::endl; + ret << " Version : " << std::dec << static_cast(version) << std::endl; ret << " Chk : " << std::dec << chk << std::endl; - ret << " Max Out Seg : " << std::dec << (uint32_t)maxOutstandingSegments << std::endl; - ret << " Max Seg Size : " << std::dec << (uint32_t)maxSegmentSize << std::endl; - ret << " Retran Tout : " << std::dec << (uint32_t)retransmissionTimeout << std::endl; - ret << " Cum Ack Tout : " << std::dec << (uint32_t)cumulativeAckTimeout << std::endl; - ret << " Null Tout : " << std::dec << (uint32_t)nullTimeout << std::endl; - ret << " Max Retrans : " << std::dec << (uint32_t)maxRetransmissions << std::endl; - ret << " Max Cum Ack : " << std::dec << (uint32_t)maxCumulativeAck << std::endl; - ret << " Timeout Unit : " << std::dec << (uint32_t)timeoutUnit << std::endl; - ret << " Conn Id : " << std::dec << (uint32_t)connectionId << std::endl; + ret << " Max Out Seg : " << std::dec << static_cast(maxOutstandingSegments) << std::endl; + ret << " Max Seg Size : " << std::dec << static_cast(maxSegmentSize) << std::endl; + ret << " Retran Tout : " << std::dec << static_cast(retransmissionTimeout) << std::endl; + ret << " Cum Ack Tout : " << std::dec << static_cast(cumulativeAckTimeout) << std::endl; + ret << " Null Tout : " << std::dec << static_cast(nullTimeout) << std::endl; + ret << " Max Retrans : " << std::dec << static_cast(maxRetransmissions) << std::endl; + ret << " Max Cum Ack : " << std::dec << static_cast(maxCumulativeAck) << std::endl; + ret << " Timeout Unit : " << std::dec << static_cast(timeoutUnit) << std::endl; + ret << " Conn Id : " << std::dec << static_cast(connectionId) << std::endl; return (ret.str()); } diff --git a/src/rogue/protocols/xilinx/JtagDriver.cpp b/src/rogue/protocols/xilinx/JtagDriver.cpp index 733a9081d..91ed7b543 100644 --- a/src/rogue/protocols/xilinx/JtagDriver.cpp +++ b/src/rogue/protocols/xilinx/JtagDriver.cpp @@ -138,7 +138,7 @@ uint32_t rpx::JtagDriver::cvtPerNs(Header reply) { tmp = static_cast(rawVal) * 4.0 / 256.0; - return (uint32_t)round(pow(10.0, tmp) * 1.0E9 / REF_FREQ_HZ()); + return static_cast(round(pow(10.0, tmp) * 1.0E9 / REF_FREQ_HZ())); } unsigned rpx::JtagDriver::getWordSize() { @@ -237,7 +237,7 @@ uint64_t rpx::JtagDriver::query() { log_->debug("Query result: wordSize %" PRId32 ", memDepth %" PRId32 ", period %l" PRId32 "ns\n", wordSize_, memDepth_, - (uint64_t)periodNs_); + static_cast(periodNs_)); if (0 == memDepth_) retry_ = 0; @@ -301,7 +301,7 @@ void rpx::JtagDriver::dumpInfo(FILE* f) { fprintf(f, "Word size: %d\n", getWordSize()); fprintf(f, "Target Memory Depth (bytes) %d\n", getWordSize() * getMemDepth()); fprintf(f, "Max. Vector Length (bytes) %ld\n", getMaxVectorSize()); - fprintf(f, "TCK Period (ns) %ld\n", (uint64_t)getPeriodNs()); + fprintf(f, "TCK Period (ns) %ld\n", static_cast(getPeriodNs())); } void rpx::JtagDriver::setup_python() {