mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/typecheck: refactor and simplify DeclFunc
This CL refactors typecheck.DeclFunc to require the caller to have already constructed the ir.Func and signature type using ir.NewFunc and types.NewSignature, and simplifies typecheck.DeclFunc to simply return the slices of param and results ONAMEs. typecheck.DeclFunc was the last reason that ir.Field still exists, so this CL also gets rid of that. Change-Id: Ib398420bac2fd135a235810b8af1635fa754965c Reviewed-on: https://go-review.googlesource.com/c/go/+/520977 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
b581e44739
commit
009ca22fe2
7 changed files with 94 additions and 111 deletions
|
|
@ -140,21 +140,25 @@ func hashFunc(t *types.Type) *ir.Func {
|
|||
return sym.Def.(*ir.Name).Func
|
||||
}
|
||||
|
||||
base.Pos = base.AutogeneratedPos // less confusing than end of input
|
||||
pos := base.AutogeneratedPos // less confusing than end of input
|
||||
base.Pos = pos
|
||||
|
||||
// func sym(p *T, h uintptr) uintptr
|
||||
args := []*ir.Field{
|
||||
ir.NewField(base.Pos, typecheck.Lookup("p"), types.NewPtr(t)),
|
||||
ir.NewField(base.Pos, typecheck.Lookup("h"), types.Types[types.TUINTPTR]),
|
||||
}
|
||||
results := []*ir.Field{ir.NewField(base.Pos, nil, types.Types[types.TUINTPTR])}
|
||||
|
||||
fn := typecheck.DeclFunc(sym, nil, args, results)
|
||||
fn := ir.NewFunc(pos, pos, sym, types.NewSignature(nil,
|
||||
[]*types.Field{
|
||||
types.NewField(pos, typecheck.Lookup("p"), types.NewPtr(t)),
|
||||
types.NewField(pos, typecheck.Lookup("h"), types.Types[types.TUINTPTR]),
|
||||
},
|
||||
[]*types.Field{
|
||||
types.NewField(pos, nil, types.Types[types.TUINTPTR]),
|
||||
},
|
||||
))
|
||||
sym.Def = fn.Nname
|
||||
fn.Pragma |= ir.Noinline // TODO(mdempsky): We need to emit this during the unified frontend instead, to allow inlining.
|
||||
|
||||
np := fn.Type().Params().Field(0).Nname.(*ir.Name)
|
||||
nh := fn.Type().Params().Field(1).Nname.(*ir.Name)
|
||||
params, _ := typecheck.DeclFunc(fn)
|
||||
np := params[0]
|
||||
nh := params[1]
|
||||
|
||||
switch t.Kind() {
|
||||
case types.TARRAY:
|
||||
|
|
@ -365,19 +369,27 @@ func eqFunc(t *types.Type) *ir.Func {
|
|||
if sym.Def != nil {
|
||||
return sym.Def.(*ir.Name).Func
|
||||
}
|
||||
base.Pos = base.AutogeneratedPos // less confusing than end of input
|
||||
|
||||
pos := base.AutogeneratedPos // less confusing than end of input
|
||||
base.Pos = pos
|
||||
|
||||
// func sym(p, q *T) bool
|
||||
fn := typecheck.DeclFunc(sym, nil,
|
||||
[]*ir.Field{ir.NewField(base.Pos, typecheck.Lookup("p"), types.NewPtr(t)), ir.NewField(base.Pos, typecheck.Lookup("q"), types.NewPtr(t))},
|
||||
[]*ir.Field{ir.NewField(base.Pos, typecheck.Lookup("r"), types.Types[types.TBOOL])},
|
||||
)
|
||||
fn := ir.NewFunc(pos, pos, sym, types.NewSignature(nil,
|
||||
[]*types.Field{
|
||||
types.NewField(pos, typecheck.Lookup("p"), types.NewPtr(t)),
|
||||
types.NewField(pos, typecheck.Lookup("q"), types.NewPtr(t)),
|
||||
},
|
||||
[]*types.Field{
|
||||
types.NewField(pos, typecheck.Lookup("r"), types.Types[types.TBOOL]),
|
||||
},
|
||||
))
|
||||
sym.Def = fn.Nname
|
||||
fn.Pragma |= ir.Noinline // TODO(mdempsky): We need to emit this during the unified frontend instead, to allow inlining.
|
||||
|
||||
np := fn.Type().Params().Field(0).Nname.(*ir.Name)
|
||||
nq := fn.Type().Params().Field(1).Nname.(*ir.Name)
|
||||
nr := fn.Type().Results().Field(0).Nname.(*ir.Name)
|
||||
params, results := typecheck.DeclFunc(fn)
|
||||
np := params[0]
|
||||
nq := params[1]
|
||||
nr := results[0]
|
||||
|
||||
// Label to jump to if an equality test fails.
|
||||
neq := typecheck.AutoLabel(".neq")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue