}
// nodes for method calls.
- if n.Type == nil || n.Type.Recv() != nil {
+ if n.Type == nil || n.IsMethod() {
break
}
fallthrough
// 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
}
// 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()
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)
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)
}
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) {
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