Skip to content

Commit d7fbcee

Browse files
committed
more cleanup, rename definition to overrider
1 parent 66492b9 commit d7fbcee

File tree

8 files changed

+70
-40
lines changed

8 files changed

+70
-40
lines changed

dev/header-check

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/env python3
2+
3+
import contextlib
4+
from pathlib import Path
5+
import os
6+
import sys
7+
8+
import mdgen
9+
10+
out_path = Path(sys.argv[2]).absolute()
11+
12+
source = os.path.abspath(sys.argv[1]).replace(os.path.abspath(mdgen.repository), "")
13+
14+
with open(sys.argv[1]) as rh:
15+
text = rh.read()
16+
17+
with contextlib.suppress(FileNotFoundError):
18+
out_path.chmod(0o600)
19+
20+
with open(out_path, "w") as wh:
21+
text = mdgen.replace_md(text, source=source)
22+
print(text, file=wh, end="")
23+
24+
out_path.chmod(0o400)

include/yorel/yomm2/core.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ method<Name, Return(Parameters...), Options...>::override_fn_impl<
11271127
p_next = &next<Function>;
11281128
}
11291129

1130-
static detail::definition_info info;
1130+
static detail::overrider_info info;
11311131

11321132
if (info.method) {
11331133
BOOST_ASSERT(info.method == &fn);

include/yorel/yomm2/detail/compiler.hpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ struct generic_compiler {
117117
}
118118
};
119119

120-
struct definition {
121-
const detail::definition_info* info;
120+
struct overrider {
121+
const detail::overrider_info* info;
122122
std::vector<class_*> vp;
123123
std::uintptr_t pf;
124124
std::size_t method_index, spec_index;
@@ -147,14 +147,14 @@ struct generic_compiler {
147147
struct method {
148148
detail::method_info* info;
149149
std::vector<class_*> vp;
150-
std::vector<definition> specs;
150+
std::vector<overrider> specs;
151151
std::vector<std::size_t> slots;
152152
std::vector<std::size_t> strides;
153-
std::vector<const definition*> dispatch_table;
153+
std::vector<const overrider*> dispatch_table;
154154
// following two are dummies, when converting to a function pointer, we will
155155
// get the corresponding pointer from method_info
156-
definition not_implemented;
157-
definition ambiguous;
156+
overrider not_implemented;
157+
overrider ambiguous;
158158
const std::uintptr_t* gv_dispatch_table{nullptr};
159159
auto arity() const {
160160
return vp.size();
@@ -199,11 +199,11 @@ trace_type<Policy>& operator<<(
199199
struct spec_name {
200200
spec_name(
201201
const detail::generic_compiler::method& method,
202-
const detail::generic_compiler::definition* def)
202+
const detail::generic_compiler::overrider* def)
203203
: method(method), def(def) {
204204
}
205205
const detail::generic_compiler::method& method;
206-
const detail::generic_compiler::definition* def;
206+
const detail::generic_compiler::overrider* def;
207207
};
208208

209209
template<class Policy>
@@ -251,10 +251,10 @@ struct compiler : detail::generic_compiler {
251251
bool concrete);
252252
void install_gv();
253253
void print(const update_method_report& report) const;
254-
static std::vector<const definition*>
255-
best(std::vector<const definition*>& candidates);
256-
static bool is_more_specific(const definition* a, const definition* b);
257-
static bool is_base(const definition* a, const definition* b);
254+
static std::vector<const overrider*>
255+
best(std::vector<const overrider*>& candidates);
256+
static bool is_more_specific(const overrider* a, const overrider* b);
257+
static bool is_base(const overrider* a, const overrider* b);
258258

259259
static type_id static_type(type_id type) {
260260
if constexpr (std::is_base_of_v<
@@ -342,15 +342,15 @@ void compiler<Policy>::resolve_static_type_ids() {
342342
}
343343

344344
if (!method.specs.empty())
345-
for (auto& definition : method.specs) {
346-
if (*definition.vp_end == 0) {
345+
for (auto& overrider : method.specs) {
346+
if (*overrider.vp_end == 0) {
347347
for (auto& ti : range{
348-
definition.vp_begin,
349-
definition.vp_end}) {
348+
overrider.vp_begin,
349+
overrider.vp_end}) {
350350
resolve(&ti);
351351
}
352352

353-
*definition.vp_end = 1;
353+
*overrider.vp_end = 1;
354354
}
355355
}
356356
}
@@ -578,18 +578,18 @@ void compiler<Policy>::augment_methods() {
578578
meth_iter->specs.resize(spec_size);
579579
auto spec_iter = meth_iter->specs.begin();
580580

581-
for (auto& definition_info : meth_info.specs) {
581+
for (auto& overrider_info : meth_info.specs) {
582582
spec_iter->method_index = meth_iter - methods.begin();
583583
spec_iter->spec_index = spec_iter - meth_iter->specs.begin();
584584

585-
++trace << type_name(definition_info.type) << " ("
586-
<< definition_info.pf << ")\n";
587-
spec_iter->info = &definition_info;
585+
++trace << type_name(overrider_info.type) << " ("
586+
<< overrider_info.pf << ")\n";
587+
spec_iter->info = &overrider_info;
588588
spec_iter->vp.reserve(meth_info.arity());
589589
std::size_t param_index = 0;
590590

591591
for (auto type :
592-
range{definition_info.vp_begin, definition_info.vp_end}) {
592+
range{overrider_info.vp_begin, overrider_info.vp_end}) {
593593
indent _(trace);
594594
auto class_ = class_map[Policy::type_index(type)];
595595
if (!class_) {
@@ -892,18 +892,18 @@ void compiler<Policy>::build_dispatch_tables() {
892892
accumulate(m.report, report);
893893
++trace << "assigning next\n";
894894

895-
std::vector<const definition*> specs;
895+
std::vector<const overrider*> specs;
896896
std::transform(
897897
m.specs.begin(), m.specs.end(), std::back_inserter(specs),
898-
[](const definition& spec) { return &spec; });
898+
[](const overrider& spec) { return &spec; });
899899

900900
for (auto& spec : m.specs) {
901901
indent _(trace);
902902
++trace << type_name(spec.info->type) << ":\n";
903-
std::vector<const definition*> candidates;
903+
std::vector<const overrider*> candidates;
904904
std::copy_if(
905905
specs.begin(), specs.end(), std::back_inserter(candidates),
906-
[&spec](const definition* other) {
906+
[&spec](const overrider* other) {
907907
return is_base(other, &spec);
908908
});
909909

@@ -922,7 +922,7 @@ void compiler<Policy>::build_dispatch_tables() {
922922
void* next;
923923

924924
if (nexts.size() == 1) {
925-
const definition_info* next_info = nexts.front()->info;
925+
const overrider_info* next_info = nexts.front()->info;
926926
next = next_info->pf;
927927
++trace << "-> "
928928
<< "#" << nexts.front()->spec_index
@@ -966,7 +966,7 @@ void compiler<Policy>::build_dispatch_table(
966966
}
967967

968968
if (dim == 0) {
969-
std::vector<const definition*> applicable;
969+
std::vector<const overrider*> applicable;
970970
std::size_t i = 0;
971971

972972
for (const auto& spec : m.specs) {
@@ -1129,12 +1129,12 @@ void compiler<Policy>::install_gv() {
11291129
}
11301130

11311131
template<class Policy>
1132-
std::vector<const detail::generic_compiler::definition*>
1133-
compiler<Policy>::best(std::vector<const definition*>& candidates) {
1134-
std::vector<const definition*> best;
1132+
std::vector<const detail::generic_compiler::overrider*>
1133+
compiler<Policy>::best(std::vector<const overrider*>& candidates) {
1134+
std::vector<const overrider*> best;
11351135

11361136
for (auto spec : candidates) {
1137-
const definition* candidate = spec;
1137+
const overrider* candidate = spec;
11381138

11391139
for (auto iter = best.begin(); iter != best.end();) {
11401140
if (is_more_specific(spec, *iter)) {
@@ -1157,7 +1157,7 @@ compiler<Policy>::best(std::vector<const definition*>& candidates) {
11571157

11581158
template<class Policy>
11591159
bool compiler<Policy>::is_more_specific(
1160-
const definition* a, const definition* b) {
1160+
const overrider* a, const overrider* b) {
11611161
bool result = false;
11621162

11631163
auto a_iter = a->vp.begin(), a_last = a->vp.end(), b_iter = b->vp.begin();
@@ -1179,7 +1179,7 @@ bool compiler<Policy>::is_more_specific(
11791179
}
11801180

11811181
template<class Policy>
1182-
bool compiler<Policy>::is_base(const definition* a, const definition* b) {
1182+
bool compiler<Policy>::is_base(const overrider* a, const overrider* b) {
11831183
bool result = false;
11841184

11851185
auto a_iter = a->vp.begin(), a_last = a->vp.end(), b_iter = b->vp.begin();

include/yorel/yomm2/detail/trace.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define YOREL_YOMM2_DETAIL_TRACE_HPP
33

44
#include <yorel/yomm2/detail/types.hpp>
5+
#include <yorel/yomm2/policies/core.hpp>
56

67
#include <boost/dynamic_bitset.hpp>
78

include/yorel/yomm2/detail/types.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ struct class_info : static_list<class_info>::static_link {
8787
// -----------
8888
// method info
8989

90-
struct definition_info;
90+
struct overrider_info;
9191

9292
struct yOMM2_API method_info : static_list<method_info>::static_link {
9393
type_id *vp_begin, *vp_end;
94-
static_list<definition_info> specs;
94+
static_list<overrider_info> specs;
9595
void* ambiguous;
9696
void* not_implemented;
9797
type_id method_type;
@@ -102,8 +102,8 @@ struct yOMM2_API method_info : static_list<method_info>::static_link {
102102
}
103103
};
104104

105-
struct definition_info : static_list<definition_info>::static_link {
106-
~definition_info() {
105+
struct overrider_info : static_list<overrider_info>::static_link {
106+
~overrider_info() {
107107
method->specs.remove(*this);
108108
}
109109

include/yorel/yomm2/policies/vectored_error_handler.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
#include <yorel/yomm2/policies/core.hpp>
1111

12+
#include <functional>
13+
#include <variant>
14+
1215
namespace yorel {
1316
namespace yomm2 {
1417
namespace policies {

include/yorel/yomm2/templates.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef YOREL_YOMM2_TEMPLATES_HPP
77
#define YOREL_YOMM2_TEMPLATES_HPP
88

9+
#include <yorel/yomm2/detail/types.hpp>
10+
911
#include <boost/mp11/algorithm.hpp>
1012
#include <boost/mp11/bind.hpp>
1113
#include <boost/mp11/list.hpp>

tests/test_compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using namespace yorel::yomm2::detail;
1515

1616
using class_ = generic_compiler::class_;
1717
using cc_method = generic_compiler::method;
18-
using definition = generic_compiler::definition;
18+
using overrider = generic_compiler::overrider;
1919

2020
std::ostream& operator<<(std::ostream& os, const class_* cls) {
2121
return os

0 commit comments

Comments
 (0)