diff --git a/CMakeLists.txt b/CMakeLists.txt index 83b2422..2fc0ae2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,6 +208,34 @@ xo_add_genfacetimpl( OUTPUT_CPP_DIR src/object2 ) +# ---------------------------------------------------------------- + +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-object2-facetimpl-printable-runtimeerror + FACET_PKG xo_printable2 + FACET Printable + REPR RuntimeError + INPUT idl/IPrintable_DRuntimeError.json5 + OUTPUT_HPP_DIR include/xo/object2 + OUTPUT_IMPL_SUBDIR error + OUTPUT_CPP_DIR src/object2 +) + +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-object2-facetimpl-gcobject-runtimeerror + FACET_PKG xo_gc + FACET GCObject + REPR RuntimeError + INPUT idl/IGCObject_DRuntimeError.json5 + OUTPUT_HPP_DIR include/xo/object2 + OUTPUT_IMPL_SUBDIR error + OUTPUT_CPP_DIR src/object2 +) + +# ---------------------------------------------------------------- + xo_add_genfacet_all(xo-object2-genfacet-all) # ---------------------------------------------------------------- diff --git a/idl/IGCObject_DRuntimeError.json5 b/idl/IGCObject_DRuntimeError.json5 new file mode 100644 index 0000000..9e416b2 --- /dev/null +++ b/idl/IGCObject_DRuntimeError.json5 @@ -0,0 +1,15 @@ +{ + mode: "implementation", + includes: [ +// "", +// "" + ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/GCObject.json5", + brief: "provide AGCObject interface for DRuntimeError", + using_doxygen: true, + repr: "DRuntimeError", + doc: [ "implement AGCObject for DRuntimeError" ], +} diff --git a/idl/IPrintable_DRuntimeError.json5 b/idl/IPrintable_DRuntimeError.json5 new file mode 100644 index 0000000..2d0f3ef --- /dev/null +++ b/idl/IPrintable_DRuntimeError.json5 @@ -0,0 +1,13 @@ +{ + mode: "implementation", + includes: [ "", + "" ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Printable.json5", + brief: "provide APrintable interface for DRuntimeError", + using_doxygen: true, + repr: "DRuntimeError", + doc: [ "implement APrintable for DRuntimeError" ], +} diff --git a/include/xo/object2/DRuntimeError.hpp b/include/xo/object2/DRuntimeError.hpp new file mode 100644 index 0000000..9da75c6 --- /dev/null +++ b/include/xo/object2/DRuntimeError.hpp @@ -0,0 +1,61 @@ +/** @file DRuntimeError.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include "String.hpp" +#include + +namespace xo { + namespace scm { + + /** @brief representation for runtime errors + **/ + class DRuntimeError { + public: + using ACollector = xo::mm::ACollector; + using AAllocator = xo::mm::AAllocator; + using ppindentinfo = xo::print::ppindentinfo; + + public: + /** create instance using memory from allocator @p mm + * @p src_fn identifies the (c++) function/method in which + * error detercted. + * @p error_descr contains human-readable error message; + * will be copied by this function. + **/ + DRuntimeError * _make(obj mm, + DString * src_fn, + DString * error_descr); + + /** @defgroup scm-runtimeerror-printable-facet printable facet **/ + ///@{ + + bool pretty(const ppindentinfo & ppii) const; + + ///@} + /** @defgroup scm-runtimeerror-gcobject-facet gcobject facet **/ + ///@{ + + std::size_t shallow_size() const noexcept; + DRuntimeError * shallow_copy(obj mm) const noexcept; + std::size_t forward_children(obj gc) noexcept; + + ///@} + + private: + DRuntimeError(DString * src_fn, DString * error_descr); + + private: + /** source location at which error identified **/ + DString * src_function_ = nullptr; + /** error description (allocated from ErrorArena) **/ + DString * error_descr_ = nullptr; + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DRuntimeError.hpp */ diff --git a/include/xo/object2/RuntimeError.hpp b/include/xo/object2/RuntimeError.hpp new file mode 100644 index 0000000..c2a5f65 --- /dev/null +++ b/include/xo/object2/RuntimeError.hpp @@ -0,0 +1,12 @@ +/** @file RuntimeError.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include "DRuntimeError.hpp" +#include "error/IGCObject_DRuntimeError.hpp" +#include "error/IPrintable_DRuntimeError.hpp" + +/* end RuntimeError.hpp */ diff --git a/include/xo/object2/error/IGCObject_DRuntimeError.hpp b/include/xo/object2/error/IGCObject_DRuntimeError.hpp new file mode 100644 index 0000000..3bb4d3d --- /dev/null +++ b/include/xo/object2/error/IGCObject_DRuntimeError.hpp @@ -0,0 +1,65 @@ +/** @file IGCObject_DRuntimeError.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DRuntimeError.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DRuntimeError.json5] + **/ + +#pragma once + +#include "GCObject.hpp" +#include "DRuntimeError.hpp" + +namespace xo { namespace scm { class IGCObject_DRuntimeError; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::mm::IGCObject_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IGCObject_DRuntimeError + **/ + class IGCObject_DRuntimeError { + public: + /** @defgroup scm-gcobject-druntimeerror-type-traits **/ + ///@{ + using size_type = xo::mm::AGCObject::size_type; + using AAllocator = xo::mm::AGCObject::AAllocator; + using ACollector = xo::mm::AGCObject::ACollector; + using Copaque = xo::mm::AGCObject::Copaque; + using Opaque = xo::mm::AGCObject::Opaque; + ///@} + /** @defgroup scm-gcobject-druntimeerror-methods **/ + ///@{ + // const methods + /** memory consumption for this instance **/ + static size_type shallow_size(const DRuntimeError & self) noexcept; + /** copy instance using allocator **/ + static Opaque shallow_copy(const DRuntimeError & self, obj mm) noexcept; + + // non-const methods + /** during GC: forward immdiate children **/ + static size_type forward_children(DRuntimeError & self, obj gc) noexcept; + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/include/xo/object2/error/IPrintable_DRuntimeError.hpp b/include/xo/object2/error/IPrintable_DRuntimeError.hpp new file mode 100644 index 0000000..8b5a4d1 --- /dev/null +++ b/include/xo/object2/error/IPrintable_DRuntimeError.hpp @@ -0,0 +1,62 @@ +/** @file IPrintable_DRuntimeError.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DRuntimeError.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DRuntimeError.json5] + **/ + +#pragma once + +#include "Printable.hpp" +#include +#include +#include "DRuntimeError.hpp" + +namespace xo { namespace scm { class IPrintable_DRuntimeError; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IPrintable_DRuntimeError + **/ + class IPrintable_DRuntimeError { + public: + /** @defgroup scm-printable-druntimeerror-type-traits **/ + ///@{ + using ppindentinfo = xo::print::APrintable::ppindentinfo; + using Copaque = xo::print::APrintable::Copaque; + using Opaque = xo::print::APrintable::Opaque; + ///@} + /** @defgroup scm-printable-druntimeerror-methods **/ + ///@{ + // const methods + /** Pretty-printing support for this object. +See [xo-indentlog/xo/indentlog/pretty.hpp] **/ + static bool pretty(const DRuntimeError & self, const ppindentinfo & ppii); + + // non-const methods + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/src/object2/CMakeLists.txt b/src/object2/CMakeLists.txt index 609290e..a559524 100644 --- a/src/object2/CMakeLists.txt +++ b/src/object2/CMakeLists.txt @@ -5,29 +5,41 @@ set(SELF_SRCS init_object2.cpp object2_register_types.cpp object2_register_facets.cpp + GCObjectConversion_DFloat.cpp GCObjectConversion_DInteger.cpp - IGCObject_DArray.cpp - IGCObject_DFloat.cpp - IGCObject_DBoolean.cpp - IGCObject_DInteger.cpp - IGCObject_DList.cpp - IGCObject_DString.cpp + ISequence_Any.cpp - ISequence_DArray.cpp - ISequence_DList.cpp - IPrintable_DArray.cpp - IPrintable_DList.cpp - IPrintable_DBoolean.cpp - IPrintable_DFloat.cpp - IPrintable_DInteger.cpp - IPrintable_DString.cpp + DArray.cpp + ISequence_DArray.cpp + IGCObject_DArray.cpp + IPrintable_DArray.cpp + DList.cpp + ISequence_DList.cpp + IGCObject_DList.cpp + IPrintable_DList.cpp + DFloat.cpp + IGCObject_DFloat.cpp + IPrintable_DFloat.cpp + DInteger.cpp + IGCObject_DInteger.cpp + IPrintable_DInteger.cpp + DBoolean.cpp + IGCObject_DBoolean.cpp + IPrintable_DBoolean.cpp + DString.cpp + IGCObject_DString.cpp + IPrintable_DString.cpp + + DRuntimeError.cpp + IGCObject_DRuntimeError.cpp + IPrintable_DRuntimeError.cpp ) xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS}) diff --git a/src/object2/DList.cpp b/src/object2/DList.cpp index 8151221..73c8cd0 100644 --- a/src/object2/DList.cpp +++ b/src/object2/DList.cpp @@ -148,6 +148,8 @@ namespace xo { } } + // ----- GCObject facet ------ + auto DList::shallow_size() const noexcept -> size_type { @@ -175,7 +177,7 @@ namespace xo { auto iface = xo::facet::impl_for(); gc.forward_inplace(&iface, (void **)(&rest_)); - return shallow_size(); + return this->shallow_size(); } } /*namespace scm*/ } /*namespace xo*/ diff --git a/src/object2/DRuntimeError.cpp b/src/object2/DRuntimeError.cpp new file mode 100644 index 0000000..972bd0c --- /dev/null +++ b/src/object2/DRuntimeError.cpp @@ -0,0 +1,82 @@ +/** @file DRuntimeError.cpp +* + * @author Roland Conybeare, Feb 2026 + **/ + +#include "DRuntimeError.hpp" + +namespace xo { + using xo::mm::AGCObject; + using xo::facet::typeseq; + + namespace scm { + + DRuntimeError * + DRuntimeError::_make(obj mm, + DString * src_fn, + DString * error_descr) + { + void * mem + = mm.alloc(typeseq::id(), + sizeof(DRuntimeError)); + + DRuntimeError * err + = new (mem) DRuntimeError(src_fn, error_descr); + + return err; + } + + DRuntimeError::DRuntimeError(DString * src_fn, + DString * error_descr) : src_function_{src_fn}, + error_descr_{error_descr} + {} + + // ----- GCObject facet ----- + + std::size_t + DRuntimeError::shallow_size() const noexcept + { + return sizeof(DRuntimeError); + } + + DRuntimeError * + DRuntimeError::shallow_copy(obj mm) const noexcept + { + DRuntimeError * copy = (DRuntimeError *)mm.alloc_copy((std::byte *)this); + + if (copy) + *copy = *this; + + return copy; + } + + std::size_t + DRuntimeError::forward_children(obj gc) noexcept + { + { + auto iface = xo::facet::impl_for(); + gc.forward_inplace(&iface, (void **)(&src_function_)); + } + + { + auto iface = xo::facet::impl_for(); + gc.forward_inplace(&iface, (void **)(&error_descr_)); + } + + return this->shallow_size(); + } + + // ----- Printable facet ----- + + bool + DRuntimeError::pretty(const ppindentinfo & ppii) const + { + return ppii.pps()->pretty_struct(ppii, + "DRuntimeError"); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DRuntimeError.cpp */ + diff --git a/src/object2/IGCObject_DRuntimeError.cpp b/src/object2/IGCObject_DRuntimeError.cpp new file mode 100644 index 0000000..d44c435 --- /dev/null +++ b/src/object2/IGCObject_DRuntimeError.cpp @@ -0,0 +1,39 @@ +/** @file IGCObject_DRuntimeError.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DRuntimeError.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DRuntimeError.json5] +**/ + +#include "error/IGCObject_DRuntimeError.hpp" + +namespace xo { + namespace scm { + auto + IGCObject_DRuntimeError::shallow_size(const DRuntimeError & self) noexcept -> size_type + { + return self.shallow_size(); + } + + auto + IGCObject_DRuntimeError::shallow_copy(const DRuntimeError & self, obj mm) noexcept -> Opaque + { + return self.shallow_copy(mm); + } + + auto + IGCObject_DRuntimeError::forward_children(DRuntimeError & self, obj gc) noexcept -> size_type + { + return self.forward_children(gc); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IGCObject_DRuntimeError.cpp */ diff --git a/src/object2/IPrintable_DRuntimeError.cpp b/src/object2/IPrintable_DRuntimeError.cpp new file mode 100644 index 0000000..eaf084c --- /dev/null +++ b/src/object2/IPrintable_DRuntimeError.cpp @@ -0,0 +1,28 @@ +/** @file IPrintable_DRuntimeError.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DRuntimeError.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DRuntimeError.json5] +**/ + +#include "error/IPrintable_DRuntimeError.hpp" + +namespace xo { + namespace scm { + auto + IPrintable_DRuntimeError::pretty(const DRuntimeError & self, const ppindentinfo & ppii) -> bool + { + return self.pretty(ppii); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IPrintable_DRuntimeError.cpp */ diff --git a/src/object2/object2_register_facets.cpp b/src/object2/object2_register_facets.cpp index a910e27..c635847 100644 --- a/src/object2/object2_register_facets.cpp +++ b/src/object2/object2_register_facets.cpp @@ -4,6 +4,7 @@ **/ #include "object2_register_facets.hpp" +#include "RuntimeError.hpp" #include #include @@ -66,6 +67,9 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + log && log(xtag("DVariantPlaceholder.tseq", typeseq::id())); log && log(xtag("DList.tseq", typeseq::id())); @@ -74,6 +78,7 @@ namespace xo { log && log(xtag("DInteger.tseq", typeseq::id())); log && log(xtag("DString.tseq", typeseq::id())); log && log(xtag("DArray.tseq", typeseq::id())); + log && log(xtag("DRuntimeError.tseq", typeseq::id())); log && log(xtag("AAllocator.tseq", typeseq::id())); log && log(xtag("APrintable.tseq", typeseq::id()));