Skip to content

Commit dc710bd

Browse files
committed
Rename bare pc to name_pc & pc_r/w to name_pc_a(w)
To try to make the code-generation code easier to follow, rename a few common variable-containing variables with more descriptive names.
1 parent f9e048d commit dc710bd

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/generate/register.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub fn fields(
218218
let BitRange { offset, width, .. } = f.bit_range;
219219
let name = util::replace_suffix(&f.name, "");
220220
let sc = Ident::new(&name.to_sanitized_snake_case(), span);
221-
let pc = name.to_sanitized_upper_case();
221+
let name_pc = name.to_sanitized_upper_case();
222222
let bits = Ident::new(if width == 1 { "bit" } else { "bits" }, span);
223223
let description = if let Some(d) = &f.description {
224224
util::respace(&util::escape_brackets(d))
@@ -249,8 +249,8 @@ pub fn fields(
249249

250250
// Reader and writer use one common `Enum_A` unless a fields have two `enumeratedValues`,
251251
// then we have one for read-only `Enum_A` and another for write-only `Enum_AW`
252-
let pc_r = Ident::new(&(pc.clone() + "_A"), span);
253-
let mut pc_w = &pc_r;
252+
let name_pc_a = Ident::new(&(name_pc.clone() + "_A"), span);
253+
let mut name_pc_aw = &name_pc_a;
254254

255255
let mut evs_r = None;
256256

@@ -298,7 +298,7 @@ pub fn fields(
298298
String::from("Reader of field ") + &quotedfield
299299
};
300300

301-
let _pc_r = Ident::new(&(pc.clone() + "_R"), span);
301+
let _pc_r = Ident::new(&(name_pc.clone() + "_R"), span);
302302

303303
let cast = if width == 1 {
304304
quote! { != 0 }
@@ -373,17 +373,17 @@ pub fn fields(
373373
let pc = util::replace_suffix(base.field, "");
374374
let pc = pc.to_sanitized_upper_case();
375375
let base_pc_r = Ident::new(&(pc + "_A"), span);
376-
derive_from_base(mod_items, &base, &pc_r, &base_pc_r, &description);
376+
derive_from_base(mod_items, &base, &name_pc_a, &base_pc_r, &description);
377377

378378
mod_items.extend(quote! {
379379
#[doc = #readerdoc]
380-
pub type #_pc_r = crate::R<#fty, #pc_r>;
380+
pub type #_pc_r = crate::R<#fty, #name_pc_a>;
381381
});
382382
} else {
383383
let has_reserved_variant = evs.values.len() != (1 << width);
384384
let variants = Variant::from_enumerated_values(evs)?;
385385

386-
add_from_variants(mod_items, &variants, &pc_r, &fty, &description, rv);
386+
add_from_variants(mod_items, &variants, &name_pc_a, &fty, &description, rv);
387387

388388
let mut enum_items = TokenStream::new();
389389

@@ -393,9 +393,9 @@ pub fn fields(
393393
let pc = &v.pc;
394394

395395
if has_reserved_variant {
396-
quote! { #i => Val(#pc_r::#pc), }
396+
quote! { #i => Val(#name_pc_a::#pc), }
397397
} else {
398-
quote! { #i => #pc_r::#pc, }
398+
quote! { #i => #name_pc_a::#pc, }
399399
}
400400
}) {
401401
arms.extend(v);
@@ -415,7 +415,7 @@ pub fn fields(
415415
enum_items.extend(quote! {
416416
///Get enumerated values variant
417417
#inline
418-
pub fn variant(&self) -> crate::Variant<#fty, #pc_r> {
418+
pub fn variant(&self) -> crate::Variant<#fty, #name_pc_a> {
419419
use crate::Variant::*;
420420
match self.bits {
421421
#arms
@@ -426,7 +426,7 @@ pub fn fields(
426426
enum_items.extend(quote! {
427427
///Get enumerated values variant
428428
#inline
429-
pub fn variant(&self) -> #pc_r {
429+
pub fn variant(&self) -> #name_pc_a {
430430
match self.bits {
431431
#arms
432432
}
@@ -452,14 +452,14 @@ pub fn fields(
452452
#[doc = #doc]
453453
#inline
454454
pub fn #is_variant(&self) -> bool {
455-
*self == #pc_r::#pc
455+
*self == #name_pc_a::#pc
456456
}
457457
});
458458
}
459459

460460
mod_items.extend(quote! {
461461
#[doc = #readerdoc]
462-
pub type #_pc_r = crate::R<#fty, #pc_r>;
462+
pub type #_pc_r = crate::R<#fty, #name_pc_a>;
463463
impl #_pc_r {
464464
#enum_items
465465
}
@@ -474,8 +474,8 @@ pub fn fields(
474474
}
475475

476476
if can_write {
477-
let new_pc_w = Ident::new(&(pc.clone() + "_AW"), span);
478-
let _pc_w = Ident::new(&(pc.clone() + "_W"), span);
477+
let new_pc_aw = Ident::new(&(name_pc.clone() + "_AW"), span);
478+
let _pc_w = Ident::new(&(name_pc.clone() + "_W"), span);
479479

480480
let mut proxy_items = TokenStream::new();
481481
let mut unsafety = unsafety(f.write_constraint.as_ref(), width);
@@ -488,22 +488,22 @@ pub fn fields(
488488
}
489489

490490
if Some(evs) != evs_r.as_ref() {
491-
pc_w = &new_pc_w;
491+
name_pc_aw = &new_pc_aw;
492492
if let Some(base) = base {
493493
let pc = util::replace_suffix(base.field, "");
494494
let pc = pc.to_sanitized_upper_case();
495495
let base_pc_w = Ident::new(&(pc + "_AW"), span);
496-
derive_from_base(mod_items, &base, &pc_w, &base_pc_w, &description)
496+
derive_from_base(mod_items, &base, &name_pc_aw, &base_pc_w, &description)
497497
} else {
498-
add_from_variants(mod_items, &variants, pc_w, &fty, &description, rv);
498+
add_from_variants(mod_items, &variants, name_pc_aw, &fty, &description, rv);
499499
}
500500
}
501501

502502
if unsafety.is_some() {
503503
proxy_items.extend(quote! {
504504
///Writes `variant` to the field
505505
#inline
506-
pub fn variant(self, variant: #pc_w) -> &'a mut W {
506+
pub fn variant(self, variant: #name_pc_aw) -> &'a mut W {
507507
unsafe {
508508
self.#bits(variant.into())
509509
}
@@ -513,7 +513,7 @@ pub fn fields(
513513
proxy_items.extend(quote! {
514514
///Writes `variant` to the field
515515
#inline
516-
pub fn variant(self, variant: #pc_w) -> &'a mut W {
516+
pub fn variant(self, variant: #name_pc_aw) -> &'a mut W {
517517
self.#bits(variant.into())
518518
}
519519
});
@@ -528,7 +528,7 @@ pub fn fields(
528528
#[doc = #doc]
529529
#inline
530530
pub fn #sc(self) -> &'a mut W {
531-
self.variant(#pc_w::#pc)
531+
self.variant(#name_pc_aw::#pc)
532532
}
533533
});
534534
}

0 commit comments

Comments
 (0)