Skip to content

Commit

Permalink
ignore support in modify_field and derive
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Dec 31, 2024
1 parent ac0c9ff commit 569e544
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
13 changes: 8 additions & 5 deletions src/patch/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ pub(crate) trait RegisterBlockExt: Name {
/// Remove fields from rname and mark it as derivedFrom rderive.
/// Update all derivedFrom referencing rname
fn derive_register(&mut self, rspec: &str, rderive: &Yaml, bpath: &BlockPath) -> PatchResult {
let (rspec, ignore) = rspec.spec();
let (rderive, info) = if let Some(rderive) = rderive.as_str() {
(
rderive,
Expand Down Expand Up @@ -277,12 +278,14 @@ pub(crate) trait RegisterBlockExt: Name {
})?;
}

let rtags = self.iter_registers(rspec).collect::<Vec<_>>();
let mut found = Vec::new();
for register in self.iter_registers(rspec) {
found.push(register.name.to_string());
register.modify_from(info.clone(), VAL_LVL)?;
}
if found.is_empty() {
if !rtags.is_empty() {
for register in rtags {
found.push(register.name.to_string());
register.modify_from(info.clone(), VAL_LVL)?;
}
} else if !ignore {
super::check_dimable_name(rspec)?;
let register = info.name(rspec.into()).build(VAL_LVL)?.single();
self.add_child(RegisterCluster::Register(register));
Expand Down
28 changes: 16 additions & 12 deletions src/patch/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,16 @@ impl RegisterExt for Register {
}

fn modify_field(&mut self, fspec: &str, fmod: &Hash, rpath: &RegisterPath) -> PatchResult {
let (fspec, ignore) = fspec.spec();
let ftags = self.iter_fields(fspec).collect::<Vec<_>>();
let field_builder = make_field(fmod, Some(rpath))?;
let dim = make_dim_element(fmod)?;
if !ftags.is_empty() {
if ftags.is_empty() && !ignore {
let present = self.present_fields();
return Err(anyhow!(
"Could not find `{rpath}:{fspec}. Present fields: {present}.`"
));
} else {
for ftag in ftags {
modify_dim_element(ftag, &dim)?;
if let Some(value) = fmod
Expand Down Expand Up @@ -362,6 +368,7 @@ impl RegisterExt for Register {
dpath.into()
}
}
let (fspec, ignore) = fspec.spec();
let info = if let Some(dpath) = fderive.as_str() {
FieldInfo::builder().derived_from(Some(make_path(dpath, rpath)))
} else if let Some(hash) = fderive.as_hash() {
Expand All @@ -372,18 +379,15 @@ impl RegisterExt for Register {
} else {
return Err(anyhow!("derive: incorrect syntax for {fspec}"));
};

let mut found = false;
for field in self.iter_fields(fspec) {
found = true;
field.modify_from(info.clone(), VAL_LVL)?;
}
if !found {
{
super::check_dimable_name(fspec)?;
let field = info.name(fspec.into()).build(VAL_LVL)?.single();
self.fields.get_or_insert(Vec::new()).push(field);
let ftags = self.iter_fields(fspec).collect::<Vec<_>>();
if !ftags.is_empty() {
for field in ftags {
field.modify_from(info.clone(), VAL_LVL)?;
}
} else if !ignore {
super::check_dimable_name(fspec)?;
let field = info.name(fspec.into()).build(VAL_LVL)?.single();
self.fields.get_or_insert(Vec::new()).push(field);
}
Ok(())
}
Expand Down

0 comments on commit 569e544

Please sign in to comment.