From 506ffd3bd96da9bac18f377822ca4f2954f75f71 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Thu, 14 Nov 2024 09:51:15 +0100 Subject: utils: Implement IWYU suggestions --- src/utils/cpp/TARGETS | 7 +-- src/utils/cpp/atomic.hpp | 6 ++- src/utils/cpp/concepts.hpp | 2 + src/utils/cpp/file_locking.cpp | 8 +-- src/utils/cpp/file_locking.hpp | 2 +- src/utils/cpp/gsl.hpp | 3 +- src/utils/cpp/hash_combine.hpp | 1 + src/utils/cpp/hex_string.hpp | 1 - src/utils/cpp/json.hpp | 5 +- src/utils/cpp/path.hpp | 1 - src/utils/cpp/prefix.hpp | 1 - src/utils/cpp/tmp_dir.cpp | 3 ++ src/utils/cpp/tmp_dir.hpp | 2 - src/utils/cpp/transformed_range.hpp | 2 +- src/utils/cpp/type_safe_arithmetic.hpp | 99 ---------------------------------- src/utils/cpp/vector.hpp | 1 + 16 files changed, 24 insertions(+), 120 deletions(-) (limited to 'src/utils/cpp') diff --git a/src/utils/cpp/TARGETS b/src/utils/cpp/TARGETS index f32a34b0..2a0b3f10 100644 --- a/src/utils/cpp/TARGETS +++ b/src/utils/cpp/TARGETS @@ -16,12 +16,7 @@ { "type": ["@", "rules", "CC", "library"] , "name": ["json"] , "hdrs": ["json.hpp"] - , "deps": - [ "gsl" - , ["@", "fmt", "", "fmt"] - , ["@", "gsl", "", "gsl"] - , ["@", "json", "", "json"] - ] + , "deps": ["gsl", ["@", "fmt", "", "fmt"], ["@", "json", "", "json"]] , "stage": ["src", "utils", "cpp"] } , "concepts": diff --git a/src/utils/cpp/atomic.hpp b/src/utils/cpp/atomic.hpp index 94bda75f..179e7f7a 100644 --- a/src/utils/cpp/atomic.hpp +++ b/src/utils/cpp/atomic.hpp @@ -17,9 +17,11 @@ #include #include +#include +#include //std::unique_lock #include -#include -#include // std::move +#include // IWYU pragma: keep +#include // IWYU pragma: keep // Atomic wrapper with notify/wait capabilities. // TODO(modernize): Replace any use this class by C++20's std::atomic, once diff --git a/src/utils/cpp/concepts.hpp b/src/utils/cpp/concepts.hpp index 7cf943b6..d1500e85 100644 --- a/src/utils/cpp/concepts.hpp +++ b/src/utils/cpp/concepts.hpp @@ -17,6 +17,8 @@ #include #include +#include +#include #include #include diff --git a/src/utils/cpp/file_locking.cpp b/src/utils/cpp/file_locking.cpp index 53cba2bf..34670708 100644 --- a/src/utils/cpp/file_locking.cpp +++ b/src/utils/cpp/file_locking.cpp @@ -14,15 +14,17 @@ #include "src/utils/cpp/file_locking.hpp" -#include // for errno -#include // for strerror() - #ifdef __unix__ #include #else #error "Non-unix is not supported yet" #endif +#include // for errno +#include // for strerror() +#include +#include + #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" diff --git a/src/utils/cpp/file_locking.hpp b/src/utils/cpp/file_locking.hpp index abcca121..cada63a1 100644 --- a/src/utils/cpp/file_locking.hpp +++ b/src/utils/cpp/file_locking.hpp @@ -15,8 +15,8 @@ #ifndef INCLUDED_SRC_OTHER_TOOLS_FILE_LOCKING_HPP #define INCLUDED_SRC_OTHER_TOOLS_FILE_LOCKING_HPP +#include #include -#include #include #include // std::move diff --git a/src/utils/cpp/gsl.hpp b/src/utils/cpp/gsl.hpp index 97e0afe7..c691d3d5 100644 --- a/src/utils/cpp/gsl.hpp +++ b/src/utils/cpp/gsl.hpp @@ -15,8 +15,6 @@ #ifndef INCLUDED_SRC_UTILS_CPP_GSL_HPP #define INCLUDED_SRC_UTILS_CPP_GSL_HPP -#include "gsl/gsl" - // implement EnsuresAudit/ExpectsAudit (from gsl-lite) only run in debug mode #ifdef NDEBUG // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) @@ -24,6 +22,7 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define EnsuresAudit(x) (void)0 #else +#include "gsl/gsl" // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define ExpectsAudit(x) Expects(x) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) diff --git a/src/utils/cpp/hash_combine.hpp b/src/utils/cpp/hash_combine.hpp index 5a63abfa..5f098507 100644 --- a/src/utils/cpp/hash_combine.hpp +++ b/src/utils/cpp/hash_combine.hpp @@ -16,6 +16,7 @@ #define INCLUDED_SRC_UTILS_CPP_HASH_COMBINE_HPP #include +#include #include "gsl/gsl" diff --git a/src/utils/cpp/hex_string.hpp b/src/utils/cpp/hex_string.hpp index 5cca094a..3edb46af 100644 --- a/src/utils/cpp/hex_string.hpp +++ b/src/utils/cpp/hex_string.hpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/src/utils/cpp/json.hpp b/src/utils/cpp/json.hpp index 589a5884..8932e71f 100644 --- a/src/utils/cpp/json.hpp +++ b/src/utils/cpp/json.hpp @@ -17,14 +17,17 @@ #include #include +#include +#include +#include #include #include #include #include +#include #include "fmt/core.h" #include "fmt/ostream.h" -#include "gsl/gsl" #include "nlohmann/json.hpp" #include "src/utils/cpp/gsl.hpp" diff --git a/src/utils/cpp/path.hpp b/src/utils/cpp/path.hpp index 77ea647c..26d25e50 100644 --- a/src/utils/cpp/path.hpp +++ b/src/utils/cpp/path.hpp @@ -16,7 +16,6 @@ #define INCLUDED_SRC_UTILS_CPP_PATH_HPP #include -#include [[nodiscard]] static inline auto ToNormalPath( std::filesystem::path const& p) noexcept -> std::filesystem::path { diff --git a/src/utils/cpp/prefix.hpp b/src/utils/cpp/prefix.hpp index 5574c01a..d6268b9c 100644 --- a/src/utils/cpp/prefix.hpp +++ b/src/utils/cpp/prefix.hpp @@ -15,7 +15,6 @@ #ifndef INCLUDED_SRC_UTILS_CPP_PREFIX_HPP #define INCLUDED_SRC_UTILS_CPP_PREFIX_HPP -#include #include #include diff --git a/src/utils/cpp/tmp_dir.cpp b/src/utils/cpp/tmp_dir.cpp index db41512b..7382ce5c 100644 --- a/src/utils/cpp/tmp_dir.cpp +++ b/src/utils/cpp/tmp_dir.cpp @@ -14,6 +14,9 @@ #include "src/utils/cpp/tmp_dir.hpp" +#include +#include + #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" diff --git a/src/utils/cpp/tmp_dir.hpp b/src/utils/cpp/tmp_dir.hpp index bff73916..92d24f52 100644 --- a/src/utils/cpp/tmp_dir.hpp +++ b/src/utils/cpp/tmp_dir.hpp @@ -15,10 +15,8 @@ #ifndef INCLUDED_SRC_OTHER_TOOLS_TMP_DIR_HPP #define INCLUDED_SRC_OTHER_TOOLS_TMP_DIR_HPP -#include #include #include -#include #include std::string const kDefaultTemplate{"tmp.XXXXXX"}; diff --git a/src/utils/cpp/transformed_range.hpp b/src/utils/cpp/transformed_range.hpp index cc3fe5d6..3d064d9c 100644 --- a/src/utils/cpp/transformed_range.hpp +++ b/src/utils/cpp/transformed_range.hpp @@ -19,7 +19,7 @@ #include #include #include -#include //std::move +#include // IWYU pragma: keep #include #include "gsl/gsl" diff --git a/src/utils/cpp/type_safe_arithmetic.hpp b/src/utils/cpp/type_safe_arithmetic.hpp index 2076a5bf..8b84e89b 100644 --- a/src/utils/cpp/type_safe_arithmetic.hpp +++ b/src/utils/cpp/type_safe_arithmetic.hpp @@ -16,7 +16,6 @@ #define INCLUDED_SRC_UTILS_CPP_TYPE_SAFE_ARITHMETIC_HPP #include -#include #include "gsl/gsl" @@ -94,48 +93,6 @@ class TypeSafeArithmetic { auto pointer() const -> const_pointer_t { return &value_; } }; -// template -// bool operator==(TypeSafeArithmetic lhs, TypeSafeArithmetic rhs) -// { -// return lhs.get() == rhs.get(); -// } -// -// template -// bool operator!=(TypeSafeArithmetic lhs, TypeSafeArithmetic rhs) -// { -// return !(lhs == rhs); -// } -// -// template -// bool operator>(TypeSafeArithmetic lhs, TypeSafeArithmetic rhs) -// { -// return lhs.get() > rhs.get(); -// } -// -// template -// bool operator>=(TypeSafeArithmetic lhs, TypeSafeArithmetic rhs) -// { -// return lhs.get() >= rhs.get(); -// } -// -// template -// bool operator<(TypeSafeArithmetic lhs, TypeSafeArithmetic rhs) -// { -// return lhs.get() < rhs.get(); -// } -// -// template -// bool operator<=(TypeSafeArithmetic lhs, TypeSafeArithmetic rhs) -// { -// return lhs.get() <= rhs.get(); -// } -// -// template -// TypeSafeArithmetic operator+(TypeSafeArithmetic lhs, -// TypeSafeArithmetic rhs) { -// return TypeSafeArithmetic{lhs.get() + rhs.get()}; -// } - template auto operator+=(TypeSafeArithmetic& lhs, TypeSafeArithmetic rhs) -> TypeSafeArithmetic& { @@ -143,50 +100,6 @@ auto operator+=(TypeSafeArithmetic& lhs, return lhs; } -// template -// TypeSafeArithmetic operator-(TypeSafeArithmetic lhs, -// TypeSafeArithmetic rhs) { -// return TypeSafeArithmetic{lhs.get() - rhs.get()}; -// } -// -// template -// TypeSafeArithmetic& operator-=(TypeSafeArithmetic& lhs, -// TypeSafeArithmetic rhs) { -// lhs.set(lhs.get() - rhs.get()); -// return lhs; -// } -// -// template -// TypeSafeArithmetic operator*(TypeSafeArithmetic lhs, -// typename TAG::value_t rhs) { -// return TypeSafeArithmetic{lhs.get() - rhs}; -// } -// -// template -// TypeSafeArithmetic& operator*=(TypeSafeArithmetic& lhs, -// typename TAG::value_t rhs) { -// lhs.set(lhs.get() * rhs); -// return lhs; -// } -// -// template -// TypeSafeArithmetic operator/(TypeSafeArithmetic lhs, -// typename TAG::value_t rhs) { -// return TypeSafeArithmetic{lhs.get() / rhs}; -// } -// -// template -// TypeSafeArithmetic& operator/=(TypeSafeArithmetic& lhs, -// typename TAG::value_t rhs) { -// lhs.set(lhs.get() / rhs); -// return lhs; -// } -// -// template -// TypeSafeArithmetic& operator++(TypeSafeArithmetic& a) { -// return a += TypeSafeArithmetic{1}; -// } - template auto operator++(TypeSafeArithmetic& a, int) -> TypeSafeArithmetic { auto r = a; @@ -194,16 +107,4 @@ auto operator++(TypeSafeArithmetic& a, int) -> TypeSafeArithmetic { return r; } -// template -// TypeSafeArithmetic& operator--(TypeSafeArithmetic& a) { -// return a -= TypeSafeArithmetic{1}; -// } -// -// template -// TypeSafeArithmetic operator--(TypeSafeArithmetic& a, int) { -// auto r = a; -// a += TypeSafeArithmetic{1}; -// return r; -// } - #endif // INCLUDED_SRC_UTILS_CPP_TYPE_SAFE_ARITHMETIC_HPP diff --git a/src/utils/cpp/vector.hpp b/src/utils/cpp/vector.hpp index e5bcd3da..f89e3bea 100644 --- a/src/utils/cpp/vector.hpp +++ b/src/utils/cpp/vector.hpp @@ -16,6 +16,7 @@ #define INCLUDED_SRC_UTILS_CPP_VECTOR_HPP // small library to manipulate vectors +#include // IWYU pragma: keep #include // sort the passed vector and remove repeated entries -- cgit v1.2.3