From 8bf2c56e853a0971276abcd1506b2105ee6482b6 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Sat, 24 Feb 2024 10:20:06 +0300 Subject: [PATCH] reexport enum --- src/generate/register.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/generate/register.rs b/src/generate/register.rs index adae8912..4068de5a 100644 --- a/src/generate/register.rs +++ b/src/generate/register.rs @@ -898,13 +898,25 @@ pub fn fields( } } } else if let Some(EV::Derived(_, base)) = rwenum.read_enum() { + // TODO: fix fmt + let fmt = if rwenum.different_enums() { + "enum_read_name" + } else { + "enum_name" + }; + let base_ident = ident( + &base.name, + config, + fmt, + span, + ); // only pub use enum when derived from another register. // If field is in the same register it emits // pub use enum from same module which is not expected - if base.register() != fpath.register() { + if base.register() != fpath.register() || base_ident != value_read_ty { // use the same enum structure name if !enum_derives.contains(&value_read_ty) { - let base_path = base_syn_path(base, &fpath, &value_read_ty, config)?; + let base_path = base_syn_path(base, &fpath, &base_ident, config)?; mod_items.extend(quote! { #[doc = #description] pub use #base_path as #value_read_ty; @@ -1146,12 +1158,25 @@ pub fn fields( }); } } else if let Some(EV::Derived(_, base)) = rwenum.write_enum() { + // TODO: fix fmt + let fmt = if rwenum.different_enums() { + "enum_write_name" + } else { + "enum_name" + }; + let base_ident = ident( + &base.name, + config, + fmt, + span, + ); + // If field is in the same register it emits pub use structure from same module. - if base.register() != fpath.register() { + if base.register() != fpath.register() || base_ident != value_write_ty { if rwenum.generate_write_enum() { // use the same enum structure name if !writer_enum_derives.contains(&value_write_ty) { - let base_path = base_syn_path(base, &fpath, &value_write_ty, config)?; + let base_path = base_syn_path(base, &fpath, &base_ident, config)?; mod_items.extend(quote! { #[doc = #description] pub use #base_path as #value_write_ty;