From 89ae226b1d1eb514bad146ebfc5e0a12818ec808 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 17 Apr 2025 01:12:05 -0500 Subject: [PATCH] [keel] Improve correctness --- src/olympic/keel/include/keel/typeconv.hpp | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/olympic/keel/include/keel/typeconv.hpp b/src/olympic/keel/include/keel/typeconv.hpp index e9f2c2cc0..44511143b 100644 --- a/src/olympic/keel/include/keel/typeconv.hpp +++ b/src/olympic/keel/include/keel/typeconv.hpp @@ -115,7 +115,7 @@ class BaseConverter { virtual ox::Result> convertPtrToPtr(keel::Context &ctx, Wrap &src) const noexcept = 0; virtual ox::Result> convertBuffToPtr( - keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept = 0; + Context &ctx, ox::BufferView const&srcBuff) const noexcept = 0; [[nodiscard]] constexpr bool matches( @@ -129,7 +129,7 @@ class BaseConverter { template -class ConverterFunc: public BaseConverter { +class ConverterFunc final: public BaseConverter { private: template struct ParamPack { @@ -137,8 +137,8 @@ class ConverterFunc: public BaseConverter { using Dst = DstType; }; - template - static ParamPack extractParams(ox::Error (*)(Context&, S&, D&)) { + template + static ParamPack extractParams(ox::Error (*)(Context&, Src&, Dst&)) { return {}; } @@ -147,17 +147,17 @@ class ConverterFunc: public BaseConverter { using DstType = typename decltype(extractParams(Func))::Dst; [[nodiscard]] - constexpr ox::StringView srcTypeName() const noexcept final { + constexpr ox::StringView srcTypeName() const noexcept override { return ox::ModelTypeName_v; } [[nodiscard]] - constexpr int srcTypeVersion() const noexcept final { + constexpr int srcTypeVersion() const noexcept override { return ox::ModelTypeVersion_v; } [[nodiscard]] - constexpr bool srcMatches(ox::StringViewCR pSrcTypeName, int pSrcTypeVersion) const noexcept final { + constexpr bool srcMatches(ox::StringViewCR pSrcTypeName, int pSrcTypeVersion) const noexcept override { constexpr auto SrcTypeName = ox::requireModelTypeName(); constexpr auto SrcTypeVersion = ox::requireModelTypeVersion(); return pSrcTypeName == SrcTypeName @@ -165,7 +165,7 @@ class ConverterFunc: public BaseConverter { } [[nodiscard]] - constexpr bool dstMatches(ox::StringViewCR dstTypeName, int dstTypeVersion) const noexcept final { + constexpr bool dstMatches(ox::StringViewCR dstTypeName, int dstTypeVersion) const noexcept override { constexpr auto DstTypeName = ox::StringView{ox::requireModelTypeName()}; constexpr auto DstTypeVersion = ox::requireModelTypeVersion(); return dstTypeName == DstTypeName @@ -173,14 +173,14 @@ class ConverterFunc: public BaseConverter { } ox::Result> convertPtrToPtr( - keel::Context &ctx, Wrap &src) const noexcept final { + Context &ctx, Wrap &src) const noexcept override { ox::Result> dst{makeWrap()}; OX_RETURN_ERROR(convert(ctx, wrapCast(src), wrapCast(*dst.value))); return dst; } ox::Result> convertBuffToPtr( - keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept final { + Context &ctx, ox::BufferView const&srcBuff) const noexcept override { OX_REQUIRE_M(src, readAsset(srcBuff)); ox::Result> dst{makeWrap()}; OX_RETURN_ERROR(convert(ctx, src, wrapCast(*dst.value))); @@ -188,7 +188,7 @@ class ConverterFunc: public BaseConverter { } protected: - ox::Error convert(keel::Context &ctx, SrcType &src, DstType &dst) const noexcept { + static ox::Error convert(Context &ctx, SrcType &src, DstType &dst) noexcept { return Func(ctx, src, dst); } @@ -200,14 +200,14 @@ class Converter { BaseConverter *m_conv{}; public: template - static Converter make() { + static Converter make() noexcept { Converter out; static_assert(sizeof(ConverterFunc) <= sizeof(out.m_buff)); out.m_conv = new (out.m_buff.data()) ConverterFunc{}; return out; } constexpr Converter() {} - Converter(Converter const &other): + Converter(Converter const &other) noexcept: m_buff{other.m_buff}, m_conv{m_buff.data()} {} [[nodiscard]] @@ -256,20 +256,20 @@ ox::Result convertObjToObj( } template -ox::Result convert(keel::Context &ctx, ox::BufferView const&src) noexcept { +ox::Result convert(Context &ctx, ox::BufferView const&src) noexcept { OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v, ox::ModelTypeVersion_v)); return std::move(wrapCast(out)); } template -ox::Error convert(keel::Context &ctx, ox::BufferView const&buff, DstType &outObj) noexcept { +ox::Error convert(Context &ctx, ox::BufferView const&buff, DstType &outObj) noexcept { OX_REQUIRE(out, convert(ctx, buff, ox::ModelTypeName_v, ox::ModelTypeVersion_v)); outObj = std::move(wrapCast(*out)); return {}; } template -ox::Error convertObjToObj(keel::Context &ctx, auto &src, DstType &outObj) noexcept { +ox::Error convertObjToObj(Context &ctx, auto &src, DstType &outObj) noexcept { OX_REQUIRE(outPtr, convert(ctx, src, ox::ModelTypeName_v, ox::ModelTypeVersion_v)); outObj = std::move(wrapCast(*outPtr)); return {}; @@ -277,13 +277,13 @@ ox::Error convertObjToObj(keel::Context &ctx, auto &src, DstType &outObj) noexce template ox::Result convertBuffToBuff( - keel::Context &ctx, ox::BufferView const&src, ox::ClawFormat const fmt) noexcept { + Context &ctx, ox::BufferView const&src, ox::ClawFormat const fmt) noexcept { OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v, ox::ModelTypeVersion_v)); return ox::writeClaw(wrapCast(*out), fmt); } template -ox::Result transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringViewCR typeId) noexcept { +ox::Result transformRule(Context &ctx, ox::Buffer &buff, ox::StringViewCR typeId) noexcept { if (typeId == ox::ModelTypeId_v) { OX_RETURN_ERROR(keel::convertBuffToBuff(ctx, buff, fmt).moveTo(buff)); return true;