]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: eliminate methtype's mustname parameter
authorMatthew Dempsky <mdempsky@google.com>
Tue, 30 Aug 2016 20:43:37 +0000 (13:43 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 30 Aug 2016 21:30:35 +0000 (21:30 +0000)
Change-Id: Idd3e677dec00eb36a2cf7baa34e772335e1f2bc8
Reviewed-on: https://go-review.googlesource.com/28173
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/typecheck.go

index c487c237eb342a396e0b5faa3ede095c381f9209..48ba1f545ee62d5b46d9f2cdd7b5457ac6389525 100644 (file)
@@ -1168,8 +1168,8 @@ func addmethod(msym *Sym, t *Type, tpkg *Pkg, local, nointerface bool) {
        }
 
        pa := rf.Type // base type
-       mt := methtype(pa, 1)
-       if mt == nil {
+       mt := methtype(pa)
+       if mt == nil || mt.Sym == nil {
                t = pa
                if t == nil { // rely on typecheck having complained before
                        return
index 7ef825360b41426c20e4800d34868cd0d266f997..4a396d293ad1c5a07e287514d6859dacb54aba01 100644 (file)
@@ -282,7 +282,7 @@ func methodfunc(f *Type, receiver *Type) *Type {
 // Generates stub functions as needed.
 func methods(t *Type) []*Sig {
        // method type
-       mt := methtype(t, 0)
+       mt := methtype(t)
 
        if mt == nil {
                return nil
index d8f9732bae0e223967a03ab6dd832a542879843b..2e279b108edcf45f946a2fddd9408e1e5c70f56a 100644 (file)
@@ -589,14 +589,15 @@ func isblanksym(s *Sym) bool {
        return s != nil && s.Name == "_"
 }
 
-// given receiver of type t (t == r or t == *r)
-// return type to hang methods off (r).
-func methtype(t *Type, mustname int) *Type {
+// methtype returns the underlying type, if any,
+// that owns methods with receiver parameter t.
+// The result is either a named type or an anonymous struct.
+func methtype(t *Type) *Type {
        if t == nil {
                return nil
        }
 
-       // strip away pointer if it's there
+       // Strip away pointer if it's there.
        if t.IsPtr() {
                if t.Sym != nil {
                        return nil
@@ -607,29 +608,20 @@ func methtype(t *Type, mustname int) *Type {
                }
        }
 
-       // need a type name
-       if t.Sym == nil && (mustname != 0 || !t.IsStruct()) {
+       // Must be a named type or anonymous struct.
+       if t.Sym == nil && !t.IsStruct() {
                return nil
        }
 
-       // check types
-       if !issimple[t.Etype] {
-               switch t.Etype {
-               default:
-                       return nil
-
-               case TSTRUCT,
-                       TARRAY,
-                       TSLICE,
-                       TMAP,
-                       TCHAN,
-                       TSTRING,
-                       TFUNC:
-                       break
-               }
+       // Check types.
+       if issimple[t.Etype] {
+               return t
        }
-
-       return t
+       switch t.Etype {
+       case TARRAY, TCHAN, TFUNC, TMAP, TSLICE, TSTRING, TSTRUCT:
+               return t
+       }
+       return nil
 }
 
 func cplxsubtype(et EType) EType {
@@ -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 {
                for _, f := range u.Methods().Slice() {
                        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) {
                return
        }
 
-       u = methtype(t, 0)
+       u = methtype(t)
        if u != nil {
                for _, f := range u.Methods().Slice() {
                        if f.Sym.Flags&SymUniq != 0 {
@@ -2015,7 +2007,7 @@ func implements(t, iface *Type, m, samename **Field, ptr *int) bool {
                return true
        }
 
-       t = methtype(t, 0)
+       t = methtype(t)
        if t != nil {
                expandmeth(t)
        }
index c97b33d91b7b8314a39bb8c3338635d875085a9c..f34f4751bc6a17dfe9865cd084c7d9b6e3dd1f92 100644 (file)
@@ -2359,7 +2359,7 @@ func looktypedot(n *Node, t *Type, dostrcmp int) bool {
 
        // Find the base type: methtype will fail if t
        // is not of the form T or *T.
-       mt := methtype(t, 0)
+       mt := methtype(t)
        if mt == nil {
                return false
        }
@@ -2410,7 +2410,7 @@ func lookdot(n *Node, t *Type, dostrcmp int) *Field {
 
        var f2 *Field
        if n.Left.Type == t || n.Left.Type.Sym == nil {
-               mt := methtype(t, 0)
+               mt := methtype(t)
                if mt != nil {
                        // Use f2->method, not f2->xmethod: adddot has
                        // already inserted all the necessary embedded dots.