Put each node in charge of its EditChildren implementation.
This removes the final generic use of Left, SetLeft, Right, SetRight,
and so on in package ir.
Passes buildall w/ toolstash -cmp.
Change-Id: I9821cc20f5b91cc9b44eb1f386cc82f20cd6770c
Reviewed-on: https://go-review.googlesource.com/c/go/+/275376
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
return err
}
+func maybeEdit(x Node, edit func(Node) Node) Node {
+ if x == nil {
+ return x
+ }
+ return edit(x)
+}
+
// A miniStmt is a miniNode with extra fields common to expressions.
// TODO(rsc): Once we are sure about the contents, compact the bools
// into a bit field and leave extra bits available for implementations
err = maybeDoList(n.list, err, do)
return err
}
+func (n *AddStringExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ editList(n.list, edit)
+}
func (n *AddStringExpr) List() Nodes { return n.list }
func (n *AddStringExpr) PtrList() *Nodes { return &n.list }
err = maybeDo(n.X, err, do)
return err
}
+func (n *AddrExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+}
func (n *AddrExpr) Left() Node { return n.X }
func (n *AddrExpr) SetLeft(x Node) { n.X = x }
err = maybeDo(n.Y, err, do)
return err
}
+func (n *BinaryExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+ n.Y = maybeEdit(n.Y, edit)
+}
func (n *BinaryExpr) Left() Node { return n.X }
func (n *BinaryExpr) SetLeft(x Node) { n.X = x }
err = maybeDoList(n.body, err, do)
return err
}
+func (n *CallExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+ editList(n.Args, edit)
+ editList(n.Rargs, edit)
+ editList(n.body, edit)
+}
func (n *CallExpr) Orig() Node { return n.orig }
func (n *CallExpr) SetOrig(x Node) { n.orig = x }
err = maybeDo(n.X, err, do)
return err
}
+func (n *CallPartExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+}
func (n *CallPartExpr) Func() *Func { return n.fn }
func (n *CallPartExpr) Left() Node { return n.X }
err = maybeDoList(n.init, err, do)
return err
}
+func (n *ClosureExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+}
func (n *ClosureExpr) Func() *Func { return n.fn }
err = maybeDoList(n.init, err, do)
return err
}
+func (n *ClosureRead) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+}
// A CompLitExpr is a composite literal Type{Vals}.
// Before type-checking, the type is Ntype.
err = maybeDoList(n.list, 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)
+}
func (n *CompLitExpr) Orig() Node { return n.orig }
func (n *CompLitExpr) SetOrig(x Node) { n.orig = x }
func (n *ConstExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *ConstExpr) copy() Node { c := *n; return &c }
func (n *ConstExpr) doChildren(do func(Node) error) error { return nil }
+func (n *ConstExpr) editChildren(edit func(Node) Node) {}
func (n *ConstExpr) Sym() *types.Sym { return n.orig.Sym() }
func (n *ConstExpr) Orig() Node { return n.orig }
err = maybeDo(n.X, err, do)
return err
}
+func (n *ConvExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+}
func (n *ConvExpr) rawCopy() Node { c := *n; return &c }
func (n *ConvExpr) Left() Node { return n.X }
err = maybeDo(n.Index, err, do)
return err
}
+func (n *IndexExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+ n.Index = maybeEdit(n.Index, edit)
+}
func (n *IndexExpr) Left() Node { return n.X }
func (n *IndexExpr) SetLeft(x Node) { n.X = x }
err = maybeDo(n.Value, err, do)
return err
}
+func (n *KeyExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.Key = maybeEdit(n.Key, edit)
+ n.Value = maybeEdit(n.Value, edit)
+}
func (n *KeyExpr) Left() Node { return n.Key }
func (n *KeyExpr) SetLeft(x Node) { n.Key = x }
err = maybeDoList(n.ReturnVars, err, do)
return err
}
+func (n *InlinedCallExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ editList(n.body, edit)
+ editList(n.ReturnVars, edit)
+}
func (n *InlinedCallExpr) Body() Nodes { return n.body }
func (n *InlinedCallExpr) PtrBody() *Nodes { return &n.body }
err = maybeDo(n.Cap, err, do)
return err
}
+func (n *MakeExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.Len = maybeEdit(n.Len, edit)
+ n.Cap = maybeEdit(n.Cap, edit)
+}
func (n *MakeExpr) Left() Node { return n.Len }
func (n *MakeExpr) SetLeft(x Node) { n.Len = x }
err = maybeDo(n.M, err, do)
return err
}
+func (n *MethodExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+ n.M = maybeEdit(n.M, edit)
+}
func (n *MethodExpr) Left() Node { return n.X }
func (n *MethodExpr) SetLeft(x Node) { n.X = x }
err = maybeDoList(n.init, err, do)
return err
}
+func (n *NilExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+}
func (n *NilExpr) Sym() *types.Sym { return n.sym }
func (n *NilExpr) SetSym(x *types.Sym) { n.sym = x }
err = maybeDo(n.X, err, do)
return err
}
+func (n *ParenExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+}
func (n *ParenExpr) Left() Node { return n.X }
func (n *ParenExpr) SetLeft(x Node) { n.X = x }
err = maybeDoList(n.init, err, do)
return err
}
+func (n *ResultExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+}
func (n *ResultExpr) Offset() int64 { return n.offset }
func (n *ResultExpr) SetOffset(x int64) { n.offset = x }
err = maybeDo(n.X, err, do)
return err
}
+func (n *SelectorExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+}
func (n *SelectorExpr) Left() Node { return n.X }
func (n *SelectorExpr) SetLeft(x Node) { n.X = x }
err = maybeDoList(n.list, err, do)
return err
}
+func (n *SliceExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+ editList(n.list, edit)
+}
func (n *SliceExpr) Left() Node { return n.X }
func (n *SliceExpr) SetLeft(x Node) { n.X = x }
err = maybeDoList(n.lenCap, err, do)
return err
}
+func (n *SliceHeaderExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.Ptr = maybeEdit(n.Ptr, edit)
+ editList(n.lenCap, edit)
+}
func (n *SliceHeaderExpr) Left() Node { return n.Ptr }
func (n *SliceHeaderExpr) SetLeft(x Node) { n.Ptr = x }
err = maybeDo(n.X, err, do)
return err
}
+func (n *StarExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+}
func (n *StarExpr) Left() Node { return n.X }
func (n *StarExpr) SetLeft(x Node) { n.X = x }
err = maybeDoList(n.Itab, err, do)
return err
}
+func (n *TypeAssertExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+ n.Ntype = maybeEdit(n.Ntype, edit)
+ editList(n.Itab, edit)
+}
func (n *TypeAssertExpr) Left() Node { return n.X }
func (n *TypeAssertExpr) SetLeft(x Node) { n.X = x }
err = maybeDo(n.X, err, do)
return err
}
+func (n *UnaryExpr) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+}
func (n *UnaryExpr) Left() Node { return n.X }
func (n *UnaryExpr) SetLeft(x Node) { n.X = x }
err = maybeDoList(f.body, err, do)
return err
}
+func (f *Func) editChildren(edit func(Node) Node) {
+ editList(f.body, edit)
+}
func (f *Func) Func() *Func { return f }
func (f *Func) Body() Nodes { return f.body }
func (n *Name) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *Name) copy() Node { c := *n; return &c }
func (n *Name) doChildren(do func(Node) error) error { return nil }
+func (n *Name) editChildren(edit func(Node) Node) {}
func (n *Name) Name() *Name { return n }
func (n *Name) Sym() *types.Sym { return n.sym }
func (p *PkgName) Format(s fmt.State, verb rune) { FmtNode(p, s, verb) }
func (p *PkgName) copy() Node { c := *p; return &c }
func (p *PkgName) doChildren(do func(Node) error) error { return nil }
+func (p *PkgName) editChildren(edit func(Node) Node) {}
func (p *PkgName) Sym() *types.Sym { return p.sym }
copy() Node
doChildren(func(Node) error) error
+ editChildren(func(Node) Node)
// Abstract graph structure, for generic traversals.
Op() Op
err = maybeDo(n.X, err, do)
return err
}
+func (n *Decl) editChildren(edit func(Node) Node) {
+ n.X = maybeEdit(n.X, edit)
+}
func (n *Decl) Left() Node { return n.X }
func (n *Decl) SetLeft(x Node) { n.X = x }
err = maybeDoList(n.Rhs, err, do)
return err
}
+func (n *AssignListStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ editList(n.Lhs, edit)
+ editList(n.Rhs, edit)
+}
func (n *AssignListStmt) List() Nodes { return n.Lhs }
func (n *AssignListStmt) PtrList() *Nodes { return &n.Lhs }
err = maybeDo(n.Y, err, do)
return err
}
+func (n *AssignStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+ n.Y = maybeEdit(n.Y, edit)
+}
func (n *AssignStmt) Left() Node { return n.X }
func (n *AssignStmt) SetLeft(x Node) { n.X = x }
err = maybeDo(n.Y, err, do)
return err
}
+func (n *AssignOpStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.X = maybeEdit(n.X, edit)
+ n.Y = maybeEdit(n.Y, edit)
+}
func (n *AssignOpStmt) Left() Node { return n.X }
func (n *AssignOpStmt) SetLeft(x Node) { n.X = x }
err = maybeDoList(n.list, err, do)
return err
}
+func (n *BlockStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ editList(n.list, edit)
+}
func (n *BlockStmt) List() Nodes { return n.list }
func (n *BlockStmt) PtrList() *Nodes { return &n.list }
err = maybeDoList(n.init, err, do)
return err
}
+func (n *BranchStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+}
func (n *BranchStmt) Sym() *types.Sym { return n.Label }
func (n *BranchStmt) SetSym(sym *types.Sym) { n.Label = sym }
err = maybeDoList(n.body, err, do)
return err
}
+func (n *CaseStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ editList(n.Vars, edit)
+ editList(n.list, edit)
+ n.Comm = maybeEdit(n.Comm, edit)
+ editList(n.body, edit)
+}
func (n *CaseStmt) List() Nodes { return n.list }
func (n *CaseStmt) PtrList() *Nodes { return &n.list }
err = maybeDo(n.Call, err, do)
return err
}
+func (n *DeferStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.Call = maybeEdit(n.Call, edit)
+}
func (n *DeferStmt) Left() Node { return n.Call }
func (n *DeferStmt) SetLeft(x Node) { n.Call = x }
err = maybeDoList(n.body, err, do)
return err
}
+func (n *ForStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.Cond = maybeEdit(n.Cond, edit)
+ editList(n.Late, edit)
+ n.Post = maybeEdit(n.Post, edit)
+ editList(n.body, edit)
+}
func (n *ForStmt) Sym() *types.Sym { return n.Label }
func (n *ForStmt) SetSym(x *types.Sym) { n.Label = x }
err = maybeDo(n.Call, err, do)
return err
}
+func (n *GoStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.Call = maybeEdit(n.Call, edit)
+}
func (n *GoStmt) Left() Node { return n.Call }
func (n *GoStmt) SetLeft(x Node) { n.Call = x }
err = maybeDoList(n.Else, err, do)
return err
}
+func (n *IfStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.Cond = maybeEdit(n.Cond, edit)
+ editList(n.body, edit)
+ editList(n.Else, edit)
+}
func (n *IfStmt) Left() Node { return n.Cond }
func (n *IfStmt) SetLeft(x Node) { n.Cond = x }
err = maybeDoList(n.init, err, do)
return err
}
+func (n *InlineMarkStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+}
func (n *InlineMarkStmt) Offset() int64 { return n.Index }
func (n *InlineMarkStmt) SetOffset(x int64) { n.Index = x }
err = maybeDoList(n.init, err, do)
return err
}
+func (n *LabelStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+}
func (n *LabelStmt) Sym() *types.Sym { return n.Label }
func (n *LabelStmt) SetSym(x *types.Sym) { n.Label = x }
err = maybeDoList(n.body, err, do)
return err
}
+func (n *RangeStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ editList(n.Vars, edit)
+ n.X = maybeEdit(n.X, edit)
+ editList(n.body, edit)
+}
func (n *RangeStmt) Sym() *types.Sym { return n.Label }
func (n *RangeStmt) SetSym(x *types.Sym) { n.Label = x }
err = maybeDoList(n.Results, err, do)
return err
}
+func (n *ReturnStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ editList(n.Results, edit)
+}
func (n *ReturnStmt) Orig() Node { return n.orig }
func (n *ReturnStmt) SetOrig(x Node) { n.orig = x }
err = maybeDoList(n.Compiled, err, do)
return err
}
+func (n *SelectStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ editList(n.Cases, edit)
+ editList(n.Compiled, edit)
+}
func (n *SelectStmt) List() Nodes { return n.Cases }
func (n *SelectStmt) PtrList() *Nodes { return &n.Cases }
err = maybeDo(n.Value, err, do)
return err
}
+func (n *SendStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.Chan = maybeEdit(n.Chan, edit)
+ n.Value = maybeEdit(n.Value, edit)
+}
func (n *SendStmt) Left() Node { return n.Chan }
func (n *SendStmt) SetLeft(x Node) { n.Chan = x }
err = maybeDoList(n.Compiled, err, do)
return err
}
+func (n *SwitchStmt) editChildren(edit func(Node) Node) {
+ editList(n.init, edit)
+ n.Tag = maybeEdit(n.Tag, edit)
+ editList(n.Cases, edit)
+ editList(n.Compiled, edit)
+}
func (n *SwitchStmt) Left() Node { return n.Tag }
func (n *SwitchStmt) SetLeft(x Node) { n.Tag = x }
err = maybeDo(n.X, err, do)
return err
}
+func (n *TypeSwitchGuard) editChildren(edit func(Node) Node) {
+ if n.name != nil {
+ n.name = edit(n.name).(*Name)
+ }
+ n.X = maybeEdit(n.X, edit)
+}
func (n *TypeSwitchGuard) Left() Node {
if n.name == nil {
err = maybeDo(n.Elem, err, do)
return err
}
+func (n *ChanType) editChildren(edit func(Node) Node) {
+ n.Elem = maybeEdit(n.Elem, edit)
+}
func (n *ChanType) SetOTYPE(t *types.Type) {
n.setOTYPE(t, n)
n.Elem = nil
err = maybeDo(n.Elem, err, do)
return err
}
+func (n *MapType) editChildren(edit func(Node) Node) {
+ n.Key = maybeEdit(n.Key, edit)
+ n.Elem = maybeEdit(n.Elem, edit)
+}
func (n *MapType) SetOTYPE(t *types.Type) {
n.setOTYPE(t, n)
n.Key = nil
err = maybeDoFields(n.Fields, err, do)
return err
}
+func (n *StructType) editChildren(edit func(Node) Node) {
+ editFields(n.Fields, edit)
+}
func (n *StructType) SetOTYPE(t *types.Type) {
n.setOTYPE(t, n)
err = maybeDoFields(n.Methods, err, do)
return err
}
+func (n *InterfaceType) editChildren(edit func(Node) Node) {
+ editFields(n.Methods, edit)
+}
func (n *InterfaceType) SetOTYPE(t *types.Type) {
n.setOTYPE(t, n)
err = maybeDoFields(n.Results, err, do)
return err
}
+func (n *FuncType) editChildren(edit func(Node) Node) {
+ editField(n.Recv, edit)
+ editFields(n.Params, edit)
+ editFields(n.Results, edit)
+}
func (n *FuncType) SetOTYPE(t *types.Type) {
n.setOTYPE(t, n)
return err
}
+func editField(f *Field, edit func(Node) Node) {
+ if f == nil {
+ return
+ }
+ if f.Decl != nil {
+ f.Decl = edit(f.Decl).(*Name)
+ }
+ if f.Ntype != nil {
+ f.Ntype = toNtype(edit(f.Ntype))
+ }
+}
+
+func editFields(list []*Field, edit func(Node) Node) {
+ for _, f := range list {
+ editField(f, edit)
+ }
+}
+
func (f *Field) deepCopy(pos src.XPos) *Field {
if f == nil {
return nil
err = maybeDo(n.Elem, err, do)
return err
}
+func (n *SliceType) editChildren(edit func(Node) Node) {
+ n.Elem = maybeEdit(n.Elem, edit)
+}
func (n *SliceType) SetOTYPE(t *types.Type) {
n.setOTYPE(t, n)
n.Elem = nil
err = maybeDo(n.Elem, err, do)
return err
}
+func (n *ArrayType) editChildren(edit func(Node) Node) {
+ n.Len = maybeEdit(n.Len, edit)
+ n.Elem = maybeEdit(n.Elem, edit)
+}
func (n *ArrayType) DeepCopy(pos src.XPos) Node {
if n.op == OTYPE {
func (n *typeNode) doChildren(do func(Node) error) error {
return nil
}
+func (n *typeNode) editChildren(edit func(Node) Node) {}
func (n *typeNode) Type() *types.Type { return n.typ }
func (n *typeNode) Sym() *types.Sym { return n.typ.Sym() }
if n == nil {
return
}
- editList(n.Init(), edit)
- if l := n.Left(); l != nil {
- n.SetLeft(edit(l))
- }
- if r := n.Right(); r != nil {
- n.SetRight(edit(r))
- }
- editList(n.List(), edit)
- editList(n.Body(), edit)
- editList(n.Rlist(), edit)
+ n.editChildren(edit)
}
// editList calls edit on each non-nil node x in the list,