mirror of
https://github.com/golang/go
synced 2024-11-17 10:34:49 -07:00
[dev.regabi] cmd/compile: allow visitor visits *ir.Name
So future CLs can refactor ir.Node to *ir.Name when possible. Passes toolstash -cmp. Change-Id: I91ae38417ba10de207ed84b65d1d69cf64f24456 Reviewed-on: https://go-review.googlesource.com/c/go/+/279448 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
5cf3c87fa6
commit
37babc97bb
@ -35,6 +35,7 @@ func main() {
|
||||
}
|
||||
|
||||
nodeType := lookup("Node")
|
||||
ptrNameType := types.NewPointer(lookup("Name"))
|
||||
ntypeType := lookup("Ntype")
|
||||
nodesType := lookup("Nodes")
|
||||
slicePtrCaseClauseType := types.NewSlice(types.NewPointer(lookup("CaseClause")))
|
||||
@ -94,7 +95,7 @@ func main() {
|
||||
fmt.Fprintf(&buf, "func (n *%s) doChildren(do func(Node) error) error { var err error\n", name)
|
||||
forNodeFields(typName, typ, func(name string, is func(types.Type) bool) {
|
||||
switch {
|
||||
case is(ptrIdentType):
|
||||
case is(ptrIdentType), is(ptrNameType):
|
||||
fmt.Fprintf(&buf, "if n.%s != nil { err = maybeDo(n.%s, err, do) }\n", name, name)
|
||||
case is(nodeType), is(ntypeType):
|
||||
fmt.Fprintf(&buf, "err = maybeDo(n.%s, err, do)\n", name)
|
||||
@ -117,6 +118,8 @@ func main() {
|
||||
switch {
|
||||
case is(ptrIdentType):
|
||||
fmt.Fprintf(&buf, "if n.%s != nil { n.%s = edit(n.%s).(*Ident) }\n", name, name, name)
|
||||
case is(ptrNameType):
|
||||
fmt.Fprintf(&buf, "if n.%s != nil { n.%s = edit(n.%s).(*Name) }\n", name, name, name)
|
||||
case is(nodeType):
|
||||
fmt.Fprintf(&buf, "n.%s = maybeEdit(n.%s, edit)\n", name, name)
|
||||
case is(ntypeType):
|
||||
|
@ -15,11 +15,17 @@ func (n *AddStringExpr) doChildren(do func(Node) error) error {
|
||||
var err error
|
||||
err = maybeDoList(n.init, err, do)
|
||||
err = maybeDoList(n.List, err, do)
|
||||
if n.Prealloc != nil {
|
||||
err = maybeDo(n.Prealloc, err, do)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (n *AddStringExpr) editChildren(edit func(Node) Node) {
|
||||
editList(n.init, edit)
|
||||
editList(n.List, edit)
|
||||
if n.Prealloc != nil {
|
||||
n.Prealloc = edit(n.Prealloc).(*Name)
|
||||
}
|
||||
}
|
||||
|
||||
func (n *AddrExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||
@ -32,11 +38,17 @@ func (n *AddrExpr) doChildren(do func(Node) error) error {
|
||||
var err error
|
||||
err = maybeDoList(n.init, err, do)
|
||||
err = maybeDo(n.X, err, do)
|
||||
if n.Alloc != nil {
|
||||
err = maybeDo(n.Alloc, err, do)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (n *AddrExpr) editChildren(edit func(Node) Node) {
|
||||
editList(n.init, edit)
|
||||
n.X = maybeEdit(n.X, edit)
|
||||
if n.Alloc != nil {
|
||||
n.Alloc = edit(n.Alloc).(*Name)
|
||||
}
|
||||
}
|
||||
|
||||
func (n *ArrayType) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||
@ -253,10 +265,16 @@ func (n *ClosureExpr) copy() Node {
|
||||
func (n *ClosureExpr) doChildren(do func(Node) error) error {
|
||||
var err error
|
||||
err = maybeDoList(n.init, err, do)
|
||||
if n.Prealloc != nil {
|
||||
err = maybeDo(n.Prealloc, err, do)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (n *ClosureExpr) editChildren(edit func(Node) Node) {
|
||||
editList(n.init, edit)
|
||||
if n.Prealloc != nil {
|
||||
n.Prealloc = edit(n.Prealloc).(*Name)
|
||||
}
|
||||
}
|
||||
|
||||
func (n *ClosureReadExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||
@ -306,12 +324,18 @@ func (n *CompLitExpr) doChildren(do func(Node) error) error {
|
||||
err = maybeDoList(n.init, err, do)
|
||||
err = maybeDo(n.Ntype, err, do)
|
||||
err = maybeDoList(n.List, err, do)
|
||||
if n.Prealloc != nil {
|
||||
err = maybeDo(n.Prealloc, err, do)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (n *CompLitExpr) editChildren(edit func(Node) Node) {
|
||||
editList(n.init, edit)
|
||||
n.Ntype = toNtype(maybeEdit(n.Ntype, edit))
|
||||
editList(n.List, edit)
|
||||
if n.Prealloc != nil {
|
||||
n.Prealloc = edit(n.Prealloc).(*Name)
|
||||
}
|
||||
}
|
||||
|
||||
func (n *ConstExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||
@ -654,10 +678,16 @@ func (n *NameOffsetExpr) copy() Node {
|
||||
func (n *NameOffsetExpr) doChildren(do func(Node) error) error {
|
||||
var err error
|
||||
err = maybeDoList(n.init, err, do)
|
||||
if n.Name_ != nil {
|
||||
err = maybeDo(n.Name_, err, do)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (n *NameOffsetExpr) editChildren(edit func(Node) Node) {
|
||||
editList(n.init, edit)
|
||||
if n.Name_ != nil {
|
||||
n.Name_ = edit(n.Name_).(*Name)
|
||||
}
|
||||
}
|
||||
|
||||
func (n *NilExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||
@ -718,6 +748,9 @@ func (n *RangeStmt) doChildren(do func(Node) error) error {
|
||||
err = maybeDo(n.Key, err, do)
|
||||
err = maybeDo(n.Value, err, do)
|
||||
err = maybeDoList(n.Body, err, do)
|
||||
if n.Prealloc != nil {
|
||||
err = maybeDo(n.Prealloc, err, do)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (n *RangeStmt) editChildren(edit func(Node) Node) {
|
||||
@ -726,6 +759,9 @@ func (n *RangeStmt) editChildren(edit func(Node) Node) {
|
||||
n.Key = maybeEdit(n.Key, edit)
|
||||
n.Value = maybeEdit(n.Value, edit)
|
||||
editList(n.Body, edit)
|
||||
if n.Prealloc != nil {
|
||||
n.Prealloc = edit(n.Prealloc).(*Name)
|
||||
}
|
||||
}
|
||||
|
||||
func (n *ResultExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||
@ -792,11 +828,17 @@ func (n *SelectorExpr) doChildren(do func(Node) error) error {
|
||||
var err error
|
||||
err = maybeDoList(n.init, err, do)
|
||||
err = maybeDo(n.X, err, do)
|
||||
if n.Prealloc != nil {
|
||||
err = maybeDo(n.Prealloc, err, do)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (n *SelectorExpr) editChildren(edit func(Node) Node) {
|
||||
editList(n.init, edit)
|
||||
n.X = maybeEdit(n.X, edit)
|
||||
if n.Prealloc != nil {
|
||||
n.Prealloc = edit(n.Prealloc).(*Name)
|
||||
}
|
||||
}
|
||||
|
||||
func (n *SendStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||
|
Loading…
Reference in New Issue
Block a user