Skip to content

Commit

Permalink
cmd/internal/gc: unembed Node.Func
Browse files Browse the repository at this point in the history
This is a follow-up to CL 7360.

It was generated with eg and gofmt -r.

The only manual changes are the unembedding in syntax.go
and backporting changes from y.go to go.y.

Passes toolstash -cmp.

Change-Id: I3d6d06ecb659809a4bc8592395d5b9a18967218e
Reviewed-on: https://go-review.googlesource.com/8053
Reviewed-by: Russ Cox <[email protected]>
Run-TryBot: Josh Bleecher Snyder <[email protected]>
  • Loading branch information
josharian committed Apr 1, 2015
1 parent 57279ba commit 3ed9e4c
Show file tree
Hide file tree
Showing 26 changed files with 162 additions and 162 deletions.
2 changes: 1 addition & 1 deletion src/cmd/5g/ggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func defframe(ptxt *obj.Prog) {
hi := int64(0)
lo := hi
r0 := uint32(0)
for l := gc.Curfn.Dcl; l != nil; l = l.Next {
for l := gc.Curfn.Func.Dcl; l != nil; l = l.Next {
n = l.N
if !n.Needzero {
continue
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/6g/ggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func defframe(ptxt *obj.Prog) {
ax := uint32(0)

// iterate through declarations - they are sorted in decreasing xoffset order.
for l := gc.Curfn.Dcl; l != nil; l = l.Next {
for l := gc.Curfn.Func.Dcl; l != nil; l = l.Next {
n = l.N
if !n.Needzero {
continue
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/7g/ggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func defframe(ptxt *obj.Prog) {
lo := hi

// iterate through declarations - they are sorted in decreasing xoffset order.
for l := gc.Curfn.Dcl; l != nil; l = l.Next {
for l := gc.Curfn.Func.Dcl; l != nil; l = l.Next {
n = l.N
if !n.Needzero {
continue
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/8g/ggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func defframe(ptxt *obj.Prog) {
hi := int64(0)
lo := hi
ax := uint32(0)
for l := gc.Curfn.Dcl; l != nil; l = l.Next {
for l := gc.Curfn.Func.Dcl; l != nil; l = l.Next {
n = l.N
if !n.Needzero {
continue
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/9g/ggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func defframe(ptxt *obj.Prog) {
lo := hi

// iterate through declarations - they are sorted in decreasing xoffset order.
for l := gc.Curfn.Dcl; l != nil; l = l.Next {
for l := gc.Curfn.Func.Dcl; l != nil; l = l.Next {
n = l.N
if !n.Needzero {
continue
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/internal/gc/cgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ func sgen(n *Node, ns *Node, w int64) {
// If copying .args, that's all the results, so record definition sites
// for them for the liveness analysis.
if ns.Op == ONAME && ns.Sym.Name == ".args" {
for l := Curfn.Dcl; l != nil; l = l.Next {
for l := Curfn.Func.Dcl; l != nil; l = l.Next {
if l.N.Class == PPARAMOUT {
Gvardef(l.N)
}
Expand Down Expand Up @@ -2384,7 +2384,7 @@ func cgen_ret(n *Node) {
if Hasdefer != 0 {
Ginscall(Deferreturn, 0)
}
Genlist(Curfn.Exit)
Genlist(Curfn.Func.Exit)
p := Thearch.Gins(obj.ARET, nil, nil)
if n != nil && n.Op == ORETJMP {
p.To.Type = obj.TYPE_MEM
Expand Down
70 changes: 35 additions & 35 deletions src/cmd/internal/gc/closure.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func closurehdr(ntype *Node) {
n := Nod(OCLOSURE, nil, nil)
n.Ntype = ntype
n.Funcdepth = Funcdepth
n.Outerfunc = Curfn
n.Func.Outerfunc = Curfn

funchdr(n)

Expand Down Expand Up @@ -62,15 +62,15 @@ func closurebody(body *NodeList) *Node {

func_ := Curfn
func_.Nbody = body
func_.Endlineno = lineno
func_.Func.Endlineno = lineno
funcbody(func_)

// closure-specific variables are hanging off the
// ordinary ones in the symbol table; see oldname.
// unhook them.
// make the list of pointers for the closure call.
var v *Node
for l := func_.Cvars; l != nil; l = l.Next {
for l := func_.Func.Cvars; l != nil; l = l.Next {
v = l.N
v.Closure.Closure = v.Outer
v.Outerexpr = oldname(v.Sym)
Expand All @@ -82,7 +82,7 @@ func closurebody(body *NodeList) *Node {
func typecheckclosure(func_ *Node, top int) {
var n *Node

for l := func_.Cvars; l != nil; l = l.Next {
for l := func_.Func.Cvars; l != nil; l = l.Next {
n = l.N.Closure
if !n.Captured {
n.Captured = true
Expand All @@ -98,7 +98,7 @@ func typecheckclosure(func_ *Node, top int) {
}
}

for l := func_.Dcl; l != nil; l = l.Next {
for l := func_.Func.Dcl; l != nil; l = l.Next {
if l.N.Op == ONAME && (l.N.Class == PPARAM || l.N.Class == PPARAMOUT) {
l.N.Decldepth = 1
}
Expand Down Expand Up @@ -141,36 +141,36 @@ func closurename(n *Node) *Sym {
gen := 0
outer := ""
prefix := ""
if n.Outerfunc == nil {
if n.Func.Outerfunc == nil {
// Global closure.
outer = "glob"

prefix = "func"
closurename_closgen++
gen = closurename_closgen
} else if n.Outerfunc.Op == ODCLFUNC {
} else if n.Func.Outerfunc.Op == ODCLFUNC {
// The outermost closure inside of a named function.
outer = n.Outerfunc.Nname.Sym.Name
outer = n.Func.Outerfunc.Nname.Sym.Name

prefix = "func"

// Yes, functions can be named _.
// Can't use function closgen in such case,
// because it would lead to name clashes.
if !isblank(n.Outerfunc.Nname) {
n.Outerfunc.Closgen++
gen = n.Outerfunc.Closgen
if !isblank(n.Func.Outerfunc.Nname) {
n.Func.Outerfunc.Func.Closgen++
gen = n.Func.Outerfunc.Func.Closgen
} else {
closurename_closgen++
gen = closurename_closgen
}
} else if n.Outerfunc.Op == OCLOSURE {
} else if n.Func.Outerfunc.Op == OCLOSURE {
// Nested closure, recurse.
outer = closurename(n.Outerfunc).Name
outer = closurename(n.Func.Outerfunc).Name

prefix = ""
n.Outerfunc.Closgen++
gen = n.Outerfunc.Closgen
n.Func.Outerfunc.Func.Closgen++
gen = n.Func.Outerfunc.Func.Closgen
} else {
Fatal("closurename called for %v", Nconv(n, obj.FmtShort))
}
Expand Down Expand Up @@ -198,10 +198,10 @@ func makeclosure(func_ *Node) *Node {
declare(xfunc.Nname, PFUNC)
xfunc.Nname.Funcdepth = func_.Funcdepth
xfunc.Funcdepth = func_.Funcdepth
xfunc.Endlineno = func_.Endlineno
xfunc.Func.Endlineno = func_.Func.Endlineno

xfunc.Nbody = func_.Nbody
xfunc.Dcl = concat(func_.Dcl, xfunc.Dcl)
xfunc.Func.Dcl = concat(func_.Func.Dcl, xfunc.Func.Dcl)
if xfunc.Nbody == nil {
Fatal("empty body - won't generate any code")
}
Expand Down Expand Up @@ -230,8 +230,8 @@ func capturevars(xfunc *Node) {
lineno = xfunc.Lineno

func_ := xfunc.Closure
func_.Enter = nil
for l := func_.Cvars; l != nil; l = l.Next {
func_.Func.Enter = nil
for l := func_.Func.Cvars; l != nil; l = l.Next {
v = l.N
if v.Type == nil {
// if v->type is nil, it means v looked like it was
Expand Down Expand Up @@ -273,7 +273,7 @@ func capturevars(xfunc *Node) {
}

typecheck(&outer, Erv)
func_.Enter = list(func_.Enter, outer)
func_.Func.Enter = list(func_.Func.Enter, outer)
}

lineno = int32(lno)
Expand Down Expand Up @@ -314,7 +314,7 @@ func transformclosure(xfunc *Node) {
var v *Node
var addr *Node
var fld *Type
for l := func_.Cvars; l != nil; l = l.Next {
for l := func_.Func.Cvars; l != nil; l = l.Next {
v = l.N
if v.Op == OXXX {
continue
Expand Down Expand Up @@ -343,7 +343,7 @@ func transformclosure(xfunc *Node) {
fld.Sym = fld.Nname.Sym

// Declare the new param and append it to input arguments.
xfunc.Dcl = list(xfunc.Dcl, fld.Nname)
xfunc.Func.Dcl = list(xfunc.Func.Dcl, fld.Nname)

*param = fld
param = &fld.Down
Expand All @@ -364,7 +364,7 @@ func transformclosure(xfunc *Node) {
var addr *Node
var v *Node
var cv *Node
for l := func_.Cvars; l != nil; l = l.Next {
for l := func_.Func.Cvars; l != nil; l = l.Next {
v = l.N
if v.Op == OXXX {
continue
Expand All @@ -389,7 +389,7 @@ func transformclosure(xfunc *Node) {
v.Class = PAUTO

v.Ullman = 1
xfunc.Dcl = list(xfunc.Dcl, v)
xfunc.Func.Dcl = list(xfunc.Func.Dcl, v)
body = list(body, Nod(OAS, v, cv))
} else {
// Declare variable holding addresses taken from closure
Expand All @@ -399,7 +399,7 @@ func transformclosure(xfunc *Node) {
addr.Class = PAUTO
addr.Used = true
addr.Curfn = xfunc
xfunc.Dcl = list(xfunc.Dcl, addr)
xfunc.Func.Dcl = list(xfunc.Func.Dcl, addr)
v.Heapaddr = addr
if v.Byval {
cv = Nod(OADDR, cv, nil)
Expand All @@ -410,16 +410,16 @@ func transformclosure(xfunc *Node) {

typechecklist(body, Etop)
walkstmtlist(body)
xfunc.Enter = body
xfunc.Needctxt = nvar > 0
xfunc.Func.Enter = body
xfunc.Func.Needctxt = nvar > 0
}

lineno = int32(lno)
}

func walkclosure(func_ *Node, init **NodeList) *Node {
// If no closure vars, don't bother wrapping.
if func_.Cvars == nil {
if func_.Func.Cvars == nil {
return func_.Closure.Nname
}

Expand All @@ -442,7 +442,7 @@ func walkclosure(func_ *Node, init **NodeList) *Node {
typ.List = list1(Nod(ODCLFIELD, newname(Lookup(".F")), typenod(Types[TUINTPTR])))
var typ1 *Node
var v *Node
for l := func_.Cvars; l != nil; l = l.Next {
for l := func_.Func.Cvars; l != nil; l = l.Next {
v = l.N
if v.Op == OXXX {
continue
Expand All @@ -457,7 +457,7 @@ func walkclosure(func_ *Node, init **NodeList) *Node {
clos := Nod(OCOMPLIT, nil, Nod(OIND, typ, nil))
clos.Esc = func_.Esc
clos.Right.Implicit = true
clos.List = concat(list1(Nod(OCFUNC, func_.Closure.Nname, nil)), func_.Enter)
clos.List = concat(list1(Nod(OCFUNC, func_.Closure.Nname, nil)), func_.Func.Enter)

// Force type conversion from *struct to the func type.
clos = Nod(OCONVNOP, clos, nil)
Expand Down Expand Up @@ -554,7 +554,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
n = newname(Lookupf("a%d", i))
i++
n.Class = PPARAM
xfunc.Dcl = list(xfunc.Dcl, n)
xfunc.Func.Dcl = list(xfunc.Func.Dcl, n)
callargs = list(callargs, n)
fld = Nod(ODCLFIELD, n, typenod(t.Type))
if t.Isddd {
Expand All @@ -573,14 +573,14 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
n = newname(Lookupf("r%d", i))
i++
n.Class = PPARAMOUT
xfunc.Dcl = list(xfunc.Dcl, n)
xfunc.Func.Dcl = list(xfunc.Func.Dcl, n)
retargs = list(retargs, n)
l = list(l, Nod(ODCLFIELD, n, typenod(t.Type)))
}

xtype.Rlist = l

xfunc.Dupok = true
xfunc.Func.Dupok = true
xfunc.Nname = newfuncname(sym)
xfunc.Nname.Sym.Flags |= SymExported // disable export
xfunc.Nname.Ntype = xtype
Expand All @@ -589,7 +589,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {

// Declare and initialize variable holding receiver.

xfunc.Needctxt = true
xfunc.Func.Needctxt = true
cv := Nod(OCLOSUREVAR, nil, nil)
cv.Xoffset = int64(Widthptr)
cv.Type = rcvrtype
Expand All @@ -603,7 +603,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
ptr.Ullman = 1
ptr.Used = true
ptr.Curfn = xfunc
xfunc.Dcl = list(xfunc.Dcl, ptr)
xfunc.Func.Dcl = list(xfunc.Func.Dcl, ptr)
var body *NodeList
if Isptr[rcvrtype.Etype] || Isinter(rcvrtype) {
ptr.Ntype = typenod(rcvrtype)
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/internal/gc/dcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func declare(n *Node, ctxt int) {
Fatal("automatic outside function")
}
if Curfn != nil {
Curfn.Dcl = list(Curfn.Dcl, n)
Curfn.Func.Dcl = list(Curfn.Func.Dcl, n)
}
if n.Op == OTYPE {
declare_typegen++
Expand Down Expand Up @@ -445,7 +445,7 @@ func oldname(s *Sym) *Node {
n.Closure = c
c.Closure = n
c.Xoffset = 0
Curfn.Cvars = list(Curfn.Cvars, c)
Curfn.Func.Cvars = list(Curfn.Func.Cvars, c)
}

// return ref to closure var, not original
Expand Down Expand Up @@ -1486,7 +1486,7 @@ func funcsym(s *Sym) *Sym {
s1 := Pkglookup(s.Name+"·f", s.Pkg)
if s1.Def == nil {
s1.Def = newfuncname(s1)
s1.Def.Shortname = newname(s)
s1.Def.Func.Shortname = newname(s)
funcsyms = list(funcsyms, s1.Def)
}
s.Fsym = s1
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/internal/gc/esc.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func escfunc(e *EscState, func_ *Node) {
savefn := Curfn
Curfn = func_

for ll := Curfn.Dcl; ll != nil; ll = ll.Next {
for ll := Curfn.Func.Dcl; ll != nil; ll = ll.Next {
if ll.N.Op != ONAME {
continue
}
Expand All @@ -362,7 +362,7 @@ func escfunc(e *EscState, func_ *Node) {

// in a mutually recursive group we lose track of the return values
if e.recursive {
for ll := Curfn.Dcl; ll != nil; ll = ll.Next {
for ll := Curfn.Func.Dcl; ll != nil; ll = ll.Next {
if ll.N.Op == ONAME && ll.N.Class == PPARAMOUT {
escflows(e, &e.theSink, ll.N)
}
Expand Down Expand Up @@ -626,7 +626,7 @@ func esc(e *EscState, n *Node, up *Node) {
ll = n.List.N.Escretval
}

for lr := Curfn.Dcl; lr != nil && ll != nil; lr = lr.Next {
for lr := Curfn.Func.Dcl; lr != nil && ll != nil; lr = lr.Next {
if lr.N.Op != ONAME || lr.N.Class != PPARAMOUT {
continue
}
Expand Down Expand Up @@ -712,7 +712,7 @@ func esc(e *EscState, n *Node, up *Node) {
case OCLOSURE:
var a *Node
var v *Node
for ll := n.Cvars; ll != nil; ll = ll.Next {
for ll := n.Func.Cvars; ll != nil; ll = ll.Next {
v = ll.N
if v.Op == OXXX { // unnamed out argument; see dcl.c:/^funcargs
continue
Expand Down Expand Up @@ -1398,7 +1398,7 @@ func esctag(e *EscState, func_ *Node) {
savefn := Curfn
Curfn = func_

for ll := Curfn.Dcl; ll != nil; ll = ll.Next {
for ll := Curfn.Func.Dcl; ll != nil; ll = ll.Next {
if ll.N.Op != ONAME || ll.N.Class != PPARAM {
continue
}
Expand Down
Loading

0 comments on commit 3ed9e4c

Please sign in to comment.