cmd/compile/internal/noder: explicitly handle separate selectors

This CL separates out the handling of selector expressions for field
values, method values, and method expressions. Again part of
refactoring to make it possible to access runtime dictionaries where
needed.

No behavioral change; just duplicating and then streamlining the
existing code paths.

Change-Id: I53b2a344f4bdba2c9f37ef370dc9a091a3941021
Reviewed-on: https://go-review.googlesource.com/c/go/+/421818
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
Matthew Dempsky 2022-08-05 20:40:45 -07:00
parent 2e6ffd6c5d
commit 88635b3862
3 changed files with 51 additions and 29 deletions

View file

@ -1881,36 +1881,41 @@ func (r *reader) expr() (res ir.Node) {
case exprFuncLit:
return r.funcLit()
case exprSelector:
var x ir.Node
if r.Bool() { // MethodExpr
if r.Bool() {
return r.dict.methodExprs[r.Len()]
}
case exprFieldVal:
x := r.expr()
pos := r.pos()
_, sym := r.selector()
n := ir.TypeNode(r.typ())
n.SetTypecheck(1)
x = n
} else { // FieldVal, MethodVal
x = r.expr()
}
return typecheck.Expr(ir.NewSelectorExpr(pos, ir.OXDOT, x, sym)).(*ir.SelectorExpr)
case exprMethodVal:
x := r.expr()
pos := r.pos()
_, sym := r.selector()
n := typecheck.Expr(ir.NewSelectorExpr(pos, ir.OXDOT, x, sym)).(*ir.SelectorExpr)
if n.Op() == ir.OMETHVALUE {
wrapper := methodValueWrapper{
rcvr: n.X.Type(),
method: n.Selection,
}
if r.importedDef() {
haveMethodValueWrappers = append(haveMethodValueWrappers, wrapper)
} else {
needMethodValueWrappers = append(needMethodValueWrappers, wrapper)
}
wrapper := methodValueWrapper{
rcvr: n.X.Type(),
method: n.Selection,
}
if r.importedDef() {
haveMethodValueWrappers = append(haveMethodValueWrappers, wrapper)
} else {
needMethodValueWrappers = append(needMethodValueWrappers, wrapper)
}
return n
case exprMethodExpr:
if r.Bool() {
return r.dict.methodExprs[r.Len()]
}
typ := r.typ()
pos := r.pos()
_, sym := r.selector()
return typecheck.Expr(ir.NewSelectorExpr(pos, ir.OXDOT, ir.TypeNode(typ), sym)).(*ir.SelectorExpr)
case exprIndex:
x := r.expr()
pos := r.pos()