Skip to content

Commit

Permalink
Inherit struct visibility on Unity class derive (#82)
Browse files Browse the repository at this point in the history
This makes it so the derives for Unity classes automatically inherit the
visibility of the struct for all the methods and the binding struct.
This way you can have the structs in inner modules and still use them
from parent modules.
  • Loading branch information
CryZe committed Dec 9, 2023
1 parent af5f3a5 commit 8bd62d7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions asr-derive/src/unity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use syn::{Data, DeriveInput, Expr, ExprLit, Ident, Lit, Meta};
pub fn process(input: TokenStream, mono_module: impl ToTokens) -> TokenStream {
let ast: DeriveInput = syn::parse(input).unwrap();

let vis = ast.vis;

let struct_data = match ast.data {
Data::Struct(s) => s,
_ => panic!("Only structs are supported"),
Expand Down Expand Up @@ -90,14 +92,14 @@ pub fn process(input: TokenStream, mono_module: impl ToTokens) -> TokenStream {
};

quote! {
struct #binding_name {
#vis struct #binding_name {
class: #mono_module::Class,
#static_table_field
#(#field_names: u32,)*
}

impl #struct_name {
async fn bind(
#vis async fn bind(
process: &asr::Process,
module: &#mono_module::Module,
image: &#mono_module::Image,
Expand All @@ -117,11 +119,11 @@ pub fn process(input: TokenStream, mono_module: impl ToTokens) -> TokenStream {
}

impl #binding_name {
fn class(&self) -> &#mono_module::Class {
#vis fn class(&self) -> &#mono_module::Class {
&self.class
}

fn read(&self, process: &asr::Process #maybe_instance_param) -> Result<#struct_name, ()> {
#vis fn read(&self, process: &asr::Process #maybe_instance_param) -> Result<#struct_name, ()> {
Ok(#struct_name {#(
#field_names: #field_reads,
)*})
Expand Down

0 comments on commit 8bd62d7

Please sign in to comment.