Skip to content

Commit e44c8d0

Browse files
committed
accessors
1 parent a5bd928 commit e44c8d0

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

src/generate/peripheral.rs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,8 @@ pub struct ArrayAccessor {
287287
pub i: syn::LitInt,
288288
}
289289

290-
impl ArrayAccessor {
291-
pub fn to_tokens(&self, method: bool) -> TokenStream {
292-
let parens = method.then(|| quote! {()});
290+
impl ToTokens for ArrayAccessor {
291+
fn to_tokens(&self, tokens: &mut TokenStream) {
293292
let doc = &self.doc;
294293
let name = &self.name;
295294
let ty = &self.ty;
@@ -299,9 +298,10 @@ impl ArrayAccessor {
299298
#[doc = #doc]
300299
#[inline(always)]
301300
pub fn #name(&self) -> &#ty {
302-
&self.#basename #parens[#i]
301+
&self.#basename()[#i]
303302
}
304303
}
304+
.to_tokens(tokens);
305305
}
306306
}
307307

@@ -592,11 +592,11 @@ fn register_or_cluster_block(
592592
reg_block_field.offset,
593593
&reg_block_field.description,
594594
);
595+
let name = &reg_block_field.syn_field.ident;
596+
let ty = &reg_block_field.syn_field.ty;
597+
let offset = reg_block_field.offset as usize;
595598

596599
if is_region_a_union {
597-
let name = &reg_block_field.syn_field.ident;
598-
let ty = &reg_block_field.syn_field.ty;
599-
let offset = reg_block_field.offset as usize;
600600
accessors.extend(quote! {
601601
#[doc = #comment]
602602
#[inline(always)]
@@ -611,13 +611,17 @@ fn register_or_cluster_block(
611611

612612
reg_block_field.syn_field.to_tokens(&mut region_rbfs);
613613
Punct::new(',', Spacing::Alone).to_tokens(&mut region_rbfs);
614+
accessors.extend(quote! {
615+
#[doc = #comment]
616+
#[inline(always)]
617+
pub fn #name(&self) -> &#ty {
618+
&self.#name
619+
}
620+
});
621+
}
622+
for a in &reg_block_field.accessors {
623+
a.to_tokens(&mut accessors);
614624
}
615-
accessors.extend(
616-
reg_block_field
617-
.accessors
618-
.iter()
619-
.map(|a| a.to_tokens(is_region_a_union)),
620-
);
621625
}
622626

623627
if !is_region_a_union {
@@ -1421,9 +1425,20 @@ fn cluster_block(
14211425

14221426
fn new_syn_field(ident: Ident, ty: syn::Type) -> syn::Field {
14231427
let span = Span::call_site();
1428+
let mut segments = Punctuated::new();
1429+
segments.push(path_segment(Ident::new("crate", span)));
1430+
let crate_path = syn::Path {
1431+
leading_colon: None,
1432+
segments,
1433+
};
14241434
syn::Field {
14251435
ident: Some(ident),
1426-
vis: syn::Visibility::Public(Token![pub](span)),
1436+
vis: syn::Visibility::Restricted(syn::VisRestricted {
1437+
pub_token: Token![pub](span),
1438+
paren_token: Default::default(),
1439+
in_token: None,
1440+
path: Box::new(crate_path),
1441+
}),
14271442
attrs: vec![],
14281443
colon_token: Some(Token![:](span)),
14291444
ty,

0 commit comments

Comments
 (0)