]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: simplify FuncName and PkgFuncName
authorMatthew Dempsky <mdempsky@google.com>
Sun, 27 Dec 2020 05:43:30 +0000 (21:43 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 28 Dec 2020 07:44:45 +0000 (07:44 +0000)
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 <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>
src/cmd/compile/internal/ir/func.go

index 6bc8cd574c5791afb5ff00a4e4d5c31ec6a0c2c2..16d67f6ae0c1147c42705bc181ef2841d7455b43 100644 (file)
@@ -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 "<nil>"
        }
-       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 "<nil>"
        }
-       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 "<nil>"
-               }
-               s = f.Nname.Sym()
-       }
+       s := f.Sym()
        pkg := s.Pkg
 
        p := base.Ctxt.Pkgpath