Skip to content

Commit ec3a8ec

Browse files
committed
doc aliases
1 parent 140f744 commit ec3a8ec

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/generate/peripheral.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,18 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
8383
let description = pi.description.as_deref().unwrap_or(&p.name);
8484
let p_ty = ident(name, &config.ident_formats.peripheral, span);
8585
let name_str = p_ty.to_string();
86+
let doc_alias = (&name_str != name).then(|| quote!(#[doc(alias = #name)]));
8687
let address = util::hex(pi.base_address + config.base_address_shift);
87-
let feature_name = config.ident_formats.peripheral_feature.apply(name);
88-
feature_names.push(feature_name.to_string());
88+
let p_feature = config.ident_formats.peripheral_feature.apply(name);
89+
feature_names.push(p_feature.to_string());
8990
let mut feature_attribute_n = feature_attribute.clone();
9091
if config.feature_peripheral {
91-
feature_attribute_n.extend(quote! { #[cfg(feature = #feature_name)] })
92+
feature_attribute_n.extend(quote! { #[cfg(feature = #p_feature)] })
9293
};
9394
// Insert the peripherals structure
9495
out.extend(quote! {
9596
#[doc = #description]
97+
#doc_alias
9698
#feature_attribute_n
9799
pub struct #p_ty { _marker: PhantomData<*const ()> }
98100

@@ -147,9 +149,9 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
147149
}
148150
}
149151
Peripheral::Single(_) => {
150-
let feature_name = config.ident_formats.peripheral_feature.apply(&name);
152+
let p_feature = config.ident_formats.peripheral_feature.apply(&name);
151153
if config.feature_peripheral {
152-
feature_attribute.extend(quote! { #[cfg(feature = #feature_name)] })
154+
feature_attribute.extend(quote! { #[cfg(feature = #p_feature)] })
153155
};
154156
// Insert the peripheral structure
155157
out.extend(quote! {
@@ -244,7 +246,8 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
244246
"Pushing {} register or cluster blocks into output",
245247
ercs.len()
246248
);
247-
let reg_block = register_or_cluster_block(&ercs, &derive_infos, None, None, config)?;
249+
let reg_block =
250+
register_or_cluster_block(&ercs, &derive_infos, None, "Register block", None, config)?;
248251

249252
let open = Punct::new('{', Spacing::Alone);
250253
let close = Punct::new('}', Spacing::Alone);
@@ -526,6 +529,7 @@ fn register_or_cluster_block(
526529
ercs: &[RegisterCluster],
527530
derive_infos: &[DeriveInfo],
528531
name: Option<&str>,
532+
doc: &str,
529533
size: Option<u32>,
530534
config: &Config,
531535
) -> Result<TokenStream> {
@@ -630,8 +634,13 @@ fn register_or_cluster_block(
630634
}
631635
});
632636

637+
let mut doc_alias = None;
633638
let block_ty = if let Some(name) = name {
634-
ident(name, &config.ident_formats.cluster, span)
639+
let ty = ident(name, &config.ident_formats.cluster, span);
640+
if ty.to_string() != name {
641+
doc_alias = Some(quote!(#[doc(alias = #name)]));
642+
}
643+
ty
635644
} else {
636645
Ident::new("RegisterBlock", span)
637646
};
@@ -645,9 +654,10 @@ fn register_or_cluster_block(
645654
});
646655

647656
Ok(quote! {
648-
///Register block
649657
#[repr(C)]
650658
#derive_debug
659+
#[doc = #doc]
660+
#doc_alias
651661
pub struct #block_ty {
652662
#rbfs
653663
}
@@ -1429,6 +1439,7 @@ fn cluster_block(
14291439
&c.children,
14301440
&mod_derive_infos,
14311441
Some(&mod_name),
1442+
&description,
14321443
cluster_size,
14331444
config,
14341445
)?;

src/generate/register.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub fn render(
4545
}
4646
let span = Span::call_site();
4747
let reg_ty = ident(&name, &config.ident_formats.register, span);
48+
let doc_alias = (&reg_ty.to_string() != &name).then(|| quote!(#[doc(alias = #name)]));
4849
let mod_ty = name.to_snake_case_ident(span);
4950
let description = util::escape_special_chars(
5051
util::respace(&register.description.clone().unwrap_or_else(|| {
@@ -108,6 +109,7 @@ pub fn render(
108109
let mut out = TokenStream::new();
109110
out.extend(quote! {
110111
#[doc = #alias_doc]
112+
#doc_alias
111113
pub type #reg_ty = crate::Reg<#mod_ty::#regspec_ty>;
112114
});
113115
let mod_items = render_register_mod(

0 commit comments

Comments
 (0)