]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: clean up methodsym
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 31 Mar 2017 16:57:38 +0000 (09:57 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 31 Mar 2017 19:30:51 +0000 (19:30 +0000)
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: Brad Fitzpatrick <bradfitz@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 b66231ab88272011ad3430255ba3ee401f8d3933..8f548895d45e822a1b8bc001b87d7afe9ece7775 100644 (file)
@@ -956,56 +956,48 @@ func functypefield0(t *Type, this *Field, in, out []*Field) {
 
 var methodsym_toppkg *Pkg
 
-func methodsym(nsym *Sym, t0 *Type, iface int) *Sym {
-       var s *Sym
-       var p string
-       var suffix string
-       var spkg *Pkg
+func methodsym(nsym *Sym, t0 *Type, iface bool) *Sym {
+       if t0 == nil {
+               Fatalf("methodsym: nil receiver type")
+       }
 
        t := t0
-       if t == nil {
-               goto bad
-       }
-       s = t.Sym
+       s := t.Sym
        if s == nil && t.IsPtr() {
                t = t.Elem()
                if t == nil {
-                       goto bad
+                       Fatalf("methodsym: ptrto nil")
                }
                s = t.Sym
        }
 
-       spkg = nil
-       if s != nil {
-               spkg = s.Pkg
-       }
-
        // if t0 == *t and t0 has a sym,
        // we want to see *t, not t0, in the method name.
        if t != t0 && t0.Sym != nil {
                t0 = typPtr(t)
        }
 
-       suffix = ""
-       if iface != 0 {
+       suffix := ""
+       if iface {
                dowidth(t0)
                if t0.Width < int64(Widthptr) {
                        suffix = "·i"
                }
        }
 
+       var spkg *Pkg
+       if s != nil {
+               spkg = s.Pkg
+       }
+       pkgprefix := ""
        if (spkg == nil || nsym.Pkg != spkg) && !exportname(nsym.Name) {
-               if t0.Sym == nil && t0.IsPtr() {
-                       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)
-               }
+               pkgprefix = "." + nsym.Pkg.Prefix
+       }
+       var p string
+       if t0.Sym == nil && t0.IsPtr() {
+               p = fmt.Sprintf("(%-S)%s.%s%s", t0, pkgprefix, nsym.Name, suffix)
        } else {
-               if t0.Sym == nil && t0.IsPtr() {
-                       p = fmt.Sprintf("(%-S).%s%s", t0, nsym.Name, suffix)
-               } 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 {
@@ -1015,13 +1007,7 @@ func methodsym(nsym *Sym, t0 *Type, iface int) *Sym {
                spkg = methodsym_toppkg
        }
 
-       s = spkg.Lookup(p)
-
-       return s
-
-bad:
-       yyerror("illegal receiver type: %v", t0)
-       return nil
+       return spkg.Lookup(p)
 }
 
 // methodname is a misnomer because this now returns a Sym, rather
index 1da20b67a12003cd36052c64b00ca8ee68b73de0..66b19988d876956eff7c5137ee8ef0bf8e537892 100644 (file)
@@ -356,8 +356,8 @@ func methods(t *Type) []*Sig {
                        sig.pkg = method.Pkg
                }
 
-               sig.isym = methodsym(method, it, 1)
-               sig.tsym = methodsym(method, t, 0)
+               sig.isym = methodsym(method, it, true)
+               sig.tsym = methodsym(method, t, false)
                sig.type_ = methodfunc(f.Type, t)
                sig.mtype = methodfunc(f.Type, nil)
 
@@ -423,7 +423,7 @@ func imethods(t *Type) []*Sig {
                // IfaceType.Method is not in the reflect data.
                // Generate the method body, so that compiled
                // code can refer to it.
-               isym := methodsym(method, t, 0)
+               isym := methodsym(method, t, false)
                if !isym.Siggen() {
                        isym.SetSiggen(true)
                        genwrapper(t, f, isym, 0)
index fb56d4eb3a47bc4a4b15386238daa8e5964548ed..a61f339a1bb048bc26355d10b77e76a572fd40fb 100644 (file)
@@ -1783,7 +1783,7 @@ func genwrapper(rcvr *Type, method *Field, newnam *Sym, iface int) {
                as.Right.Type = rcvr
                fn.Nbody.Append(as)
                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)
                // When tail-calling, we can't use a frame pointer.
                fn.Func.SetNoFramePointer(true)
index 00045930ebc5504967b2759f24c6eee69b6e7574..17301ea820fc0ff81858f03526789a83db8d85c3 100644 (file)
@@ -2384,7 +2384,7 @@ func looktypedot(n *Node, t *Type, dostrcmp int) bool {
                        return false
                }
 
-               n.Sym = methodsym(n.Sym, t, 0)
+               n.Sym = methodsym(n.Sym, t, false)
                n.Xoffset = f1.Offset
                n.Type = f1.Type
                n.Op = ODOTINTER
@@ -2410,7 +2410,7 @@ func looktypedot(n *Node, t *Type, dostrcmp int) bool {
                return false
        }
 
-       n.Sym = methodsym(n.Sym, t, 0)
+       n.Sym = methodsym(n.Sym, t, false)
        n.Xoffset = f2.Offset
        n.Type = f2.Type
        n.Op = ODOTMETH
@@ -2529,7 +2529,7 @@ func lookdot(n *Node, t *Type, dostrcmp int) *Field {
                        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.Type = f2.Type