Improve Class generation
MODIFY
binding-generator/src/class.rs
binding-generator/src/class.rs
@@ -23,7 +23,7 @@ pub enum Kind {
pub struct Class<'tu, 'ge> {
entity: Entity<'tu>,
custom_fullname: Option<String>,
- gen_env: &'ge GeneratorEnv<'tu>,
+ pub(crate) gen_env: &'ge GeneratorEnv<'tu>,
}
impl<'tu, 'ge> Class<'tu, 'ge> {

MODIFY
binding-generator/src/writer/rust_native/class.rs
binding-generator/src/writer/rust_native/class.rs
@@ -5,7 +5,8 @@ use once_cell::sync::Lazy;
use crate::class::Kind;
use crate::type_ref::{Constness, ConstnessOverride, CppNameStyle, FishStyle, NameStyle};
-use crate::{get_debug, Class, CompiledInterpolation, Element, Func, IteratorExt, NamePool, StrExt};
+use crate::writer::rust_native::func_desc::{ClassDesc, CppFuncDesc, FuncDescCppCall, FuncDescKind};
+use crate::{get_debug, Class, CompiledInterpolation, Element, Func, FunctionTypeHint, IteratorExt, NamePool, StrExt, TypeRef};
use super::type_ref::TypeRefExt;
use super::RustNativeGeneratedElement;
@@ -385,11 +386,13 @@ fn gen_cpp_boxed(c: &Class) -> String {
}
let type_ref = c.type_ref();
+ let delete = method_delete(&rust_local, ClassDesc::from(c), c.gen_env.resolve_typeref("void"));
out += &BOXED_CPP_TPL.interpolate(&hashmap! {
"rust_local" => type_ref.rust_name(NameStyle::decl()),
"cpp_full" => type_ref.cpp_name(CppNameStyle::Reference),
"cpp_extern" => type_ref.cpp_extern(),
"casts" => casts.into(),
+ "delete" => delete.into(),
})
}
out
@@ -460,3 +463,19 @@ impl RustNativeGeneratedElement for Class<'_, '_> {
out + &methods.join("")
}
}
+
+fn method_delete(rust_local: &str, class_desc: ClassDesc, void: TypeRef) -> String {
+ CppFuncDesc {
+ extern_name: format!("cv_{}_delete", rust_local).into(),
+ constness: Constness::Mut,
+ is_infallible: true,
+ is_naked_return: true,
+ return_type: void,
+ kind: FuncDescKind::InstanceMethod(class_desc),
+ type_hint: FunctionTypeHint::None,
+ call: FuncDescCppCall::Manual("delete instance".compile_interpolation()),
+ debug: "".to_string(),
+ arguments: vec![],
+ }
+ .gen_cpp()
+}

MODIFY
binding-generator/src/writer/rust_native/tpl/class/boxed.tpl.cpp
binding-generator/src/writer/rust_native/tpl/class/boxed.tpl.cpp
{{casts}}
-void cv_{{rust_local}}_delete({{cpp_full}}* instance) {
- delete instance;
-}
+{{delete}}

Improve Class generation