sys: More compile time improvements

This commit is contained in:
WerWolv
2021-08-29 22:15:18 +02:00
parent 1ba185bf71
commit 633fa7213a
53 changed files with 258 additions and 217 deletions

View File

@@ -1,10 +1,8 @@
#pragma once
#include <cstdint>
#include <cstddef>
#include <hex/helpers/lang.hpp>
#include <hex/helpers/logger.hpp>
using namespace hex::lang_literals;
constexpr static const auto ImHexApiURL = "https://api.werwolv.net/imhex";
@@ -22,6 +20,11 @@ using s32 = std::int32_t;
using s64 = std::int64_t;
using s128 = __int128_t;
struct Region {
u64 address;
size_t size;
};
#ifdef OS_WINDOWS
#define MAGIC_PATH_SEPARATOR ";"
#else

View File

@@ -1,8 +1,7 @@
#pragma once
#include <hex.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/concepts.hpp>
#include <functional>
#include <map>

View File

@@ -1,9 +1,9 @@
#pragma once
#include <hex.hpp>
#include <hex/helpers/utils.hpp>
#include <list>
#include <vector>
namespace hex {

View File

@@ -2,6 +2,7 @@
#include <hex.hpp>
#include <string_view>
#include <vector>
namespace hex::dp {

View File

@@ -2,7 +2,6 @@
#include <hex.hpp>
#include <hex/data_processor/attribute.hpp>
#include <hex/helpers/utils.hpp>
#include <set>
#include <string_view>

View File

@@ -0,0 +1,148 @@
#pragma once
#include <type_traits>
namespace hex {
template<typename>
struct is_integral_helper : public std::false_type { };
template<>
struct is_integral_helper<u8> : public std::true_type { };
template<>
struct is_integral_helper<s8> : public std::true_type { };
template<>
struct is_integral_helper<u16> : public std::true_type { };
template<>
struct is_integral_helper<s16> : public std::true_type { };
template<>
struct is_integral_helper<u32> : public std::true_type { };
template<>
struct is_integral_helper<s32> : public std::true_type { };
template<>
struct is_integral_helper<u64> : public std::true_type { };
template<>
struct is_integral_helper<s64> : public std::true_type { };
template<>
struct is_integral_helper<u128> : public std::true_type { };
template<>
struct is_integral_helper<s128> : public std::true_type { };
template<>
struct is_integral_helper<bool> : public std::true_type { };
template<>
struct is_integral_helper<char> : public std::true_type { };
template<>
struct is_integral_helper<char8_t> : public std::true_type { };
template<>
struct is_integral_helper<char16_t> : public std::true_type { };
template<>
struct is_integral_helper<char32_t> : public std::true_type { };
template<>
struct is_integral_helper<wchar_t> : public std::true_type { };
template<typename T>
struct is_integral : public is_integral_helper<std::remove_cvref_t<T>>::type { };
template<typename>
struct is_signed_helper : public std::false_type { };
template<>
struct is_signed_helper<s8> : public std::true_type { };
template<>
struct is_signed_helper<s16> : public std::true_type { };
template<>
struct is_signed_helper<s32> : public std::true_type { };
template<>
struct is_signed_helper<s64> : public std::true_type { };
template<>
struct is_signed_helper<s128> : public std::true_type { };
template<>
struct is_signed_helper<char> : public std::true_type { };
template<>
struct is_signed_helper<float> : public std::true_type { };
template<>
struct is_signed_helper<double> : public std::true_type { };
template<>
struct is_signed_helper<long double> : public std::true_type { };
template<typename T>
struct is_signed : public is_signed_helper<std::remove_cvref_t<T>>::type { };
template<typename>
struct is_floating_point_helper : public std::false_type { };
template<>
struct is_floating_point_helper<float> : public std::true_type { };
template<>
struct is_floating_point_helper<double> : public std::true_type { };
template<>
struct is_floating_point_helper<long double> : public std::true_type { };
template<typename T>
struct is_floating_point : public is_floating_point_helper<std::remove_cvref_t<T>>::type { };
}
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION <= 12000
#if __has_include(<concepts>)
// Make sure we break when derived_from is implemented in libc++. Then we can fix a compatibility version above
#include <concepts>
#endif
// libcxx 12 still doesn't have many default concepts implemented, as a result we need to define it ourself using clang built-ins.
// [concept.derived] (patch from https://reviews.llvm.org/D74292)
namespace hex {
template<class _Dp, class _Bp>
concept derived_from =
__is_base_of(_Bp, _Dp) && __is_convertible_to(const volatile _Dp*, const volatile _Bp*);
}
#else
// Assume supported
#include <concepts>
namespace hex {
using std::derived_from;
}
#endif
// [concepts.arithmetic]
namespace hex {
template<class T>
concept integral = hex::is_integral<T>::value;
template<class T>
concept signed_integral = integral<T> && hex::is_signed<T>::value;
template<class T>
concept unsigned_integral = integral<T> && !signed_integral<T>;
template<class T>
concept floating_point = std::is_floating_point<T>::value;
}
template<typename T>
struct always_false : std::false_type {};

View File

@@ -0,0 +1,19 @@
#pragma once
#include <string_view>
#include <fmt/format.h>
#include <fmt/chrono.h>
namespace hex {
template<typename ... Args>
inline std::string format(std::string_view format, Args ... args) {
return fmt::format(fmt::runtime(format), args...);
}
template<typename ... Args>
inline void print(std::string_view format, Args ... args) {
fmt::print(fmt::runtime(format), args...);
}
}

View File

@@ -1,6 +1,8 @@
#pragma once
#include <hex.hpp>
#include <cstring>
#include <future>
#include <string>
#include <filesystem>

View File

@@ -2,6 +2,8 @@
#include <hex.hpp>
#include <hex/helpers/concepts.hpp>
#include <array>
#include <cstring>
#include <functional>
@@ -11,166 +13,15 @@
#include <type_traits>
#include <vector>
#include <fmt/format.h>
#include <fmt/chrono.h>
#ifdef __MINGW32__
#include <winsock2.h>
#else
#include <arpa/inet.h>
#endif
#include <nfd.hpp>
#if defined(__APPLE__) || defined(__FreeBSD__)
#if defined(OS_MACOS)
#define off64_t off_t
#define fopen64 fopen
#define fseeko64 fseek
#define ftello64 ftell
#endif
namespace hex {
template<typename>
struct is_integral_helper : public std::false_type { };
template<>
struct is_integral_helper<u8> : public std::true_type { };
template<>
struct is_integral_helper<s8> : public std::true_type { };
template<>
struct is_integral_helper<u16> : public std::true_type { };
template<>
struct is_integral_helper<s16> : public std::true_type { };
template<>
struct is_integral_helper<u32> : public std::true_type { };
template<>
struct is_integral_helper<s32> : public std::true_type { };
template<>
struct is_integral_helper<u64> : public std::true_type { };
template<>
struct is_integral_helper<s64> : public std::true_type { };
template<>
struct is_integral_helper<u128> : public std::true_type { };
template<>
struct is_integral_helper<s128> : public std::true_type { };
template<>
struct is_integral_helper<bool> : public std::true_type { };
template<>
struct is_integral_helper<char> : public std::true_type { };
template<>
struct is_integral_helper<char8_t> : public std::true_type { };
template<>
struct is_integral_helper<char16_t> : public std::true_type { };
template<>
struct is_integral_helper<char32_t> : public std::true_type { };
template<>
struct is_integral_helper<wchar_t> : public std::true_type { };
template<typename T>
struct is_integral : public is_integral_helper<std::remove_cvref_t<T>>::type { };
template<typename>
struct is_signed_helper : public std::false_type { };
template<>
struct is_signed_helper<s8> : public std::true_type { };
template<>
struct is_signed_helper<s16> : public std::true_type { };
template<>
struct is_signed_helper<s32> : public std::true_type { };
template<>
struct is_signed_helper<s64> : public std::true_type { };
template<>
struct is_signed_helper<s128> : public std::true_type { };
template<>
struct is_signed_helper<char> : public std::true_type { };
template<>
struct is_signed_helper<float> : public std::true_type { };
template<>
struct is_signed_helper<double> : public std::true_type { };
template<>
struct is_signed_helper<long double> : public std::true_type { };
template<typename T>
struct is_signed : public is_signed_helper<std::remove_cvref_t<T>>::type { };
template<typename>
struct is_floating_point_helper : public std::false_type { };
template<>
struct is_floating_point_helper<float> : public std::true_type { };
template<>
struct is_floating_point_helper<double> : public std::true_type { };
template<>
struct is_floating_point_helper<long double> : public std::true_type { };
template<typename T>
struct is_floating_point : public is_floating_point_helper<std::remove_cvref_t<T>>::type { };
}
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION <= 12000
#if __has_include(<concepts>)
// Make sure we break when derived_from is implemented in libc++. Then we can fix a compatibility version above
#include <concepts>
#endif
// libcxx 12 still doesn't have many default concepts implemented, as a result we need to define it ourself using clang built-ins.
// [concept.derived] (patch from https://reviews.llvm.org/D74292)
namespace hex {
template<class _Dp, class _Bp>
concept derived_from =
__is_base_of(_Bp, _Dp) && __is_convertible_to(const volatile _Dp*, const volatile _Bp*);
}
#else
// Assume supported
#include <concepts>
namespace hex {
using std::derived_from;
}
#endif
// [concepts.arithmetic]
namespace hex {
template<class _Tp>
concept integral = hex::is_integral<_Tp>::value;
template<class _Tp>
concept signed_integral = integral<_Tp> && hex::is_signed<_Tp>::value;
template<class _Tp>
concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>;
template<class _Tp>
concept floating_point = std::is_floating_point<_Tp>::value;
}
#define TOKEN_CONCAT_IMPL(x, y) x ## y
#define TOKEN_CONCAT(x, y) TOKEN_CONCAT_IMPL(x, y)
#define ANONYMOUS_VARIABLE(prefix) TOKEN_CONCAT(prefix, __COUNTER__)
@@ -186,16 +37,6 @@ namespace hex {
void runCommand(const std::string &command);
void openWebpage(std::string url);
template<typename ... Args>
inline std::string format(std::string_view format, Args ... args) {
return fmt::format(fmt::runtime(format), args...);
}
template<typename ... Args>
inline void print(std::string_view format, Args ... args) {
fmt::print(fmt::runtime(format), args...);
}
[[nodiscard]] constexpr inline u64 extract(u8 from, u8 to, const hex::unsigned_integral auto &value) {
using ValueType = std::remove_cvref_t<decltype(value)>;
ValueType mask = (std::numeric_limits<ValueType>::max() >> (((sizeof(value) * 8) - 1) - (from - to))) << to;
@@ -203,9 +44,6 @@ namespace hex {
return (value & mask) >> to;
}
template<typename T>
struct always_false : std::false_type {};
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
@@ -416,9 +254,4 @@ namespace hex {
}
struct Region {
u64 address;
size_t size;
};
}

View File

@@ -2,20 +2,21 @@
#include <hex.hpp>
#include <hex/providers/provider.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/lang/pattern_data.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/lang/ast_node.hpp>
#include <hex/lang/log_console.hpp>
#include <bit>
#include <span>
#include <string>
#include <unordered_map>
#include <map>
#include <vector>
namespace hex::prv { class Provider; }
namespace hex::lang {
class PatternData;
class Evaluator {
public:
Evaluator() = default;

View File

@@ -1,12 +1,11 @@
#pragma once
#include <hex.hpp>
#include <hex/helpers/utils.hpp>
#include "token.hpp"
#include "ast_node.hpp"
#include <hex/helpers/utils.hpp>
#include <unordered_map>
#include <stdexcept>
#include <utility>

View File

@@ -5,9 +5,10 @@
#include <imgui.h>
#include <hex/providers/provider.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/lang/token.hpp>
#include <hex/views/view.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/fmt.hpp>
#include <cstring>
#include <codecvt>

View File

@@ -8,7 +8,6 @@
#include <string_view>
#include <vector>
#include <hex/lang/pattern_data.hpp>
#include <hex/lang/log_console.hpp>
namespace hex::prv { class Provider; }
@@ -20,6 +19,7 @@ namespace hex::lang {
class Parser;
class Validator;
class Evaluator;
class PatternData;
class PatternLanguage {
public:

View File

@@ -2,8 +2,6 @@
#include <hex.hpp>
#include <hex/helpers/utils.hpp>
#include <utility>
#include <string>
#include <variant>