@@ -211,11 +211,14 @@ pub fn fields(
211
211
r_impl_items : & mut TokenStream ,
212
212
w_impl_items : & mut TokenStream ,
213
213
) -> Result < ( ) > {
214
+ let span = Span :: call_site ( ) ;
215
+ let can_read = [ Access :: ReadOnly , Access :: ReadWriteOnce , Access :: ReadWrite ] . contains ( & access) ;
216
+ let can_write = access != Access :: ReadOnly ;
217
+
214
218
// TODO enumeratedValues
215
- for f in fields. into_iter ( ) {
219
+ for f in fields. iter ( ) {
216
220
// TODO(AJM) - do we need to do anything with this range type?
217
221
let BitRange { offset, width, .. } = f. bit_range ;
218
- let span = Span :: call_site ( ) ;
219
222
let sc = Ident :: new ( & f. name . to_sanitized_snake_case ( ) , span) ;
220
223
let pc = f. name . to_sanitized_upper_case ( ) ;
221
224
let bits = Ident :: new ( if width == 1 { "bit" } else { "bits" } , span) ;
@@ -234,18 +237,19 @@ pub fn fields(
234
237
description_with_bits. push_str ( & description) ;
235
238
}
236
239
237
- let can_read = [ Access :: ReadOnly , Access :: ReadWriteOnce , Access :: ReadWrite ]
238
- . contains ( & access)
240
+ let can_read = can_read
239
241
&& ( f. access != Some ( Access :: WriteOnly ) )
240
242
&& ( f. access != Some ( Access :: WriteOnce ) ) ;
241
- let can_write = ( access != Access :: ReadOnly ) && ( f. access != Some ( Access :: ReadOnly ) ) ;
243
+ let can_write = can_write && ( f. access != Some ( Access :: ReadOnly ) ) ;
242
244
243
245
let mask = 1u64 . wrapping_neg ( ) >> ( 64 - width) ;
244
246
let hexmask = & util:: hex ( mask) ;
245
247
let offset = u64:: from ( offset) ;
246
248
let rv = reset_value. map ( |rv| ( rv >> offset) & mask) ;
247
249
let fty = width. to_ty ( ) ?;
248
250
let evs = & f. enumerated_values ;
251
+ let quotedfield = String :: from ( "`" ) + & f. name + "`" ;
252
+ let readerdoc = String :: from ( "Reader of field " ) + & quotedfield;
249
253
250
254
let lookup_results = lookup (
251
255
evs,
@@ -298,9 +302,8 @@ pub fn fields(
298
302
let base_pc_r = Ident :: new ( & ( pc. clone ( ) + "_A" ) , span) ;
299
303
derive_from_base ( mod_items, & base, & pc_r, & base_pc_r, & description) ;
300
304
301
- let doc = format ! ( "Reader of field `{}`" , f. name) ;
302
305
mod_items. extend ( quote ! {
303
- #[ doc = #doc ]
306
+ #[ doc = #readerdoc ]
304
307
pub type #_pc_r = crate :: R <#fty, #pc_r>;
305
308
} ) ;
306
309
} else {
@@ -381,19 +384,17 @@ pub fn fields(
381
384
} ) ;
382
385
}
383
386
384
- let doc = format ! ( "Reader of field `{}`" , f. name) ;
385
387
mod_items. extend ( quote ! {
386
- #[ doc = #doc ]
388
+ #[ doc = #readerdoc ]
387
389
pub type #_pc_r = crate :: R <#fty, #pc_r>;
388
390
impl #_pc_r {
389
391
#enum_items
390
392
}
391
393
} ) ;
392
394
}
393
395
} else {
394
- let doc = format ! ( "Reader of field `{}`" , f. name) ;
395
396
mod_items. extend ( quote ! {
396
- #[ doc = #doc ]
397
+ #[ doc = #readerdoc ]
397
398
pub type #_pc_r = crate :: R <#fty, #fty>;
398
399
} )
399
400
}
0 commit comments