]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: extract common noding code from func{Decl,Lit}
authorMatthew Dempsky <mdempsky@google.com>
Wed, 14 Mar 2018 23:53:30 +0000 (16:53 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 15 Mar 2018 01:09:42 +0000 (01:09 +0000)
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>
src/cmd/compile/internal/gc/closure.go
src/cmd/compile/internal/gc/noder.go

index fd728fd7bfe6ff2c321136149db81e08c3751183..113556e356e207bfbdbb45d116b544dbbc5dcfe9 100644 (file)
@@ -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.
index 1d491d2acca7072145c978d6435ca1c6da28285d..e2f60c1a8d7cbc4627b047252a5828474d92ab34 100644 (file)
@@ -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
 }