Skip to main content

Module vtable

Module vtable 

Source
Expand description

Vtable static generation, C wrapper generation, and method attribute parsing for trait impls.

This module contains the core codegen for #[miniextendr] on impl Trait for Type blocks. It produces the vtable static constant, C-callable wrapper functions for each method and associated constant, and delegates to super::r_wrappers for R wrapper code generation.

Re-exports§

use proc_macro2::TokenStream; 🔒
use quote::format_ident; 🔒
use syn::ItemImpl; 🔒
use super::r_wrappers::TraitWrapperOpts; 🔒
use super::r_wrappers::binds_trait_namespace; 🔒
use super::r_wrappers::generate_trait_r_wrapper; 🔒
use super::TraitAbiMetadata; 🔒
use super::TraitConst; 🔒
use super::TraitMethod; 🔒
use super::type_to_symbol_name; 🔒
use crate::miniextendr_impl::ClassSystem; 🔒
use crate::miniextendr_impl::ImplAttrs; 🔒

Structs§

RenamedParam 🔒
One parameter of an impl method, which the wrappers name as the declaration does.
TraitMethodAttrs 🔒
Parsed #[miniextendr(...)] attributes for a single trait method.

Functions§

check_r_code_uses_declared_names 🔒
Refuse a method’s R code (r_entry, r_post_checks, r_on_exit, a defaults(...) value) that uses a parameter by the impl’s name where the wrapper’s formal has the declaration’s: R would find no such variable when the wrapper runs.
check_trait_method_defaults 🔒
Reject a defaults(...) entry that names no parameter of the trait method, with the inherent-impl wording (a typo would otherwise drop the default without a word).
declared_param_names 🔒
The parameter names the declaration’s metadata gives method, in order. The metadata names every parameter (arg<i> for a declaration pattern).
extract_consts 🔒
Extract associated constant items from a trait impl block.
extract_methods 🔒
Extract all methods from a trait impl block as TraitMethod structs.
generate_concrete_vtable_shims 🔒
Generate concrete vtable shims for a generic trait impl.
generate_impl_vtable 🔒
Reproduce the declaration’s repr(C) layout locally, with its exact field order and callback types. The versioned declaration tag guards the cast to the consumer’s nominal vtable type. The exported static’s name and byte representation stay the same for native and wasm registration.
generate_trait_const_c_wrapper 🔒
Generate a C wrapper function and R_CallMethodDef for a trait associated constant.
generate_trait_method_c_wrapper 🔒
Generate a C wrapper function and R_CallMethodDef for a single trait method.
generate_vtable_static 🔒
Generate the vtable static, C wrappers, R wrappers, and call defs for a trait implementation.
inherit_method_metadata 🔒
Inherit only declaration-level R naming/export metadata. The implementation owns its execution options, docs and signatures; an explicit impl rename wins, while a declaration’s skipped method is never exported accidentally.
name_params_as_declared 🔒
Name every parameter of sig, a copy of an impl method’s signature, as the declaration’s metadata does (declared; arg<i> for a declaration pattern), so every impl of a trait has the same R formals and argument errors. Without the declaration’s names, or with another count, which rustc refuses, a named parameter keeps its name and a pattern becomes arg<i>. A name already taken gets a _ suffix. Returns each parameter’s names, in order.
parse_trait_method_attrs 🔒
Parse #[miniextendr(...)] attributes from a trait method.
rekey_params 🔒
options, keyed by parameter names as the impl method spells them, keyed by the declared names. A key may also be the declared name already; one that names no parameter stays, for the caller’s check to refuse. Naming one parameter both ways is an error at span.