Commit 4eb2fa17 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: eliminate methtype's mustname parameter

Change-Id: Idd3e677dec00eb36a2cf7baa34e772335e1f2bc8
Reviewed-on: https://go-review.googlesource.com/28173
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 8c85e230
...@@ -1168,8 +1168,8 @@ func addmethod(msym *Sym, t *Type, tpkg *Pkg, local, nointerface bool) { ...@@ -1168,8 +1168,8 @@ func addmethod(msym *Sym, t *Type, tpkg *Pkg, local, nointerface bool) {
} }
pa := rf.Type // base type pa := rf.Type // base type
mt := methtype(pa, 1) mt := methtype(pa)
if mt == nil { if mt == nil || mt.Sym == nil {
t = pa t = pa
if t == nil { // rely on typecheck having complained before if t == nil { // rely on typecheck having complained before
return return
......
...@@ -282,7 +282,7 @@ func methodfunc(f *Type, receiver *Type) *Type { ...@@ -282,7 +282,7 @@ func methodfunc(f *Type, receiver *Type) *Type {
// Generates stub functions as needed. // Generates stub functions as needed.
func methods(t *Type) []*Sig { func methods(t *Type) []*Sig {
// method type // method type
mt := methtype(t, 0) mt := methtype(t)
if mt == nil { if mt == nil {
return nil return nil
......
...@@ -589,14 +589,15 @@ func isblanksym(s *Sym) bool { ...@@ -589,14 +589,15 @@ func isblanksym(s *Sym) bool {
return s != nil && s.Name == "_" return s != nil && s.Name == "_"
} }
// given receiver of type t (t == r or t == *r) // methtype returns the underlying type, if any,
// return type to hang methods off (r). // that owns methods with receiver parameter t.
func methtype(t *Type, mustname int) *Type { // The result is either a named type or an anonymous struct.
func methtype(t *Type) *Type {
if t == nil { if t == nil {
return nil return nil
} }
// strip away pointer if it's there // Strip away pointer if it's there.
if t.IsPtr() { if t.IsPtr() {
if t.Sym != nil { if t.Sym != nil {
return nil return nil
...@@ -607,29 +608,20 @@ func methtype(t *Type, mustname int) *Type { ...@@ -607,29 +608,20 @@ func methtype(t *Type, mustname int) *Type {
} }
} }
// need a type name // Must be a named type or anonymous struct.
if t.Sym == nil && (mustname != 0 || !t.IsStruct()) { if t.Sym == nil && !t.IsStruct() {
return nil return nil
} }
// check types // Check types.
if !issimple[t.Etype] { if issimple[t.Etype] {
switch t.Etype { return t
default:
return nil
case TSTRUCT,
TARRAY,
TSLICE,
TMAP,
TCHAN,
TSTRING,
TFUNC:
break
}
} }
switch t.Etype {
return t case TARRAY, TCHAN, TFUNC, TMAP, TSLICE, TSTRING, TSTRUCT:
return t
}
return nil
} }
func cplxsubtype(et EType) EType { func cplxsubtype(et EType) EType {
...@@ -1487,7 +1479,7 @@ func lookdot0(s *Sym, t *Type, save **Field, ignorecase bool) int { ...@@ -1487,7 +1479,7 @@ func lookdot0(s *Sym, t *Type, save **Field, ignorecase bool) int {
} }
} }
u = methtype(t, 0) u = methtype(t)
if u != nil { if u != nil {
for _, f := range u.Methods().Slice() { for _, f := range u.Methods().Slice() {
if f.Embedded == 0 && (f.Sym == s || (ignorecase && strings.EqualFold(f.Sym.Name, s.Name))) { if f.Embedded == 0 && (f.Sym == s || (ignorecase && strings.EqualFold(f.Sym.Name, s.Name))) {
...@@ -1653,7 +1645,7 @@ func expand0(t *Type, followptr bool) { ...@@ -1653,7 +1645,7 @@ func expand0(t *Type, followptr bool) {
return return
} }
u = methtype(t, 0) u = methtype(t)
if u != nil { if u != nil {
for _, f := range u.Methods().Slice() { for _, f := range u.Methods().Slice() {
if f.Sym.Flags&SymUniq != 0 { if f.Sym.Flags&SymUniq != 0 {
...@@ -2015,7 +2007,7 @@ func implements(t, iface *Type, m, samename **Field, ptr *int) bool { ...@@ -2015,7 +2007,7 @@ func implements(t, iface *Type, m, samename **Field, ptr *int) bool {
return true return true
} }
t = methtype(t, 0) t = methtype(t)
if t != nil { if t != nil {
expandmeth(t) expandmeth(t)
} }
......
...@@ -2359,7 +2359,7 @@ func looktypedot(n *Node, t *Type, dostrcmp int) bool { ...@@ -2359,7 +2359,7 @@ func looktypedot(n *Node, t *Type, dostrcmp int) bool {
// Find the base type: methtype will fail if t // Find the base type: methtype will fail if t
// is not of the form T or *T. // is not of the form T or *T.
mt := methtype(t, 0) mt := methtype(t)
if mt == nil { if mt == nil {
return false return false
} }
...@@ -2410,7 +2410,7 @@ func lookdot(n *Node, t *Type, dostrcmp int) *Field { ...@@ -2410,7 +2410,7 @@ func lookdot(n *Node, t *Type, dostrcmp int) *Field {
var f2 *Field var f2 *Field
if n.Left.Type == t || n.Left.Type.Sym == nil { if n.Left.Type == t || n.Left.Type.Sym == nil {
mt := methtype(t, 0) mt := methtype(t)
if mt != nil { if mt != nil {
// Use f2->method, not f2->xmethod: adddot has // Use f2->method, not f2->xmethod: adddot has
// already inserted all the necessary embedded dots. // already inserted all the necessary embedded dots.
......
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