Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] disable respace #879

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 18 additions & 25 deletions src/generate/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
let p_ty = ident(&name, config, "peripheral", span);
let name_str = p_ty.to_string();
let address = util::hex(p.base_address + config.base_address_shift);
let description = util::respace(p.description.as_ref().unwrap_or(&p.name));
let doc = util::respace(p.description.as_ref().unwrap_or(&name));
let doc = util::escape_special_chars(&doc);

let mod_ty = ident(&name, config, "peripheral_mod", span);
let (derive_regs, base, path) = if let Some(path) = path {
Expand Down Expand Up @@ -88,12 +89,12 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result

let per_to_tokens = |out: &mut TokenStream,
feature_attribute: &TokenStream,
description: &str,
doc: &str,
p_ty: &Ident,
doc_alias: Option<TokenStream>,
address: LitInt| {
out.extend(quote! {
#[doc = #description]
#[doc = #doc]
#phtml
#doc_alias
#feature_attribute
Expand Down Expand Up @@ -140,7 +141,8 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
let mut feature_names = Vec::with_capacity(dim.dim as _);
for pi in svd::peripheral::expand(p, dim) {
let name = &pi.name;
let description = pi.description.as_deref().unwrap_or(&p.name);
let doc = util::respace(pi.description.as_ref().unwrap_or(&pi.name));
let doc = util::escape_special_chars(&doc);
let p_ty = ident(name, config, "peripheral", span);
let name_str = p_ty.to_string();
let doc_alias = (&name_str != name).then(|| quote!(#[doc(alias = #name)]));
Expand All @@ -155,7 +157,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
per_to_tokens(
&mut out,
&feature_attribute_n,
description,
&doc,
&p_ty,
doc_alias,
address,
Expand All @@ -169,7 +171,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
if derive_regs {
// re-export the base module to allow deriveFrom this one
out.extend(quote! {
#[doc = #description]
#[doc = #doc]
#feature_any_attribute
pub use self::#base as #mod_ty;
});
Expand All @@ -182,21 +184,14 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
feature_attribute.extend(quote! { #[cfg(feature = #p_feature)] })
};
// Insert the peripheral structure
per_to_tokens(
&mut out,
&feature_attribute,
&description,
&p_ty,
None,
address,
);
per_to_tokens(&mut out, &feature_attribute, &doc, &p_ty, None, address);

// Derived peripherals may not require re-implementation, and will instead
// use a single definition of the non-derived version.
if derive_regs {
// re-export the base module to allow deriveFrom this one
out.extend(quote! {
#[doc = #description]
#[doc = #doc]
#feature_attribute
pub use self::#base as #mod_ty;
});
Expand All @@ -205,9 +200,6 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
}
}

let description = util::respace(p.description.as_ref().unwrap_or(&name));
let description = util::escape_special_chars(&description);

// Build up an alternate erc list by expanding any derived registers/clusters
// erc: *E*ither *R*egister or *C*luster
let mut ercs = p.registers.take().unwrap_or_default();
Expand Down Expand Up @@ -246,7 +238,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
register_or_cluster_block(&ercs, &derive_infos, None, "Register block", None, config)?;

out.extend(quote! {
#[doc = #description]
#[doc = #doc]
#feature_attribute
pub mod #mod_ty
});
Expand Down Expand Up @@ -1381,8 +1373,9 @@ fn cluster_block(
index: &Index,
config: &Config,
) -> Result<TokenStream> {
let description = util::respace(c.description.as_ref().unwrap_or(&c.name));
let description = util::escape_special_chars(&description);
let doc = c.description.as_ref().unwrap_or(&c.name);
let doc = util::respace(doc);
let doc = util::escape_special_chars(&doc);
let mod_name = c.name.remove_dim().to_string();

// name_snake_case needs to take into account array type.
Expand All @@ -1409,7 +1402,7 @@ fn cluster_block(
.push(path_segment(ident(&dname, config, "cluster_mod", span)));

Ok(quote! {
#[doc = #description]
#[doc = #doc]
pub use self::#derived as #block_ty;
pub use self::#mod_derived as #mod_ty;
})
Expand All @@ -1429,7 +1422,7 @@ fn cluster_block(
&c.children,
&mod_derive_infos,
Some(&mod_name),
&description,
&doc,
cluster_size,
config,
)?;
Expand All @@ -1441,11 +1434,11 @@ fn cluster_block(
};

Ok(quote! {
#[doc = #description]
#[doc = #doc]
pub use self::#mod_ty::#block_ty;

///Cluster
#[doc = #description]
#[doc = #doc]
pub mod #mod_ty {
#mod_items
}
Expand Down
11 changes: 7 additions & 4 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,13 @@ pub fn sanitize_keyword(sc: Cow<str>) -> Cow<str> {
}

pub fn respace(s: &str) -> String {
s.split_whitespace()
.collect::<Vec<_>>()
.join(" ")
.replace(r"\n", "\n")
let s = if s.matches("\n").count() == 1 {
// Special case for STM32
s.split_whitespace().collect::<Vec<_>>().join(" ")
} else {
s.into()
};
s.replace(r"\n", "\n")
}

pub fn escape_brackets(s: &str) -> String {
Expand Down
Loading