mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
463fe95bdd
commit
29517daff9
2 changed files with 17 additions and 30 deletions
|
|
@ -26,18 +26,7 @@ func (p *noder) funcLit(expr *syntax.FuncLit) *Node {
|
||||||
xfunc.Func.Closure = clo
|
xfunc.Func.Closure = clo
|
||||||
clo.Func.Closure = xfunc
|
clo.Func.Closure = xfunc
|
||||||
|
|
||||||
oldScope := p.funchdr(xfunc)
|
p.funcBody(xfunc, expr.Body)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
// closure-specific variables are hanging off the
|
// closure-specific variables are hanging off the
|
||||||
// ordinary ones in the symbol table; see oldname.
|
// ordinary ones in the symbol table; see oldname.
|
||||||
|
|
|
||||||
|
|
@ -136,16 +136,24 @@ type noder struct {
|
||||||
lastCloseScopePos syntax.Pos
|
lastCloseScopePos syntax.Pos
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *noder) funchdr(n *Node) ScopeID {
|
func (p *noder) funcBody(fn *Node, block *syntax.BlockStmt) {
|
||||||
old := p.scope
|
oldScope := p.scope
|
||||||
p.scope = 0
|
p.scope = 0
|
||||||
funchdr(n)
|
funchdr(fn)
|
||||||
return old
|
|
||||||
|
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()
|
funcbody()
|
||||||
p.scope = old
|
p.scope = oldScope
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *noder) openScope(pos syntax.Pos) {
|
func (p *noder) openScope(pos syntax.Pos) {
|
||||||
|
|
@ -459,28 +467,18 @@ func (p *noder) funcDecl(fun *syntax.FuncDecl) *Node {
|
||||||
declare(f.Func.Nname, PFUNC)
|
declare(f.Func.Nname, PFUNC)
|
||||||
}
|
}
|
||||||
|
|
||||||
oldScope := p.funchdr(f)
|
p.funcBody(f, fun.Body)
|
||||||
|
|
||||||
if fun.Body != nil {
|
if fun.Body != nil {
|
||||||
if f.Noescape() {
|
if f.Noescape() {
|
||||||
yyerrorl(f.Pos, "can only use //go:noescape with external func implementations")
|
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 {
|
} else {
|
||||||
if pure_go || strings.HasPrefix(f.funcname(), "init.") {
|
if pure_go || strings.HasPrefix(f.funcname(), "init.") {
|
||||||
yyerrorl(f.Pos, "missing function body")
|
yyerrorl(f.Pos, "missing function body")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.funcbody(oldScope)
|
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue