From d7fbcee8f584730d52e6c487f9fa3bd3756f42a6 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Tue, 17 Sep 2024 20:17:23 -0400 Subject: [PATCH] more cleanup, rename definition to overrider --- dev/header-check | 24 +++++++ include/yorel/yomm2/core.hpp | 2 +- include/yorel/yomm2/detail/compiler.hpp | 68 +++++++++---------- include/yorel/yomm2/detail/trace.hpp | 1 + include/yorel/yomm2/detail/types.hpp | 8 +-- .../yomm2/policies/vectored_error_handler.hpp | 3 + include/yorel/yomm2/templates.hpp | 2 + tests/test_compiler.cpp | 2 +- 8 files changed, 70 insertions(+), 40 deletions(-) create mode 100644 dev/header-check diff --git a/dev/header-check b/dev/header-check new file mode 100644 index 00000000..e22ad940 --- /dev/null +++ b/dev/header-check @@ -0,0 +1,24 @@ +#!/bin/env python3 + +import contextlib +from pathlib import Path +import os +import sys + +import mdgen + +out_path = Path(sys.argv[2]).absolute() + +source = os.path.abspath(sys.argv[1]).replace(os.path.abspath(mdgen.repository), "") + +with open(sys.argv[1]) as rh: + text = rh.read() + +with contextlib.suppress(FileNotFoundError): + out_path.chmod(0o600) + +with open(out_path, "w") as wh: + text = mdgen.replace_md(text, source=source) + print(text, file=wh, end="") + +out_path.chmod(0o400) diff --git a/include/yorel/yomm2/core.hpp b/include/yorel/yomm2/core.hpp index e4e03e23..ec965968 100644 --- a/include/yorel/yomm2/core.hpp +++ b/include/yorel/yomm2/core.hpp @@ -1127,7 +1127,7 @@ method::override_fn_impl< p_next = &next; } - static detail::definition_info info; + static detail::overrider_info info; if (info.method) { BOOST_ASSERT(info.method == &fn); diff --git a/include/yorel/yomm2/detail/compiler.hpp b/include/yorel/yomm2/detail/compiler.hpp index 2dbb21ce..71da381f 100644 --- a/include/yorel/yomm2/detail/compiler.hpp +++ b/include/yorel/yomm2/detail/compiler.hpp @@ -117,8 +117,8 @@ struct generic_compiler { } }; - struct definition { - const detail::definition_info* info; + struct overrider { + const detail::overrider_info* info; std::vector vp; std::uintptr_t pf; std::size_t method_index, spec_index; @@ -147,14 +147,14 @@ struct generic_compiler { struct method { detail::method_info* info; std::vector vp; - std::vector specs; + std::vector specs; std::vector slots; std::vector strides; - std::vector dispatch_table; + std::vector dispatch_table; // following two are dummies, when converting to a function pointer, we will // get the corresponding pointer from method_info - definition not_implemented; - definition ambiguous; + overrider not_implemented; + overrider ambiguous; const std::uintptr_t* gv_dispatch_table{nullptr}; auto arity() const { return vp.size(); @@ -199,11 +199,11 @@ trace_type& operator<<( struct spec_name { spec_name( const detail::generic_compiler::method& method, - const detail::generic_compiler::definition* def) + const detail::generic_compiler::overrider* def) : method(method), def(def) { } const detail::generic_compiler::method& method; - const detail::generic_compiler::definition* def; + const detail::generic_compiler::overrider* def; }; template @@ -251,10 +251,10 @@ struct compiler : detail::generic_compiler { bool concrete); void install_gv(); void print(const update_method_report& report) const; - static std::vector - best(std::vector& candidates); - static bool is_more_specific(const definition* a, const definition* b); - static bool is_base(const definition* a, const definition* b); + static std::vector + best(std::vector& candidates); + static bool is_more_specific(const overrider* a, const overrider* b); + static bool is_base(const overrider* a, const overrider* b); static type_id static_type(type_id type) { if constexpr (std::is_base_of_v< @@ -342,15 +342,15 @@ void compiler::resolve_static_type_ids() { } if (!method.specs.empty()) - for (auto& definition : method.specs) { - if (*definition.vp_end == 0) { + for (auto& overrider : method.specs) { + if (*overrider.vp_end == 0) { for (auto& ti : range{ - definition.vp_begin, - definition.vp_end}) { + overrider.vp_begin, + overrider.vp_end}) { resolve(&ti); } - *definition.vp_end = 1; + *overrider.vp_end = 1; } } } @@ -578,18 +578,18 @@ void compiler::augment_methods() { meth_iter->specs.resize(spec_size); auto spec_iter = meth_iter->specs.begin(); - for (auto& definition_info : meth_info.specs) { + for (auto& overrider_info : meth_info.specs) { spec_iter->method_index = meth_iter - methods.begin(); spec_iter->spec_index = spec_iter - meth_iter->specs.begin(); - ++trace << type_name(definition_info.type) << " (" - << definition_info.pf << ")\n"; - spec_iter->info = &definition_info; + ++trace << type_name(overrider_info.type) << " (" + << overrider_info.pf << ")\n"; + spec_iter->info = &overrider_info; spec_iter->vp.reserve(meth_info.arity()); std::size_t param_index = 0; for (auto type : - range{definition_info.vp_begin, definition_info.vp_end}) { + range{overrider_info.vp_begin, overrider_info.vp_end}) { indent _(trace); auto class_ = class_map[Policy::type_index(type)]; if (!class_) { @@ -892,18 +892,18 @@ void compiler::build_dispatch_tables() { accumulate(m.report, report); ++trace << "assigning next\n"; - std::vector specs; + std::vector specs; std::transform( m.specs.begin(), m.specs.end(), std::back_inserter(specs), - [](const definition& spec) { return &spec; }); + [](const overrider& spec) { return &spec; }); for (auto& spec : m.specs) { indent _(trace); ++trace << type_name(spec.info->type) << ":\n"; - std::vector candidates; + std::vector candidates; std::copy_if( specs.begin(), specs.end(), std::back_inserter(candidates), - [&spec](const definition* other) { + [&spec](const overrider* other) { return is_base(other, &spec); }); @@ -922,7 +922,7 @@ void compiler::build_dispatch_tables() { void* next; if (nexts.size() == 1) { - const definition_info* next_info = nexts.front()->info; + const overrider_info* next_info = nexts.front()->info; next = next_info->pf; ++trace << "-> " << "#" << nexts.front()->spec_index @@ -966,7 +966,7 @@ void compiler::build_dispatch_table( } if (dim == 0) { - std::vector applicable; + std::vector applicable; std::size_t i = 0; for (const auto& spec : m.specs) { @@ -1129,12 +1129,12 @@ void compiler::install_gv() { } template -std::vector -compiler::best(std::vector& candidates) { - std::vector best; +std::vector +compiler::best(std::vector& candidates) { + std::vector best; for (auto spec : candidates) { - const definition* candidate = spec; + const overrider* candidate = spec; for (auto iter = best.begin(); iter != best.end();) { if (is_more_specific(spec, *iter)) { @@ -1157,7 +1157,7 @@ compiler::best(std::vector& candidates) { template bool compiler::is_more_specific( - const definition* a, const definition* b) { + const overrider* a, const overrider* b) { bool result = false; auto a_iter = a->vp.begin(), a_last = a->vp.end(), b_iter = b->vp.begin(); @@ -1179,7 +1179,7 @@ bool compiler::is_more_specific( } template -bool compiler::is_base(const definition* a, const definition* b) { +bool compiler::is_base(const overrider* a, const overrider* b) { bool result = false; auto a_iter = a->vp.begin(), a_last = a->vp.end(), b_iter = b->vp.begin(); diff --git a/include/yorel/yomm2/detail/trace.hpp b/include/yorel/yomm2/detail/trace.hpp index 70ca0f81..76da247f 100644 --- a/include/yorel/yomm2/detail/trace.hpp +++ b/include/yorel/yomm2/detail/trace.hpp @@ -2,6 +2,7 @@ #define YOREL_YOMM2_DETAIL_TRACE_HPP #include +#include #include diff --git a/include/yorel/yomm2/detail/types.hpp b/include/yorel/yomm2/detail/types.hpp index 7e7be4b8..b5b675fd 100644 --- a/include/yorel/yomm2/detail/types.hpp +++ b/include/yorel/yomm2/detail/types.hpp @@ -87,11 +87,11 @@ struct class_info : static_list::static_link { // ----------- // method info -struct definition_info; +struct overrider_info; struct yOMM2_API method_info : static_list::static_link { type_id *vp_begin, *vp_end; - static_list specs; + static_list specs; void* ambiguous; void* not_implemented; type_id method_type; @@ -102,8 +102,8 @@ struct yOMM2_API method_info : static_list::static_link { } }; -struct definition_info : static_list::static_link { - ~definition_info() { +struct overrider_info : static_list::static_link { + ~overrider_info() { method->specs.remove(*this); } diff --git a/include/yorel/yomm2/policies/vectored_error_handler.hpp b/include/yorel/yomm2/policies/vectored_error_handler.hpp index 74ea6afb..59c14400 100644 --- a/include/yorel/yomm2/policies/vectored_error_handler.hpp +++ b/include/yorel/yomm2/policies/vectored_error_handler.hpp @@ -9,6 +9,9 @@ #include +#include +#include + namespace yorel { namespace yomm2 { namespace policies { diff --git a/include/yorel/yomm2/templates.hpp b/include/yorel/yomm2/templates.hpp index 90ea5328..c0edde88 100644 --- a/include/yorel/yomm2/templates.hpp +++ b/include/yorel/yomm2/templates.hpp @@ -6,6 +6,8 @@ #ifndef YOREL_YOMM2_TEMPLATES_HPP #define YOREL_YOMM2_TEMPLATES_HPP +#include + #include #include #include diff --git a/tests/test_compiler.cpp b/tests/test_compiler.cpp index a4d875b6..3bc53032 100644 --- a/tests/test_compiler.cpp +++ b/tests/test_compiler.cpp @@ -15,7 +15,7 @@ using namespace yorel::yomm2::detail; using class_ = generic_compiler::class_; using cc_method = generic_compiler::method; -using definition = generic_compiler::definition; +using overrider = generic_compiler::overrider; std::ostream& operator<<(std::ostream& os, const class_* cls) { return os