Passes toolstash -cmp.
Change-Id: Ifc98a408c154a05997963e2c731466842ebbf50e
Reviewed-on: https://go-review.googlesource.com/c/go/+/279958
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
// A SliceHeader expression constructs a slice header from its parts.
type SliceHeaderExpr struct {
miniExpr
- Ptr Node
- LenCap Nodes // TODO(rsc): Split into two Node fields
+ Ptr Node
+ Len Node
+ Cap Node
}
func NewSliceHeaderExpr(pos src.XPos, typ *types.Type, ptr, len, cap Node) *SliceHeaderExpr {
- n := &SliceHeaderExpr{Ptr: ptr}
+ n := &SliceHeaderExpr{Ptr: ptr, Len: len, Cap: cap}
n.pos = pos
n.op = OSLICEHEADER
n.typ = typ
- n.LenCap = []Node{len, cap}
return n
}
case OSLICEHEADER:
n := n.(*SliceHeaderExpr)
- if len(n.LenCap) != 2 {
- base.Fatalf("bad OSLICEHEADER list length %d", len(n.LenCap))
- }
- fmt.Fprintf(s, "sliceheader{%v,%v,%v}", n.Ptr, n.LenCap[0], n.LenCap[1])
+ fmt.Fprintf(s, "sliceheader{%v,%v,%v}", n.Ptr, n.Len, n.Cap)
case OCOMPLEX, OCOPY:
n := n.(*BinaryExpr)
func (n *SliceHeaderExpr) copy() Node {
c := *n
c.init = c.init.Copy()
- c.LenCap = c.LenCap.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)
+ err = maybeDo(n.Len, err, do)
+ err = maybeDo(n.Cap, 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)
+ n.Len = maybeEdit(n.Len, edit)
+ n.Cap = maybeEdit(n.Cap, edit)
}
func (n *SliceType) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
case ir.OSLICEHEADER:
n := n.(*ir.SliceHeaderExpr)
p := s.expr(n.Ptr)
- l := s.expr(n.LenCap[0])
- c := s.expr(n.LenCap[1])
+ l := s.expr(n.Len)
+ c := s.expr(n.Cap)
return s.newValue3(ssa.OpSliceMake, n.Type(), p, l, c)
case ir.OSLICE, ir.OSLICEARR, ir.OSLICE3, ir.OSLICE3ARR:
base.Fatalf("need unsafe.Pointer for OSLICEHEADER")
}
- if x := len(n.LenCap); x != 2 {
- base.Fatalf("expected 2 params (len, cap) for OSLICEHEADER, got %d", x)
- }
-
n.Ptr = Expr(n.Ptr)
- l := Expr(n.LenCap[0])
- c := Expr(n.LenCap[1])
- l = DefaultLit(l, types.Types[types.TINT])
- c = DefaultLit(c, types.Types[types.TINT])
+ n.Len = DefaultLit(Expr(n.Len), types.Types[types.TINT])
+ n.Cap = DefaultLit(Expr(n.Cap), types.Types[types.TINT])
- if ir.IsConst(l, constant.Int) && ir.Int64Val(l) < 0 {
+ if ir.IsConst(n.Len, constant.Int) && ir.Int64Val(n.Len) < 0 {
base.Fatalf("len for OSLICEHEADER must be non-negative")
}
- if ir.IsConst(c, constant.Int) && ir.Int64Val(c) < 0 {
+ if ir.IsConst(n.Cap, constant.Int) && ir.Int64Val(n.Cap) < 0 {
base.Fatalf("cap for OSLICEHEADER must be non-negative")
}
- if ir.IsConst(l, constant.Int) && ir.IsConst(c, constant.Int) && constant.Compare(l.Val(), token.GTR, c.Val()) {
+ if ir.IsConst(n.Len, constant.Int) && ir.IsConst(n.Cap, constant.Int) && constant.Compare(n.Len.Val(), token.GTR, n.Cap.Val()) {
base.Fatalf("len larger than cap for OSLICEHEADER")
}
- n.LenCap[0] = l
- n.LenCap[1] = c
return n
}
fn := typecheck.LookupRuntime(fnname)
m.Ptr = mkcall1(fn, types.Types[types.TUNSAFEPTR], init, reflectdata.TypePtr(t.Elem()), typecheck.Conv(len, argtype), typecheck.Conv(cap, argtype))
m.Ptr.MarkNonNil()
- m.LenCap = []ir.Node{typecheck.Conv(len, types.Types[types.TINT]), typecheck.Conv(cap, types.Types[types.TINT])}
+ m.Len = typecheck.Conv(len, types.Types[types.TINT])
+ m.Cap = typecheck.Conv(cap, types.Types[types.TINT])
return walkExpr(typecheck.Expr(m), init)
}
sh := ir.NewSliceHeaderExpr(base.Pos, nil, nil, nil, nil)
sh.Ptr = mkcall1(fn, types.Types[types.TUNSAFEPTR], init, size, typecheck.NodNil(), ir.NewBool(false))
sh.Ptr.MarkNonNil()
- sh.LenCap = []ir.Node{length, length}
+ sh.Len = length
+ sh.Cap = length
sh.SetType(t)
s := typecheck.Temp(t)
s := ir.NewSliceHeaderExpr(base.Pos, nil, nil, nil, nil)
s.Ptr = mkcall1(fn, types.Types[types.TUNSAFEPTR], init, reflectdata.TypePtr(t.Elem()), length, copylen, typecheck.Conv(copyptr, types.Types[types.TUNSAFEPTR]))
s.Ptr.MarkNonNil()
- s.LenCap = []ir.Node{length, length}
+ s.Len = length
+ s.Cap = length
s.SetType(t)
return walkExpr(typecheck.Expr(s), init)
}
// walkSliceHeader walks an OSLICEHEADER node.
func walkSliceHeader(n *ir.SliceHeaderExpr, init *ir.Nodes) ir.Node {
n.Ptr = walkExpr(n.Ptr, init)
- n.LenCap[0] = walkExpr(n.LenCap[0], init)
- n.LenCap[1] = walkExpr(n.LenCap[1], init)
+ n.Len = walkExpr(n.Len, init)
+ n.Cap = walkExpr(n.Cap, init)
return n
}