mirror of
				https://github.com/golang/go.git
				synced 2025-11-03 18:20:59 +00:00 
			
		
		
		
	[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 <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:
		
							parent
							
								
									676d794b81
								
							
						
					
					
						commit
						6c67677541
					
				
					 1 changed files with 5 additions and 33 deletions
				
			
		| 
						 | 
					@ -206,50 +206,22 @@ func (f *Func) SetWBPos(pos src.XPos) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// funcname returns the name (without the package) of the function n.
 | 
					// funcname returns the name (without the package) of the function n.
 | 
				
			||||||
func FuncName(n Node) string {
 | 
					func FuncName(f *Func) 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
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if f == nil || f.Nname == nil {
 | 
						if f == nil || f.Nname == nil {
 | 
				
			||||||
		return "<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.
 | 
					// 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
 | 
					// 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
 | 
					// 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.
 | 
					// if the compilation package is actually the empty string.
 | 
				
			||||||
func PkgFuncName(n Node) string {
 | 
					func PkgFuncName(f *Func) string {
 | 
				
			||||||
	var s *types.Sym
 | 
						if f == nil || f.Nname == nil {
 | 
				
			||||||
	if n == nil {
 | 
					 | 
				
			||||||
		return "<nil>"
 | 
							return "<nil>"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if n.Op() == ONAME {
 | 
						s := f.Sym()
 | 
				
			||||||
		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()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	pkg := s.Pkg
 | 
						pkg := s.Pkg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	p := base.Ctxt.Pkgpath
 | 
						p := base.Ctxt.Pkgpath
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue