Commit 2f072a42 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: clean up methodsym

Convert yyerrors into Fatals.
Remove the goto.
Move variable declaration closer to use.
Unify printing strings a bit.
Convert an int param into a bool.

Passes toolstash-check. No compiler performance impact.

Change-Id: I9017681417b785cf8693d18b124ac4f1ff37f2b5
Reviewed-on: https://go-review.googlesource.com/39170
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 3237af2d
...@@ -956,56 +956,48 @@ func functypefield0(t *Type, this *Field, in, out []*Field) { ...@@ -956,56 +956,48 @@ func functypefield0(t *Type, this *Field, in, out []*Field) {
var methodsym_toppkg *Pkg var methodsym_toppkg *Pkg
func methodsym(nsym *Sym, t0 *Type, iface int) *Sym { func methodsym(nsym *Sym, t0 *Type, iface bool) *Sym {
var s *Sym if t0 == nil {
var p string Fatalf("methodsym: nil receiver type")
var suffix string }
var spkg *Pkg
t := t0 t := t0
if t == nil { s := t.Sym
goto bad
}
s = t.Sym
if s == nil && t.IsPtr() { if s == nil && t.IsPtr() {
t = t.Elem() t = t.Elem()
if t == nil { if t == nil {
goto bad Fatalf("methodsym: ptrto nil")
} }
s = t.Sym s = t.Sym
} }
spkg = nil
if s != nil {
spkg = s.Pkg
}
// if t0 == *t and t0 has a sym, // if t0 == *t and t0 has a sym,
// we want to see *t, not t0, in the method name. // we want to see *t, not t0, in the method name.
if t != t0 && t0.Sym != nil { if t != t0 && t0.Sym != nil {
t0 = typPtr(t) t0 = typPtr(t)
} }
suffix = "" suffix := ""
if iface != 0 { if iface {
dowidth(t0) dowidth(t0)
if t0.Width < int64(Widthptr) { if t0.Width < int64(Widthptr) {
suffix = "·i" suffix = "·i"
} }
} }
var spkg *Pkg
if s != nil {
spkg = s.Pkg
}
pkgprefix := ""
if (spkg == nil || nsym.Pkg != spkg) && !exportname(nsym.Name) { if (spkg == nil || nsym.Pkg != spkg) && !exportname(nsym.Name) {
if t0.Sym == nil && t0.IsPtr() { pkgprefix = "." + nsym.Pkg.Prefix
p = fmt.Sprintf("(%-S).%s.%s%s", t0, nsym.Pkg.Prefix, nsym.Name, suffix)
} else {
p = fmt.Sprintf("%-S.%s.%s%s", t0, nsym.Pkg.Prefix, nsym.Name, suffix)
} }
} else { var p string
if t0.Sym == nil && t0.IsPtr() { if t0.Sym == nil && t0.IsPtr() {
p = fmt.Sprintf("(%-S).%s%s", t0, nsym.Name, suffix) p = fmt.Sprintf("(%-S)%s.%s%s", t0, pkgprefix, nsym.Name, suffix)
} else { } else {
p = fmt.Sprintf("%-S.%s%s", t0, nsym.Name, suffix) p = fmt.Sprintf("%-S%s.%s%s", t0, pkgprefix, nsym.Name, suffix)
}
} }
if spkg == nil { if spkg == nil {
...@@ -1015,13 +1007,7 @@ func methodsym(nsym *Sym, t0 *Type, iface int) *Sym { ...@@ -1015,13 +1007,7 @@ func methodsym(nsym *Sym, t0 *Type, iface int) *Sym {
spkg = methodsym_toppkg spkg = methodsym_toppkg
} }
s = spkg.Lookup(p) return spkg.Lookup(p)
return s
bad:
yyerror("illegal receiver type: %v", t0)
return nil
} }
// methodname is a misnomer because this now returns a Sym, rather // methodname is a misnomer because this now returns a Sym, rather
......
...@@ -356,8 +356,8 @@ func methods(t *Type) []*Sig { ...@@ -356,8 +356,8 @@ func methods(t *Type) []*Sig {
sig.pkg = method.Pkg sig.pkg = method.Pkg
} }
sig.isym = methodsym(method, it, 1) sig.isym = methodsym(method, it, true)
sig.tsym = methodsym(method, t, 0) sig.tsym = methodsym(method, t, false)
sig.type_ = methodfunc(f.Type, t) sig.type_ = methodfunc(f.Type, t)
sig.mtype = methodfunc(f.Type, nil) sig.mtype = methodfunc(f.Type, nil)
...@@ -423,7 +423,7 @@ func imethods(t *Type) []*Sig { ...@@ -423,7 +423,7 @@ func imethods(t *Type) []*Sig {
// IfaceType.Method is not in the reflect data. // IfaceType.Method is not in the reflect data.
// Generate the method body, so that compiled // Generate the method body, so that compiled
// code can refer to it. // code can refer to it.
isym := methodsym(method, t, 0) isym := methodsym(method, t, false)
if !isym.Siggen() { if !isym.Siggen() {
isym.SetSiggen(true) isym.SetSiggen(true)
genwrapper(t, f, isym, 0) genwrapper(t, f, isym, 0)
......
...@@ -1783,7 +1783,7 @@ func genwrapper(rcvr *Type, method *Field, newnam *Sym, iface int) { ...@@ -1783,7 +1783,7 @@ func genwrapper(rcvr *Type, method *Field, newnam *Sym, iface int) {
as.Right.Type = rcvr as.Right.Type = rcvr
fn.Nbody.Append(as) fn.Nbody.Append(as)
n := nod(ORETJMP, nil, nil) n := nod(ORETJMP, nil, nil)
n.Left = newname(methodsym(method.Sym, methodrcvr, 0)) n.Left = newname(methodsym(method.Sym, methodrcvr, false))
fn.Nbody.Append(n) fn.Nbody.Append(n)
// When tail-calling, we can't use a frame pointer. // When tail-calling, we can't use a frame pointer.
fn.Func.SetNoFramePointer(true) fn.Func.SetNoFramePointer(true)
......
...@@ -2384,7 +2384,7 @@ func looktypedot(n *Node, t *Type, dostrcmp int) bool { ...@@ -2384,7 +2384,7 @@ func looktypedot(n *Node, t *Type, dostrcmp int) bool {
return false return false
} }
n.Sym = methodsym(n.Sym, t, 0) n.Sym = methodsym(n.Sym, t, false)
n.Xoffset = f1.Offset n.Xoffset = f1.Offset
n.Type = f1.Type n.Type = f1.Type
n.Op = ODOTINTER n.Op = ODOTINTER
...@@ -2410,7 +2410,7 @@ func looktypedot(n *Node, t *Type, dostrcmp int) bool { ...@@ -2410,7 +2410,7 @@ func looktypedot(n *Node, t *Type, dostrcmp int) bool {
return false return false
} }
n.Sym = methodsym(n.Sym, t, 0) n.Sym = methodsym(n.Sym, t, false)
n.Xoffset = f2.Offset n.Xoffset = f2.Offset
n.Type = f2.Type n.Type = f2.Type
n.Op = ODOTMETH n.Op = ODOTMETH
...@@ -2529,7 +2529,7 @@ func lookdot(n *Node, t *Type, dostrcmp int) *Field { ...@@ -2529,7 +2529,7 @@ func lookdot(n *Node, t *Type, dostrcmp int) *Field {
return nil return nil
} }
n.Sym = methodsym(n.Sym, n.Left.Type, 0) n.Sym = methodsym(n.Sym, n.Left.Type, false)
n.Xoffset = f2.Offset n.Xoffset = f2.Offset
n.Type = f2.Type n.Type = f2.Type
......
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