mirror of
https://github.com/golang/go.git
synced 2025-11-11 22:21:06 +00:00
[dev.regabi] cmd/compile: use Node getters and setters [generated]
Now that we have all the getters and setters defined, use them
and unexport all the actual Node fields. This is the next step
toward replacing Node with an interface.
[git-generate]
cd src/cmd/compile/internal/gc
rf '
ex . ../ir ../ssa {
import "cmd/compile/internal/ir"
import "cmd/compile/internal/types"
import "cmd/internal/src"
var n, x *ir.Node
var op ir.Op
var t *types.Type
var f *ir.Func
var m *ir.Name
var s *types.Sym
var p src.XPos
var i int64
var e uint16
var nodes ir.Nodes
n.Op = op -> n.SetOp(op)
n.Left = x -> n.SetLeft(x)
n.Right = x -> n.SetRight(x)
n.Orig = x -> n.SetOrig(x)
n.Type = t -> n.SetType(t)
n.Func = f -> n.SetFunc(f)
n.Name = m -> n.SetName(m)
n.Sym = s -> n.SetSym(s)
n.Pos = p -> n.SetPos(p)
n.Xoffset = i -> n.SetXoffset(i)
n.Esc = e -> n.SetEsc(e)
n.Ninit.Append -> n.PtrNinit().Append
n.Ninit.AppendNodes -> n.PtrNinit().AppendNodes
n.Ninit.MoveNodes -> n.PtrNinit().MoveNodes
n.Ninit.Prepend -> n.PtrNinit().Prepend
n.Ninit.Set -> n.PtrNinit().Set
n.Ninit.Set1 -> n.PtrNinit().Set1
n.Ninit.Set2 -> n.PtrNinit().Set2
n.Ninit.Set3 -> n.PtrNinit().Set3
&n.Ninit -> n.PtrNinit()
n.Ninit = nodes -> n.SetNinit(nodes)
n.Nbody.Append -> n.PtrNbody().Append
n.Nbody.AppendNodes -> n.PtrNbody().AppendNodes
n.Nbody.MoveNodes -> n.PtrNbody().MoveNodes
n.Nbody.Prepend -> n.PtrNbody().Prepend
n.Nbody.Set -> n.PtrNbody().Set
n.Nbody.Set1 -> n.PtrNbody().Set1
n.Nbody.Set2 -> n.PtrNbody().Set2
n.Nbody.Set3 -> n.PtrNbody().Set3
&n.Nbody -> n.PtrNbody()
n.Nbody = nodes -> n.SetNbody(nodes)
n.List.Append -> n.PtrList().Append
n.List.AppendNodes -> n.PtrList().AppendNodes
n.List.MoveNodes -> n.PtrList().MoveNodes
n.List.Prepend -> n.PtrList().Prepend
n.List.Set -> n.PtrList().Set
n.List.Set1 -> n.PtrList().Set1
n.List.Set2 -> n.PtrList().Set2
n.List.Set3 -> n.PtrList().Set3
&n.List -> n.PtrList()
n.List = nodes -> n.SetList(nodes)
n.Rlist.Append -> n.PtrRlist().Append
n.Rlist.AppendNodes -> n.PtrRlist().AppendNodes
n.Rlist.MoveNodes -> n.PtrRlist().MoveNodes
n.Rlist.Prepend -> n.PtrRlist().Prepend
n.Rlist.Set -> n.PtrRlist().Set
n.Rlist.Set1 -> n.PtrRlist().Set1
n.Rlist.Set2 -> n.PtrRlist().Set2
n.Rlist.Set3 -> n.PtrRlist().Set3
&n.Rlist -> n.PtrRlist()
n.Rlist = nodes -> n.SetRlist(nodes)
}
ex . ../ir ../ssa {
import "cmd/compile/internal/ir"
var n *ir.Node
n.Op -> n.GetOp()
n.Left -> n.GetLeft()
n.Right -> n.GetRight()
n.Orig -> n.GetOrig()
n.Type -> n.GetType()
n.Func -> n.GetFunc()
n.Name -> n.GetName()
n.Sym -> n.GetSym()
n.Pos -> n.GetPos()
n.Xoffset -> n.GetXoffset()
n.Esc -> n.GetEsc()
avoid (*ir.Node).PtrNinit
avoid (*ir.Node).PtrNbody
avoid (*ir.Node).PtrList
avoid (*ir.Node).PtrRlist
n.Ninit -> n.GetNinit()
n.Nbody -> n.GetNbody()
n.List -> n.GetList()
n.Rlist -> n.GetRlist()
}
'
cd ../ir
rf '
mv Node.Op Node.op
mv Node.GetOp Node.Op
mv Node.Left Node.left
mv Node.GetLeft Node.Left
mv Node.Right Node.right
mv Node.GetRight Node.Right
mv Node.Orig Node.orig
mv Node.GetOrig Node.Orig
mv Node.Type Node.typ
mv Node.GetType Node.Type
mv Node.Func Node.fn
mv Node.GetFunc Node.Func
mv Node.Name Node.name
mv Node.GetName Node.Name
# All uses are in other Node methods already.
mv Node.E Node.e
mv Node.Sym Node.sym
mv Node.GetSym Node.Sym
mv Node.Pos Node.pos
mv Node.GetPos Node.Pos
mv Node.Esc Node.esc
mv Node.GetEsc Node.Esc
# While we are here, rename Xoffset to more idiomatic Offset.
mv Node.Xoffset Node.offset
mv Node.GetXoffset Node.Offset
mv Node.SetXoffset Node.SetOffset
# While we are here, rename Ninit, Nbody to more idiomatic Init, Body.
mv Node.Ninit Node.init
mv Node.GetNinit Node.Init
mv Node.PtrNinit Node.PtrInit
mv Node.SetNinit Node.SetInit
mv Node.Nbody Node.body
mv Node.GetNbody Node.Body
mv Node.PtrNbody Node.PtrBody
mv Node.SetNbody Node.SetBody
mv Node.List Node.list
mv Node.GetList Node.List
mv Node.Rlist Node.rlist
mv Node.GetRlist Node.Rlist
# Unexport these
mv Node.SetHasOpt Node.setHasOpt
mv Node.SetHasVal Node.setHasVal
'
Change-Id: I9894f633375c5237a29b6d6d7b89ba181b56ca3a
Reviewed-on: https://go-review.googlesource.com/c/go/+/273009
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
41ab6689ed
commit
acb4d1cef1
44 changed files with 5188 additions and 5186 deletions
|
|
@ -14,36 +14,36 @@ import (
|
|||
func typecheckselect(sel *ir.Node) {
|
||||
var def *ir.Node
|
||||
lno := setlineno(sel)
|
||||
typecheckslice(sel.Ninit.Slice(), ctxStmt)
|
||||
for _, ncase := range sel.List.Slice() {
|
||||
if ncase.Op != ir.OCASE {
|
||||
typecheckslice(sel.Init().Slice(), ctxStmt)
|
||||
for _, ncase := range sel.List().Slice() {
|
||||
if ncase.Op() != ir.OCASE {
|
||||
setlineno(ncase)
|
||||
base.Fatalf("typecheckselect %v", ncase.Op)
|
||||
base.Fatalf("typecheckselect %v", ncase.Op())
|
||||
}
|
||||
|
||||
if ncase.List.Len() == 0 {
|
||||
if ncase.List().Len() == 0 {
|
||||
// default
|
||||
if def != nil {
|
||||
base.ErrorfAt(ncase.Pos, "multiple defaults in select (first at %v)", ir.Line(def))
|
||||
base.ErrorfAt(ncase.Pos(), "multiple defaults in select (first at %v)", ir.Line(def))
|
||||
} else {
|
||||
def = ncase
|
||||
}
|
||||
} else if ncase.List.Len() > 1 {
|
||||
base.ErrorfAt(ncase.Pos, "select cases cannot be lists")
|
||||
} else if ncase.List().Len() > 1 {
|
||||
base.ErrorfAt(ncase.Pos(), "select cases cannot be lists")
|
||||
} else {
|
||||
ncase.List.SetFirst(typecheck(ncase.List.First(), ctxStmt))
|
||||
n := ncase.List.First()
|
||||
ncase.Left = n
|
||||
ncase.List.Set(nil)
|
||||
switch n.Op {
|
||||
ncase.List().SetFirst(typecheck(ncase.List().First(), ctxStmt))
|
||||
n := ncase.List().First()
|
||||
ncase.SetLeft(n)
|
||||
ncase.PtrList().Set(nil)
|
||||
switch n.Op() {
|
||||
default:
|
||||
pos := n.Pos
|
||||
if n.Op == ir.ONAME {
|
||||
pos := n.Pos()
|
||||
if n.Op() == ir.ONAME {
|
||||
// We don't have the right position for ONAME nodes (see #15459 and
|
||||
// others). Using ncase.Pos for now as it will provide the correct
|
||||
// line number (assuming the expression follows the "case" keyword
|
||||
// on the same line). This matches the approach before 1.10.
|
||||
pos = ncase.Pos
|
||||
pos = ncase.Pos()
|
||||
}
|
||||
base.ErrorfAt(pos, "select case must be receive, send or assign recv")
|
||||
|
||||
|
|
@ -51,41 +51,41 @@ func typecheckselect(sel *ir.Node) {
|
|||
// remove implicit conversions; the eventual assignment
|
||||
// will reintroduce them.
|
||||
case ir.OAS:
|
||||
if (n.Right.Op == ir.OCONVNOP || n.Right.Op == ir.OCONVIFACE) && n.Right.Implicit() {
|
||||
n.Right = n.Right.Left
|
||||
if (n.Right().Op() == ir.OCONVNOP || n.Right().Op() == ir.OCONVIFACE) && n.Right().Implicit() {
|
||||
n.SetRight(n.Right().Left())
|
||||
}
|
||||
|
||||
if n.Right.Op != ir.ORECV {
|
||||
base.ErrorfAt(n.Pos, "select assignment must have receive on right hand side")
|
||||
if n.Right().Op() != ir.ORECV {
|
||||
base.ErrorfAt(n.Pos(), "select assignment must have receive on right hand side")
|
||||
break
|
||||
}
|
||||
|
||||
n.Op = ir.OSELRECV
|
||||
n.SetOp(ir.OSELRECV)
|
||||
|
||||
// convert x, ok = <-c into OSELRECV2(x, <-c) with ntest=ok
|
||||
case ir.OAS2RECV:
|
||||
if n.Right.Op != ir.ORECV {
|
||||
base.ErrorfAt(n.Pos, "select assignment must have receive on right hand side")
|
||||
if n.Right().Op() != ir.ORECV {
|
||||
base.ErrorfAt(n.Pos(), "select assignment must have receive on right hand side")
|
||||
break
|
||||
}
|
||||
|
||||
n.Op = ir.OSELRECV2
|
||||
n.Left = n.List.First()
|
||||
n.List.Set1(n.List.Second())
|
||||
n.SetOp(ir.OSELRECV2)
|
||||
n.SetLeft(n.List().First())
|
||||
n.PtrList().Set1(n.List().Second())
|
||||
|
||||
// convert <-c into OSELRECV(N, <-c)
|
||||
case ir.ORECV:
|
||||
n = ir.NodAt(n.Pos, ir.OSELRECV, nil, n)
|
||||
n = ir.NodAt(n.Pos(), ir.OSELRECV, nil, n)
|
||||
|
||||
n.SetTypecheck(1)
|
||||
ncase.Left = n
|
||||
ncase.SetLeft(n)
|
||||
|
||||
case ir.OSEND:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
typecheckslice(ncase.Nbody.Slice(), ctxStmt)
|
||||
typecheckslice(ncase.Body().Slice(), ctxStmt)
|
||||
}
|
||||
|
||||
base.Pos = lno
|
||||
|
|
@ -93,18 +93,18 @@ func typecheckselect(sel *ir.Node) {
|
|||
|
||||
func walkselect(sel *ir.Node) {
|
||||
lno := setlineno(sel)
|
||||
if sel.Nbody.Len() != 0 {
|
||||
if sel.Body().Len() != 0 {
|
||||
base.Fatalf("double walkselect")
|
||||
}
|
||||
|
||||
init := sel.Ninit.Slice()
|
||||
sel.Ninit.Set(nil)
|
||||
init := sel.Init().Slice()
|
||||
sel.PtrInit().Set(nil)
|
||||
|
||||
init = append(init, walkselectcases(&sel.List)...)
|
||||
sel.List.Set(nil)
|
||||
init = append(init, walkselectcases(sel.PtrList())...)
|
||||
sel.PtrList().Set(nil)
|
||||
|
||||
sel.Nbody.Set(init)
|
||||
walkstmtlist(sel.Nbody.Slice())
|
||||
sel.PtrBody().Set(init)
|
||||
walkstmtlist(sel.Body().Slice())
|
||||
|
||||
base.Pos = lno
|
||||
}
|
||||
|
|
@ -122,38 +122,38 @@ func walkselectcases(cases *ir.Nodes) []*ir.Node {
|
|||
if ncas == 1 {
|
||||
cas := cases.First()
|
||||
setlineno(cas)
|
||||
l := cas.Ninit.Slice()
|
||||
if cas.Left != nil { // not default:
|
||||
n := cas.Left
|
||||
l = append(l, n.Ninit.Slice()...)
|
||||
n.Ninit.Set(nil)
|
||||
switch n.Op {
|
||||
l := cas.Init().Slice()
|
||||
if cas.Left() != nil { // not default:
|
||||
n := cas.Left()
|
||||
l = append(l, n.Init().Slice()...)
|
||||
n.PtrInit().Set(nil)
|
||||
switch n.Op() {
|
||||
default:
|
||||
base.Fatalf("select %v", n.Op)
|
||||
base.Fatalf("select %v", n.Op())
|
||||
|
||||
case ir.OSEND:
|
||||
// already ok
|
||||
|
||||
case ir.OSELRECV, ir.OSELRECV2:
|
||||
if n.Op == ir.OSELRECV || n.List.Len() == 0 {
|
||||
if n.Left == nil {
|
||||
n = n.Right
|
||||
if n.Op() == ir.OSELRECV || n.List().Len() == 0 {
|
||||
if n.Left() == nil {
|
||||
n = n.Right()
|
||||
} else {
|
||||
n.Op = ir.OAS
|
||||
n.SetOp(ir.OAS)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if n.Left == nil {
|
||||
if n.Left() == nil {
|
||||
ir.BlankNode = typecheck(ir.BlankNode, ctxExpr|ctxAssign)
|
||||
n.Left = ir.BlankNode
|
||||
n.SetLeft(ir.BlankNode)
|
||||
}
|
||||
|
||||
n.Op = ir.OAS2
|
||||
n.List.Prepend(n.Left)
|
||||
n.Rlist.Set1(n.Right)
|
||||
n.Right = nil
|
||||
n.Left = nil
|
||||
n.SetOp(ir.OAS2)
|
||||
n.PtrList().Prepend(n.Left())
|
||||
n.PtrRlist().Set1(n.Right())
|
||||
n.SetRight(nil)
|
||||
n.SetLeft(nil)
|
||||
n.SetTypecheck(0)
|
||||
n = typecheck(n, ctxStmt)
|
||||
}
|
||||
|
|
@ -161,7 +161,7 @@ func walkselectcases(cases *ir.Nodes) []*ir.Node {
|
|||
l = append(l, n)
|
||||
}
|
||||
|
||||
l = append(l, cas.Nbody.Slice()...)
|
||||
l = append(l, cas.Body().Slice()...)
|
||||
l = append(l, ir.Nod(ir.OBREAK, nil, nil))
|
||||
return l
|
||||
}
|
||||
|
|
@ -171,24 +171,24 @@ func walkselectcases(cases *ir.Nodes) []*ir.Node {
|
|||
var dflt *ir.Node
|
||||
for _, cas := range cases.Slice() {
|
||||
setlineno(cas)
|
||||
n := cas.Left
|
||||
n := cas.Left()
|
||||
if n == nil {
|
||||
dflt = cas
|
||||
continue
|
||||
}
|
||||
switch n.Op {
|
||||
switch n.Op() {
|
||||
case ir.OSEND:
|
||||
n.Right = ir.Nod(ir.OADDR, n.Right, nil)
|
||||
n.Right = typecheck(n.Right, ctxExpr)
|
||||
n.SetRight(ir.Nod(ir.OADDR, n.Right(), nil))
|
||||
n.SetRight(typecheck(n.Right(), ctxExpr))
|
||||
|
||||
case ir.OSELRECV, ir.OSELRECV2:
|
||||
if n.Op == ir.OSELRECV2 && n.List.Len() == 0 {
|
||||
n.Op = ir.OSELRECV
|
||||
if n.Op() == ir.OSELRECV2 && n.List().Len() == 0 {
|
||||
n.SetOp(ir.OSELRECV)
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
n.Left = ir.Nod(ir.OADDR, n.Left, nil)
|
||||
n.Left = typecheck(n.Left, ctxExpr)
|
||||
if n.Left() != nil {
|
||||
n.SetLeft(ir.Nod(ir.OADDR, n.Left(), nil))
|
||||
n.SetLeft(typecheck(n.Left(), ctxExpr))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -200,43 +200,43 @@ func walkselectcases(cases *ir.Nodes) []*ir.Node {
|
|||
cas = cases.Second()
|
||||
}
|
||||
|
||||
n := cas.Left
|
||||
n := cas.Left()
|
||||
setlineno(n)
|
||||
r := ir.Nod(ir.OIF, nil, nil)
|
||||
r.Ninit.Set(cas.Ninit.Slice())
|
||||
switch n.Op {
|
||||
r.PtrInit().Set(cas.Init().Slice())
|
||||
switch n.Op() {
|
||||
default:
|
||||
base.Fatalf("select %v", n.Op)
|
||||
base.Fatalf("select %v", n.Op())
|
||||
|
||||
case ir.OSEND:
|
||||
// if selectnbsend(c, v) { body } else { default body }
|
||||
ch := n.Left
|
||||
r.Left = mkcall1(chanfn("selectnbsend", 2, ch.Type), types.Types[types.TBOOL], &r.Ninit, ch, n.Right)
|
||||
ch := n.Left()
|
||||
r.SetLeft(mkcall1(chanfn("selectnbsend", 2, ch.Type()), types.Types[types.TBOOL], r.PtrInit(), ch, n.Right()))
|
||||
|
||||
case ir.OSELRECV:
|
||||
// if selectnbrecv(&v, c) { body } else { default body }
|
||||
ch := n.Right.Left
|
||||
elem := n.Left
|
||||
ch := n.Right().Left()
|
||||
elem := n.Left()
|
||||
if elem == nil {
|
||||
elem = nodnil()
|
||||
}
|
||||
r.Left = mkcall1(chanfn("selectnbrecv", 2, ch.Type), types.Types[types.TBOOL], &r.Ninit, elem, ch)
|
||||
r.SetLeft(mkcall1(chanfn("selectnbrecv", 2, ch.Type()), types.Types[types.TBOOL], r.PtrInit(), elem, ch))
|
||||
|
||||
case ir.OSELRECV2:
|
||||
// if selectnbrecv2(&v, &received, c) { body } else { default body }
|
||||
ch := n.Right.Left
|
||||
elem := n.Left
|
||||
ch := n.Right().Left()
|
||||
elem := n.Left()
|
||||
if elem == nil {
|
||||
elem = nodnil()
|
||||
}
|
||||
receivedp := ir.Nod(ir.OADDR, n.List.First(), nil)
|
||||
receivedp := ir.Nod(ir.OADDR, n.List().First(), nil)
|
||||
receivedp = typecheck(receivedp, ctxExpr)
|
||||
r.Left = mkcall1(chanfn("selectnbrecv2", 2, ch.Type), types.Types[types.TBOOL], &r.Ninit, elem, receivedp, ch)
|
||||
r.SetLeft(mkcall1(chanfn("selectnbrecv2", 2, ch.Type()), types.Types[types.TBOOL], r.PtrInit(), elem, receivedp, ch))
|
||||
}
|
||||
|
||||
r.Left = typecheck(r.Left, ctxExpr)
|
||||
r.Nbody.Set(cas.Nbody.Slice())
|
||||
r.Rlist.Set(append(dflt.Ninit.Slice(), dflt.Nbody.Slice()...))
|
||||
r.SetLeft(typecheck(r.Left(), ctxExpr))
|
||||
r.PtrBody().Set(cas.Body().Slice())
|
||||
r.PtrRlist().Set(append(dflt.Init().Slice(), dflt.Body().Slice()...))
|
||||
return []*ir.Node{r, ir.Nod(ir.OBREAK, nil, nil)}
|
||||
}
|
||||
|
||||
|
|
@ -270,29 +270,29 @@ func walkselectcases(cases *ir.Nodes) []*ir.Node {
|
|||
for _, cas := range cases.Slice() {
|
||||
setlineno(cas)
|
||||
|
||||
init = append(init, cas.Ninit.Slice()...)
|
||||
cas.Ninit.Set(nil)
|
||||
init = append(init, cas.Init().Slice()...)
|
||||
cas.PtrInit().Set(nil)
|
||||
|
||||
n := cas.Left
|
||||
n := cas.Left()
|
||||
if n == nil { // default:
|
||||
continue
|
||||
}
|
||||
|
||||
var i int
|
||||
var c, elem *ir.Node
|
||||
switch n.Op {
|
||||
switch n.Op() {
|
||||
default:
|
||||
base.Fatalf("select %v", n.Op)
|
||||
base.Fatalf("select %v", n.Op())
|
||||
case ir.OSEND:
|
||||
i = nsends
|
||||
nsends++
|
||||
c = n.Left
|
||||
elem = n.Right
|
||||
c = n.Left()
|
||||
elem = n.Right()
|
||||
case ir.OSELRECV, ir.OSELRECV2:
|
||||
nrecvs++
|
||||
i = ncas - nrecvs
|
||||
c = n.Right.Left
|
||||
elem = n.Left
|
||||
c = n.Right().Left()
|
||||
elem = n.Left()
|
||||
}
|
||||
|
||||
casorder[i] = cas
|
||||
|
|
@ -326,9 +326,9 @@ func walkselectcases(cases *ir.Nodes) []*ir.Node {
|
|||
chosen := temp(types.Types[types.TINT])
|
||||
recvOK := temp(types.Types[types.TBOOL])
|
||||
r = ir.Nod(ir.OAS2, nil, nil)
|
||||
r.List.Set2(chosen, recvOK)
|
||||
r.PtrList().Set2(chosen, recvOK)
|
||||
fn := syslook("selectgo")
|
||||
r.Rlist.Set1(mkcall1(fn, fn.Type.Results(), nil, bytePtrToIndex(selv, 0), bytePtrToIndex(order, 0), pc0, nodintconst(int64(nsends)), nodintconst(int64(nrecvs)), nodbool(dflt == nil)))
|
||||
r.PtrRlist().Set1(mkcall1(fn, fn.Type().Results(), nil, bytePtrToIndex(selv, 0), bytePtrToIndex(order, 0), pc0, nodintconst(int64(nsends)), nodintconst(int64(nrecvs)), nodbool(dflt == nil)))
|
||||
r = typecheck(r, ctxStmt)
|
||||
init = append(init, r)
|
||||
|
||||
|
|
@ -346,14 +346,14 @@ func walkselectcases(cases *ir.Nodes) []*ir.Node {
|
|||
|
||||
r := ir.Nod(ir.OIF, cond, nil)
|
||||
|
||||
if n := cas.Left; n != nil && n.Op == ir.OSELRECV2 {
|
||||
x := ir.Nod(ir.OAS, n.List.First(), recvOK)
|
||||
if n := cas.Left(); n != nil && n.Op() == ir.OSELRECV2 {
|
||||
x := ir.Nod(ir.OAS, n.List().First(), recvOK)
|
||||
x = typecheck(x, ctxStmt)
|
||||
r.Nbody.Append(x)
|
||||
r.PtrBody().Append(x)
|
||||
}
|
||||
|
||||
r.Nbody.AppendNodes(&cas.Nbody)
|
||||
r.Nbody.Append(ir.Nod(ir.OBREAK, nil, nil))
|
||||
r.PtrBody().AppendNodes(cas.PtrBody())
|
||||
r.PtrBody().Append(ir.Nod(ir.OBREAK, nil, nil))
|
||||
init = append(init, r)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue