]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add Node.IsMethod helper
authorJosh Bleecher Snyder <josharian@gmail.com>
Sun, 11 Sep 2016 21:43:37 +0000 (14:43 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sun, 11 Sep 2016 22:46:38 +0000 (22:46 +0000)
Changes generated with eg:

func before(n *gc.Node) bool { return n.Type.Recv() != nil }
func after(n *gc.Node) bool  { return n.IsMethod() }

func before(n *gc.Node) bool { return n.Type.Recv() == nil }
func after(n *gc.Node) bool  { return !n.IsMethod() }

Change-Id: I28e544490d17bbdc06ab11ed32464af5802ab206
Reviewed-on: https://go-review.googlesource.com/28968
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/pgen.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/typecheck.go

index 967b7ba140ea988e250eff3f86a3cc9c1b987bca..fa8eef4184ebbfb1dfe88f00afc307db7d66cd3f 100644 (file)
@@ -116,7 +116,7 @@ func reexportdep(n *Node) {
                        }
 
                        // nodes for method calls.
-                       if n.Type == nil || n.Type.Recv() != nil {
+                       if n.Type == nil || n.IsMethod() {
                                break
                        }
                        fallthrough
index 8043ac8444c9b8d805c864efeee86ad0cdb1ccd7..7c172e6489e0952b43cb566c199e8b4c66d7daad 100644 (file)
@@ -32,7 +32,7 @@ import "fmt"
 // Get the function's package. For ordinary functions it's on the ->sym, but for imported methods
 // the ->sym can be re-used in the local package, so peel it off the receiver's type.
 func fnpkg(fn *Node) *Pkg {
-       if fn.Type.Recv() != nil {
+       if fn.IsMethod() {
                // method
                rcvr := fn.Type.Recv().Type
 
@@ -615,7 +615,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
        }
 
        // assign receiver.
-       if fn.Type.Recv() != nil && n.Left.Op == ODOTMETH {
+       if fn.IsMethod() && n.Left.Op == ODOTMETH {
                // method call with a receiver.
                t := fn.Type.Recv()
 
@@ -679,7 +679,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
        li := 0
 
        // TODO: if len(nlist) == 1 but multiple args, check that n->list->n is a call?
-       if fn.Type.Recv() != nil && n.Left.Op != ODOTMETH {
+       if fn.IsMethod() && n.Left.Op != ODOTMETH {
                // non-method call to method
                if n.List.Len() == 0 {
                        Fatalf("non-method call to method without first arg: %+v", n)
index da2e6752a2b6101de3aacc41da77ec86bc84ddcb..402459b3c33276a246dd855b92c0f97a2413d5bf 100644 (file)
@@ -144,7 +144,7 @@ func emitptrargsmap() {
        off := duint32(sym, 0, uint32(nbitmap))
        off = duint32(sym, off, uint32(bv.n))
        var xoffset int64
-       if Curfn.Type.Recv() != nil {
+       if Curfn.IsMethod() {
                xoffset = 0
                onebitwalktype1(Curfn.Type.Recvs(), &xoffset, bv)
        }
index 8e6634c9f051ed3e7dcbc42eaf9363d6008096f3..7e30efcf7589187b3bb3a92a1cf119868a6090d7 100644 (file)
@@ -1038,6 +1038,12 @@ func Is64(t *Type) bool {
        return false
 }
 
+// IsMethod reports whether n is a method.
+// n must be a function or a method.
+func (n *Node) IsMethod() bool {
+       return n.Type.Recv() != nil
+}
+
 // SliceBounds returns n's slice bounds: low, high, and max in expr[low:high:max].
 // n must be a slice expression. max is nil if n is a simple slice expression.
 func (n *Node) SliceBounds() (low, high, max *Node) {
index 68b0fd8e560d55422d02ed8156528d83543442ab..8a4431205a2a074a19fae18ec1c116a5e6834e13 100644 (file)
@@ -860,7 +860,7 @@ OpSwitch:
                                return n
                        }
 
-                       if n.Type.Etype != TFUNC || n.Type.Recv() == nil {
+                       if n.Type.Etype != TFUNC || !n.IsMethod() {
                                Yyerror("type %v has no method %1v", n.Left.Type, n.Right.Sym)
                                n.Type = nil
                                return n