Skip to content

Commit d96bebb

Browse files
committed
accessors
1 parent 4afaf47 commit d96bebb

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

src/generate/peripheral.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,8 @@ pub struct ArrayAccessor {
231231
pub i: syn::LitInt,
232232
}
233233

234-
impl ArrayAccessor {
235-
pub fn to_tokens(&self, method: bool) -> TokenStream {
236-
let parens = method.then(|| quote! {()});
234+
impl ToTokens for ArrayAccessor {
235+
fn to_tokens(&self, tokens: &mut TokenStream) {
237236
let doc = &self.doc;
238237
let name = &self.name;
239238
let ty = &self.ty;
@@ -243,9 +242,10 @@ impl ArrayAccessor {
243242
#[doc = #doc]
244243
#[inline(always)]
245244
pub fn #name(&self) -> &#ty {
246-
&self.#basename #parens[#i]
245+
&self.#basename()[#i]
247246
}
248247
}
248+
.to_tokens(tokens);
249249
}
250250
}
251251

@@ -527,11 +527,11 @@ fn register_or_cluster_block(
527527
reg_block_field.offset,
528528
&reg_block_field.description,
529529
);
530+
let name = &reg_block_field.syn_field.ident;
531+
let ty = &reg_block_field.syn_field.ty;
532+
let offset = reg_block_field.offset as usize;
530533

531534
if is_region_a_union {
532-
let name = &reg_block_field.syn_field.ident;
533-
let ty = &reg_block_field.syn_field.ty;
534-
let offset = reg_block_field.offset as usize;
535535
accessors.extend(quote! {
536536
#[doc = #comment]
537537
#[inline(always)]
@@ -548,13 +548,17 @@ fn register_or_cluster_block(
548548

549549
reg_block_field.syn_field.to_tokens(&mut region_rbfs);
550550
Punct::new(',', Spacing::Alone).to_tokens(&mut region_rbfs);
551+
accessors.extend(quote! {
552+
#[doc = #comment]
553+
#[inline(always)]
554+
pub fn #name(&self) -> &#ty {
555+
&self.#name
556+
}
557+
});
558+
}
559+
for a in &reg_block_field.accessors {
560+
a.to_tokens(&mut accessors);
551561
}
552-
accessors.extend(
553-
reg_block_field
554-
.accessors
555-
.iter()
556-
.map(|a| a.to_tokens(is_region_a_union)),
557-
);
558562
}
559563

560564
if !is_region_a_union {
@@ -1066,10 +1070,19 @@ fn cluster_block(
10661070

10671071
fn new_syn_field(ident: Ident, ty: syn::Type) -> syn::Field {
10681072
let span = Span::call_site();
1073+
let mut segments = Punctuated::new();
1074+
segments.push(path_segment(Ident::new("crate", span)));
1075+
let crate_path = syn::Path {
1076+
leading_colon: None,
1077+
segments,
1078+
};
10691079
syn::Field {
10701080
ident: Some(ident),
1071-
vis: syn::Visibility::Public(syn::VisPublic {
1081+
vis: syn::Visibility::Restricted(syn::VisRestricted {
10721082
pub_token: Token![pub](span),
1083+
paren_token: Default::default(),
1084+
in_token: None,
1085+
path: Box::new(crate_path),
10731086
}),
10741087
attrs: vec![],
10751088
colon_token: Some(Token![:](span)),

0 commit comments

Comments
 (0)