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>
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
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,
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
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,
}
}
+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
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)
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
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)