From f4db0eefce141f7943540bc41051cfbe3a974da7 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 18 Jun 2024 17:16:05 -0400 Subject: [PATCH] xo-reflect: + FunctionTdxInfo::make_canonical_name() --- include/xo/reflect/TypeDescr.hpp | 13 ++++++++----- src/reflect/TypeDescr.cpp | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/include/xo/reflect/TypeDescr.hpp b/include/xo/reflect/TypeDescr.hpp index cd59697..77303a8 100644 --- a/include/xo/reflect/TypeDescr.hpp +++ b/include/xo/reflect/TypeDescr.hpp @@ -148,18 +148,21 @@ namespace xo { return true; } + /** construct canonical description for this type + * will be like + * Retval(*)(Arg1,..,Argn) + **/ + std::string make_canonical_name() const; + + public: /** function return value **/ TypeDescr retval_td_ = nullptr; /** function arguments, in positional order **/ std::vector arg_td_v_; /** true iff function promises never to throw **/ bool is_noexcept_ = false; - }; - } -} + }; /*FunctionTdxInfo*/ -namespace xo { - namespace reflect { class TypeDescrExtra; /* run-time description for a native c++ type */ diff --git a/src/reflect/TypeDescr.cpp b/src/reflect/TypeDescr.cpp index 7c2eb19..84579d5 100644 --- a/src/reflect/TypeDescr.cpp +++ b/src/reflect/TypeDescr.cpp @@ -15,6 +15,25 @@ namespace xo { uint32_t TypeId::s_next_id = 1; + std::string + FunctionTdxInfo::make_canonical_name() const + { + std::ostringstream ss; + + ss << retval_td_->canonical_name(); + ss << "(*)("; + for (std::size_t i = 0, n = arg_td_v_.size(); i < n; ++i) { + if (i > 0) + ss << ","; + ss << arg_td_v_[i]->canonical_name(); + } + ss << ")"; + + return ss.str(); + } /*make_canonical_name*/ + + // ----- TypeDescrBase ----- + std::unordered_map TypeDescrBase::s_function_type_map;