From: Matthew Dempsky Date: Sun, 27 Dec 2020 05:43:30 +0000 (-0800) Subject: [dev.regabi] cmd/compile: simplify FuncName and PkgFuncName X-Git-Tag: go1.17beta1~1539^2~212 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6c676775419b4cfc9f1a3b8959d538b81cec754e;p=gostls13.git [dev.regabi] cmd/compile: simplify FuncName and PkgFuncName Now that we have proper types, these functions can be restricted to only allowing *ir.Func, rather than any ir.Node. And even more fortunately, all of their callers already happen to always pass *ir.Func arguments, making this CL pretty simple. Passes toolstash -cmp. Change-Id: I21ecd4c8cee3ccb8ba86b17cedb2e71c56ffe87a Reviewed-on: https://go-review.googlesource.com/c/go/+/280440 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- diff --git a/src/cmd/compile/internal/ir/func.go b/src/cmd/compile/internal/ir/func.go index 6bc8cd574c..16d67f6ae0 100644 --- a/src/cmd/compile/internal/ir/func.go +++ b/src/cmd/compile/internal/ir/func.go @@ -206,50 +206,22 @@ func (f *Func) SetWBPos(pos src.XPos) { } // funcname returns the name (without the package) of the function n. -func FuncName(n Node) string { - var f *Func - switch n := n.(type) { - case *Func: - f = n - case *Name: - f = n.Func - case *CallPartExpr: - f = n.Func - case *ClosureExpr: - f = n.Func - } +func FuncName(f *Func) string { if f == nil || f.Nname == nil { return "" } - return f.Nname.Sym().Name + return f.Sym().Name } // pkgFuncName returns the name of the function referenced by n, with package prepended. // This differs from the compiler's internal convention where local functions lack a package // because the ultimate consumer of this is a human looking at an IDE; package is only empty // if the compilation package is actually the empty string. -func PkgFuncName(n Node) string { - var s *types.Sym - if n == nil { +func PkgFuncName(f *Func) string { + if f == nil || f.Nname == nil { return "" } - if n.Op() == ONAME { - s = n.Sym() - } else { - var f *Func - switch n := n.(type) { - case *CallPartExpr: - f = n.Func - case *ClosureExpr: - f = n.Func - case *Func: - f = n - } - if f == nil || f.Nname == nil { - return "" - } - s = f.Nname.Sym() - } + s := f.Sym() pkg := s.Pkg p := base.Ctxt.Pkgpath