]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: refactor ODCLFUNC creation
authorMatthew Dempsky <mdempsky@google.com>
Mon, 10 Apr 2017 20:03:14 +0000 (13:03 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 10 Apr 2017 20:17:54 +0000 (20:17 +0000)
Extract out some common boiler plate logic.

Passes toolstash-check -all.

Change-Id: Iddc8a733af8262558f56d13c91d9c27ee0d61330
Reviewed-on: https://go-review.googlesource.com/40253
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/alg.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/init.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/walk.go

index fa09cb5b9626fde8b1c19776f462ed2e7979b745..528748fdf7e84f87c41ddc68447b6ed6e2025537 100644 (file)
@@ -194,13 +194,7 @@ func genhash(sym *types.Sym, t *types.Type) {
        types.Markdcl(lineno)
 
        // func sym(p *T, h uintptr) uintptr
-       fn := nod(ODCLFUNC, nil, nil)
-
-       fn.Func.Nname = newname(sym)
-       fn.Func.Nname.Class = PFUNC
        tfn := nod(OTFUNC, nil, nil)
-       fn.Func.Nname.Name.Param.Ntype = tfn
-
        n := namedfield("p", types.NewPtr(t))
        tfn.List.Append(n)
        np := n.Left
@@ -210,8 +204,7 @@ func genhash(sym *types.Sym, t *types.Type) {
        n = anonfield(types.Types[TUINTPTR]) // return value
        tfn.Rlist.Append(n)
 
-       funchdr(fn)
-       fn.Func.Nname.Name.Param.Ntype = typecheck(fn.Func.Nname.Name.Param.Ntype, Etype)
+       fn := dclfunc(sym, tfn)
 
        // genhash is only called for types that have equality but
        // cannot be handled by the standard algorithms,
@@ -372,13 +365,7 @@ func geneq(sym *types.Sym, t *types.Type) {
        types.Markdcl(lineno)
 
        // func sym(p, q *T) bool
-       fn := nod(ODCLFUNC, nil, nil)
-
-       fn.Func.Nname = newname(sym)
-       fn.Func.Nname.Class = PFUNC
        tfn := nod(OTFUNC, nil, nil)
-       fn.Func.Nname.Name.Param.Ntype = tfn
-
        n := namedfield("p", types.NewPtr(t))
        tfn.List.Append(n)
        np := n.Left
@@ -388,8 +375,7 @@ func geneq(sym *types.Sym, t *types.Type) {
        n = anonfield(types.Types[TBOOL])
        tfn.Rlist.Append(n)
 
-       funchdr(fn)
-       fn.Func.Nname.Name.Param.Ntype = typecheck(fn.Func.Nname.Name.Param.Ntype, Etype)
+       fn := dclfunc(sym, tfn)
 
        // geneq is only called for types that have equality but
        // cannot be handled by the standard algorithms,
index 222881771d6761790997a0156bd76eed086ae934..7dadc6224dc405407d6c0428a6c2b328f838363b 100644 (file)
@@ -1100,6 +1100,21 @@ func makefuncsym(s *types.Sym) {
        }
 }
 
+func dclfunc(sym *types.Sym, tfn *Node) *Node {
+       if tfn.Op != OTFUNC {
+               Fatalf("expected OTFUNC node, got %v", tfn)
+       }
+
+       fn := nod(ODCLFUNC, nil, nil)
+       fn.Func.Nname = newname(sym)
+       fn.Func.Nname.Name.Defn = fn
+       fn.Func.Nname.Name.Param.Ntype = tfn
+       declare(fn.Func.Nname, PFUNC)
+       funchdr(fn)
+       fn.Func.Nname.Name.Param.Ntype = typecheck(fn.Func.Nname.Name.Param.Ntype, Etype)
+       return fn
+}
+
 type nowritebarrierrecChecker struct {
        curfn  *Node
        stable bool
index e26718dfdc26193e1875113f8d3b711dc4dc1554..df2d70fcafb1760aeb0aaad56b603e3e0b80d20e 100644 (file)
@@ -86,13 +86,8 @@ func fninit(n []*Node) {
        addvar(gatevar, types.Types[TUINT8], PEXTERN)
 
        // (2)
-       fn := nod(ODCLFUNC, nil, nil)
        initsym := lookup("init")
-       fn.Func.Nname = newname(initsym)
-       fn.Func.Nname.Name.Defn = fn
-       fn.Func.Nname.Name.Param.Ntype = nod(OTFUNC, nil, nil)
-       declare(fn.Func.Nname, PFUNC)
-       funchdr(fn)
+       fn := dclfunc(initsym, nod(OTFUNC, nil, nil))
 
        // (3)
        a := nod(OIF, nil, nil)
index d9fdd76f233b9fdab474d93cff8af0af07b512b1..a3be163c4eb346c72a697c6ebe5823a2f43c3c8e 100644 (file)
@@ -1710,14 +1710,9 @@ func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym, iface
        t.List.Set(append(l, in...))
        t.Rlist.Set(out)
 
-       fn := nod(ODCLFUNC, nil, nil)
+       fn := dclfunc(newnam, t)
        fn.Func.SetDupok(true)
-       fn.Func.Nname = newname(newnam)
-       fn.Func.Nname.Name.Defn = fn
-       fn.Func.Nname.Name.Param.Ntype = t
        fn.Func.Nname.Sym.SetExported(true) // prevent export; see closure.go
-       declare(fn.Func.Nname, PFUNC)
-       funchdr(fn)
 
        // arg list
        var args []*Node
index 4c06fe5e6c9e880289bb02fe1520fbd966d86e84..7cdc56d05cfc46063f579a8aec0a7ce909d9b19c 100644 (file)
@@ -3652,17 +3652,12 @@ func walkprintfunc(n *Node, init *Nodes) *Node {
                printargs = append(printargs, a.Left)
        }
 
-       fn := nod(ODCLFUNC, nil, nil)
-       walkprintfunc_prgen++
-       buf = fmt.Sprintf("print·%d", walkprintfunc_prgen)
-       fn.Func.Nname = newname(lookup(buf))
-       fn.Func.Nname.Name.Defn = fn
-       fn.Func.Nname.Name.Param.Ntype = t
-       declare(fn.Func.Nname, PFUNC)
-
        oldfn := Curfn
        Curfn = nil
-       funchdr(fn)
+
+       walkprintfunc_prgen++
+       sym := lookupN("print·%d", walkprintfunc_prgen)
+       fn := dclfunc(sym, t)
 
        a = nod(n.Op, nil, nil)
        a.List.Set(printargs)