mirror of
https://github.com/golang/go
synced 2024-11-19 14:54:43 -07:00
cmd/compile: add Type.NumResults and friends
Passes toolstash-check. Change-Id: Id62bacff13fbd30de62b925d97a4e7bee1c66120 Reviewed-on: https://go-review.googlesource.com/59331 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
e3442b4ee8
commit
2dd1f87d38
@ -645,7 +645,7 @@ func makepartialcall(fn *Node, t0 *types.Type, meth *types.Sym) *Node {
|
||||
call := nod(OCALL, nodSym(OXDOT, ptr, meth), nil)
|
||||
call.List.Set(callargs)
|
||||
call.SetIsddd(ddd)
|
||||
if t0.Results().NumFields() == 0 {
|
||||
if t0.NumResults() == 0 {
|
||||
body = append(body, call)
|
||||
} else {
|
||||
n := nod(OAS2, nil, nil)
|
||||
|
@ -848,7 +848,7 @@ func (e *EscState) esc(n *Node, parent *Node) {
|
||||
|
||||
case ORETURN:
|
||||
retList := n.List
|
||||
if retList.Len() == 1 && Curfn.Type.Results().NumFields() > 1 {
|
||||
if retList.Len() == 1 && Curfn.Type.NumResults() > 1 {
|
||||
// OAS2FUNC in disguise
|
||||
// esccall already done on n.List.First()
|
||||
// tie e.nodeEscState(n.List.First()).Retval to Curfn.Func.Dcl PPARAMOUT's
|
||||
|
@ -814,7 +814,7 @@ func typefmt(t *types.Type, flag FmtFlag, mode fmtMode, depth int) string {
|
||||
}
|
||||
buf = append(buf, tmodeString(t.Params(), mode, depth)...)
|
||||
|
||||
switch t.Results().NumFields() {
|
||||
switch t.NumResults() {
|
||||
case 0:
|
||||
// nothing to do
|
||||
|
||||
|
@ -208,8 +208,7 @@ func fninit(n []*Node) {
|
||||
}
|
||||
|
||||
func (n *Node) checkInitFuncSignature() {
|
||||
ft := n.Type.FuncType()
|
||||
if ft.Receiver.Fields().Len()+ft.Params.Fields().Len()+ft.Results.Fields().Len() > 0 {
|
||||
if n.Type.NumRecvs()+n.Type.NumParams()+n.Type.NumResults() > 0 {
|
||||
Fatalf("init function cannot have receiver, params, or results: %v (%v)", n, n.Type)
|
||||
}
|
||||
}
|
||||
|
@ -346,14 +346,14 @@ func ismulticall(l Nodes) bool {
|
||||
}
|
||||
|
||||
// call must return multiple values
|
||||
return n.Left.Type.Results().NumFields() > 1
|
||||
return n.Left.Type.NumResults() > 1
|
||||
}
|
||||
|
||||
// Copyret emits t1, t2, ... = n, where n is a function call,
|
||||
// and then returns the list t1, t2, ....
|
||||
func copyret(n *Node, order *Order) []*Node {
|
||||
if !n.Type.IsFuncArgStruct() {
|
||||
Fatalf("copyret %v %d", n.Type, n.Left.Type.Results().NumFields())
|
||||
Fatalf("copyret %v %d", n.Type, n.Left.Type.NumResults())
|
||||
}
|
||||
|
||||
var l1 []*Node
|
||||
|
@ -37,7 +37,7 @@ func emitptrargsmap() {
|
||||
nptr := int(Curfn.Type.ArgWidth() / int64(Widthptr))
|
||||
bv := bvalloc(int32(nptr) * 2)
|
||||
nbitmap := 1
|
||||
if Curfn.Type.Results().NumFields() > 0 {
|
||||
if Curfn.Type.NumResults() > 0 {
|
||||
nbitmap = 2
|
||||
}
|
||||
off := duint32(lsym, 0, uint32(nbitmap))
|
||||
@ -48,13 +48,13 @@ func emitptrargsmap() {
|
||||
onebitwalktype1(Curfn.Type.Recvs(), &xoffset, bv)
|
||||
}
|
||||
|
||||
if Curfn.Type.Params().NumFields() > 0 {
|
||||
if Curfn.Type.NumParams() > 0 {
|
||||
xoffset = 0
|
||||
onebitwalktype1(Curfn.Type.Params(), &xoffset, bv)
|
||||
}
|
||||
|
||||
off = dbvec(lsym, off, bv)
|
||||
if Curfn.Type.Results().NumFields() > 0 {
|
||||
if Curfn.Type.NumResults() > 0 {
|
||||
xoffset = 0
|
||||
onebitwalktype1(Curfn.Type.Results(), &xoffset, bv)
|
||||
off = dbvec(lsym, off, bv)
|
||||
|
@ -1187,8 +1187,8 @@ ok:
|
||||
}
|
||||
|
||||
ot = dcommontype(lsym, ot, t)
|
||||
inCount := t.Recvs().NumFields() + t.Params().NumFields()
|
||||
outCount := t.Results().NumFields()
|
||||
inCount := t.NumRecvs() + t.NumParams()
|
||||
outCount := t.NumResults()
|
||||
if isddd {
|
||||
outCount |= 1 << 15
|
||||
}
|
||||
@ -1198,7 +1198,7 @@ ok:
|
||||
ot += 4 // align for *rtype
|
||||
}
|
||||
|
||||
dataAdd := (inCount + t.Results().NumFields()) * Widthptr
|
||||
dataAdd := (inCount + t.NumResults()) * Widthptr
|
||||
ot = dextratype(lsym, ot, t, dataAdd)
|
||||
|
||||
// Array of rtype pointers follows funcType.
|
||||
|
@ -1756,7 +1756,7 @@ func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym, iface
|
||||
call := nod(OCALL, dot, nil)
|
||||
call.List.Set(args)
|
||||
call.SetIsddd(isddd)
|
||||
if method.Type.Results().NumFields() > 0 {
|
||||
if method.Type.NumResults() > 0 {
|
||||
n := nod(ORETURN, nil, nil)
|
||||
n.List.Set1(call)
|
||||
call = n
|
||||
|
@ -1294,11 +1294,11 @@ OpSwitch:
|
||||
|
||||
typecheckaste(OCALL, n.Left, n.Isddd(), t.Params(), n.List, func() string { return fmt.Sprintf("argument to %v", n.Left) })
|
||||
ok |= Etop
|
||||
if t.Results().NumFields() == 0 {
|
||||
if t.NumResults() == 0 {
|
||||
break OpSwitch
|
||||
}
|
||||
ok |= Erv
|
||||
if t.Results().NumFields() == 1 {
|
||||
if t.NumResults() == 1 {
|
||||
n.Type = l.Type.Results().Field(0).Type
|
||||
|
||||
if n.Op == OCALLFUNC && n.Left.Op == ONAME && isRuntimePkg(n.Left.Sym.Pkg) && n.Left.Sym.Name == "getg" {
|
||||
@ -1476,8 +1476,8 @@ OpSwitch:
|
||||
// Bail. This error will be reported elsewhere.
|
||||
return n
|
||||
}
|
||||
if t.Results().NumFields() != 2 {
|
||||
yyerror("invalid operation: complex expects two arguments, %v returns %d results", n.List.First(), t.Results().NumFields())
|
||||
if t.NumResults() != 2 {
|
||||
yyerror("invalid operation: complex expects two arguments, %v returns %d results", n.List.First(), t.NumResults())
|
||||
n.Type = nil
|
||||
return n
|
||||
}
|
||||
@ -4001,7 +4001,7 @@ func (n *Node) isterminating() bool {
|
||||
|
||||
// checkreturn makes sure that fn terminates appropriately.
|
||||
func checkreturn(fn *Node) {
|
||||
if fn.Type.Results().NumFields() != 0 && fn.Nbody.Len() != 0 {
|
||||
if fn.Type.NumResults() != 0 && fn.Nbody.Len() != 0 {
|
||||
markbreaklist(fn.Nbody, nil)
|
||||
if !fn.Nbody.isterminating() {
|
||||
yyerrorl(fn.Func.Endlineno, "missing return at end of function")
|
||||
|
@ -647,7 +647,7 @@ opswitch:
|
||||
|
||||
// Update type of OCALLFUNC node.
|
||||
// Output arguments had not changed, but their offsets could.
|
||||
if n.Left.Type.Results().NumFields() == 1 {
|
||||
if n.Left.Type.NumResults() == 1 {
|
||||
n.Type = n.Left.Type.Results().Field(0).Type
|
||||
} else {
|
||||
n.Type = n.Left.Type.Results()
|
||||
@ -2778,14 +2778,14 @@ func vmkcall(fn *Node, t *types.Type, init *Nodes, va []*Node) *Node {
|
||||
Fatalf("mkcall %v %v", fn, fn.Type)
|
||||
}
|
||||
|
||||
n := fn.Type.Params().NumFields()
|
||||
n := fn.Type.NumParams()
|
||||
if n != len(va) {
|
||||
Fatalf("vmkcall %v needs %v args got %v", fn, n, len(va))
|
||||
}
|
||||
|
||||
r := nod(OCALL, fn, nil)
|
||||
r.List.Set(va)
|
||||
if fn.Type.Results().NumFields() > 0 {
|
||||
if fn.Type.NumResults() > 0 {
|
||||
r = typecheck(r, Erv|Efnstruct)
|
||||
} else {
|
||||
r = typecheck(r, Etop)
|
||||
@ -3706,16 +3706,16 @@ func usemethod(n *Node) {
|
||||
//
|
||||
// TODO(crawshaw): improve precision of match by working out
|
||||
// how to check the method name.
|
||||
if n := t.Params().NumFields(); n != 1 {
|
||||
if n := t.NumParams(); n != 1 {
|
||||
return
|
||||
}
|
||||
if n := t.Results().NumFields(); n != 1 && n != 2 {
|
||||
if n := t.NumResults(); n != 1 && n != 2 {
|
||||
return
|
||||
}
|
||||
p0 := t.Params().Field(0)
|
||||
res0 := t.Results().Field(0)
|
||||
var res1 *types.Field
|
||||
if t.Results().NumFields() == 2 {
|
||||
if t.NumResults() == 2 {
|
||||
res1 = t.Results().Field(1)
|
||||
}
|
||||
|
||||
|
@ -707,6 +707,10 @@ func (t *Type) Recvs() *Type { return t.FuncType().Receiver }
|
||||
func (t *Type) Params() *Type { return t.FuncType().Params }
|
||||
func (t *Type) Results() *Type { return t.FuncType().Results }
|
||||
|
||||
func (t *Type) NumRecvs() int { return t.FuncType().Receiver.NumFields() }
|
||||
func (t *Type) NumParams() int { return t.FuncType().Params.NumFields() }
|
||||
func (t *Type) NumResults() int { return t.FuncType().Results.NumFields() }
|
||||
|
||||
// Recv returns the receiver of function type t, if any.
|
||||
func (t *Type) Recv() *Field {
|
||||
s := t.Recvs()
|
||||
|
Loading…
Reference in New Issue
Block a user