Skip to content

Commit

Permalink
Make improvements suggested by clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Apr 19, 2024
1 parent 758751a commit 2bd33be
Show file tree
Hide file tree
Showing 33 changed files with 261 additions and 136 deletions.
2 changes: 0 additions & 2 deletions Sming/Arch/Host/Components/driver/hw_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class CTimerThread : public CThread
private:
typedef std::ratio<HW_TIMER_BASE_CLK, 1000000> base_ticks_per_us;
uint32_t divisor = 1;
uint32_t frequency = HW_TIMER_BASE_CLK;
uint64_t start_time = 0;
uint64_t interval = 0; // In microseconds
CSemaphore sem; // Signals state change
Expand All @@ -130,7 +129,6 @@ class CTimerThread : public CThread
State state = stopped;

hw_timer_source_type_t source_type = TIMER_FRC1_SOURCE;
unsigned irq_level = 1;
struct {
hw_timer_callback_t func = nullptr;
void* arg = nullptr;
Expand Down
5 changes: 0 additions & 5 deletions Sming/Arch/Host/Components/driver/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ void notify(smg_uart_t* uart, smg_uart_notify_code_t code)
}
}

__forceinline bool smg_uart_isr_enabled(uint8_t nr)
{
return bitRead(isrMask, nr);
}

} // namespace

smg_uart_t* smg_uart_get_uart(uint8_t uart_nr)
Expand Down
11 changes: 8 additions & 3 deletions Sming/Arch/Host/Components/hostlib/sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ class CSocket
assign(fd, addr);
}

virtual ~CSocket()
~CSocket()
{
close();
}

virtual void close();
void close();

bool setblocking(bool block);
bool bind(const CSockAddr& sa);
Expand Down Expand Up @@ -217,7 +217,12 @@ class CServerSocket : public CSocket
{
}

void close() override
virtual ~CServerSocket()
{
close();
}

void close()
{
m_clients.closeall();
CSocket::close();
Expand Down
6 changes: 2 additions & 4 deletions Sming/Components/Network/src/IpAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ class IpAddress
ip_addr_set_ip4_u32(&this->address, address);
}

IpAddress(ip_addr_t& addr)
IpAddress(ip_addr_t& addr) : address(addr)
{
address = addr;
}

IpAddress(const ip_addr_t& addr)
IpAddress(const ip_addr_t& addr) : address(addr)
{
address = addr;
}

#if LWIP_VERSION_MAJOR == 2 && LWIP_IPV6
Expand Down
5 changes: 5 additions & 0 deletions Sming/Components/Storage/src/include/Storage/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class Device : public LinkedObjectTemplate<Device>
{
}

Device(const Device&) = delete;
Device(Device&&) = delete;
Device& operator=(const Device&) = delete;
Device& operator=(Device&&) = delete;

~Device();

bool operator==(const String& name) const
Expand Down
9 changes: 9 additions & 0 deletions Sming/Components/Storage/src/include/Storage/Partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,19 @@ class Partition
{
}

Partition(Partition&& other) = default;

Partition(Device& device, const Info& info) : mDevice(&device), mPart(&info)
{
}

~Partition()
{
}

Partition& operator=(const Partition& other) = default;
Partition& operator=(Partition&& other) = default;

/**
* @name Confirm partition is of the expected type
* @{
Expand Down
8 changes: 7 additions & 1 deletion Sming/Components/lwip/src/Arch/Host/Linux/lwip_arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
* If not, see <https://www.gnu.org/licenses/>.
*
****/

// Use implementations defined in <netinet/in.h>
#define lwip_htonl nthol
#define lwip_htons htons

#include "../lwip_arch.h"
#include <hostlib/hostmsg.h>
#include <lwip/timeouts.h>
Expand All @@ -40,7 +45,8 @@ void getMacAddress(const char* ifname, uint8_t hwaddr[6])
return;
}

struct ifreq ifr = {0};
struct ifreq ifr {
};
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ - 1] = '\0';
Expand Down
4 changes: 2 additions & 2 deletions Sming/Components/malloc_count/malloc_count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void* operator new(size_t size)
return mc_malloc(size);
}

void* operator new(size_t size, const std::nothrow_t&)
void* operator new(size_t size, const std::nothrow_t&) noexcept
{
return mc_malloc(size);
}
Expand All @@ -377,7 +377,7 @@ void* operator new[](size_t size)
return mc_malloc(size);
}

void* operator new[](size_t size, const std::nothrow_t&)
void* operator new[](size_t size, const std::nothrow_t&) noexcept
{
return mc_malloc(size);
}
Expand Down
6 changes: 6 additions & 0 deletions Sming/Core/Data/CString.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class CString : public std::unique_ptr<char[]>
assign(src.get());
}

CString(CString&& other) = default;

CString(const String& src)
{
assign(src);
Expand All @@ -43,6 +45,8 @@ class CString : public std::unique_ptr<char[]>
assign(src);
}

~CString() = default;

void assign(const String& src)
{
if(src) {
Expand Down Expand Up @@ -74,6 +78,8 @@ class CString : public std::unique_ptr<char[]>
return *this;
}

CString& operator=(CString&& src) = default;

CString& operator=(const String& src)
{
assign(src);
Expand Down
15 changes: 15 additions & 0 deletions Sming/Core/Data/LinkedObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
class LinkedObject
{
public:
LinkedObject() = default;
LinkedObject(const LinkedObject&) = default;
LinkedObject(LinkedObject&&) = default;
LinkedObject& operator=(const LinkedObject&) = default;
LinkedObject& operator=(LinkedObject&&) = default;

virtual ~LinkedObject()
{
}
Expand Down Expand Up @@ -82,6 +88,15 @@ template <typename ObjectType> class LinkedObjectTemplate : public LinkedObject
{
}

IteratorTemplate(IteratorTemplate&&) = default;

~IteratorTemplate()
{
}

IteratorTemplate& operator=(const IteratorTemplate&) = default;
IteratorTemplate& operator=(IteratorTemplate&&) = default;

IteratorTemplate& operator++()
{
this->mObject = static_cast<TPtr>(this->mObject->next());
Expand Down
23 changes: 18 additions & 5 deletions Sming/Core/Data/LinkedObjectList.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ template <typename ObjectType> class LinkedObjectListTemplate : public LinkedObj

ObjectType* head()
{
return reinterpret_cast<ObjectType*>(mHead);
return static_cast<ObjectType*>(mHead);
}

const ObjectType* head() const
{
return reinterpret_cast<const ObjectType*>(mHead);
return static_cast<const ObjectType*>(mHead);
}

Iterator begin()
Expand Down Expand Up @@ -153,7 +153,7 @@ template <typename ObjectType> class LinkedObjectListTemplate : public LinkedObj

ObjectType* pop()
{
return reinterpret_cast<ObjectType*>(LinkedObjectList::pop());
return static_cast<ObjectType*>(LinkedObjectList::pop());
}

size_t count() const
Expand All @@ -176,8 +176,21 @@ template <typename ObjectType> class OwnedLinkedObjectListTemplate : public Link
public:
OwnedLinkedObjectListTemplate() = default;

OwnedLinkedObjectListTemplate(const OwnedLinkedObjectListTemplate& other) = delete;
OwnedLinkedObjectListTemplate& operator=(const OwnedLinkedObjectListTemplate& other) = delete;
OwnedLinkedObjectListTemplate(const OwnedLinkedObjectListTemplate&) = delete;

OwnedLinkedObjectListTemplate(OwnedLinkedObjectListTemplate&& other)
{
std::swap(other.mHead, this->mHead);
}

OwnedLinkedObjectListTemplate& operator=(const OwnedLinkedObjectListTemplate&) = delete;

OwnedLinkedObjectListTemplate& operator=(OwnedLinkedObjectListTemplate&& other)
{
clear();
std::swap(other.mHead, this->mHead);
return *this;
}

~OwnedLinkedObjectListTemplate()
{
Expand Down
2 changes: 1 addition & 1 deletion Sming/Core/Data/Stream/DataSourceStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class IDataSourceStream : public Stream
* @brief Return the total length of the stream
* @retval int -1 is returned when the size cannot be determined
*/
virtual int available()
int available() override
{
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion Sming/Core/Data/Stream/ReadWriteStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ReadWriteStream : public IDataSourceStream
* uses this as the core output method so descendants are required
* to implement it
*/
virtual size_t write(const uint8_t* buffer, size_t size) = 0;
virtual size_t write(const uint8_t* buffer, size_t size) override = 0;

/** @brief Copy data from a source stream
* @param source Stream to read data from
Expand Down
2 changes: 1 addition & 1 deletion Sming/Core/Data/StreamTransformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class StreamTransformer : public IDataSourceStream
return -1;
}

bool isValid() const
bool isValid() const override
{
return sourceStream && sourceStream->isValid();
}
Expand Down
6 changes: 3 additions & 3 deletions Sming/Core/PolledTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Timer : public NanoTime::TimeSource<Clock, unit_, TimeType>
*/
__forceinline bool IRAM_ATTR reset(const TimeType& timeInterval)
{
return resetTicks(this->template timeToTicks(timeInterval));
return resetTicks(this->timeToTicks(timeInterval));
}

/**
Expand Down Expand Up @@ -185,7 +185,7 @@ class Timer : public NanoTime::TimeSource<Clock, unit_, TimeType>
*/
__forceinline NanoTime::Time<TimeType> elapsedTime() const
{
return this->template ticksToTime(elapsedTicks());
return this->ticksToTime(elapsedTicks());
}

/**
Expand All @@ -202,7 +202,7 @@ class Timer : public NanoTime::TimeSource<Clock, unit_, TimeType>
*/
__forceinline NanoTime::Time<TimeType> remainingTime() const
{
return this->template ticksToTime(remainingTicks());
return this->ticksToTime(remainingTicks());
}

__forceinline bool canExpire() const
Expand Down
2 changes: 1 addition & 1 deletion Sming/Core/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ template <class TimerClass> class OsTimer64Api : public CallbackTimerApi<OsTimer

template <class TimerClass> void OsTimer64Api<TimerClass>::setInterval(TickType interval)
{
constexpr auto maxTicks = osTimer.maxTicks();
constexpr auto maxTicks = OsTimerApi::maxTicks();
if(interval > maxTicks) {
// interval too large, calculate a good divider
uint32_t div = (interval / (maxTicks + 1)) + 1; // integer division, intended
Expand Down
4 changes: 3 additions & 1 deletion Sming/Libraries/OtaUpgrade/OtaUpgrade/BasicStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ class BasicStream : public ReadWriteStream
{
return 0;
}
virtual int available() override

int available() override
{
return 0;
}

bool isFinished() override
{
return true;
Expand Down
8 changes: 4 additions & 4 deletions Sming/Services/Profiling/MinMaxTimes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ template <class Timer> class MinMaxTimes : public MinMax32, public Timer

NanoTime::Time<uint32_t> getMinTime() const
{
return this->template ticksToTime(getMin());
return this->ticksToTime(getMin());
}

NanoTime::Time<uint32_t> getMaxTime() const
{
return this->template ticksToTime(getMax());
return this->ticksToTime(getMax());
}

NanoTime::Time<uint32_t> getAverageTime() const
{
return this->template ticksToTime(getAverage());
return this->ticksToTime(getAverage());
}

NanoTime::Time<uint32_t> getTotalTime() const
{
return this->template ticksToTime(getTotal());
return this->ticksToTime(getTotal());
}

size_t printTo(Print& p) const
Expand Down
Loading

0 comments on commit 2bd33be

Please sign in to comment.