Commit e40dffe5 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: refactor visitBottomUp to use inspectList

Passes toolstash-check.

Change-Id: I02efba7bab3ea49d87c8472bbb99116565bf8423
Reviewed-on: https://go-review.googlesource.com/c/go/+/173321Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent ef2806e4
......@@ -71,9 +71,25 @@ func (v *bottomUpVisitor) visit(n *Node) uint32 {
v.nodeID[n] = id
v.visitgen++
min := v.visitgen
v.stack = append(v.stack, n)
min = v.visitcodelist(n.Nbody, min)
inspectList(n.Nbody, func(n *Node) bool {
switch n.Op {
case OCALLFUNC, OCALLMETH:
fn := asNode(n.Left.Type.Nname())
if fn != nil && fn.Op == ONAME && fn.Class() == PFUNC && fn.Name.Defn != nil {
if m := v.visit(fn.Name.Defn); m < min {
min = m
}
}
case OCLOSURE:
if m := v.visit(n.Func.Closure); m < min {
min = m
}
}
return true
})
if (min == id || min == id+1) && !n.Func.IsHiddenClosure() {
// This node is the root of a strongly connected component.
......@@ -104,42 +120,3 @@ func (v *bottomUpVisitor) visit(n *Node) uint32 {
return min
}
func (v *bottomUpVisitor) visitcodelist(l Nodes, min uint32) uint32 {
for _, n := range l.Slice() {
min = v.visitcode(n, min)
}
return min
}
func (v *bottomUpVisitor) visitcode(n *Node, min uint32) uint32 {
if n == nil {
return min
}
switch n.Op {
case OCALLFUNC, OCALLMETH:
fn := asNode(n.Left.Type.Nname())
if fn != nil && fn.Op == ONAME && fn.Class() == PFUNC && fn.Name.Defn != nil {
m := v.visit(fn.Name.Defn)
if m < min {
min = m
}
}
case OCLOSURE:
m := v.visit(n.Func.Closure)
if m < min {
min = m
}
}
min = v.visitcodelist(n.Ninit, min)
min = v.visitcode(n.Left, min)
min = v.visitcode(n.Right, min)
min = v.visitcodelist(n.List, min)
min = v.visitcodelist(n.Nbody, min)
min = v.visitcodelist(n.Rlist, min)
return min
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment