Skip to content

Commit

Permalink
Apply some fixes from the new clang-tidy
Browse files Browse the repository at this point in the history
They are mostly ensuring that IWYU is followed and ensuring functions that are only used in a cpp file they have internal linkage.

However there are also a few instances of ensuring the CRTP classes are used as CRTP, and one issue that was found where a type was being forwarded twice (potentially moving data when it shouldn't)
  • Loading branch information
TrentHouliston committed Dec 25, 2024
1 parent 9d2fa74 commit 899a463
Show file tree
Hide file tree
Showing 98 changed files with 914 additions and 378 deletions.
1 change: 0 additions & 1 deletion src/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#ifndef NUCLEAR_CONFIGURATION_HPP
#define NUCLEAR_CONFIGURATION_HPP

#include <cstddef>
#include <thread>

namespace NUClear {
Expand Down
2 changes: 1 addition & 1 deletion src/Environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#define NUCLEAR_ENVIRONMENT_HPP

#include <string>
#include <utility>

#include "LogLevel.hpp"

namespace NUClear {

Expand Down
2 changes: 2 additions & 0 deletions src/LogLevel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#ifndef NUCLEAR_LOGLEVEL_HPP
#define NUCLEAR_LOGLEVEL_HPP

#include <cstdint>
#include <ostream>
#include <string>

// Why do we need to include platform.hpp here?
// Because windows defines a bunch of things for legacy reasons, one of which is a #define for ERROR as blank
Expand Down
11 changes: 5 additions & 6 deletions src/PowerPlant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@

#include "PowerPlant.hpp"

#include <exception>
#include <tuple>
#include <memory>
#include <utility>

#include "Configuration.hpp"
#include "Reactor.hpp"
#include "dsl/store/DataStore.hpp"
#include "dsl/word/Shutdown.hpp"
#include "dsl/word/Startup.hpp"
#include "dsl/word/emit/Inline.hpp"
#include "extension/ChronoController.hpp"
#include "extension/IOController.hpp"
#include "extension/NetworkController.hpp"
#include "id.hpp"
#include "message/CommandLineArguments.hpp"
#include "message/LogMessage.hpp"
#include "threading/Reaction.hpp"
#include "threading/ReactionTask.hpp"

namespace NUClear {
Expand Down
8 changes: 4 additions & 4 deletions src/PowerPlant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
#ifndef NUCLEAR_POWER_PLANT_HPP
#define NUCLEAR_POWER_PLANT_HPP

#include <atomic>
#include <functional>
#include <memory>
#include <sstream>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

// Utilities
#include "Configuration.hpp"
#include "Configuration.hpp" // IWYU pragma: export
#include "Environment.hpp"
#include "LogLevel.hpp"
#include "id.hpp"
#include "threading/Reaction.hpp"
#include "threading/ReactionTask.hpp"
#include "threading/scheduler/Scheduler.hpp"
#include "util/FunctionFusion.hpp"
Expand Down
2 changes: 2 additions & 0 deletions src/Reactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "Reactor.hpp"

#include "LogLevel.hpp"

namespace NUClear {

constexpr LogLevel Reactor::TRACE;
Expand Down
18 changes: 11 additions & 7 deletions src/Reactor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@
#define NUCLEAR_REACTOR_HPP

#include <chrono>
#include <functional>
#include <cstddef>
#include <memory>
#include <regex>
#include <string>
#include <typeindex>
#include <tuple>
#include <utility>
#include <vector>

#include "Environment.hpp"
#include "LogLevel.hpp"
#include "Environment.hpp" // IWYU pragma: export
#include "LogLevel.hpp" // IWYU pragma: export
#include "clock.hpp" // IWYU pragma: export
#include "dsl/Parse.hpp"
#include "threading/Reaction.hpp"
#include "threading/ReactionHandle.hpp"
#include "threading/ReactionIdentifiers.hpp"
#include "id.hpp" // IWYU pragma: export
#include "threading/Reaction.hpp" // IWYU pragma: export
#include "threading/ReactionHandle.hpp" // IWYU pragma: export
#include "threading/ReactionIdentifiers.hpp" // IWYU pragma: export
#include "util/CallbackGenerator.hpp"
#include "util/Sequence.hpp"
#include "util/demangle.hpp"
Expand Down
4 changes: 2 additions & 2 deletions src/dsl/fusion/BindFusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ namespace dsl {
reaction,
std::forward<Arguments>(args)...))>::value,
NoReturn,
Return>::template call(reaction, std::forward<Arguments>(args)...)) {
Return>::call(reaction, std::forward<Arguments>(args)...)) {

return std::conditional_t<
std::is_void<decltype(Function::template bind<DSL>(reaction,
std::forward<Arguments>(args)...))>::value,
NoReturn,
Return>::template call(reaction, std::forward<Arguments>(args)...);
Return>::call(reaction, std::forward<Arguments>(args)...);
}
};

Expand Down
4 changes: 4 additions & 0 deletions src/dsl/operation/CacheGet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "../store/ThreadStore.hpp"

namespace NUClear {
namespace threading {
class ReactionTask; // Forward declare ReactionTask
} // namespace threading
namespace dsl {
namespace operation {

Expand All @@ -41,6 +44,7 @@ namespace dsl {
*/
template <typename DataType>
struct CacheGet {
CacheGet() = delete; // Ensure that DSL words are not instantiated

template <typename DSL, typename T = DataType>
static std::shared_ptr<const T> get(const threading::ReactionTask& /*task*/) {
Expand Down
2 changes: 2 additions & 0 deletions src/dsl/operation/ChronoTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#ifndef NUCLEAR_DSL_OPERATION_CHRONO_TASK_HPP
#define NUCLEAR_DSL_OPERATION_CHRONO_TASK_HPP

#include <functional>

#include "../../clock.hpp"
#include "../../id.hpp"

Expand Down
3 changes: 3 additions & 0 deletions src/dsl/operation/TypeBind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#ifndef NUCLEAR_DSL_OPERATION_TYPE_BIND_HPP
#define NUCLEAR_DSL_OPERATION_TYPE_BIND_HPP

#include <algorithm>

#include "../store/TypeCallbackStore.hpp"

namespace NUClear {
Expand Down Expand Up @@ -56,6 +58,7 @@ namespace dsl {
*/
template <typename DataType>
struct TypeBind {
TypeBind() = delete; // Ensure that DSL words are not instantiated

template <typename DSL>
static void bind(const std::shared_ptr<threading::Reaction>& reaction) {
Expand Down
14 changes: 11 additions & 3 deletions src/dsl/word/Shutdown.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ namespace dsl {
* @par Implements
* Bind
*/
struct Shutdown
: operation::TypeBind<Shutdown>
, Priority::IDLE {};
struct Shutdown {};

} // namespace word

namespace operation {

template <>
struct DSLProxy<word::Shutdown>
: operation::TypeBind<word::Shutdown>
, word::Priority::IDLE {};

} // namespace operation

} // namespace dsl
} // namespace NUClear

Expand Down
10 changes: 9 additions & 1 deletion src/dsl/word/Startup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ namespace dsl {
* @par Implements
* Bind
*/
struct Startup : operation::TypeBind<Startup> {};
struct Startup {};

} // namespace word

namespace operation {

template <>
struct DSLProxy<word::Startup> : operation::TypeBind<word::Startup> {};

} // namespace operation

} // namespace dsl
} // namespace NUClear

Expand Down
4 changes: 2 additions & 2 deletions src/dsl/word/emit/Delay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace dsl {
struct Delay {

static void emit(PowerPlant& powerplant,
std::shared_ptr<DataType> data,
const std::shared_ptr<DataType>& data,
NUClear::clock::duration delay) {

// Our chrono task is just to do a normal emit in the amount of time
Expand All @@ -67,7 +67,7 @@ namespace dsl {
}

static void emit(PowerPlant& powerplant,
std::shared_ptr<DataType> data,
const std::shared_ptr<DataType>& data,
NUClear::clock::time_point at_time) {

// Our chrono task is just to do a normal emit in the amount of time
Expand Down
10 changes: 9 additions & 1 deletion src/extension/ChronoController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@

#include "ChronoController.hpp"

#include <algorithm>
#include <atomic>

#include <chrono>
#include <memory>
#include <mutex>
#include <utility>

#include "../Reactor.hpp"
#include "../dsl/operation/Unbind.hpp"
#include "../message/TimeTravel.hpp"
#include "../util/precise_sleep.hpp"

namespace NUClear {
Expand Down
15 changes: 15 additions & 0 deletions src/extension/NetworkController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,22 @@

#include "NetworkController.hpp"

#include <algorithm>
#include <chrono>
#include <cstdint>
#include <memory>
#include <mutex>
#include <utility>
#include <vector>

#include "../Reactor.hpp"
#include "../dsl/operation/Unbind.hpp"
#include "../dsl/store/ThreadStore.hpp"
#include "../dsl/word/Network.hpp"
#include "../dsl/word/emit/Network.hpp"
#include "../message/NetworkConfiguration.hpp"
#include "../message/NetworkEvent.hpp"
#include "../util/get_hostname.hpp"

namespace NUClear {
namespace extension {
Expand Down
Loading

0 comments on commit 899a463

Please sign in to comment.