cmd/compile/internal/noder: explicit receiver expression handling

This CL adds a helper expression code for receiver addressing; i.e.,
the implicit addressing, dereferencing, and field selections involved
in changing the `x` in `x.M()` into an appropriate expression to pass
as an argument to the method.

Change-Id: I9be933e2a38c8f94f6a85d95b54f34164e5efb0a
Reviewed-on: https://go-review.googlesource.com/c/go/+/421820
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
Matthew Dempsky 2022-08-06 16:08:41 -07:00
parent 29b07037b1
commit de95dca32f
3 changed files with 50 additions and 2 deletions

View file

@ -1914,6 +1914,19 @@ func (r *reader) expr() (res ir.Node) {
}
return typecheck.Expr(ir.NewBinaryExpr(pos, op, x, y))
case exprRecv:
x := r.expr()
pos := r.pos()
for i, n := 0, r.Len(); i < n; i++ {
x = Implicit(DotField(pos, x, r.Len()))
}
if r.Bool() { // needs deref
x = Implicit(Deref(pos, x.Type().Elem(), x))
} else if r.Bool() { // needs addr
x = Implicit(Addr(pos, x))
}
return x
case exprCall:
fun := r.expr()
if r.Bool() { // method call