[ox/std] Replace Error with a multi-field struct

This commit is contained in:
Gary Talent 2019-10-27 16:21:41 -05:00
parent 3df78cd515
commit 656039e011
3 changed files with 23 additions and 19 deletions

@ -22,14 +22,21 @@
namespace ox {
class BaseError {};
struct BaseError {
const char *file = "";
uint16_t line = 0;
BaseError() = default;
constexpr BaseError(const BaseError &o) noexcept {
file = o.file;
line = o.line;
}
};
using Error = Integer<uint64_t, BaseError>;
constexpr Error errCode(Error err) {
return (err >> 59) & onMask<Error>(5);
}
struct ErrorInfo {
const char *file = nullptr;
int line = -1;
@ -38,22 +45,17 @@ struct ErrorInfo {
ErrorInfo() = default;
ErrorInfo(Error err) {
this->file = reinterpret_cast<const char*>(static_cast<uint64_t>(err & onMask<Error>(48)));
this->line = static_cast<int>((err >> 48) & onMask<Error>(11));
this->errCode = ox::errCode(err);
this->file = err.file;
this->line = err.line;
this->errCode = err;
}
};
static constexpr Error _errorTags(Error line, Error errCode) {
line &= onMask<Error>(11);
line <<= 48;
errCode &= onMask<Error>(5);
errCode <<= 59;
return errCode | line;
}
static constexpr Error _error(const char *file, uint32_t line, Error errCode) {
return Error(errCode ? reinterpret_cast<uint64_t>(file) | _errorTags(Error(line), errCode) : 0);
Error err = errCode;
err.file = file;
err.line = line;
return err;
}
template<typename T>

@ -19,7 +19,7 @@ class BaseInteger {};
* integers.
*/
template<typename T, class Base = BaseInteger>
class Integer: Base {
class Integer: public Base {
private:
T m_i;
@ -110,7 +110,7 @@ constexpr Integer<T, Base>::Integer(T i) noexcept {
}
template<typename T, class Base>
constexpr Integer<T, Base>::Integer(const Integer<T, Base> &i) noexcept:m_i(i.m_i) {
constexpr Integer<T, Base>::Integer(const Integer<T, Base> &i) noexcept: Base(i), m_i(i.m_i) {
}
template<typename T, class Base>

@ -15,6 +15,8 @@
#include "trace.hpp"
int counter = 0;
extern "C"
void oxTraceHook([[maybe_unused]] const char *file, [[maybe_unused]] int line,
[[maybe_unused]] const char *ch, [[maybe_unused]] const char *msg) {