Commit 29517daf authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: extract common noding code from func{Decl,Lit}

Passes toolstash-check.

Change-Id: I8290221d6169e077dfa4ea737d685c7fcecf6841
Reviewed-on: https://go-review.googlesource.com/100835
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent 463fe95b
......@@ -26,18 +26,7 @@ func (p *noder) funcLit(expr *syntax.FuncLit) *Node {
xfunc.Func.Closure = clo
clo.Func.Closure = xfunc
oldScope := p.funchdr(xfunc)
body := p.stmts(expr.Body.List)
if body == nil {
body = []*Node{nod(OEMPTY, nil, nil)}
}
xfunc.Nbody.Set(body)
lineno = p.makeXPos(expr.Body.Rbrace)
xfunc.Func.Endlineno = lineno
p.funcbody(oldScope)
p.funcBody(xfunc, expr.Body)
// closure-specific variables are hanging off the
// ordinary ones in the symbol table; see oldname.
......
......@@ -136,16 +136,24 @@ type noder struct {
lastCloseScopePos syntax.Pos
}
func (p *noder) funchdr(n *Node) ScopeID {
old := p.scope
func (p *noder) funcBody(fn *Node, block *syntax.BlockStmt) {
oldScope := p.scope
p.scope = 0
funchdr(n)
return old
}
funchdr(fn)
if block != nil {
body := p.stmts(block.List)
if body == nil {
body = []*Node{nod(OEMPTY, nil, nil)}
}
fn.Nbody.Set(body)
lineno = p.makeXPos(block.Rbrace)
fn.Func.Endlineno = lineno
}
func (p *noder) funcbody(old ScopeID) {
funcbody()
p.scope = old
p.scope = oldScope
}
func (p *noder) openScope(pos syntax.Pos) {
......@@ -459,28 +467,18 @@ func (p *noder) funcDecl(fun *syntax.FuncDecl) *Node {
declare(f.Func.Nname, PFUNC)
}
oldScope := p.funchdr(f)
p.funcBody(f, fun.Body)
if fun.Body != nil {
if f.Noescape() {
yyerrorl(f.Pos, "can only use //go:noescape with external func implementations")
}
body := p.stmts(fun.Body.List)
if body == nil {
body = []*Node{p.nod(fun, OEMPTY, nil, nil)}
}
f.Nbody.Set(body)
lineno = p.makeXPos(fun.Body.Rbrace)
f.Func.Endlineno = lineno
} else {
if pure_go || strings.HasPrefix(f.funcname(), "init.") {
yyerrorl(f.Pos, "missing function body")
}
}
p.funcbody(oldScope)
return f
}
......
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