From 34aaf766a453d8d81d31ca96fa36f10133b62664 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 5 Jul 2025 13:51:47 -0500 Subject: [PATCH 1/9] xo-reflect: provide xo::bp alias for xo::ref::borrow --- include/xo/refcnt/Refcounted.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/xo/refcnt/Refcounted.hpp b/include/xo/refcnt/Refcounted.hpp index bab9f1ba..13feed3d 100644 --- a/include/xo/refcnt/Refcounted.hpp +++ b/include/xo/refcnt/Refcounted.hpp @@ -13,11 +13,17 @@ namespace xo { namespace ref { template class intrusive_ptr; + + template + class Borrow; } template using rp = ref::intrusive_ptr; + template + using bp = ref::Borrow; + namespace ref { class Refcount; From f75f556d99da118703f7acefdd0678242527c9f6 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 5 Jul 2025 13:55:00 -0500 Subject: [PATCH 2/9] use xo::bp instead of xo::ref::brw --- utest/intrusive_ptr.test.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/utest/intrusive_ptr.test.cpp b/utest/intrusive_ptr.test.cpp index 78e3181a..7bc931da 100644 --- a/utest/intrusive_ptr.test.cpp +++ b/utest/intrusive_ptr.test.cpp @@ -9,7 +9,6 @@ namespace xo { using xo::ref::Refcount; using xo::ref::Borrow; - using xo::ref::brw; using xo::ref::intrusive_ptr_refcount; using xo::ref::intrusive_ptr_add_ref; using xo::ref::intrusive_ptr_release; @@ -71,8 +70,8 @@ namespace xo { intrusive_ptr_release(nullptr); /* can borrow a null intrusive_ptr */ - brw p1_brw = p1.borrow(); - brw p2_brw = p2.borrow(); + bp p1_brw = p1.borrow(); + bp p2_brw = p2.borrow(); REQUIRE(p1_brw.get() == nullptr); REQUIRE(p1_brw.operator->() == nullptr); From 389b9ac6f3095790fc4626fb49ba4d2fd4ae47c3 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 5 Jul 2025 16:17:03 -0500 Subject: [PATCH 3/9] xo-refcnt: xo::ref::brw -> xo::bp --- utest/intrusive_ptr.test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utest/intrusive_ptr.test.cpp b/utest/intrusive_ptr.test.cpp index 7bc931da..e2f94f84 100644 --- a/utest/intrusive_ptr.test.cpp +++ b/utest/intrusive_ptr.test.cpp @@ -129,7 +129,7 @@ namespace xo { REQUIRE(p2->reference_counter() == 1); /* can borrow a non-null intrusive-ptr */ - brw p1_brw = p1.borrow(); + bp p1_brw = p1.borrow(); REQUIRE(p1_brw.get() == p1.get()); @@ -139,7 +139,7 @@ namespace xo { REQUIRE(p1.get()->reference_counter() == 1); /* copying borrowed pointer does not touch refcount */ - brw p1_brw2 = p1_brw; + bp p1_brw2 = p1_brw; REQUIRE(ctor_count == cc + 2); REQUIRE(dtor_count == dc); From 89a046700cc5694cce405a022cb09a1867c6f2e2 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 13 Jul 2025 21:19:13 -0500 Subject: [PATCH 4/9] xo-refcnt: + pretty_refcnt.hpp --- CMakeLists.txt | 2 +- include/xo/refcnt/Refcounted.hpp | 2 +- include/xo/refcnt/pretty_refcnt.hpp | 77 +++++++++++++++++++++++++++++ src/Refcounted.cpp | 1 + 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 include/xo/refcnt/pretty_refcnt.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ef7c6c4..d5e487ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ xo_cxx_toplevel_options3() # c++ settings set(XO_PROJECT_NAME refcnt) # is this used? -set(PROJECT_CXX_FLAGS "") +set(PROJECT_CXX_FLAGS "-ftemplate-backtrace-limit=0") #set(PROJECT_CXX_FLAGS "-fconcepts-diagnostics-depth=2") # gcc-only! add_definitions(${PROJECT_CXX_FLAGS}) diff --git a/include/xo/refcnt/Refcounted.hpp b/include/xo/refcnt/Refcounted.hpp index 13feed3d..732acb0b 100644 --- a/include/xo/refcnt/Refcounted.hpp +++ b/include/xo/refcnt/Refcounted.hpp @@ -230,7 +230,7 @@ namespace xo { template inline std::ostream & operator<<(std::ostream & os, intrusive_ptr const & x) { - if(x.get()) { + if (x.get()) { os << *(x.get()); } else { os << "() << ">"; diff --git a/include/xo/refcnt/pretty_refcnt.hpp b/include/xo/refcnt/pretty_refcnt.hpp new file mode 100644 index 00000000..ecf53aba --- /dev/null +++ b/include/xo/refcnt/pretty_refcnt.hpp @@ -0,0 +1,77 @@ +/* @file pretty_refcnt.hpp + * + * author: Roland Conybeare, Jul 2025 + */ + +#pragma once + +#include "Refcounted.hpp" +#include "xo/indentlog/print/pretty.hpp" + +namespace xo { + namespace print { + template <> + struct ppdetail { + static bool print_upto(ppstate * pps, const xo::ref::Refcount * x) { + return ppdetail_atomic::print_upto(pps, x); + } + static void print_pretty(ppstate * pps, const xo::ref::Refcount * x) { + ppdetail_atomic::print_pretty(pps, x); + } + }; + + template + struct ppdetail> { + static bool print_upto(ppstate * pps, const rp & x) { + if (auto p = x.get()) { + return ppdetail::print_upto(pps, *p); + } else { + /* note: degenerate case here, since never write newline for nullptr */ + + pps->write("write(reflect::type_name()); + pps->write(">"); + + return pps->has_margin(); + } + } + + static void print_pretty(ppstate * pps, const rp & x) { + if (auto p = x.get()) { + ppdetail::print_pretty(pps, *p); + } else { + pps->write("write(reflect::type_name()); + pps->write(">"); + } + } + }; + + template + struct ppdetail> { + static bool print_upto(ppstate * pps, const bp & x) { + if (auto p = x.get()) { + return ppdetail::print_upto(pps, *p); + } else { + /* note: degenerate case here, since never write newline for nullptr */ + + pps->write("write(reflect::type_name()); + pps->write(">"); + + return pps->has_margin(); + } + } + + static void print_pretty(ppstate * pps, const bp & x) { + if (auto p = x.get()) { + ppdetail::print_pretty(pps, *p); + } else { + pps->write("write(reflect::type_name()); + pps->write(">"); + } + } + }; + } +} diff --git a/src/Refcounted.cpp b/src/Refcounted.cpp index 38accc85..f08d9c62 100644 --- a/src/Refcounted.cpp +++ b/src/Refcounted.cpp @@ -1,6 +1,7 @@ /* @file Refcounted.cpp */ #include "Refcounted.hpp" +#include "pretty_refcnt.hpp" namespace xo { namespace ref { From 450fbdb74deeb97b2633e50dcd9215d71f5387dc Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 19 Jul 2025 11:47:03 -0500 Subject: [PATCH 5/9] pretty printing -- copmlete for xo::ast::GeneralizedExpression --- include/xo/refcnt/pretty_refcnt.hpp | 91 +++++++++++++++-------------- 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/include/xo/refcnt/pretty_refcnt.hpp b/include/xo/refcnt/pretty_refcnt.hpp index ecf53aba..8c1903f1 100644 --- a/include/xo/refcnt/pretty_refcnt.hpp +++ b/include/xo/refcnt/pretty_refcnt.hpp @@ -10,66 +10,67 @@ namespace xo { namespace print { +#ifndef ppdetail_atomic template <> struct ppdetail { - static bool print_upto(ppstate * pps, const xo::ref::Refcount * x) { - return ppdetail_atomic::print_upto(pps, x); - } - static void print_pretty(ppstate * pps, const xo::ref::Refcount * x) { - ppdetail_atomic::print_pretty(pps, x); + static bool print_pretty(const ppindentinfo & ppii, const xo::ref::Refcount * x) { + return ppdetail_atomic::print_pretty(ppii, x); } }; +#endif template struct ppdetail> { - static bool print_upto(ppstate * pps, const rp & x) { - if (auto p = x.get()) { - return ppdetail::print_upto(pps, *p); + static bool print_pretty(const ppindentinfo & ppii, const rp & x) { + if (ppii.upto()) { + if (auto p = x.get()) { + return ppdetail::print_pretty(ppii, *p); + } else { + /* note: degenerate case here, since never write newline for nullptr */ + + ppii.pps()->write("write(reflect::type_name()); + ppii.pps()->write(">"); + + return ppii.pps()->has_margin(); + } } else { - /* note: degenerate case here, since never write newline for nullptr */ - - pps->write("write(reflect::type_name()); - pps->write(">"); - - return pps->has_margin(); - } - } - - static void print_pretty(ppstate * pps, const rp & x) { - if (auto p = x.get()) { - ppdetail::print_pretty(pps, *p); - } else { - pps->write("write(reflect::type_name()); - pps->write(">"); + if (auto p = x.get()) { + ppdetail::print_pretty(ppii, *p); + } else { + ppii.pps()->write("write(reflect::type_name()); + ppii.pps()->write(">"); + } + return false; } } }; template struct ppdetail> { - static bool print_upto(ppstate * pps, const bp & x) { - if (auto p = x.get()) { - return ppdetail::print_upto(pps, *p); + static bool print_pretty(const ppindentinfo & ppii, const bp & x) { + if (ppii.upto()) { + if (auto p = x.get()) { + return ppdetail::print_pretty(ppii, *p); + } else { + /* note: degenerate case here, since never write newline for nullptr */ + + ppii.pps()->write("write(reflect::type_name()); + ppii.pps()->write(">"); + + return ppii.pps()->has_margin(); + } } else { - /* note: degenerate case here, since never write newline for nullptr */ - - pps->write("write(reflect::type_name()); - pps->write(">"); - - return pps->has_margin(); - } - } - - static void print_pretty(ppstate * pps, const bp & x) { - if (auto p = x.get()) { - ppdetail::print_pretty(pps, *p); - } else { - pps->write("write(reflect::type_name()); - pps->write(">"); + if (auto p = x.get()) { + ppdetail::print_pretty(ppii, *p); + } else { + ppii.pps()->write("write(reflect::type_name()); + ppii.pps()->write(">"); + } + return false; } } }; From be2951e1528278d396d67ff504365721f127ad56 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 19 Nov 2025 12:38:54 -0500 Subject: [PATCH 6/9] xo-alloc / xo-refcnt: feature flags for easy tests. --- include/xo/refcnt/Refcounted.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/xo/refcnt/Refcounted.hpp b/include/xo/refcnt/Refcounted.hpp index 732acb0b..622f2a74 100644 --- a/include/xo/refcnt/Refcounted.hpp +++ b/include/xo/refcnt/Refcounted.hpp @@ -80,6 +80,11 @@ namespace xo { x.ptr_ = nullptr; } + /** convenience tests for static_assert() **/ + static constexpr bool is_rc_ptr = true; + /** see also: xo/alloc/Object.hpp **/ + static constexpr bool is_gc_ptr = false; + /* aliasing ctor. see ctor (8) here: * [[https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr]] * and this dicsussion: From 5b0b53416f4bf09c7ba66309d34cf0a20da141a4 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 15 Feb 2026 22:57:15 -0500 Subject: [PATCH 7/9] xo-reader2 stack: + TypeRegistry --- include/xo/cxxutil/demangle.hpp | 87 +-------------------------------- src/CMakeLists.txt | 1 + 2 files changed, 2 insertions(+), 86 deletions(-) diff --git a/include/xo/cxxutil/demangle.hpp b/include/xo/cxxutil/demangle.hpp index e2184f5d..fd7425ba 100644 --- a/include/xo/cxxutil/demangle.hpp +++ b/include/xo/cxxutil/demangle.hpp @@ -2,91 +2,6 @@ #pragma once -#include -#include -#include // std::array -#include // std::index_sequence - -namespace xo { - namespace reflect { - - template - constexpr auto - substring_as_array(std::string_view str, - std::index_sequence indexes) - { - //return std::array{str[Idxs]..., '\n'}; - return std::array{str[Idxs]...}; - } /*substring_as_array*/ - - template constexpr auto type_name_array() { -#if defined(__clang__) - constexpr auto prefix = std::string_view{"[T = "}; - constexpr auto suffix = std::string_view{"]"}; - constexpr auto function = std::string_view{__PRETTY_FUNCTION__}; -#elif defined(__GNUC__) - constexpr auto prefix = std::string_view{"with T = "}; - constexpr auto suffix = std::string_view{"]"}; - constexpr auto function = std::string_view{__PRETTY_FUNCTION__}; -#elif defined(_MSC_VER) - constexpr auto prefix = std::string_view{"type_name_array<"}; - constexpr auto suffix = std::string_view{">(void)"}; - constexpr auto function = std::string_view{__FUNCSIG__}; -#else -# error type_name_array: Unsupported compiler -#endif - - constexpr auto start = function.find(prefix) + prefix.size(); - constexpr auto end = function.rfind(suffix); - - //static_assert(start < end); - - constexpr auto name = function.substr(start, (end - start)); - - constexpr auto ixseq = std::make_index_sequence{}; - - return substring_as_array(name, ixseq); - } /*type_name_array*/ - - template - struct type_name_holder { - static inline constexpr auto value = type_name_array(); - }; - - template - constexpr auto type_name() -> std::string_view - { - constexpr auto& value = type_name_holder::value; - return std::string_view{value.data(), value.size()}; - } - -#ifdef NOT_IN_USE - template - struct join - { - // Join all strings into a single std::array of chars - static constexpr auto impl() noexcept - { - constexpr std::size_t len = (Strs.size() + ... + 0); - std::array arr{}; - auto append = [i = 0, &arr](auto const& s) mutable { - for (auto c : s) arr[i++] = c; - }; - (append(Strs), ...); - arr[len] = 0; - return arr; - } - // Give the joined string static storage - static constexpr auto arr = impl(); - // View as a std::string_view - static constexpr std::string_view value {arr.data(), arr.size() - 1}; - }; - - // Helper to get the value out - template - static constexpr auto join_v = join::value; -#endif - } /*namespace reflect*/ -} /*namespace xo*/ +#include /* end demangle.hpp */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9cbc92ff..e8b5288f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,4 +7,5 @@ xo_install_include_tree3(include/xo/cxxutil) # NOTE: # dependency set here must be kept consistent with refcnt/cmake/refcntConfig.cmake.in # +xo_dependency(${SELF_LIB} xo_reflectutil) xo_dependency(${SELF_LIB} indentlog) From 44d02a020071c38b18205139b9efb85a19d0bb00 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 26 Feb 2026 12:15:45 +1100 Subject: [PATCH 8/9] xo-refcnt: missing xo-reflectutil dep in cmake export --- cmake/refcntConfig.cmake.in | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/refcntConfig.cmake.in b/cmake/refcntConfig.cmake.in index 5b38fa74..edc16a80 100644 --- a/cmake/refcntConfig.cmake.in +++ b/cmake/refcntConfig.cmake.in @@ -1,6 +1,7 @@ @PACKAGE_INIT@ include(CMakeFindDependencyMacro) +find_dependency(xo_reflectutil) find_dependency(indentlog) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") check_required_components("@PROJECT_NAME@") From bad785bd08321239d433c69190f4557874fdb59d Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 27 Feb 2026 19:38:53 +1100 Subject: [PATCH 9/9] xo-cmake: setup to make share target available via cmake install --- cmake/refcntConfig.cmake.in | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/refcntConfig.cmake.in b/cmake/refcntConfig.cmake.in index edc16a80..4df193f6 100644 --- a/cmake/refcntConfig.cmake.in +++ b/cmake/refcntConfig.cmake.in @@ -4,4 +4,5 @@ include(CMakeFindDependencyMacro) find_dependency(xo_reflectutil) find_dependency(indentlog) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Share.cmake") check_required_components("@PROJECT_NAME@")