Commit aa3650f0 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: eliminate IterParams

It's only used once, so just make the caller responsible for iterating
both the receiver and input params.

Change-Id: Icb34f3f0cf96e80fbe27f3f49d12eddc26599b92
Reviewed-on: https://go-review.googlesource.com/20454Reviewed-by: default avatarDave Cheney <dave@cheney.net>
parent 33fd4535
......@@ -618,15 +618,11 @@ func typeinit() {
func Argsize(t *Type) int {
var w int64
for fp, ip := IterFields(t.Results()); fp != nil; fp = ip.Next() {
if x := fp.Width + fp.Type.Width; x > w {
w = x
}
}
for fp, ip := IterParams(t); fp != nil; fp = ip.Next() {
if x := fp.Width + fp.Type.Width; x > w {
w = x
for _, p := range recvParamsResults {
for f, it := IterFields(p(t)); f != nil; f = it.Next() {
if x := f.Width + f.Type.Width; x > w {
w = x
}
}
}
......
......@@ -164,10 +164,10 @@ type Type struct {
Lastfn *Node // for usefield
}
// Iter provides an abstraction for iterating across struct fields,
// interface methods, and function parameters.
// Iter provides an abstraction for iterating across struct fields and
// interface methods.
type Iter struct {
a, b *Type
x *Type
}
// IterFields returns the first field or method in struct or interface type t
......@@ -176,35 +176,21 @@ func IterFields(t *Type) (*Type, Iter) {
if t.Etype != TSTRUCT && t.Etype != TINTER {
Fatalf("IterFields: type %v does not have fields", t)
}
i := Iter{a: t.Type}
i := Iter{x: t.Type}
f := i.Next()
return f, i
}
// IterParams returns the first reeiver or input parameter in function type t
// and an Iter value to continue iterating across the rest.
func IterParams(t *Type) (*Type, Iter) {
if t.Etype != TFUNC {
Fatalf("IterParams: type %v does not have params", t)
}
i := Iter{a: t.Recv().Type, b: t.Params().Type}
f := i.Next()
return f, i
}
// Next returns the next field, method, or parameter, if any.
// Next returns the next field or method, if any.
func (i *Iter) Next() *Type {
if i.a == nil {
if i.b == nil {
return nil
}
i.a, i.b = i.b, nil
if i.x == nil {
return nil
}
t := i.a
t := i.x
if t.Etype != TFIELD {
Fatalf("Iter.Next: type %v is not a field", t)
}
i.a = t.Down
i.x = t.Down
return t
}
......@@ -233,6 +219,13 @@ func (t *Type) Recv() *Type { return *t.RecvP() }
func (t *Type) Params() *Type { return *t.ParamsP() }
func (t *Type) Results() *Type { return *t.ResultsP() }
// recvParamsResults stores the accessor functions for a function Type's
// receiver, parameters, and result parameters, in that order.
// It can be used to iterate over all of a function's parameter lists.
var recvParamsResults = [3]func(*Type) *Type{
(*Type).Recv, (*Type).Params, (*Type).Results,
}
func (t *Type) Size() int64 {
dowidth(t)
return t.Width
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment