From 88b94690aedc6055cb8a6714a935b33152850943 Mon Sep 17 00:00:00 2001 From: Antonio Yang Date: Wed, 10 Apr 2024 16:16:21 +0800 Subject: [PATCH] iface: break if overflow --- src/interface/inheritance.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/interface/inheritance.rs b/src/interface/inheritance.rs index 29d884fc..d14d7c51 100644 --- a/src/interface/inheritance.rs +++ b/src/interface/inheritance.rs @@ -169,7 +169,6 @@ impl Iface { let mut overflow = false; for (name, e) in ext.global_state { match self.global_state.get_mut(&name) { - None if overflow => continue, None => { self.global_state .insert(name, e) @@ -178,6 +177,9 @@ impl Iface { errors.push(ExtensionError::GlobalOverflow) }) .ok(); + if overflow { + break; + } } Some(orig) => { if orig.sem_id.is_some() && e.sem_id != orig.sem_id { @@ -194,7 +196,6 @@ impl Iface { overflow = false; for (name, e) in ext.assignments { match self.assignments.get_mut(&name) { - None if overflow => continue, None => { self.assignments .insert(name, e) @@ -203,6 +204,9 @@ impl Iface { errors.push(ExtensionError::AssignmentOverflow) }) .ok(); + if overflow { + break; + } } Some(orig) => { if !orig.owned_state.is_superset(e.owned_state) { @@ -221,7 +225,6 @@ impl Iface { overflow = false; for (name, e) in ext.valencies { match self.valencies.get_mut(&name) { - None if overflow => continue, None => { self.valencies .insert(name, e) @@ -230,6 +233,9 @@ impl Iface { errors.push(ExtensionError::ValencyOverflow) }) .ok(); + if overflow { + break; + } } Some(orig) => { if orig.required > e.required { @@ -251,7 +257,6 @@ impl Iface { overflow = false; for (name, op) in ext.transitions { match self.transitions.remove(&name) { - Ok(None) if overflow => continue, Ok(None) if op.optional => continue, Ok(None) => { self.transitions @@ -261,6 +266,9 @@ impl Iface { errors.push(ExtensionError::TransitionOverflow) }) .ok(); + if overflow { + break; + } } Ok(Some(orig)) => { orig.extended(op, name.clone()) @@ -275,7 +283,6 @@ impl Iface { overflow = false; for (name, op) in ext.extensions { match self.extensions.remove(&name) { - Ok(None) if overflow => continue, Ok(None) if op.optional => continue, Ok(None) => { self.extensions @@ -285,6 +292,9 @@ impl Iface { errors.push(ExtensionError::TransitionOverflow) }) .ok(); + if overflow { + break; + } } Ok(Some(orig)) => { orig.extended(op, name.clone()) @@ -341,7 +351,6 @@ fn check_occs( let mut overflow = false; for (name, occ) in ext { match orig.get_mut(&name) { - None if overflow => continue, None => { orig.insert(name, occ) .map_err(|_| { @@ -349,6 +358,9 @@ fn check_occs( errors.push(ExtensionError::OpOverflow(op.clone(), state)) }) .ok(); + if overflow { + break; + } } Some(orig) => { if orig.min_value() > occ.min_value() || orig.max_value() > occ.max_value() { @@ -370,15 +382,15 @@ fn check_presence( ) { let mut overflow = false; for name in ext { - if overflow { - continue; - } orig.push(name) .map_err(|_| { overflow = true; errors.push(ExtensionError::OpOverflow(op.clone(), state)) }) .ok(); + if overflow { + break; + } } }