Skip to content

Commit

Permalink
iface: break if overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
yanganto committed Apr 10, 2024
1 parent f663b1b commit 88b9469
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/interface/inheritance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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)
Expand All @@ -230,6 +233,9 @@ impl Iface {
errors.push(ExtensionError::ValencyOverflow)
})
.ok();
if overflow {
break;
}
}
Some(orig) => {
if orig.required > e.required {
Expand All @@ -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
Expand All @@ -261,6 +266,9 @@ impl Iface {
errors.push(ExtensionError::TransitionOverflow)
})
.ok();
if overflow {
break;
}
}
Ok(Some(orig)) => {
orig.extended(op, name.clone())
Expand All @@ -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
Expand All @@ -285,6 +292,9 @@ impl Iface {
errors.push(ExtensionError::TransitionOverflow)
})
.ok();
if overflow {
break;
}
}
Ok(Some(orig)) => {
orig.extended(op, name.clone())
Expand Down Expand Up @@ -341,14 +351,16 @@ 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(|_| {
overflow = true;
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() {
Expand All @@ -370,15 +382,15 @@ fn check_presence<T: Ord + ToString>(
) {
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;
}
}
}

Expand Down

0 comments on commit 88b9469

Please sign in to comment.