Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lilizoey committed Feb 20, 2024
1 parent e6f6d95 commit de439bc
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 79 deletions.
18 changes: 9 additions & 9 deletions godot-codegen/src/generator/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ fn make_special_builtin_methods(class_name: &TyName, _ctx: &Context) -> TokenStr
}
}

/// Get the safety docs of a method if it should be unsafe
/// Get the safety docs of an unsafe method, or `None` if it is safe.
fn method_safety_doc(class_name: &TyName, method: &BuiltinMethod) -> Option<TokenStream> {
if class_name.godot_ty == "Array" {
if &method.return_value().type_tokens().to_string() == "VariantArray" {
return Some(quote! {
#[doc = "# Safety"]
#[doc = ""]
#[doc = "You must ensure that the returned array fulfils the safety invariants of [`Array`](crate::builtin::Array)"]
});
}
if class_name.godot_ty == "Array"
&& &method.return_value().type_tokens().to_string() == "VariantArray"
{
return Some(quote! {
/// # Safety
///
/// You must ensure that the returned array fulfils the safety invariants of [`Array`](crate::builtin::Array).
});
}

None
Expand Down
12 changes: 11 additions & 1 deletion godot-codegen/src/generator/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,18 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
let instance_id = rtti.check_type::<Self>();
Some(instance_id)
}

#[doc(hidden)]
pub fn __object_ptr(&self) -> sys::GDExtensionObjectPtr {
self.object_ptr
}
};

let inherits_macro_safety_doc = format!(
"The provided class must be a subclass of all the superclasses of [`{}`]",
class_name.rust_ty
);

// mod re_export needed, because class should not appear inside the file module, and we can't re-export private struct as pub.
let imports = util::make_imports();
let tokens = quote! {
Expand Down Expand Up @@ -197,7 +207,7 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas

/// # Safety
///
#[doc = concat!("The provided class must be a subclass of all the superclasses of ", stringify!(#class_name))]
#[doc = #inherits_macro_safety_doc]
#[macro_export]
#[allow(non_snake_case)]
macro_rules! #inherits_macro {
Expand Down

0 comments on commit de439bc

Please sign in to comment.