1
0
mirror of https://github.com/golang/go synced 2024-11-23 08:30:05 -07:00

cmd/compile: small cleanups for structargs

Suggested by Dave Cheney in golang.org/cl/20405.

Change-Id: I581c11ae80034cb6ebef3de976e8ae9484472322
Reviewed-on: https://go-review.googlesource.com/20453
Reviewed-by: Dave Cheney <dave@cheney.net>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2016-03-08 17:30:51 -08:00
parent 38921b36ba
commit 4db3dde522

View File

@ -1877,25 +1877,20 @@ func expandmeth(t *Type) {
} }
// Given funarg struct list, return list of ODCLFIELD Node fn args. // Given funarg struct list, return list of ODCLFIELD Node fn args.
func structargs(tl **Type, mustname int) []*Node { func structargs(tl *Type, mustname bool) []*Node {
var a *Node
var n *Node
var buf string
var args []*Node var args []*Node
gen := 0 gen := 0
for t, it := IterFields(*tl); t != nil; t = it.Next() { for t, it := IterFields(tl); t != nil; t = it.Next() {
n = nil var n *Node
if mustname != 0 && (t.Sym == nil || t.Sym.Name == "_") { if mustname && (t.Sym == nil || t.Sym.Name == "_") {
// invent a name so that we can refer to it in the trampoline // invent a name so that we can refer to it in the trampoline
buf = fmt.Sprintf(".anon%d", gen) buf := fmt.Sprintf(".anon%d", gen)
gen++ gen++
n = newname(Lookup(buf)) n = newname(Lookup(buf))
} else if t.Sym != nil { } else if t.Sym != nil {
n = newname(t.Sym) n = newname(t.Sym)
} }
a = Nod(ODCLFIELD, n, typenod(t.Type)) a := Nod(ODCLFIELD, n, typenod(t.Type))
a.Isddd = t.Isddd a.Isddd = t.Isddd
if n != nil { if n != nil {
n.Isddd = t.Isddd n.Isddd = t.Isddd
@ -1949,8 +1944,8 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) {
this := Nod(ODCLFIELD, newname(Lookup(".this")), typenod(rcvr)) this := Nod(ODCLFIELD, newname(Lookup(".this")), typenod(rcvr))
this.Left.Name.Param.Ntype = this.Right this.Left.Name.Param.Ntype = this.Right
in := structargs(method.Type.ParamsP(), 1) in := structargs(method.Type.Params(), true)
out := structargs(method.Type.ResultsP(), 0) out := structargs(method.Type.Results(), false)
t := Nod(OTFUNC, nil, nil) t := Nod(OTFUNC, nil, nil)
l := []*Node{this} l := []*Node{this}