Skip to content

Commit 8d69826

Browse files
authored
Try #139:
2 parents 3ec0906 + e9563d8 commit 8d69826

File tree

8 files changed

+67
-25
lines changed

8 files changed

+67
-25
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,19 @@ jobs:
4444
- uses: actions-rs/cargo@v1
4545
with:
4646
command: test
47+
48+
test strict:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Checkout repository
52+
uses: actions/checkout@v2
53+
- name: Install Rust
54+
uses: actions-rs/toolchain@v1
55+
with:
56+
toolchain: stable
57+
profile: minimal
58+
override: true
59+
- uses: actions-rs/cargo@v1
60+
with:
61+
command: test
62+
args: --all-features

src/error.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
44
pub use anyhow::{Context, Result};
55
use core::u64;
6+
#[cfg(feature = "strict")]
67
use once_cell::sync::Lazy;
8+
#[cfg(feature = "strict")]
79
use regex::Regex;
810
use xmltree::Element;
911

@@ -87,6 +89,7 @@ pub enum ResetValueError {
8789
MaskTooLarge(u64, u32),
8890
}
8991

92+
#[cfg(feature = "strict")]
9093
pub(crate) fn check_name(name: &str, tag: &str) -> Result<()> {
9194
static PATTERN: Lazy<Regex> = Lazy::new(|| Regex::new("^[_A-Za-z0-9]*$").unwrap());
9295
if PATTERN.is_match(name) {
@@ -98,6 +101,7 @@ pub(crate) fn check_name(name: &str, tag: &str) -> Result<()> {
98101
}
99102
}
100103

104+
#[cfg(feature = "strict")]
101105
pub(crate) fn check_dimable_name(name: &str, tag: &str) -> Result<()> {
102106
static PATTERN: Lazy<Regex> = Lazy::new(|| {
103107
Regex::new("^(((%s)|(%s)[_A-Za-z]{1}[_A-Za-z0-9]*)|([_A-Za-z]{1}[_A-Za-z0-9]*(\\[%s\\])?)|([_A-Za-z]{1}[_A-Za-z0-9]*(%s)?[_A-Za-z0-9]*))$").unwrap()
@@ -117,6 +121,7 @@ pub(crate) fn check_has_placeholder(name: &str, tag: &str) -> Result<()> {
117121
}
118122
}
119123

124+
#[cfg(feature = "strict")]
120125
pub(crate) fn check_derived_name(name: &str, tag: &str) -> Result<()> {
121126
for x in name.split('.') {
122127
check_dimable_name(x, tag)?
@@ -127,7 +132,7 @@ pub(crate) fn check_derived_name(name: &str, tag: &str) -> Result<()> {
127132
pub(crate) fn check_reset_value(
128133
size: Option<u32>,
129134
value: Option<u64>,
130-
mask: Option<u64>,
135+
_mask: Option<u64>,
131136
) -> Result<()> {
132137
const MAX_BITS: u32 = u64::MAX.count_ones();
133138

@@ -136,14 +141,17 @@ pub(crate) fn check_reset_value(
136141
return Err(ResetValueError::ValueTooLarge(value, size).into());
137142
}
138143
}
139-
if let (Some(size), Some(mask)) = (size, mask) {
140-
if MAX_BITS - mask.leading_zeros() > size {
141-
return Err(ResetValueError::MaskTooLarge(mask, size).into());
144+
#[cfg(feature = "strict")]
145+
{
146+
if let (Some(size), Some(mask)) = (size, _mask) {
147+
if MAX_BITS - mask.leading_zeros() > size {
148+
return Err(ResetValueError::MaskTooLarge(mask, size).into());
149+
}
142150
}
143-
}
144-
if let (Some(value), Some(mask)) = (value, mask) {
145-
if value & mask != value {
146-
return Err(ResetValueError::MaskConflict(value, mask).into());
151+
if let (Some(value), Some(mask)) = (value, _mask) {
152+
if value & mask != value {
153+
return Err(ResetValueError::MaskConflict(value, mask).into());
154+
}
147155
}
148156
}
149157

src/svd/clusterinfo.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ impl ClusterInfoBuilder {
107107

108108
impl ClusterInfo {
109109
fn validate(self) -> Result<Self> {
110+
#[cfg(feature = "strict")]
110111
check_dimable_name(&self.name, "name")?;
111-
if let Some(name) = self.derived_from.as_ref() {
112-
check_derived_name(name, "derivedFrom")?;
112+
if let Some(_name) = self.derived_from.as_ref() {
113+
#[cfg(feature = "strict")]
114+
check_derived_name(_name, "derivedFrom")?;
113115
} else if self.children.is_empty() {
114116
#[cfg(feature = "strict")]
115117
return Err(SVDError::EmptyCluster)?;

src/svd/enumeratedvalue.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ impl EnumeratedValueBuilder {
8585

8686
impl EnumeratedValue {
8787
fn validate(self) -> Result<Self> {
88+
#[cfg(feature = "strict")]
8889
check_name(&self.name, "name")?;
8990
match (&self.value, &self.is_default) {
9091
(Some(_), None) | (None, Some(_)) => Ok(self),

src/svd/enumeratedvalues.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ impl EnumeratedValuesBuilder {
8181

8282
impl EnumeratedValues {
8383
fn validate(self) -> Result<Self> {
84-
if let Some(name) = self.name.as_ref() {
85-
check_name(name, "name")?;
84+
#[cfg(feature = "strict")]
85+
{
86+
if let Some(name) = self.name.as_ref() {
87+
check_name(name, "name")?;
88+
}
8689
}
87-
if let Some(dname) = self.derived_from.as_ref() {
88-
check_derived_name(dname, "derivedFrom")?;
90+
if let Some(_dname) = self.derived_from.as_ref() {
91+
#[cfg(feature = "strict")]
92+
check_derived_name(_dname, "derivedFrom")?;
8993
Ok(self)
9094
} else if self.values.is_empty() {
9195
Err(EnumeratedValuesError::Empty.into())

src/svd/fieldinfo.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,13 @@ impl FieldInfoBuilder {
125125

126126
impl FieldInfo {
127127
fn validate(self) -> Result<Self> {
128+
#[cfg(feature = "strict")]
128129
check_dimable_name(&self.name, "name")?;
129-
if let Some(name) = self.derived_from.as_ref() {
130-
check_derived_name(name, "derivedFrom")?;
130+
#[cfg(feature = "strict")]
131+
{
132+
if let Some(name) = self.derived_from.as_ref() {
133+
check_derived_name(name, "derivedFrom")?;
134+
}
131135
}
132136

133137
if self.bit_range.width == 0 {

src/svd/peripheral.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,11 @@ impl PeripheralBuilder {
157157
impl Peripheral {
158158
fn validate(self) -> Result<Self> {
159159
// TODO
160+
#[cfg(feature = "strict")]
160161
check_dimable_name(&self.name, "name")?;
161-
if let Some(name) = self.derived_from.as_ref() {
162-
check_dimable_name(name, "derivedFrom")?;
162+
if let Some(_name) = self.derived_from.as_ref() {
163+
#[cfg(feature = "strict")]
164+
check_dimable_name(_name, "derivedFrom")?;
163165
} else if let Some(registers) = self.registers.as_ref() {
164166
if registers.is_empty() {
165167
#[cfg(feature = "strict")]

src/svd/registerinfo.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,20 @@ impl RegisterInfoBuilder {
180180

181181
impl RegisterInfo {
182182
fn validate(self) -> Result<Self> {
183+
#[cfg(feature = "strict")]
183184
check_dimable_name(&self.name, "name")?;
184-
if let Some(name) = self.alternate_group.as_ref() {
185-
check_name(name, "alternateGroup")?;
186-
}
187-
if let Some(name) = self.alternate_register.as_ref() {
188-
check_dimable_name(name, "alternateRegister")?;
185+
#[cfg(feature = "strict")]
186+
{
187+
if let Some(name) = self.alternate_group.as_ref() {
188+
check_name(name, "alternateGroup")?;
189+
}
190+
if let Some(name) = self.alternate_register.as_ref() {
191+
check_dimable_name(name, "alternateRegister")?;
192+
}
189193
}
190-
if let Some(name) = self.derived_from.as_ref() {
191-
check_derived_name(name, "derivedFrom")?;
194+
if let Some(_name) = self.derived_from.as_ref() {
195+
#[cfg(feature = "strict")]
196+
check_derived_name(_name, "derivedFrom")?;
192197
} else if let Some(fields) = self.fields.as_ref() {
193198
if fields.is_empty() {
194199
#[cfg(feature = "strict")]

0 commit comments

Comments
 (0)