1
0
mirror of https://github.com/golang/go synced 2024-11-26 09:48:14 -07:00

[dev.regabi] cmd/compile: simplify some tree traversal code

When looking for referenced functions within bottomUpVisitor and
initDeps, the logic for ODOTMETH, OCALLPART, and OMETHEXPR are
basically identical, especially after previous refactorings to make
them use MethodExprName. This CL makes them exactly identical.

Passes toolstash -cmp.

Change-Id: I1f59c9be99aa9484d0397a0a6fb8ddd894a31c68
Reviewed-on: https://go-review.googlesource.com/c/go/+/280441
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Matthew Dempsky 2020-12-26 22:00:53 -08:00
parent 6c67677541
commit fbc4458c06
2 changed files with 15 additions and 40 deletions

View File

@ -76,48 +76,27 @@ func (v *bottomUpVisitor) visit(n *Func) uint32 {
min := v.visitgen
v.stack = append(v.stack, n)
do := func(defn Node) {
if defn != nil {
if m := v.visit(defn.(*Func)); m < min {
min = m
}
}
}
Visit(n, func(n Node) {
switch n.Op() {
case ONAME:
n := n.(*Name)
if n.Class_ == PFUNC {
if n != nil && n.Name().Defn != nil {
if m := v.visit(n.Name().Defn.(*Func)); m < min {
min = m
}
}
if n := n.(*Name); n.Class_ == PFUNC {
do(n.Defn)
}
case OMETHEXPR:
n := n.(*MethodExpr)
fn := MethodExprName(n)
if fn != nil && fn.Defn != nil {
if m := v.visit(fn.Defn.(*Func)); m < min {
min = m
}
}
case ODOTMETH:
n := n.(*SelectorExpr)
fn := MethodExprName(n)
if fn != nil && fn.Op() == ONAME && fn.Class_ == PFUNC && fn.Defn != nil {
if m := v.visit(fn.Defn.(*Func)); m < min {
min = m
}
}
case OCALLPART:
n := n.(*CallPartExpr)
fn := AsNode(n.Method.Nname)
if fn != nil && fn.Op() == ONAME {
if fn := fn.(*Name); fn.Class_ == PFUNC && fn.Name().Defn != nil {
if m := v.visit(fn.Name().Defn.(*Func)); m < min {
min = m
}
}
case ODOTMETH, OCALLPART, OMETHEXPR:
if fn := MethodExprName(n); fn != nil {
do(fn.Defn)
}
case OCLOSURE:
n := n.(*ClosureExpr)
if m := v.visit(n.Func); m < min {
min = m
}
do(n.Func)
}
})

View File

@ -289,10 +289,6 @@ func (d *initDeps) inspectList(l ir.Nodes) { ir.VisitList(l, d.cachedVisit()) }
// referenced by n, if any.
func (d *initDeps) visit(n ir.Node) {
switch n.Op() {
case ir.OMETHEXPR:
n := n.(*ir.MethodExpr)
d.foundDep(ir.MethodExprName(n))
case ir.ONAME:
n := n.(*ir.Name)
switch n.Class_ {
@ -304,7 +300,7 @@ func (d *initDeps) visit(n ir.Node) {
n := n.(*ir.ClosureExpr)
d.inspectList(n.Func.Body)
case ir.ODOTMETH, ir.OCALLPART:
case ir.ODOTMETH, ir.OCALLPART, ir.OMETHEXPR:
d.foundDep(ir.MethodExprName(n))
}
}