mirror of
https://github.com/golang/go
synced 2024-11-17 21:54:49 -07:00
cmd/compile/internal/gc: refactor ODCLFUNC creation
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>
This commit is contained in:
parent
b83a916f71
commit
97b89dc055
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user