From 0707571945155eb9e05e51426d3c96a83eea99c6 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 17 Oct 2023 14:52:44 -0400 Subject: [PATCH] cosmetic: indentation --- src/reflect/TypeDescr.cpp | 300 +++++++++++++++++++------------------- 1 file changed, 150 insertions(+), 150 deletions(-) diff --git a/src/reflect/TypeDescr.cpp b/src/reflect/TypeDescr.cpp index 93a0bfc..b0a0dfd 100644 --- a/src/reflect/TypeDescr.cpp +++ b/src/reflect/TypeDescr.cpp @@ -7,188 +7,188 @@ #include "xo/indentlog/scope.hpp" namespace xo { - using xo::scope; - using xo::xtag; - using xo::tostr; + using xo::scope; + using xo::xtag; + using xo::tostr; - namespace reflect { - uint32_t - TypeId::s_next_id = 1; + namespace reflect { + uint32_t + TypeId::s_next_id = 1; - std::unordered_map> - TypeDescrBase::s_type_table_map; + std::unordered_map> + TypeDescrBase::s_type_table_map; - std::unordered_map - TypeDescrBase::s_coalesced_type_table_map; + std::unordered_map + TypeDescrBase::s_coalesced_type_table_map; - std::vector - TypeDescrBase::s_type_table_v; + std::vector + TypeDescrBase::s_type_table_v; - TypeDescrW - TypeDescrBase::require(std::type_info const * tinfo, - std::string_view canonical_name, - std::unique_ptr tdextra) - { - /* 1. lookup by tinfo hash_code in s_type_table_map */ - { - auto ix = s_type_table_map.find(TypeInfoRef(tinfo)); + TypeDescrW + TypeDescrBase::require(std::type_info const * tinfo, + std::string_view canonical_name, + std::unique_ptr tdextra) + { + /* 1. lookup by tinfo hash_code in s_type_table_map */ + { + auto ix = s_type_table_map.find(TypeInfoRef(tinfo)); - if ((ix != s_type_table_map.end()) && ix->second) - return ix->second.get(); - } + if ((ix != s_type_table_map.end()) && ix->second) + return ix->second.get(); + } - /* 2. lookup by tinfo hash_code in s_coalesced_type_table_map */ - { - auto ix = s_coalesced_type_table_map.find(TypeInfoRef(tinfo)); + /* 2. lookup by tinfo hash_code in s_coalesced_type_table_map */ + { + auto ix = s_coalesced_type_table_map.find(TypeInfoRef(tinfo)); - if ((ix != s_coalesced_type_table_map.end()) && ix->second) - return ix->second; - } + if ((ix != s_coalesced_type_table_map.end()) && ix->second) + return ix->second; + } - /* 3. O(n) lookup by canonical_name, before we create a new slot. - * - * Have to accept that on clang type_info objects aren't always unique (!$@#!!) - * - * TODO: lookup table keyed by canonical_name - */ - for (TypeDescrBase * x : s_type_table_v) { - if (x && (x->canonical_name() == canonical_name)) { - /* 1. assume *x represents the type associated with tinfo. - * 2. *do* store tinfo in s_coalesced_type_table_map[], - * for faster lookup next time - */ - s_coalesced_type_table_map[TypeInfoRef(tinfo)] = x; + /* 3. O(n) lookup by canonical_name, before we create a new slot. + * + * Have to accept that on clang type_info objects aren't always unique (!$@#!!) + * + * TODO: lookup table keyed by canonical_name + */ + for (TypeDescrBase * x : s_type_table_v) { + if (x && (x->canonical_name() == canonical_name)) { + /* 1. assume *x represents the type associated with tinfo. + * 2. *do* store tinfo in s_coalesced_type_table_map[], + * for faster lookup next time + */ + s_coalesced_type_table_map[TypeInfoRef(tinfo)] = x; - return x; - } - } + return x; + } + } - TypeId id = TypeId::allocate(); + TypeId id = TypeId::allocate(); - std::unique_ptr & slot = s_type_table_map[TypeInfoRef(tinfo)]; + std::unique_ptr & slot = s_type_table_map[TypeInfoRef(tinfo)]; - slot.reset(new TypeDescrBase(id, - tinfo, - canonical_name, - std::move(tdextra))); + slot.reset(new TypeDescrBase(id, + tinfo, + canonical_name, + std::move(tdextra))); - if (s_type_table_v.size() <= id.id()) - s_type_table_v.resize(id.id() + 1); + if (s_type_table_v.size() <= id.id()) + s_type_table_v.resize(id.id() + 1); - s_type_table_v[id.id()] = slot.get(); + s_type_table_v[id.id()] = slot.get(); - return slot.get(); - } /*require*/ + return slot.get(); + } /*require*/ - void - TypeDescrBase::print_reflected_types(std::ostream & os) - { - os << "display(os); - } - } + for (TypeDescrBase * td : s_type_table_v) { + os << "\n "; + if (td) { + td->display(os); + } + } - os << ">\n"; - } /*print_reflected_types*/ + os << ">\n"; + } /*print_reflected_types*/ - namespace { - /* readability hack: - * foo::bar::Quux ==> Quux - * but lookout for template names: - * std::pair ==> pair - */ - std::string_view - unqualified_name(std::string_view const & canonical_name) - { - size_t m = canonical_name.find_first_of('<'); + namespace { + /* readability hack: + * foo::bar::Quux ==> Quux + * but lookout for template names: + * std::pair ==> pair + */ + std::string_view + unqualified_name(std::string_view const & canonical_name) + { + size_t m = canonical_name.find_first_of('<'); - /* skip ':', but only in range [0..m) */ - size_t p = canonical_name.find_last_of(':', m); + /* skip ':', but only in range [0..m) */ + size_t p = canonical_name.find_last_of(':', m); - if (p == std::string_view::npos) { - return canonical_name; - } else { - if ((canonical_name.substr(0, 9) == "std::pair") - || (canonical_name.substr(0, 13) == "std::_1::pair")) - { - return std::string_view("pair"); - } else { - return std::string_view(canonical_name.substr(p+1)); - } - } - } /*unqualified_name*/ - } /*namespace*/ + if (p == std::string_view::npos) { + return canonical_name; + } else { + if ((canonical_name.substr(0, 9) == "std::pair") + || (canonical_name.substr(0, 13) == "std::_1::pair")) + { + return std::string_view("pair"); + } else { + return std::string_view(canonical_name.substr(p+1)); + } + } + } /*unqualified_name*/ + } /*namespace*/ - TypeDescrBase::TypeDescrBase(TypeId id, - std::type_info const * tinfo, - std::string_view canonical_name, - std::unique_ptr tdextra) - : id_{std::move(id)}, - typeinfo_{tinfo}, - canonical_name_{std::move(canonical_name)}, - short_name_{unqualified_name(canonical_name_)}, - tdextra_{std::move(tdextra)} - { - } + TypeDescrBase::TypeDescrBase(TypeId id, + std::type_info const * tinfo, + std::string_view canonical_name, + std::unique_ptr tdextra) + : id_{std::move(id)}, + typeinfo_{tinfo}, + canonical_name_{std::move(canonical_name)}, + short_name_{unqualified_name(canonical_name_)}, + tdextra_{std::move(tdextra)} + { + } - TaggedPtr - TypeDescrBase::most_derived_self_tp(void * object) const - { - return this->tdextra_->most_derived_self_tp(this, object); - } /*most_derived_self_tp*/ + TaggedPtr + TypeDescrBase::most_derived_self_tp(void * object) const + { + return this->tdextra_->most_derived_self_tp(this, object); + } /*most_derived_self_tp*/ - TaggedPtr - TypeDescrBase::child_tp(uint32_t i, void * object) const - { - return this->tdextra_->child_tp(i, object); - } /*child_tp*/ + TaggedPtr + TypeDescrBase::child_tp(uint32_t i, void * object) const + { + return this->tdextra_->child_tp(i, object); + } /*child_tp*/ - void - TypeDescrBase::display(std::ostream & os) const - { - os << "metatype()) - << ">"; - } /*display*/ + void + TypeDescrBase::display(std::ostream & os) const + { + os << "metatype()) + << ">"; + } /*display*/ - std::string - TypeDescrBase::display_string() const - { - return tostr(*this); - } /*display_string*/ + std::string + TypeDescrBase::display_string() const + { + return tostr(*this); + } /*display_string*/ - bool - TypeDescrBase::mark_complete() - { - bool retval = this->complete_flag_; + bool + TypeDescrBase::mark_complete() + { + bool retval = this->complete_flag_; - this->complete_flag_ = true; + this->complete_flag_ = true; - return retval; - } /*mark_complete*/ + return retval; + } /*mark_complete*/ - void - TypeDescrBase::assign_tdextra(std::unique_ptr tdx) - { - scope log(XO_ENTER0(verbose), - xtag("canonical_name", this->canonical_name()), - xtag("tdextra.old", this->tdextra_.get()), - xtag("metatype.old", (this->tdextra_ - ? this->tdextra_->metatype() - : Metatype::mt_invalid)), - xtag("metatype.new", tdx->metatype())); + void + TypeDescrBase::assign_tdextra(std::unique_ptr tdx) + { + scope log(XO_ENTER0(verbose), + xtag("canonical_name", this->canonical_name()), + xtag("tdextra.old", this->tdextra_.get()), + xtag("metatype.old", (this->tdextra_ + ? this->tdextra_->metatype() + : Metatype::mt_invalid)), + xtag("metatype.new", tdx->metatype())); - this->complete_flag_ = true; - this->tdextra_ = std::move(tdx); - } /*assign_tdextra*/ - } /*namespace reflect*/ + this->complete_flag_ = true; + this->tdextra_ = std::move(tdx); + } /*assign_tdextra*/ + } /*namespace reflect*/ } /*namespace xo*/ /* end TypeDescr.cpp */