diff --git a/CMakeLists.txt b/CMakeLists.txt index d5801fb5..06e5b73f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -315,6 +315,8 @@ list ( debug/system.hpp debug/validate.cpp debug/validate.hpp + debug/warn.cpp + debug/warn.hpp encode/number.hpp encode/base.cpp encode/base.hpp diff --git a/alloc/chunked.cpp b/alloc/chunked.cpp index 3909a226..95d2f9fa 100644 --- a/alloc/chunked.cpp +++ b/alloc/chunked.cpp @@ -8,6 +8,7 @@ #include "chunked.hpp" +#include "../debug/warn.hpp" #include "../log.hpp" #include "../maths.hpp" #include "../pointer.hpp" diff --git a/debug/assert.cpp b/debug/assert.cpp index b381f132..0f775d3e 100644 --- a/debug/assert.cpp +++ b/debug/assert.cpp @@ -37,29 +37,4 @@ void cruft::debug::detail::unreachable (const char *msg) { panic (msg); -} - - -//////////////////////////////////////////////////////////////////////////////// -void -warn (void) -{ - warn ("Unusual code path found."); -} - - -//----------------------------------------------------------------------------- -void -warn (const std::string &msg) -{ - warn (msg.c_str ()); -} - - -//----------------------------------------------------------------------------- -void -warn (const char *msg) -{ - LOG_WARN (msg); -} - +} \ No newline at end of file diff --git a/debug/assert.hpp b/debug/assert.hpp index a9986a57..2f2db604 100644 --- a/debug/assert.hpp +++ b/debug/assert.hpp @@ -65,67 +65,6 @@ constexpr bool debug_enabled = false; } -#define WARN(C) do { \ - DEBUG_ONLY ( \ - if (C) { \ - std::cerr << __FILE__ \ - << ":" << __func__ \ - << ":" << __LINE__ \ - << ", " << #C \ - << '\n'; \ - } \ - ); \ -} while (0) - - -#define RETURN_FALSE_UNLESS(CONDITION) { \ - if (const auto &__return_false_unless = (CONDITION); !__return_false_unless) { \ - if constexpr (debug_enabled) { \ - std::cerr << __FILE__ << ':' \ - << __LINE__ << ':' \ - << __PRETTY_FUNCTION__ << "; " \ - << #CONDITION << '\n'; \ - breakpoint (); \ - } \ - \ - return false; \ - } \ -} while (0) - - -#define WARN_RETURN(CONDITION,VALUE) do { \ - if (const auto& __warn_return = (CONDITION); !!__warn_return) { \ - if constexpr (debug_enabled) { \ - std::cerr << __FILE__ << ':' \ - << __LINE__ << ':' \ - << __PRETTY_FUNCTION__ << "; " \ - << #CONDITION << '\n'; \ - breakpoint (); \ - } \ - \ - return (VALUE); \ - } \ -} while (0) - - -#define WARN_AND_RETURN_IF(COND, VALUE) WARN_RETURN((COND), (VALUE)) - - -#define RETURN_UNLESS(VALUE,CONDITION) do { \ - if (const auto &__return_unless = (CONDITION); !__return_unless) { \ - if constexpr (debug_enabled) { \ - std::cerr << __FILE__ << ':' \ - << __LINE__ << ':' \ - << __PRETTY_FUNCTION__ << "; " \ - << #CONDITION << '\n'; \ - breakpoint (); \ - } \ - \ - return (VALUE); \ - } \ -} while (0) - - /////////////////////////////////////////////////////////////////////////////// #ifdef COMPILER_GCC #define CHECK(C) do { \ @@ -405,24 +344,3 @@ constexpr bool debug_enabled = false; } \ ); \ } while (0) - - -/////////////////////////////////////////////////////////////////////////////// -#include -#include - -void warn (void); -void warn (std::string const&); -void warn (std::string_view); -void warn (const char *); - - -template -decltype(auto) -warn_return ( - char const *message, - ValueT &&value -) { - warn (message); - return std::forward (value); -} diff --git a/debug/warn.cpp b/debug/warn.cpp new file mode 100644 index 00000000..4373f406 --- /dev/null +++ b/debug/warn.cpp @@ -0,0 +1,36 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2010-2021 Danny Robson + */ + +#include "./warn.hpp" + +#include "../log.hpp" + + +//////////////////////////////////////////////////////////////////////////////// +void +warn (void) +{ + warn ("Unusual code path found."); +} + + +//----------------------------------------------------------------------------- +void +warn (const std::string &msg) +{ + warn (msg.c_str ()); +} + + +//----------------------------------------------------------------------------- +void +warn (const char *msg) +{ + LOG_WARN (msg); +} + diff --git a/debug/warn.hpp b/debug/warn.hpp new file mode 100644 index 00000000..ed45f4ca --- /dev/null +++ b/debug/warn.hpp @@ -0,0 +1,94 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2010-2021 Danny Robson + */ + +#pragma once + +#include "./assert.hpp" + +#include + +#define WARN(C) do { \ + DEBUG_ONLY ( \ + if (C) { \ + std::cerr << __FILE__ \ + << ":" << __func__ \ + << ":" << __LINE__ \ + << ", " << #C \ + << '\n'; \ + } \ + ); \ +} while (0) + + +#define RETURN_FALSE_UNLESS(CONDITION) { \ + if (const auto &__return_false_unless = (CONDITION); !__return_false_unless) { \ + if constexpr (debug_enabled) { \ + std::cerr << __FILE__ << ':' \ + << __LINE__ << ':' \ + << __PRETTY_FUNCTION__ << "; " \ + << #CONDITION << '\n'; \ + breakpoint (); \ + } \ + \ + return false; \ + } \ +} while (0) + + +#define WARN_RETURN(CONDITION,VALUE) do { \ + if (const auto& __warn_return = (CONDITION); !!__warn_return) { \ + if constexpr (debug_enabled) { \ + std::cerr << __FILE__ << ':' \ + << __LINE__ << ':' \ + << __PRETTY_FUNCTION__ << "; " \ + << #CONDITION << '\n'; \ + breakpoint (); \ + } \ + \ + return (VALUE); \ + } \ +} while (0) + + +#define WARN_AND_RETURN_IF(COND, VALUE) WARN_RETURN((COND), (VALUE)) + + +#define RETURN_UNLESS(VALUE,CONDITION) do { \ + if (const auto &__return_unless = (CONDITION); !__return_unless) { \ + if constexpr (debug_enabled) { \ + std::cerr << __FILE__ << ':' \ + << __LINE__ << ':' \ + << __PRETTY_FUNCTION__ << "; " \ + << #CONDITION << '\n'; \ + breakpoint (); \ + } \ + \ + return (VALUE); \ + } \ +} while (0) + + +/////////////////////////////////////////////////////////////////////////////// +#include +#include + +void warn (void); +void warn (std::string const&); +void warn (std::string_view); +void warn (const char *); + + +template +decltype(auto) +warn_return ( + char const *message, + ValueT &&value +) { + warn (message); + return std::forward (value); +} diff --git a/log/sink/console.cpp b/log/sink/console.cpp index 54cbe606..c34fdac1 100644 --- a/log/sink/console.cpp +++ b/log/sink/console.cpp @@ -12,7 +12,7 @@ #include "../packet.hpp" #include "../../term.hpp" -#include "../../debug/assert.hpp" +#include "../../debug/warn.hpp" #include "../../cast.hpp" #include diff --git a/log/sink/path.cpp b/log/sink/path.cpp index 6ce8c736..9c9351d9 100644 --- a/log/sink/path.cpp +++ b/log/sink/path.cpp @@ -11,6 +11,7 @@ #include "../level.hpp" #include "../packet.hpp" #include "../../paths.hpp" +#include "../../debug/warn.hpp" using cruft::log::sink::path; diff --git a/types/description.cpp b/types/description.cpp index 0b6aba38..fe16e667 100644 --- a/types/description.cpp +++ b/types/description.cpp @@ -8,7 +8,7 @@ #include "description.hpp" -#include "../debug/assert.hpp" +#include "../debug/warn.hpp" #include "../maths.hpp"