diff --git a/svd-parser/src/expand.rs b/svd-parser/src/expand.rs index 431705b..f776f47 100644 --- a/svd-parser/src/expand.rs +++ b/svd-parser/src/expand.rs @@ -56,6 +56,28 @@ impl BlockPath { } } +impl PartialEq for BlockPath { + fn eq(&self, other: &str) -> bool { + if other.split('.').count() != self.path.len() + 1 { + return false; + } + let mut parts = other.split('.'); + if let Some(part1) = parts.next() { + if self.peripheral != part1 { + return false; + } + for p in parts.zip(self.path.iter()) { + if p.0 != p.1 { + return false; + } + } + true + } else { + false + } + } +} + impl fmt::Display for BlockPath { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(&self.peripheral)?; @@ -95,6 +117,16 @@ impl RegisterPath { } } +impl PartialEq for RegisterPath { + fn eq(&self, other: &str) -> bool { + if let Some((block, reg)) = other.rsplit_once('.') { + self.name == reg && &self.block == block + } else { + false + } + } +} + impl fmt::Display for RegisterPath { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.block.fmt(f)?; @@ -145,6 +177,16 @@ impl FieldPath { } } +impl PartialEq for FieldPath { + fn eq(&self, other: &str) -> bool { + if let Some((reg, field)) = other.rsplit_once('.') { + self.name == field && &self.register == reg + } else { + false + } + } +} + impl fmt::Display for FieldPath { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.register.fmt(f)?; @@ -179,6 +221,16 @@ impl EnumPath { } } +impl PartialEq for EnumPath { + fn eq(&self, other: &str) -> bool { + if let Some((field, evs)) = other.rsplit_once('.') { + self.name == evs && &self.field == field + } else { + false + } + } +} + impl fmt::Display for EnumPath { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.field.fmt(f)?;