mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/ir: add Func.DeclareParams
There's several copies of this function. We only need one. While here, normalize so that we always declare parameters, and always use the names ~pNN for params and ~rNN for results. Change-Id: I49e90d3fd1820f3c07936227ed5cfefd75d49a1c Reviewed-on: https://go-review.googlesource.com/c/go/+/528415 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
de4ead8102
commit
d18e9407b0
15 changed files with 179 additions and 361 deletions
|
|
@ -65,9 +65,7 @@ type Func struct {
|
|||
// include closurevars until transforming closures during walk.
|
||||
// Names must be listed PPARAMs, PPARAMOUTs, then PAUTOs,
|
||||
// with PPARAMs and PPARAMOUTs in order corresponding to the function signature.
|
||||
// However, as anonymous or blank PPARAMs are not actually declared,
|
||||
// they are omitted from Dcl.
|
||||
// Anonymous and blank PPARAMOUTs are declared as ~rNN and ~bNN Names, respectively.
|
||||
// Anonymous and blank params are declared as ~pNN (for PPARAMs) and ~rNN (for PPARAMOUTs).
|
||||
Dcl []*Name
|
||||
|
||||
// ClosureVars lists the free variables that are used within a
|
||||
|
|
@ -455,3 +453,40 @@ func IsFuncPCIntrinsic(n *CallExpr) bool {
|
|||
return (fn.Name == "FuncPCABI0" || fn.Name == "FuncPCABIInternal") &&
|
||||
fn.Pkg.Path == "internal/abi"
|
||||
}
|
||||
|
||||
// DeclareParams creates Names for all of the parameters in fn's
|
||||
// signature and adds them to fn.Dcl.
|
||||
//
|
||||
// If setNname is true, then it also sets types.Field.Nname for each
|
||||
// parameter.
|
||||
func (fn *Func) DeclareParams(setNname bool) {
|
||||
if fn.Dcl != nil {
|
||||
base.FatalfAt(fn.Pos(), "%v already has Dcl", fn)
|
||||
}
|
||||
|
||||
declareParams := func(params []*types.Field, ctxt Class, prefix string, offset int) {
|
||||
for i, param := range params {
|
||||
sym := param.Sym
|
||||
if sym == nil || sym.IsBlank() {
|
||||
sym = fn.Sym().Pkg.LookupNum(prefix, i)
|
||||
}
|
||||
|
||||
name := NewNameAt(param.Pos, sym, param.Type)
|
||||
name.Class = ctxt
|
||||
name.Curfn = fn
|
||||
fn.Dcl[offset+i] = name
|
||||
|
||||
if setNname {
|
||||
param.Nname = name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sig := fn.Type()
|
||||
params := sig.RecvParams()
|
||||
results := sig.Results()
|
||||
|
||||
fn.Dcl = make([]*Name, len(params)+len(results))
|
||||
declareParams(params, PPARAM, "~p", 0)
|
||||
declareParams(results, PPARAMOUT, "~r", len(params))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue