clos.List.Set(append([]*Node{nod(OCFUNC, xfunc.Func.Nname, nil)}, clo.Func.Enter.Slice()...))
// Force type conversion from *struct to the func type.
- clos = nod(OCONVNOP, clos, nil)
- clos.Type = clo.Type
-
- clos = typecheck(clos, Erv)
+ clos = convnop(clos, clo.Type)
// typecheck will insert a PTRLIT node under CONVNOP,
// tag it with escape analysis result.
clos.List.Append(n.Left)
// Force type conversion from *struct to the func type.
- clos = nod(OCONVNOP, clos, nil)
- clos.Type = n.Type
-
- clos = typecheck(clos, Erv)
+ clos = convnop(clos, n.Type)
// typecheck will insert a PTRLIT node under CONVNOP,
// tag it with escape analysis result.
tmp := nod(OINDEX, a, nodintconst(0))
tmp.SetBounded(true)
tmp = nod(OADDR, tmp, nil)
- tmp = nod(OCONVNOP, tmp, nil)
- tmp.Type = types.Types[TUNSAFEPTR]
+ tmp = convnop(tmp, types.Types[TUNSAFEPTR])
n.Nbody.Append(nod(OAS, hp, tmp))
// hn = len(a) * sizeof(elem(a))
setField("kind", nodintconst(kind))
if c != nil {
- c = nod(OCONVNOP, c, nil)
- c.Type = types.Types[TUNSAFEPTR]
+ c = convnop(c, types.Types[TUNSAFEPTR])
setField("c", c)
}
if elem != nil {
- elem = nod(OCONVNOP, elem, nil)
- elem.Type = types.Types[TUNSAFEPTR]
+ elem = convnop(elem, types.Types[TUNSAFEPTR])
setField("elem", elem)
}
// bytePtrToIndex returns a Node representing "(*byte)(&n[i])".
func bytePtrToIndex(n *Node, i int64) *Node {
- s := nod(OCONVNOP, nod(OADDR, nod(OINDEX, n, nodintconst(i)), nil), nil)
- s.Type = types.NewPtr(types.Types[TUINT8])
- s = typecheck(s, Erv)
- return s
+ s := nod(OADDR, nod(OINDEX, n, nodintconst(i)), nil)
+ t := types.NewPtr(types.Types[TUINT8])
+ return convnop(s, t)
}
var scase *types.Type
if !dotlist[0].field.Type.IsPtr() {
dot = nod(OADDR, dot, nil)
}
- as := nod(OAS, nthis, nod(OCONVNOP, dot, nil))
- as.Right.Type = rcvr
+ as := nod(OAS, nthis, convnop(dot, rcvr))
fn.Nbody.Append(as)
fn.Nbody.Append(nodSym(ORETJMP, nil, methodSym(methodrcvr, method.Sym)))
} else {
a = typecheck(a, Etop)
a = walkexpr(a, init)
init.Append(a)
- n = nod(OCONVNOP, h, nil)
- n.Type = t
- n = typecheck(n, Erv)
+ n = convnop(h, t)
} else {
// Call runtime.makehmap to allocate an
// hmap on the heap and initialize hmap's hash0 field.
// optimization - can do block copy
if eqtypenoname(rhs[0].Type, lhs) {
nl := nodarg(lhs, fp)
- nr := nod(OCONVNOP, rhs[0], nil)
- nr.Type = nl.Type
+ nr := convnop(rhs[0], nl.Type)
n := convas(nod(OAS, nl, nr), init)
n.SetTypecheck(1)
return []*Node{n}
return n
}
+// convnop converts node n to type t using the OCONVNOP op
+// and typechecks the result with Erv.
+func convnop(n *Node, t *types.Type) *Node {
+ n = nod(OCONVNOP, n, nil)
+ n.Type = t
+ n = typecheck(n, Erv)
+ return n
+}
+
// byteindex converts n, which is byte-sized, to a uint8.
// We cannot use conv, because we allow converting bool to uint8 here,
// which is forbidden in user code.
hp := nod(OINDEX, s, nod(OLEN, l1, nil))
hp.SetBounded(true)
hp = nod(OADDR, hp, nil)
- hp = nod(OCONVNOP, hp, nil)
- hp.Type = types.Types[TUNSAFEPTR]
+ hp = convnop(hp, types.Types[TUNSAFEPTR])
// hn := l2 * sizeof(elem(s))
hn := nod(OMUL, l2, nodintconst(elemtype.Width))