Commit c7917de0 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: simplify transformclosure

Use idiomatic slicing operations instead of incrementally building a
linked list.

Passes toolstash -cmp.

Change-Id: Idb0e40c7b4d7d1110d23828afa8ae1d157ba905f
Reviewed-on: https://go-review.googlesource.com/20556Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 501b1fc3
......@@ -296,20 +296,14 @@ func transformclosure(xfunc *Node) {
// f is ONAME of the actual function.
f := xfunc.Func.Nname
// Get pointer to input arguments.
// We are going to insert captured variables before input args.
param := &f.Type.Params().Type
original_args := *param // old input args
original_dcl := xfunc.Func.Dcl
xfunc.Func.Dcl = nil
var addr *Node
var fld *Type
var params []*Type
var decls []*Node
for _, v := range func_.Func.Cvars.Slice() {
if v.Op == OXXX {
continue
}
fld = typ(TFIELD)
fld := typ(TFIELD)
fld.Funarg = true
if v.Name.Byval {
// If v is captured by value, we merely downgrade it to PPARAM.
......@@ -322,7 +316,7 @@ func transformclosure(xfunc *Node) {
// we introduce function param &v *T
// and v remains PPARAMREF with &v heapaddr
// (accesses will implicitly deref &v).
addr = newname(Lookupf("&%s", v.Sym.Name))
addr := newname(Lookupf("&%s", v.Sym.Name))
addr.Type = Ptrto(v.Type)
addr.Class = PPARAM
v.Name.Heapaddr = addr
......@@ -332,14 +326,15 @@ func transformclosure(xfunc *Node) {
fld.Type = fld.Nname.Type
fld.Sym = fld.Nname.Sym
// Declare the new param and add it the first part of the input arguments.
xfunc.Func.Dcl = append(xfunc.Func.Dcl, fld.Nname)
params = append(params, fld)
decls = append(decls, fld.Nname)
}
*param = fld
param = &fld.Down
if len(params) > 0 {
// Prepend params and decls.
f.Type.Params().SetFields(append(params, f.Type.Params().FieldSlice()...))
xfunc.Func.Dcl = append(decls, xfunc.Func.Dcl...)
}
*param = original_args
xfunc.Func.Dcl = append(xfunc.Func.Dcl, original_dcl...)
// Recalculate param offsets.
if f.Type.Width > 0 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment