[ox/std] Make oxAssert sort of usable in constexpr
This commit is contained in:
parent
180cac5cc6
commit
ac9cd26367
49
deps/ox/src/ox/std/assert.cpp
vendored
49
deps/ox/src/ox/std/assert.cpp
vendored
@ -17,53 +17,24 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
void assertFunc([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]bool pass, [[maybe_unused]]const char *assertTxt, [[maybe_unused]]const char *msg) noexcept {
|
||||
if (!pass) {
|
||||
#if defined(OX_USE_STDLIB)
|
||||
std::cerr << "\033[31;1;1mASSERT FAILURE:\033[0m " << assertTxt << " [" << file << ':' << line << "]: " << msg << std::endl;
|
||||
printStackTrace(2);
|
||||
oxTrace("assert").del("") << "Failed assert: " << msg << " (" << assertTxt << ") " << " [" << file << ":" << line << "]";
|
||||
std::abort();
|
||||
#else
|
||||
panic(file, line, msg);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void assertFunc(const char *file, int line, const Error &err, const char*, const char *assertMsg) noexcept {
|
||||
if (err) {
|
||||
#if defined(OX_USE_STDLIB)
|
||||
std::cerr << "\033[31;1;1mASSERT FAILURE:\033[0m (" << file << ':' << line << "): " << assertMsg << '\n';
|
||||
void panic([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]const char *panicMsg, [[maybe_unused]]const Error &err) noexcept {
|
||||
#ifdef OX_USE_STDLIB
|
||||
if (!std::is_constant_evaluated()) {
|
||||
std::cerr << "\033[31;1;1mPANIC:\033[0m (" << file << ':' << line << "): " << panicMsg << '\n';
|
||||
if (err.msg) {
|
||||
std::cerr << "\tError Message:\t" << err.msg << '\n';
|
||||
std::cerr << "\tError Message:\t" << err.msg << '\n';
|
||||
}
|
||||
std::cerr << "\tError Code:\t" << err << '\n';
|
||||
std::cerr << "\tError Code:\t" << err << '\n';
|
||||
if (err.file != nullptr) {
|
||||
std::cerr << "\tError Location:\t" << err.file << ':' << err.line << '\n';
|
||||
}
|
||||
printStackTrace(2);
|
||||
oxTrace("panic").del("") << "Panic: " << assertMsg << " [" << file << ":" << line << "]";
|
||||
oxTrace("panic").del("") << "Panic: " << panicMsg << " (" << file << ":" << line << ")";
|
||||
std::abort();
|
||||
#else
|
||||
panic(file, line, assertMsg);
|
||||
#endif
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(OX_USE_STDLIB)
|
||||
void panic(const char *file, int line, const char *panicMsg, const Error &err) noexcept {
|
||||
std::cerr << "\033[31;1;1mPANIC:\033[0m (" << file << ':' << line << "): " << panicMsg << '\n';
|
||||
if (err.msg) {
|
||||
std::cerr << "\tError Message:\t" << err.msg << '\n';
|
||||
}
|
||||
std::cerr << "\tError Code:\t" << err << '\n';
|
||||
if (err.file != nullptr) {
|
||||
std::cerr << "\tError Location:\t" << err.file << ':' << err.line << '\n';
|
||||
}
|
||||
printStackTrace(2);
|
||||
oxTrace("panic").del("") << "Panic: " << panicMsg << " (" << file << ":" << line << ")";
|
||||
std::abort();
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
64
deps/ox/src/ox/std/assert.hpp
vendored
64
deps/ox/src/ox/std/assert.hpp
vendored
@ -8,22 +8,72 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if __has_include(<cassert>)
|
||||
#include <cassert>
|
||||
#else
|
||||
#define assert(e) while (1);
|
||||
#if defined(OX_USE_STDLIB)
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
#include "def.hpp"
|
||||
#include "defines.hpp"
|
||||
#include "error.hpp"
|
||||
#include "realstd.hpp"
|
||||
#include "stacktrace.hpp"
|
||||
#include "trace.hpp"
|
||||
#include "typetraits.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
void assertFunc(const char *file, int line, bool pass, const char *assertTxt, const char *msg) noexcept;
|
||||
void panic(const char *file, int line, const char *panicMsg, const Error &err = OxError(0)) noexcept;
|
||||
|
||||
void assertFunc(const char *file, int line, const Error &err, const char *assertTxt, const char *msg) noexcept;
|
||||
constexpr void constexprPanic(const char *file, int line, const char *panicMsg, const Error &err = OxError(0)) noexcept {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
panic(file, line, panicMsg, err);
|
||||
} else {
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
void panic([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]const char *msg, [[maybe_unused]]const Error &err = OxError(0)) noexcept;
|
||||
constexpr void assertFunc(const char *file, int line, bool pass, [[maybe_unused]]const char *assertTxt, [[maybe_unused]]const char *msg) noexcept {
|
||||
if (!pass) {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
#ifdef OX_USE_STDLIB
|
||||
std::cerr << "\033[31;1;1mASSERT FAILURE:\033[0m " << assertTxt << " [" << file << ':' << line << "]: "
|
||||
<< msg << std::endl;
|
||||
printStackTrace(2);
|
||||
oxTrace("assert").del("") << "Failed assert: " << msg << " (" << assertTxt << ") " << " [" << file
|
||||
<< ":"
|
||||
<< line << "]";
|
||||
std::abort();
|
||||
#else
|
||||
constexprPanic(file, line, msg);
|
||||
#endif
|
||||
} else {
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void assertFunc(const char *file, int line, const Error &err, const char*, const char *assertMsg) noexcept {
|
||||
if (err) {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
#if defined(OX_USE_STDLIB)
|
||||
std::cerr << "\033[31;1;1mASSERT FAILURE:\033[0m (" << file << ':' << line << "): " << assertMsg << '\n';
|
||||
if (err.msg) {
|
||||
std::cerr << "\tError Message:\t" << err.msg << '\n';
|
||||
}
|
||||
std::cerr << "\tError Code:\t" << err << '\n';
|
||||
if (err.file != nullptr) {
|
||||
std::cerr << "\tError Location:\t" << err.file << ':' << err.line << '\n';
|
||||
}
|
||||
printStackTrace(2);
|
||||
oxTrace("constexprPanic").del("") << "Panic: " << assertMsg << " [" << file << ":" << line << "]";
|
||||
std::abort();
|
||||
#else
|
||||
constexprPanic(file, line, assertMsg);
|
||||
#endif
|
||||
} else {
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
2
deps/ox/src/ox/std/fmt.hpp
vendored
2
deps/ox/src/ox/std/fmt.hpp
vendored
@ -16,7 +16,7 @@
|
||||
#include <QString>
|
||||
#endif
|
||||
|
||||
#include "assert.hpp"
|
||||
#include "realstd.hpp"
|
||||
#include "error.hpp"
|
||||
#include "bstring.hpp"
|
||||
#include "string.hpp"
|
||||
|
15
deps/ox/src/ox/std/realstd.hpp
vendored
Normal file
15
deps/ox/src/ox/std/realstd.hpp
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2015 - 2022 gary@drinkingtea.net
|
||||
*
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if __has_include(<cassert>)
|
||||
#include <cassert>
|
||||
#else
|
||||
#define assert(e) while (1);
|
||||
#endif
|
1
deps/ox/src/ox/std/std.hpp
vendored
1
deps/ox/src/ox/std/std.hpp
vendored
@ -27,6 +27,7 @@
|
||||
#include "new.hpp"
|
||||
#include "optional.hpp"
|
||||
#include "random.hpp"
|
||||
#include "realstd.hpp"
|
||||
#include "stacktrace.hpp"
|
||||
#include "stddef.hpp"
|
||||
#include "string.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user