Skip to content

Commit

Permalink
resolving c++ linter
Browse files Browse the repository at this point in the history
Using C-style cast.  Use static_cast<XXXXXXX>(...) instead  [readability/casting] [4]
  • Loading branch information
ruck314 committed Oct 16, 2024
1 parent b4b6fed commit 96d7224
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/rogue/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(tid64);
#else
tid = 0;
#endif
Expand Down
12 changes: 7 additions & 5 deletions src/rogue/interfaces/memory/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ void rim::Block::addVariables(std::vector<rim::VariablePtr> 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<uint32_t>(verifyMask_[x]) << " ";
x++;
rem--;
if (rem == 0 || x % 10 == 0) {
Expand Down Expand Up @@ -1013,7 +1013,7 @@ bp::object rim::Block::getUIntPy(rim::Variable* var, int32_t index) {
PyArrayObject* arr = reinterpret_cast<PyArrayObject*>(obj);
uint32_t* dst = reinterpret_cast<uint32_t*>(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<uint32_t>(getUInt(var, x));
}
boost::python::handle<> handle(obj);
ret = bp::object(handle);
Expand Down Expand Up @@ -1178,7 +1178,7 @@ bp::object rim::Block::getIntPy(rim::Variable* var, int32_t index) {
PyArrayObject* arr = reinterpret_cast<PyArrayObject*>(obj);
int32_t* dst = reinterpret_cast<int32_t*>(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<int32_t>(getInt(var, x));
}
boost::python::handle<> handle(obj);
ret = bp::object(handle);
Expand Down Expand Up @@ -1217,7 +1217,9 @@ int64_t rim::Block::getInt(rim::Variable* var, int32_t index) {
getBytes(reinterpret_cast<uint8_t*>(&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<uint64_t>(pow(2, var->valueBits_ - 1))) {
tmp -= static_cast<uint64_t>(pow(2, var->valueBits_));
}
}
return tmp;
}
Expand Down Expand Up @@ -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<int64_t>(round(val * pow(2, var->binPoint_)));
// Check for positive edge case
uint64_t mask = 1 << (var->valueBits_ - 1);
if (val > 0 && ((fPoint & mask) != 0)) {
Expand Down
8 changes: 4 additions & 4 deletions src/rogue/interfaces/memory/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,23 +705,23 @@ std::string rim::Variable::getDumpValue(bool read) {
else
index = 0;

while (index < (int32_t)numValues_) {
while (index < static_cast<int32_t>(numValues_)) {
ret << " ";

switch (modelId_) {
case rim::Bytes:
(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<uint32_t>(byteData[x]);
break;

case rim::UInt:
if (valueBits_ > 64) {
(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<uint32_t>(byteData[x]);
} else {
ret << (block_->*getUInt_)(this, index);
}
Expand All @@ -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<uint32_t>(byteData[x]);
} else {
ret << (block_->*getInt_)(this, index);
}
Expand Down
10 changes: 5 additions & 5 deletions src/rogue/interfaces/stream/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(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<uint32_t>(value) > (rawSize_ - (headRoom_ + tailRoom_)))
throw(rogue::GeneralError::create("Buffer::adjustHeader",
"Attempt to increase header by %" PRIi32 " in buffer with size %" PRIu32,
value,
Expand All @@ -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<uint32_t>(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<uint32_t>(value) > (rawSize_ - (headRoom_ + tailRoom_)))
throw(rogue::GeneralError::create("Buffer::adjustTail",
"Attempt to increase header by %" PRIi32 " in buffer with size %" PRIu32,
value,
Expand Down Expand Up @@ -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<uint32_t>(abs(value)) > getPayload())
throw(rogue::GeneralError::create("Buffer::adjustPayload",
"Attempt to decrease payload by %" PRIi32 " in buffer with size %" PRIu32,
value,
Expand Down
2 changes: 1 addition & 1 deletion src/rogue/interfaces/stream/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(abs(value)) > size)
throw(rogue::GeneralError::create("Frame::adjustPayload",
"Attempt to reduce payload by %" PRIi32 " in frame with size %" PRIu32,
value,
Expand Down
2 changes: 1 addition & 1 deletion src/rogue/interfaces/stream/FrameIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t>(offset));
return *ret;
}

Expand Down
6 changes: 3 additions & 3 deletions src/rogue/interfaces/stream/RateDrop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(value);
dropTarget_ = static_cast<uint32_t>(value);
} else {
periodFlag_ = true;

per = (uint32_t)(value * 1e6);
per = static_cast<uint32_t>(value * 1e6);

div_t divResult = div(per, 1000000);
timePeriod_.tv_sec = divResult.quot;
Expand Down
16 changes: 8 additions & 8 deletions src/rogue/protocols/packetizer/ControllerV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(data[4]) << 0;
tmpCount |= static_cast<uint32_t>(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<uint32_t>(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<uint32_t>(data[size - 1]) << 0;
tmpCrc |= static_cast<uint32_t>(data[size - 2]) << 8;
tmpCrc |= static_cast<uint32_t>(data[size - 3]) << 16;
tmpCrc |= static_cast<uint32_t>(data[size - 4]) << 24;

// Compute CRC
if (tmpSof)
Expand Down Expand Up @@ -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<int32_t>(last) - 8));

// Add 8 bytes to headroom and tail reservation
buff->adjustHeader(8);
Expand Down
2 changes: 1 addition & 1 deletion src/rogue/protocols/rssi/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(rssiTime);

uint32_t usec = (uint32_t)(value / 1e-6);
uint32_t usec = static_cast<uint32_t>(value / 1e-6);

div_t divResult = div(usec, 1000000);
tme.tv_sec = divResult.quot;
Expand Down
26 changes: 13 additions & 13 deletions src/rogue/protocols/rssi/Header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(data[x]) << " ";
if ((x % 8) == 7 && (x + 1) != data[1]) ret << std::endl << " ";
}
ret << std::endl;
Expand All @@ -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<uint32_t>(sequence) << std::endl;
ret << " Acknowledge : " << std::dec << static_cast<uint32_t>(acknowledge) << std::endl;

if (!syn) return (ret.str());

ret << " Version : " << std::dec << (uint32_t)version << std::endl;
ret << " Version : " << std::dec << static_cast<uint32_t>(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<uint32_t>(maxOutstandingSegments) << std::endl;
ret << " Max Seg Size : " << std::dec << static_cast<uint32_t>(maxSegmentSize) << std::endl;
ret << " Retran Tout : " << std::dec << static_cast<uint32_t>(retransmissionTimeout) << std::endl;
ret << " Cum Ack Tout : " << std::dec << static_cast<uint32_t>(cumulativeAckTimeout) << std::endl;
ret << " Null Tout : " << std::dec << static_cast<uint32_t>(nullTimeout) << std::endl;
ret << " Max Retrans : " << std::dec << static_cast<uint32_t>(maxRetransmissions) << std::endl;
ret << " Max Cum Ack : " << std::dec << static_cast<uint32_t>(maxCumulativeAck) << std::endl;
ret << " Timeout Unit : " << std::dec << static_cast<uint32_t>(timeoutUnit) << std::endl;
ret << " Conn Id : " << std::dec << static_cast<uint32_t>(connectionId) << std::endl;

return (ret.str());
}
6 changes: 3 additions & 3 deletions src/rogue/protocols/xilinx/JtagDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ uint32_t rpx::JtagDriver::cvtPerNs(Header reply) {

tmp = static_cast<double>(rawVal) * 4.0 / 256.0;

return (uint32_t)round(pow(10.0, tmp) * 1.0E9 / REF_FREQ_HZ());
return static_cast<uint32_t>(round(pow(10.0, tmp) * 1.0E9 / REF_FREQ_HZ()));
}

unsigned rpx::JtagDriver::getWordSize() {
Expand Down Expand Up @@ -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<uint64_t>(periodNs_));

if (0 == memDepth_)
retry_ = 0;
Expand Down Expand Up @@ -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<uint64_t>(getPeriodNs()));
}

void rpx::JtagDriver::setup_python() {
Expand Down

0 comments on commit 96d7224

Please sign in to comment.