mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 08:55:11 +01:00
check: drop facts before/after an IOManip
This commit is contained in:
1 parent
e5dc87e4d3
commit
569a91892e
2 files changed
+12
-8
No files matched your search
@@ -84,6 +84,15 @@ func (z *facts) appendFact(fact *a.Expr) {
|
|||||||
*z = append(*z, fact)
|
*z = append(*z, fact)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (z *facts) dropAnyFactsMentioning(n *a.Expr) error {
|
||||||
|
return z.update(func(x *a.Expr) (*a.Expr, error) {
|
||||||
|
if x.Mentions(n) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return x, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// update applies f to each fact, replacing the slice element with the result
|
// update applies f to each fact, replacing the slice element with the result
|
||||||
// of the function call. The slice is then compacted to remove all nils.
|
// of the function call. The slice is then compacted to remove all nils.
|
||||||
func (z *facts) update(f func(*a.Expr) (*a.Expr, error)) error {
|
func (z *facts) update(f func(*a.Expr) (*a.Expr, error)) error {
|
||||||
|
|||||||
@@ -275,10 +275,11 @@ func (q *checker) bcheckStatement(n *a.Node) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
q.facts.dropAnyFactsMentioning(n.IO())
|
||||||
if err := q.bcheckBlock(n.Body()); err != nil {
|
if err := q.bcheckBlock(n.Body()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// TODO: invalidate any facts regarding the io_bind expressions.
|
q.facts.dropAnyFactsMentioning(n.IO())
|
||||||
|
|
||||||
case a.KIf:
|
case a.KIf:
|
||||||
if err := q.bcheckIf(n.AsIf()); err != nil {
|
if err := q.bcheckIf(n.AsIf()); err != nil {
|
||||||
@@ -509,13 +510,7 @@ func (q *checker) bcheckAssignment(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if op == t.IDEq {
|
if op == t.IDEq {
|
||||||
// Drop any facts involving lhs.
|
if err := q.facts.dropAnyFactsMentioning(lhs); err != nil {
|
||||||
if err := q.facts.update(func(x *a.Expr) (*a.Expr, error) {
|
|
||||||
if x.Mentions(lhs) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
return x, nil
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user