mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 08:55:11 +01:00
Remove liveness analysis' subExprFilter type
This commit is contained in:
1 parent
f61798c2a8
commit
1fc8910952
1 file changed
+9
-53
@@ -70,17 +70,6 @@ import (
|
|||||||
t "github.com/google/wuffs/lang/token"
|
t "github.com/google/wuffs/lang/token"
|
||||||
)
|
)
|
||||||
|
|
||||||
// subExprFilter is used, when analyzing an expression containing a coroutine
|
|
||||||
// call, for multiple analysis passes: before, during and after that call.
|
|
||||||
type subExprFilter uint32
|
|
||||||
|
|
||||||
const (
|
|
||||||
subExprFilterNone = subExprFilter(0)
|
|
||||||
subExprFilterBeforeCoroutine = subExprFilter(1)
|
|
||||||
subExprFilterDuringCoroutine = subExprFilter(2)
|
|
||||||
subExprFilterAfterCoroutine = subExprFilter(3)
|
|
||||||
)
|
|
||||||
|
|
||||||
// resumability tracks whether a local variable's value will need to be kept
|
// resumability tracks whether a local variable's value will need to be kept
|
||||||
// across CSPs (coroutine suspension points).
|
// across CSPs (coroutine suspension points).
|
||||||
type resumability uint32
|
type resumability uint32
|
||||||
@@ -238,7 +227,7 @@ loop:
|
|||||||
|
|
||||||
func (h *resumabilityHelper) doAssign(r resumabilities, n *a.Assign, depth uint32) error {
|
func (h *resumabilityHelper) doAssign(r resumabilities, n *a.Assign, depth uint32) error {
|
||||||
if n.Operator() == t.IDEqQuestion {
|
if n.Operator() == t.IDEqQuestion {
|
||||||
if err := h.doExpr1(r, n.RHS(), subExprFilterNone, 0); err != nil {
|
if err := h.doExpr1(r, n.RHS(), 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -272,57 +261,24 @@ func (h *resumabilityHelper) doAssign(r resumabilities, n *a.Assign, depth uint3
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *resumabilityHelper) doExpr(r resumabilities, n *a.Expr) error {
|
func (h *resumabilityHelper) doExpr(r resumabilities, n *a.Expr) error {
|
||||||
if !n.Effect().Coroutine() {
|
if err := h.doExpr1(r, n, 0); err != nil {
|
||||||
return h.doExpr1(r, n, subExprFilterNone, 0)
|
return err
|
||||||
}
|
}
|
||||||
for sef := subExprFilterBeforeCoroutine; sef <= subExprFilterAfterCoroutine; sef++ {
|
if n.Effect().Coroutine() {
|
||||||
if err := h.doExpr1(r, n, sef, 0); err != nil {
|
r.raiseNoneToWeak()
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *resumabilityHelper) doExpr1(r resumabilities, n *a.Expr, sef subExprFilter, depth uint32) error {
|
func (h *resumabilityHelper) doExpr1(r resumabilities, n *a.Expr, depth uint32) error {
|
||||||
if depth > a.MaxBodyDepth {
|
if depth > a.MaxBodyDepth {
|
||||||
return fmt.Errorf("body recursion depth too large")
|
return fmt.Errorf("body recursion depth too large")
|
||||||
}
|
}
|
||||||
depth++
|
depth++
|
||||||
|
|
||||||
processOnlySubExprs := false
|
|
||||||
if sef != subExprFilterNone {
|
|
||||||
switch sef {
|
|
||||||
case subExprFilterBeforeCoroutine:
|
|
||||||
if !n.Effect().Coroutine() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
sef = subExprFilterNone
|
|
||||||
processOnlySubExprs = true
|
|
||||||
|
|
||||||
case subExprFilterDuringCoroutine:
|
|
||||||
if n.Effect().Coroutine() {
|
|
||||||
switch n.Operator() {
|
|
||||||
case t.IDOpenParen:
|
|
||||||
r.raiseNoneToWeak()
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("unrecognized ast.Expr coroutine operator")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
panic("TODO: unreachable; delete")
|
|
||||||
processOnlySubExprs = true
|
|
||||||
|
|
||||||
case subExprFilterAfterCoroutine:
|
|
||||||
if n.Effect().Coroutine() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
panic("TODO: unreachable; delete")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, o := range n.AsNode().AsRaw().SubNodes() {
|
for _, o := range n.AsNode().AsRaw().SubNodes() {
|
||||||
if o != nil && o.Kind() == a.KExpr {
|
if o != nil && o.Kind() == a.KExpr {
|
||||||
if err := h.doExpr1(r, o.AsExpr(), sef, depth); err != nil {
|
if err := h.doExpr1(r, o.AsExpr(), depth); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -337,12 +293,12 @@ func (h *resumabilityHelper) doExpr1(r resumabilities, n *a.Expr, sef subExprFil
|
|||||||
default:
|
default:
|
||||||
return fmt.Errorf("unrecognized arg kind")
|
return fmt.Errorf("unrecognized arg kind")
|
||||||
}
|
}
|
||||||
if err := h.doExpr1(r, e, sef, depth); err != nil {
|
if err := h.doExpr1(r, e, depth); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !processOnlySubExprs && n.Operator() == 0 {
|
if n.Operator() == 0 {
|
||||||
if i, ok := h.vars[n.Ident()]; ok {
|
if i, ok := h.vars[n.Ident()]; ok {
|
||||||
r.raiseWeakToStrong(i)
|
r.raiseWeakToStrong(i)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user