[dev.regabi] cmd/compile: generate Node methods using program

Add Node method generator by Matthew Dempsky,
lightly adapted to account for a few special cases.
No more writing these by hand.

Change-Id: I6933b895df666928b851bddf81b994799c0c97f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/275434
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Russ Cox 2020-12-04 10:17:50 -05:00
parent d90b199e9c
commit 2cec6c4a8c
8 changed files with 1214 additions and 975 deletions

View File

@ -8,7 +8,6 @@ import (
"cmd/compile/internal/base"
"cmd/compile/internal/types"
"cmd/internal/src"
"fmt"
"go/constant"
)
@ -95,25 +94,6 @@ func NewAddStringExpr(pos src.XPos, list []Node) *AddStringExpr {
return n
}
func (n *AddStringExpr) String() string { return fmt.Sprint(n) }
func (n *AddStringExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *AddStringExpr) copy() Node {
c := *n
c.init = c.init.Copy()
c.list = c.list.Copy()
return &c
}
func (n *AddStringExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
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 }
func (n *AddStringExpr) SetList(x Nodes) { n.list = x }
@ -133,24 +113,6 @@ func NewAddrExpr(pos src.XPos, x Node) *AddrExpr {
return n
}
func (n *AddrExpr) String() string { return fmt.Sprint(n) }
func (n *AddrExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *AddrExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *AddrExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
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 }
func (n *AddrExpr) Right() Node { return n.Alloc }
@ -180,26 +142,6 @@ func NewBinaryExpr(pos src.XPos, op Op, x, y Node) *BinaryExpr {
return n
}
func (n *BinaryExpr) String() string { return fmt.Sprint(n) }
func (n *BinaryExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *BinaryExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *BinaryExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.X, err, do)
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 }
func (n *BinaryExpr) Right() Node { return n.Y }
@ -250,33 +192,6 @@ func NewCallExpr(pos src.XPos, fun Node, args []Node) *CallExpr {
return n
}
func (n *CallExpr) String() string { return fmt.Sprint(n) }
func (n *CallExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *CallExpr) copy() Node {
c := *n
c.init = c.init.Copy()
c.Args = c.Args.Copy()
c.Rargs = c.Rargs.Copy()
c.body = c.body.Copy()
return &c
}
func (n *CallExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.X, err, do)
err = maybeDoList(n.Args, err, do)
err = maybeDoList(n.Rargs, err, do)
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 }
func (n *CallExpr) Left() Node { return n.X }
@ -322,24 +237,6 @@ func NewCallPartExpr(pos src.XPos, x Node, method *types.Field, fn *Func) *CallP
return n
}
func (n *CallPartExpr) String() string { return fmt.Sprint(n) }
func (n *CallPartExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *CallPartExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *CallPartExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
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 }
func (n *CallPartExpr) Sym() *types.Sym { return n.Method.Sym }
@ -358,22 +255,6 @@ func NewClosureExpr(pos src.XPos, fn *Func) *ClosureExpr {
return n
}
func (n *ClosureExpr) String() string { return fmt.Sprint(n) }
func (n *ClosureExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *ClosureExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *ClosureExpr) doChildren(do func(Node) error) error {
var err error
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 }
// A ClosureRead denotes reading a variable stored within a closure struct.
@ -389,24 +270,8 @@ func NewClosureRead(typ *types.Type, offset int64) *ClosureRead {
return n
}
func (n *ClosureRead) String() string { return fmt.Sprint(n) }
func (n *ClosureRead) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *ClosureRead) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *ClosureRead) Type() *types.Type { return n.typ }
func (n *ClosureRead) Offset() int64 { return n.offset }
func (n *ClosureRead) doChildren(do func(Node) error) error {
var err error
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.
@ -426,27 +291,6 @@ func NewCompLitExpr(pos src.XPos, typ Ntype, list []Node) *CompLitExpr {
return n
}
func (n *CompLitExpr) String() string { return fmt.Sprint(n) }
func (n *CompLitExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *CompLitExpr) copy() Node {
c := *n
c.init = c.init.Copy()
c.list = c.list.Copy()
return &c
}
func (n *CompLitExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.Ntype, err, do)
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 *CompLitExpr) Right() Node { return n.Ntype }
@ -480,12 +324,6 @@ func NewConstExpr(val constant.Value, orig Node) Node {
return n
}
func (n *ConstExpr) String() string { return fmt.Sprint(n) }
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 }
func (n *ConstExpr) SetOrig(orig Node) { panic(n.no("SetOrig")) }
@ -495,8 +333,7 @@ func (n *ConstExpr) Val() constant.Value { return n.val }
// It may end up being a value or a type.
type ConvExpr struct {
miniExpr
orig Node
X Node
X Node
}
func NewConvExpr(pos src.XPos, op Op, typ *types.Type, x Node) *ConvExpr {
@ -504,29 +341,9 @@ func NewConvExpr(pos src.XPos, op Op, typ *types.Type, x Node) *ConvExpr {
n.pos = pos
n.typ = typ
n.SetOp(op)
n.orig = n
return n
}
func (n *ConvExpr) String() string { return fmt.Sprint(n) }
func (n *ConvExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *ConvExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *ConvExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
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 }
func (n *ConvExpr) SetLeft(x Node) { n.X = x }
@ -554,26 +371,6 @@ func NewIndexExpr(pos src.XPos, x, index Node) *IndexExpr {
return n
}
func (n *IndexExpr) String() string { return fmt.Sprint(n) }
func (n *IndexExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *IndexExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *IndexExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.X, err, do)
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 }
func (n *IndexExpr) Right() Node { return n.Index }
@ -608,26 +405,6 @@ func NewKeyExpr(pos src.XPos, key, value Node) *KeyExpr {
return n
}
func (n *KeyExpr) String() string { return fmt.Sprint(n) }
func (n *KeyExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *KeyExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *KeyExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.Key, err, do)
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 }
func (n *KeyExpr) Right() Node { return n.Value }
@ -662,28 +439,6 @@ func NewInlinedCallExpr(pos src.XPos, body, retvars []Node) *InlinedCallExpr {
return n
}
func (n *InlinedCallExpr) String() string { return fmt.Sprint(n) }
func (n *InlinedCallExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *InlinedCallExpr) copy() Node {
c := *n
c.init = c.init.Copy()
c.body = c.body.Copy()
c.ReturnVars = c.ReturnVars.Copy()
return &c
}
func (n *InlinedCallExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDoList(n.body, err, do)
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 }
func (n *InlinedCallExpr) SetBody(x Nodes) { n.body = x }
@ -707,26 +462,6 @@ func NewMakeExpr(pos src.XPos, op Op, len, cap Node) *MakeExpr {
return n
}
func (n *MakeExpr) String() string { return fmt.Sprint(n) }
func (n *MakeExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *MakeExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *MakeExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.Len, err, do)
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 }
func (n *MakeExpr) Right() Node { return n.Cap }
@ -760,26 +495,6 @@ func NewMethodExpr(pos src.XPos, op Op, x, m Node) *MethodExpr {
return n
}
func (n *MethodExpr) String() string { return fmt.Sprint(n) }
func (n *MethodExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *MethodExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *MethodExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.X, err, do)
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 }
func (n *MethodExpr) Right() Node { return n.M }
@ -805,22 +520,6 @@ func NewNilExpr(pos src.XPos) *NilExpr {
return n
}
func (n *NilExpr) String() string { return fmt.Sprint(n) }
func (n *NilExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *NilExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *NilExpr) doChildren(do func(Node) error) error {
var err error
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 }
@ -838,24 +537,6 @@ func NewParenExpr(pos src.XPos, x Node) *ParenExpr {
return n
}
func (n *ParenExpr) String() string { return fmt.Sprint(n) }
func (n *ParenExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *ParenExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *ParenExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
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 }
@ -883,22 +564,6 @@ func NewResultExpr(pos src.XPos, typ *types.Type, offset int64) *ResultExpr {
return n
}
func (n *ResultExpr) String() string { return fmt.Sprint(n) }
func (n *ResultExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *ResultExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *ResultExpr) doChildren(do func(Node) error) error {
var err error
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 }
@ -928,24 +593,6 @@ func (n *SelectorExpr) SetOp(op Op) {
}
}
func (n *SelectorExpr) String() string { return fmt.Sprint(n) }
func (n *SelectorExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *SelectorExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *SelectorExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
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 }
func (n *SelectorExpr) Sym() *types.Sym { return n.Sel }
@ -971,27 +618,6 @@ func NewSliceExpr(pos src.XPos, op Op, x Node) *SliceExpr {
return n
}
func (n *SliceExpr) String() string { return fmt.Sprint(n) }
func (n *SliceExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *SliceExpr) copy() Node {
c := *n
c.init = c.init.Copy()
c.list = c.list.Copy()
return &c
}
func (n *SliceExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.X, err, do)
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 }
func (n *SliceExpr) List() Nodes { return n.list }
@ -1091,26 +717,6 @@ func NewSliceHeaderExpr(pos src.XPos, typ *types.Type, ptr, len, cap Node) *Slic
return n
}
func (n *SliceHeaderExpr) String() string { return fmt.Sprint(n) }
func (n *SliceHeaderExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *SliceHeaderExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *SliceHeaderExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.Ptr, err, do)
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 }
func (n *SliceHeaderExpr) List() Nodes { return n.lenCap }
@ -1131,24 +737,6 @@ func NewStarExpr(pos src.XPos, x Node) *StarExpr {
return n
}
func (n *StarExpr) String() string { return fmt.Sprint(n) }
func (n *StarExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *StarExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *StarExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
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 }
@ -1179,29 +767,6 @@ func NewTypeAssertExpr(pos src.XPos, x Node, typ Ntype) *TypeAssertExpr {
return n
}
func (n *TypeAssertExpr) String() string { return fmt.Sprint(n) }
func (n *TypeAssertExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *TypeAssertExpr) copy() Node {
c := *n
c.init = c.init.Copy()
c.Itab = c.Itab.Copy()
return &c
}
func (n *TypeAssertExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.X, err, do)
err = maybeDo(n.Ntype, err, do)
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 }
func (n *TypeAssertExpr) Right() Node { return n.Ntype }
@ -1233,24 +798,6 @@ func NewUnaryExpr(pos src.XPos, op Op, x Node) *UnaryExpr {
return n
}
func (n *UnaryExpr) String() string { return fmt.Sprint(n) }
func (n *UnaryExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *UnaryExpr) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *UnaryExpr) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
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 }

View File

@ -9,7 +9,6 @@ import (
"cmd/compile/internal/types"
"cmd/internal/obj"
"cmd/internal/src"
"fmt"
)
// A Func corresponds to a single function in a Go program
@ -115,18 +114,6 @@ func NewFunc(pos src.XPos) *Func {
return f
}
func (f *Func) String() string { return fmt.Sprint(f) }
func (f *Func) Format(s fmt.State, verb rune) { FmtNode(f, s, verb) }
func (f *Func) copy() Node { panic(f.no("copy")) }
func (f *Func) doChildren(do func(Node) error) error {
var err error
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 (f *Func) PtrBody() *Nodes { return &f.body }

View File

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:generate go run -mod=mod mknode.go
package ir
import (
@ -33,6 +35,12 @@ type miniNode struct {
esc uint16
}
func (n *miniNode) String() string { panic(1) }
func (n *miniNode) Format(s fmt.State, verb rune) { panic(1) }
func (n *miniNode) copy() Node { panic(1) }
func (n *miniNode) doChildren(do func(Node) error) error { panic(1) }
func (n *miniNode) editChildren(edit func(Node) Node) { panic(1) }
// posOr returns pos if known, or else n.pos.
// For use in DeepCopy.
func (n *miniNode) posOr(pos src.XPos) src.XPos {

View File

@ -0,0 +1,175 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
import (
"bytes"
"fmt"
"go/format"
"go/types"
"io/ioutil"
"log"
"strings"
"golang.org/x/tools/go/packages"
)
func main() {
cfg := &packages.Config{
Mode: packages.NeedSyntax | packages.NeedTypes,
}
pkgs, err := packages.Load(cfg, "cmd/compile/internal/ir")
if err != nil {
log.Fatal(err)
}
pkg := pkgs[0].Types
scope := pkg.Scope()
lookup := func(name string) *types.Named {
return scope.Lookup(name).(*types.TypeName).Type().(*types.Named)
}
nodeType := lookup("Node")
ntypeType := lookup("Ntype")
nodesType := lookup("Nodes")
ptrFieldType := types.NewPointer(lookup("Field"))
slicePtrFieldType := types.NewSlice(ptrFieldType)
ptrNameType := types.NewPointer(lookup("Name"))
var buf bytes.Buffer
fmt.Fprintln(&buf, "// Code generated by mknode.go. DO NOT EDIT.")
fmt.Fprintln(&buf)
fmt.Fprintln(&buf, "package ir")
fmt.Fprintln(&buf)
fmt.Fprintln(&buf, `import "fmt"`)
for _, name := range scope.Names() {
obj, ok := scope.Lookup(name).(*types.TypeName)
if !ok {
continue
}
typName := obj.Name()
typ, ok := obj.Type().(*types.Named).Underlying().(*types.Struct)
if !ok {
continue
}
if strings.HasPrefix(typName, "mini") || !hasMiniNode(typ) {
continue
}
fmt.Fprintf(&buf, "\n")
fmt.Fprintf(&buf, "func (n *%s) String() string { return fmt.Sprint(n) }\n", name)
fmt.Fprintf(&buf, "func (n *%s) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }\n", name)
fmt.Fprintf(&buf, "func (n *%s) copy() Node { c := *n\n", name)
forNodeFields(typName, typ, func(name string, is func(types.Type) bool) {
switch {
case is(nodesType):
fmt.Fprintf(&buf, "c.%s = c.%s.Copy()\n", name, name)
case is(ptrFieldType):
fmt.Fprintf(&buf, "if c.%s != nil { c.%s = c.%s.copy() }\n", name, name, name)
case is(slicePtrFieldType):
fmt.Fprintf(&buf, "c.%s = copyFields(c.%s)\n", name, name)
}
})
fmt.Fprintf(&buf, "return &c }\n")
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(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)
case is(nodesType):
fmt.Fprintf(&buf, "err = maybeDoList(n.%s, err, do)\n", name)
case is(ptrFieldType):
fmt.Fprintf(&buf, "err = maybeDoField(n.%s, err, do)\n", name)
case is(slicePtrFieldType):
fmt.Fprintf(&buf, "err = maybeDoFields(n.%s, err, do)\n", name)
}
})
fmt.Fprintf(&buf, "return err }\n")
fmt.Fprintf(&buf, "func (n *%s) editChildren(edit func(Node) Node) {\n", name)
forNodeFields(typName, typ, func(name string, is func(types.Type) bool) {
switch {
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):
fmt.Fprintf(&buf, "n.%s = toNtype(maybeEdit(n.%s, edit))\n", name, name)
case is(nodesType):
fmt.Fprintf(&buf, "editList(n.%s, edit)\n", name)
case is(ptrFieldType):
fmt.Fprintf(&buf, "editField(n.%s, edit)\n", name)
case is(slicePtrFieldType):
fmt.Fprintf(&buf, "editFields(n.%s, edit)\n", name)
}
})
fmt.Fprintf(&buf, "}\n")
}
out, err := format.Source(buf.Bytes())
if err != nil {
// write out mangled source so we can see the bug.
out = buf.Bytes()
}
err = ioutil.WriteFile("node_gen.go", out, 0666)
if err != nil {
log.Fatal(err)
}
}
func forNodeFields(typName string, typ *types.Struct, f func(name string, is func(types.Type) bool)) {
for i, n := 0, typ.NumFields(); i < n; i++ {
v := typ.Field(i)
if v.Embedded() {
if typ, ok := v.Type().Underlying().(*types.Struct); ok {
forNodeFields(typName, typ, f)
continue
}
}
switch typName {
case "Func":
if v.Name() != "body" {
continue
}
case "Name", "Pack":
continue
}
switch v.Name() {
case "orig":
continue
}
switch typName + "." + v.Name() {
case "AddStringExpr.Alloc":
continue
}
f(v.Name(), func(t types.Type) bool { return types.Identical(t, v.Type()) })
}
}
func hasMiniNode(typ *types.Struct) bool {
for i, n := 0, typ.NumFields(); i < n; i++ {
v := typ.Field(i)
if v.Name() == "miniNode" {
return true
}
if v.Embedded() {
if typ, ok := v.Type().Underlying().(*types.Struct); ok && hasMiniNode(typ) {
return true
}
}
}
return false
}

View File

@ -9,7 +9,7 @@ import (
"cmd/compile/internal/types"
"cmd/internal/objabi"
"cmd/internal/src"
"fmt"
"go/constant"
)
@ -149,12 +149,6 @@ func newNameAt(pos src.XPos, op Op, sym *types.Sym) *Name {
return n
}
func (n *Name) String() string { return fmt.Sprint(n) }
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 (n *Name) SetSym(x *types.Sym) { n.sym = x }
@ -361,12 +355,6 @@ type PkgName struct {
Used bool
}
func (p *PkgName) String() string { return fmt.Sprint(p) }
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 }
func (*PkgName) CanBeNtype() {}

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,6 @@ package ir
import (
"cmd/compile/internal/types"
"cmd/internal/src"
"fmt"
)
// A Decl is a declaration of a const, type, or var. (A declared func is a Func.)
@ -28,18 +27,6 @@ func NewDecl(pos src.XPos, op Op, x Node) *Decl {
return n
}
func (n *Decl) String() string { return fmt.Sprint(n) }
func (n *Decl) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *Decl) copy() Node { c := *n; return &c }
func (n *Decl) doChildren(do func(Node) error) error {
var err error
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 }
@ -76,28 +63,6 @@ func NewAssignListStmt(pos src.XPos, lhs, rhs []Node) *AssignListStmt {
return n
}
func (n *AssignListStmt) String() string { return fmt.Sprint(n) }
func (n *AssignListStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *AssignListStmt) copy() Node {
c := *n
c.init = c.init.Copy()
c.Lhs = c.Lhs.Copy()
c.Rhs = c.Rhs.Copy()
return &c
}
func (n *AssignListStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDoList(n.Lhs, err, do)
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 }
func (n *AssignListStmt) SetList(x Nodes) { n.Lhs = x }
@ -136,26 +101,6 @@ func NewAssignStmt(pos src.XPos, x, y Node) *AssignStmt {
return n
}
func (n *AssignStmt) String() string { return fmt.Sprint(n) }
func (n *AssignStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *AssignStmt) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *AssignStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.X, err, do)
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 }
func (n *AssignStmt) Right() Node { return n.Y }
@ -191,26 +136,6 @@ func NewAssignOpStmt(pos src.XPos, op Op, x, y Node) *AssignOpStmt {
return n
}
func (n *AssignOpStmt) String() string { return fmt.Sprint(n) }
func (n *AssignOpStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *AssignOpStmt) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *AssignOpStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.X, err, do)
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 }
func (n *AssignOpStmt) Right() Node { return n.Y }
@ -236,25 +161,6 @@ func NewBlockStmt(pos src.XPos, list []Node) *BlockStmt {
return n
}
func (n *BlockStmt) String() string { return fmt.Sprint(n) }
func (n *BlockStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *BlockStmt) copy() Node {
c := *n
c.init = c.init.Copy()
c.list = c.list.Copy()
return &c
}
func (n *BlockStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
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 }
func (n *BlockStmt) SetList(x Nodes) { n.list = x }
@ -281,22 +187,6 @@ func NewBranchStmt(pos src.XPos, op Op, label *types.Sym) *BranchStmt {
return n
}
func (n *BranchStmt) String() string { return fmt.Sprint(n) }
func (n *BranchStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *BranchStmt) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *BranchStmt) doChildren(do func(Node) error) error {
var err error
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 }
@ -318,33 +208,6 @@ func NewCaseStmt(pos src.XPos, list, body []Node) *CaseStmt {
return n
}
func (n *CaseStmt) String() string { return fmt.Sprint(n) }
func (n *CaseStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *CaseStmt) copy() Node {
c := *n
c.init = c.init.Copy()
c.Vars = c.Vars.Copy()
c.list = c.list.Copy()
c.body = c.body.Copy()
return &c
}
func (n *CaseStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDoList(n.Vars, err, do)
err = maybeDoList(n.list, err, do)
err = maybeDo(n.Comm, err, do)
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 }
func (n *CaseStmt) SetList(x Nodes) { n.list = x }
@ -370,24 +233,6 @@ func NewDeferStmt(pos src.XPos, call Node) *DeferStmt {
return n
}
func (n *DeferStmt) String() string { return fmt.Sprint(n) }
func (n *DeferStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *DeferStmt) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *DeferStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
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 }
@ -412,32 +257,6 @@ func NewForStmt(pos src.XPos, init []Node, cond, post Node, body []Node) *ForStm
return n
}
func (n *ForStmt) String() string { return fmt.Sprint(n) }
func (n *ForStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *ForStmt) copy() Node {
c := *n
c.init = c.init.Copy()
c.Late = c.Late.Copy()
c.body = c.body.Copy()
return &c
}
func (n *ForStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.Cond, err, do)
err = maybeDoList(n.Late, err, do)
err = maybeDo(n.Post, err, do)
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 }
func (n *ForStmt) Left() Node { return n.Cond }
@ -473,24 +292,6 @@ func NewGoStmt(pos src.XPos, call Node) *GoStmt {
return n
}
func (n *GoStmt) String() string { return fmt.Sprint(n) }
func (n *GoStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *GoStmt) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *GoStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
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 }
@ -512,30 +313,6 @@ func NewIfStmt(pos src.XPos, cond Node, body, els []Node) *IfStmt {
return n
}
func (n *IfStmt) String() string { return fmt.Sprint(n) }
func (n *IfStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *IfStmt) copy() Node {
c := *n
c.init = c.init.Copy()
c.body = c.body.Copy()
c.Else = c.Else.Copy()
return &c
}
func (n *IfStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.Cond, err, do)
err = maybeDoList(n.body, err, do)
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 }
func (n *IfStmt) Body() Nodes { return n.body }
@ -560,22 +337,6 @@ func NewInlineMarkStmt(pos src.XPos, index int64) *InlineMarkStmt {
return n
}
func (n *InlineMarkStmt) String() string { return fmt.Sprint(n) }
func (n *InlineMarkStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *InlineMarkStmt) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *InlineMarkStmt) doChildren(do func(Node) error) error {
var err error
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 }
@ -592,22 +353,6 @@ func NewLabelStmt(pos src.XPos, label *types.Sym) *LabelStmt {
return n
}
func (n *LabelStmt) String() string { return fmt.Sprint(n) }
func (n *LabelStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *LabelStmt) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *LabelStmt) doChildren(do func(Node) error) error {
var err error
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 }
@ -633,30 +378,6 @@ func NewRangeStmt(pos src.XPos, vars []Node, x Node, body []Node) *RangeStmt {
return n
}
func (n *RangeStmt) String() string { return fmt.Sprint(n) }
func (n *RangeStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *RangeStmt) copy() Node {
c := *n
c.init = c.init.Copy()
c.Vars = c.Vars.Copy()
c.body = c.body.Copy()
return &c
}
func (n *RangeStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDoList(n.Vars, err, do)
err = maybeDo(n.X, err, do)
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 }
func (n *RangeStmt) Right() Node { return n.X }
@ -690,25 +411,6 @@ func NewReturnStmt(pos src.XPos, results []Node) *ReturnStmt {
return n
}
func (n *ReturnStmt) String() string { return fmt.Sprint(n) }
func (n *ReturnStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *ReturnStmt) copy() Node {
c := *n
c.init = c.init.Copy()
c.Results = c.Results.Copy()
return &c
}
func (n *ReturnStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
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 }
func (n *ReturnStmt) List() Nodes { return n.Results }
@ -735,28 +437,6 @@ func NewSelectStmt(pos src.XPos, cases []Node) *SelectStmt {
return n
}
func (n *SelectStmt) String() string { return fmt.Sprint(n) }
func (n *SelectStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *SelectStmt) copy() Node {
c := *n
c.init = c.init.Copy()
c.Cases = c.Cases.Copy()
c.Compiled = c.Compiled.Copy()
return &c
}
func (n *SelectStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDoList(n.Cases, err, do)
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 }
func (n *SelectStmt) SetList(x Nodes) { n.Cases = x }
@ -782,26 +462,6 @@ func NewSendStmt(pos src.XPos, ch, value Node) *SendStmt {
return n
}
func (n *SendStmt) String() string { return fmt.Sprint(n) }
func (n *SendStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *SendStmt) copy() Node {
c := *n
c.init = c.init.Copy()
return &c
}
func (n *SendStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.Chan, err, do)
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 }
func (n *SendStmt) Right() Node { return n.Value }
@ -827,30 +487,6 @@ func NewSwitchStmt(pos src.XPos, tag Node, cases []Node) *SwitchStmt {
return n
}
func (n *SwitchStmt) String() string { return fmt.Sprint(n) }
func (n *SwitchStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *SwitchStmt) copy() Node {
c := *n
c.init = c.init.Copy()
c.Cases = c.Cases.Copy()
c.Compiled = c.Compiled.Copy()
return &c
}
func (n *SwitchStmt) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.Tag, err, do)
err = maybeDoList(n.Cases, err, do)
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 }
func (n *SwitchStmt) List() Nodes { return n.Cases }
@ -881,24 +517,6 @@ func NewTypeSwitchGuard(pos src.XPos, name, x Node) *TypeSwitchGuard {
return n
}
func (n *TypeSwitchGuard) String() string { return fmt.Sprint(n) }
func (n *TypeSwitchGuard) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *TypeSwitchGuard) copy() Node { c := *n; return &c }
func (n *TypeSwitchGuard) doChildren(do func(Node) error) error {
var err error
if n.name != nil {
err = maybeDo(n.name, err, do)
}
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 {
return nil

View File

@ -72,17 +72,6 @@ func NewChanType(pos src.XPos, elem Node, dir types.ChanDir) *ChanType {
return n
}
func (n *ChanType) String() string { return fmt.Sprint(n) }
func (n *ChanType) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *ChanType) copy() Node { c := *n; return &c }
func (n *ChanType) doChildren(do func(Node) error) error {
var err error
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
@ -102,19 +91,6 @@ func NewMapType(pos src.XPos, key, elem Node) *MapType {
return n
}
func (n *MapType) String() string { return fmt.Sprint(n) }
func (n *MapType) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *MapType) copy() Node { c := *n; return &c }
func (n *MapType) doChildren(do func(Node) error) error {
var err error
err = maybeDo(n.Key, err, do)
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
@ -134,22 +110,6 @@ func NewStructType(pos src.XPos, fields []*Field) *StructType {
return n
}
func (n *StructType) String() string { return fmt.Sprint(n) }
func (n *StructType) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *StructType) copy() Node {
c := *n
c.Fields = copyFields(c.Fields)
return &c
}
func (n *StructType) doChildren(do func(Node) error) error {
var err error
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)
n.Fields = nil
@ -176,22 +136,6 @@ func NewInterfaceType(pos src.XPos, methods []*Field) *InterfaceType {
return n
}
func (n *InterfaceType) String() string { return fmt.Sprint(n) }
func (n *InterfaceType) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *InterfaceType) copy() Node {
c := *n
c.Methods = copyFields(c.Methods)
return &c
}
func (n *InterfaceType) doChildren(do func(Node) error) error {
var err error
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)
n.Methods = nil
@ -212,30 +156,6 @@ func NewFuncType(pos src.XPos, rcvr *Field, args, results []*Field) *FuncType {
return n
}
func (n *FuncType) String() string { return fmt.Sprint(n) }
func (n *FuncType) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *FuncType) copy() Node {
c := *n
if c.Recv != nil {
c.Recv = c.Recv.copy()
}
c.Params = copyFields(c.Params)
c.Results = copyFields(c.Results)
return &c
}
func (n *FuncType) doChildren(do func(Node) error) error {
var err error
err = maybeDoField(n.Recv, err, do)
err = maybeDoFields(n.Params, err, do)
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)
n.Recv = nil
@ -365,17 +285,6 @@ func NewSliceType(pos src.XPos, elem Node) *SliceType {
return n
}
func (n *SliceType) String() string { return fmt.Sprint(n) }
func (n *SliceType) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *SliceType) copy() Node { c := *n; return &c }
func (n *SliceType) doChildren(do func(Node) error) error {
var err error
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
@ -396,20 +305,6 @@ func NewArrayType(pos src.XPos, size Node, elem Node) *ArrayType {
return n
}
func (n *ArrayType) String() string { return fmt.Sprint(n) }
func (n *ArrayType) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *ArrayType) copy() Node { c := *n; return &c }
func (n *ArrayType) doChildren(do func(Node) error) error {
var err error
err = maybeDo(n.Len, err, do)
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) SetOTYPE(t *types.Type) {
n.setOTYPE(t, n)
n.Len = nil
@ -429,14 +324,6 @@ func newTypeNode(pos src.XPos, typ *types.Type) *typeNode {
return n
}
func (n *typeNode) String() string { return fmt.Sprint(n) }
func (n *typeNode) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *typeNode) copy() Node { c := *n; return &c }
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() }
func (n *typeNode) CanBeNtype() {}