44 s.insert(s.begin(),
char(
'0' + n % 10));
53 if (std::meta::has_identifier(ent))
54 tail = std::meta::identifier_of(ent);
55 for (std::meta::info p{std::meta::parent_of(ent)};
56 p != std::meta::info{} && p != ^^:: && std::meta::has_identifier(p);
57 p = std::meta::parent_of(p))
58 tail = std::string{std::meta::identifier_of(p)} +
"::" + tail;
66 if (std::meta::has_identifier(type))
67 s = std::meta::identifier_of(type);
68 for (std::meta::info p{std::meta::parent_of(type)};
69 p != std::meta::info{} && p != ^^:: && std::meta::has_identifier(p);
70 p = std::meta::parent_of(p))
71 s = std::string{std::meta::identifier_of(p)} +
"_" + s;
72 return s +
"_trampoline";
83 std::string s{std::meta::display_string_of(std::meta::type_of(fn))};
84 return s.find(
"...") != std::string::npos;
91 if (std::meta::is_const(fn))
93 if (std::meta::is_volatile(fn))
95 if (std::meta::is_lvalue_reference_qualified(fn))
97 if (std::meta::is_rvalue_reference_qualified(fn))
99 if (std::meta::is_noexcept(fn))
106 "::welder::rods::trampolines::generated"};
119 s +=
"struct " + ident +
" : " + base +
" {\n";
120 s +=
" WELDER_PY_TRAMPOLINE(" + base +
");\n";
124 const std::string name{std::meta::identifier_of(slot)};
126 s +=
" static_assert(false, \"welder: '" + base +
"::" + name +
127 "' is a C-variadic virtual; C++26 reflection cannot reproduce its "
128 "'...' parameter. Mark it "
129 "[[=welder::rods::python::bind_flat]] to bind it non-overridably.\");\n";
134 const std::string idx{
"::welder::rods::python::overridable_virtuals(^^" + base +
136 s +=
" [: ::std::meta::return_type_of(" + idx +
") :] " + name +
"(";
139 for (
auto p : std::meta::parameters_of(slot)) {
146 s +=
"[: ::std::meta::type_of(::std::meta::parameters_of(" + idx +
")[" +
156 idx +
"), " + name + (args.empty() ?
"" :
", " + args) +
"); }\n";
165 return "template <> constexpr ::std::meta::info\n"
166 " ::welder::rods::python::trampoline_for<" +
184 template <std::meta::info Type>
192 static_assert(std::meta::has_identifier(Type),
193 "welder: cannot generate a trampoline for a class-template "
194 "specialization spelled directly (it has no identifier); "
195 "declare a namespace-scope alias — using IntRing = "
196 "Ring<int>; — and weld that instead");
204 out +=
"#pragma once\n";
205 out +=
"// AUTO-GENERATED by welder (welder::rods::trampolines). Do not edit.\n";
207 out +=
"// Include AFTER your welded type headers and the active backend's\n";
208 out +=
"// <welder/rods/python/{pybind11,nanobind}/trampoline.hpp>.\n";
209 out +=
"#include <meta>\n";
210 out +=
"#include <welder/rods/python/trampoline.hpp>\n\n";
211 out +=
"namespace welder::rods::trampolines::generated {\n\n";
213 out +=
"\n} // namespace welder::rods::trampolines::generated\n\n";
consteval std::vector< std::meta::info > overridable_virtuals(std::meta::info type)
Every overridable virtual slot of type — the ones welder routes through a trampoline — folding in vir...
consteval std::string cpp_qualified_name(std::meta::info ent)
The fully ::-qualified name of a namespace-scope entity, leading :: included (geometry::Point → "geom...
consteval std::string render_trampoline(std::meta::info type)
Render the trampoline struct for welded virtual type type — one override per overridable virtual,...
consteval bool is_c_variadic(std::meta::info fn)
Is fn a C-style variadic function (R(…, ...))?
consteval std::string int_string(std::size_t n)
Render a non-negative integer as decimal (constexpr std::to_string is not available on gcc-16 in a co...
constexpr const char * generated_namespace
The namespace the generated trampoline structs are emitted into (fully qualified).
consteval std::string render_registration(std::meta::info type)
The trampoline_for<type> specialization pointing at type's generated struct.
consteval std::string trampoline_ident(std::meta::info type)
A collision-free identifier for type's generated trampoline: its qualified name with :: folded to _ (...
consteval std::string qualifier_tokens(std::meta::info fn)
The trailing cv / ref-qualifier / noexcept tokens of a member function fn, in grammatical order (" co...
The growing generated header: the trampoline struct bodies and their trampoline_for registrations,...
std::string structs
Accumulated trampoline struct definitions.
std::string render() const
The finished, self-contained header text.
void add()
Append the generated trampoline + registration for welded virtual Type.
std::string registrations
Accumulated trampoline_for specializations.
Virtual-function overriding support shared by welder's Python backends.