n := p.nod(expr, OCLOSURE, nil, nil)
n.Func.SetIsHiddenClosure(Curfn != nil)
n.Func.Ntype = ntype
- n.Func.Depth = funcdepth
n.Func.Outerfunc = Curfn
old := p.funchdr(n)
xfunc.Func.Nname.Name.Param.Ntype = xtype
xfunc.Func.Nname.Name.Defn = xfunc
declare(xfunc.Func.Nname, PFUNC)
- xfunc.Func.Nname.Name.Funcdepth = func_.Func.Depth
- xfunc.Func.Depth = func_.Func.Depth
xfunc.Func.Endlineno = func_.Func.Endlineno
if Ctxt.Flag_dynlink {
makefuncsym(xfunc.Func.Nname.Sym)
s.Lastlineno = lineno
s.Def = asTypesNode(n)
n.Name.Vargen = int32(gen)
- n.Name.Funcdepth = funcdepth
n.SetClass(ctxt)
autoexport(n, ctxt)
declare(v, dclcontext)
v.Name.Param.Ntype = t
v.Name.Defn = as2
- if funcdepth > 0 {
+ if Curfn != nil {
init = append(init, nod(ODCL, v, nil))
}
}
declare(v, dclcontext)
v.Name.Param.Ntype = t
- if e != nil || funcdepth > 0 || isblank(v) {
- if funcdepth > 0 {
+ if e != nil || Curfn != nil || isblank(v) {
+ if Curfn != nil {
init = append(init, nod(ODCL, v, nil))
}
e = nod(OAS, v, e)
return newnoname(s)
}
- if Curfn != nil && n.Op == ONAME && n.Name.Funcdepth > 0 && n.Name.Funcdepth != funcdepth {
+ if Curfn != nil && n.Op == ONAME && n.Name.Curfn != nil && n.Name.Curfn != Curfn {
// Inner func is referring to var in outer func.
//
// TODO(rsc): If there is an outer variable x and we
// the := it looks like a reference to the outer x so we'll
// make x a closure variable unnecessarily.
c := n.Name.Param.Innermost
- if c == nil || c.Name.Funcdepth != funcdepth {
+ if c == nil || c.Name.Curfn != Curfn {
// Do not have a closure var for the active closure yet; make one.
c = newname(s)
c.SetClass(PAUTOHEAP)
c.SetIsddd(n.Isddd())
c.Name.Defn = n
c.SetAddable(false)
- c.Name.Funcdepth = funcdepth
// Link into list of active closure variables.
// Popped from list in func closurebody.
// returns in auto-declaration context.
func funchdr(n *Node) {
// change the declaration context from extern to auto
- if funcdepth == 0 && dclcontext != PEXTERN {
+ if Curfn == nil && dclcontext != PEXTERN {
Fatalf("funchdr: dclcontext = %d", dclcontext)
}
dclcontext = PAUTO
- funcstart(n)
+ types.Markdcl()
+ funcstack = append(funcstack, Curfn)
+ Curfn = n
if n.Func.Nname != nil {
funcargs(n.Func.Nname.Name.Param.Ntype)
}
var funcstack []*Node // stack of previous values of Curfn
-var funcdepth int32 // len(funcstack) during parsing, but then forced to be the same later during compilation
-
-// start the function.
-// called before funcargs; undone at end of funcbody.
-func funcstart(n *Node) {
- types.Markdcl()
- funcstack = append(funcstack, Curfn)
- funcdepth++
- Curfn = n
-}
// finish the body.
// called in auto-declaration context.
}
types.Popdcl()
funcstack, Curfn = funcstack[:len(funcstack)-1], funcstack[len(funcstack)-1]
- funcdepth--
- if funcdepth == 0 {
+ if Curfn == nil {
dclcontext = PEXTERN
}
}
Param *Param // additional fields for ONAME, OTYPE
Decldepth int32 // declaration loop depth, increased for every loop or label
Vargen int32 // unique name for ONAME within a function. Function outputs are numbered starting at one.
- Funcdepth int32
used bool // for variable declared and not used error
flags bitset8
Inl Nodes // copy of the body for use in inlining
InlCost int32
- Depth int32
Label int32 // largest auto-generated label in this function