mirror of
https://github.com/golang/go
synced 2024-11-18 03:14:44 -07:00
cmd/compile: make ifaceData accept a position
This lets us provide a better position in its use in swt.go. Change-Id: I7c0da6bd0adea81acfc9a591e6a01b241a5e0942 Reviewed-on: https://go-review.googlesource.com/c/go/+/228219 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
ae253719a2
commit
02ab2c040e
@ -376,7 +376,13 @@ func newnamel(pos src.XPos, s *types.Sym) *Node {
|
||||
// nodSym makes a Node with Op op and with the Left field set to left
|
||||
// and the Sym field set to sym. This is for ODOT and friends.
|
||||
func nodSym(op Op, left *Node, sym *types.Sym) *Node {
|
||||
n := nod(op, left, nil)
|
||||
return nodlSym(lineno, op, left, sym)
|
||||
}
|
||||
|
||||
// nodlSym makes a Node with position Pos, with Op op, and with the Left field set to left
|
||||
// and the Sym field set to sym. This is for ODOT and friends.
|
||||
func nodlSym(pos src.XPos, op Op, left *Node, sym *types.Sym) *Node {
|
||||
n := nodl(pos, op, left, nil)
|
||||
n.Sym = sym
|
||||
return n
|
||||
}
|
||||
@ -1896,11 +1902,11 @@ func itabType(itab *Node) *Node {
|
||||
// ifaceData loads the data field from an interface.
|
||||
// The concrete type must be known to have type t.
|
||||
// It follows the pointer if !isdirectiface(t).
|
||||
func ifaceData(n *Node, t *types.Type) *Node {
|
||||
func ifaceData(pos src.XPos, n *Node, t *types.Type) *Node {
|
||||
if t.IsInterface() {
|
||||
Fatalf("ifaceData interface: %v", t)
|
||||
}
|
||||
ptr := nodSym(OIDATA, n, nil)
|
||||
ptr := nodlSym(pos, OIDATA, n, nil)
|
||||
if isdirectiface(t) {
|
||||
ptr.Type = t
|
||||
ptr.SetTypecheck(1)
|
||||
@ -1909,7 +1915,7 @@ func ifaceData(n *Node, t *types.Type) *Node {
|
||||
ptr.Type = types.NewPtr(t)
|
||||
ptr.SetBounded(true)
|
||||
ptr.SetTypecheck(1)
|
||||
ind := nod(ODEREF, ptr, nil)
|
||||
ind := nodl(pos, ODEREF, ptr, nil)
|
||||
ind.Type = t
|
||||
ind.SetTypecheck(1)
|
||||
return ind
|
||||
|
@ -584,7 +584,7 @@ func walkTypeSwitch(sw *Node) {
|
||||
if singleType.IsInterface() {
|
||||
Fatalf("singleType interface should have been handled in Add")
|
||||
}
|
||||
val = ifaceData(s.facename, singleType)
|
||||
val = ifaceData(ncase.Pos, s.facename, singleType)
|
||||
}
|
||||
l := []*Node{
|
||||
nodl(ncase.Pos, ODCL, caseVar, nil),
|
||||
|
@ -886,7 +886,7 @@ opswitch:
|
||||
init.Append(nif)
|
||||
|
||||
// Build the result.
|
||||
e := nod(OEFACE, tmp, ifaceData(c, types.NewPtr(types.Types[TUINT8])))
|
||||
e := nod(OEFACE, tmp, ifaceData(n.Pos, c, types.NewPtr(types.Types[TUINT8])))
|
||||
e.Type = toType // assign type manually, typecheck doesn't understand OEFACE.
|
||||
e.SetTypecheck(1)
|
||||
n = e
|
||||
@ -3165,7 +3165,7 @@ func walkcompare(n *Node, init *Nodes) *Node {
|
||||
eqtype = nod(andor, nonnil, match)
|
||||
}
|
||||
// Check for data equal.
|
||||
eqdata := nod(eq, ifaceData(l, r.Type), r)
|
||||
eqdata := nod(eq, ifaceData(n.Pos, l, r.Type), r)
|
||||
// Put it all together.
|
||||
expr := nod(andor, eqtype, eqdata)
|
||||
n = finishcompare(n, expr, init)
|
||||
|
Loading…
Reference in New Issue
Block a user