From fa0b45b552347d97eb8c0d575487f46b5e066c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johel=20Ernesto=20Guerrero=20Pe=C3=B1a?= Date: Sun, 6 Mar 2022 11:32:23 -0400 Subject: [PATCH] refactor(bits): move macros to config/macros.h --- src/core/include/units/bits/config/macros.h | 82 +++++++++++++++++++ .../include/units/bits/external/downcasting.h | 8 -- src/core/include/units/bits/external/hacks.h | 56 +------------ 3 files changed, 83 insertions(+), 63 deletions(-) create mode 100644 src/core/include/units/bits/config/macros.h diff --git a/src/core/include/units/bits/config/macros.h b/src/core/include/units/bits/config/macros.h new file mode 100644 index 000000000..4996afaf9 --- /dev/null +++ b/src/core/include/units/bits/config/macros.h @@ -0,0 +1,82 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include + +#if __clang__ +#define UNITS_COMP_CLANG __clang_major__ +#elif __GNUC__ +#define UNITS_COMP_GCC __GNUC__ +#define UNITS_COMP_GCC_MINOR __GNUC_MINOR__ +#elif _MSC_VER +#define UNITS_COMP_MSVC _MSC_VER +#endif + +// Adapted from https://github.com/ericniebler/range-v3/blob/master/include/range/v3/detail/config.hpp#L185. +#define UNITS_PRAGMA(X) _Pragma(#X) +#if !UNITS_COMP_MSVC +#define UNITS_DIAGNOSTIC_PUSH UNITS_PRAGMA(GCC diagnostic push) +#define UNITS_DIAGNOSTIC_POP UNITS_PRAGMA(GCC diagnostic pop) +#define UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(GCC diagnostic ignored "-Wpragmas") +#define UNITS_DIAGNOSTIC_IGNORE(X) \ + UNITS_DIAGNOSTIC_IGNORE_PRAGMAS \ + UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-pragmas") \ + UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-warning-option") \ + UNITS_PRAGMA(GCC diagnostic ignored X) +#define UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF +#define UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA +#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES UNITS_DIAGNOSTIC_IGNORE("-Wmissing-braces") +#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND UNITS_DIAGNOSTIC_IGNORE("-Wnon-template-friend") +#define UNITS_DIAGNOSTIC_IGNORE_SHADOW UNITS_DIAGNOSTIC_IGNORE("-Wshadow") +#define UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE +#else +#define UNITS_DIAGNOSTIC_PUSH UNITS_PRAGMA(warning(push)) +#define UNITS_DIAGNOSTIC_POP UNITS_PRAGMA(warning(pop)) +#define UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : 4068)) +#define UNITS_DIAGNOSTIC_IGNORE(X) UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : X)) +#define UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF UNITS_DIAGNOSTIC_IGNORE(4296) +#define UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA UNITS_DIAGNOSTIC_IGNORE(4244) +#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES +#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND +#define UNITS_DIAGNOSTIC_IGNORE_SHADOW UNITS_DIAGNOSTIC_IGNORE(4459) +#define UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE UNITS_DIAGNOSTIC_IGNORE(4702) +#endif + +#if _LIBCPP_VERSION +#define UNITS_LIBCXX _LIBCPP_VERSION +#endif + +#if UNITS_COMP_MSVC || UNITS_COMP_CLANG +#define TYPENAME typename +#else +#define TYPENAME +#endif + +#ifdef UNITS_DOWNCAST_MODE +#if UNITS_DOWNCAST_MODE < 0 || UNITS_DOWNCAST_MODE > 2 +#error "Invalid UNITS_DOWNCAST_MODE value" +#endif +#else +#define UNITS_DOWNCAST_MODE 1 +#endif diff --git a/src/core/include/units/bits/external/downcasting.h b/src/core/include/units/bits/external/downcasting.h index 96974644d..b62146fae 100644 --- a/src/core/include/units/bits/external/downcasting.h +++ b/src/core/include/units/bits/external/downcasting.h @@ -25,14 +25,6 @@ #include #include -#ifdef UNITS_DOWNCAST_MODE -#if UNITS_DOWNCAST_MODE < 0 || UNITS_DOWNCAST_MODE > 2 -#error "Invalid UNITS_DOWNCAST_MODE value" -#endif -#else -#define UNITS_DOWNCAST_MODE 1 -#endif - namespace units { template diff --git a/src/core/include/units/bits/external/hacks.h b/src/core/include/units/bits/external/hacks.h index 5a9835402..f9b608723 100644 --- a/src/core/include/units/bits/external/hacks.h +++ b/src/core/include/units/bits/external/hacks.h @@ -22,50 +22,7 @@ #pragma once -#include - -#if __clang__ -#define UNITS_COMP_CLANG __clang_major__ -#elif __GNUC__ -#define UNITS_COMP_GCC __GNUC__ -#define UNITS_COMP_GCC_MINOR __GNUC_MINOR__ -#elif _MSC_VER -#define UNITS_COMP_MSVC _MSC_VER -#endif - -// Adapted from https://github.com/ericniebler/range-v3/blob/master/include/range/v3/detail/config.hpp#L185. -#define UNITS_PRAGMA(X) _Pragma(#X) -#if !UNITS_COMP_MSVC -#define UNITS_DIAGNOSTIC_PUSH UNITS_PRAGMA(GCC diagnostic push) -#define UNITS_DIAGNOSTIC_POP UNITS_PRAGMA(GCC diagnostic pop) -#define UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(GCC diagnostic ignored "-Wpragmas") -#define UNITS_DIAGNOSTIC_IGNORE(X) \ - UNITS_DIAGNOSTIC_IGNORE_PRAGMAS \ - UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-pragmas") \ - UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-warning-option") \ - UNITS_PRAGMA(GCC diagnostic ignored X) -#define UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF -#define UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA -#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES UNITS_DIAGNOSTIC_IGNORE("-Wmissing-braces") -#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND UNITS_DIAGNOSTIC_IGNORE("-Wnon-template-friend") -#define UNITS_DIAGNOSTIC_IGNORE_SHADOW UNITS_DIAGNOSTIC_IGNORE("-Wshadow") -#define UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE -#else -#define UNITS_DIAGNOSTIC_PUSH UNITS_PRAGMA(warning(push)) -#define UNITS_DIAGNOSTIC_POP UNITS_PRAGMA(warning(pop)) -#define UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : 4068)) -#define UNITS_DIAGNOSTIC_IGNORE(X) UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : X)) -#define UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF UNITS_DIAGNOSTIC_IGNORE(4296) -#define UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA UNITS_DIAGNOSTIC_IGNORE(4244) -#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES -#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND -#define UNITS_DIAGNOSTIC_IGNORE_SHADOW UNITS_DIAGNOSTIC_IGNORE(4459) -#define UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE UNITS_DIAGNOSTIC_IGNORE(4702) -#endif - -#if _LIBCPP_VERSION -#define UNITS_LIBCXX _LIBCPP_VERSION -#endif +#include #if UNITS_LIBCXX @@ -90,17 +47,6 @@ #include #include -#if UNITS_COMP_MSVC || UNITS_COMP_CLANG - -#define TYPENAME typename - -#else - -#define TYPENAME - -#endif - - namespace std { #if UNITS_COMP_GCC