1
0
mirror of https://github.com/golang/go synced 2024-11-19 16:44: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:
Josh Bleecher Snyder 2017-05-02 09:16:22 -07:00
parent e3442b4ee8
commit 2dd1f87d38
11 changed files with 28 additions and 25 deletions

View File

@ -645,7 +645,7 @@ func makepartialcall(fn *Node, t0 *types.Type, meth *types.Sym) *Node {
call := nod(OCALL, nodSym(OXDOT, ptr, meth), nil) call := nod(OCALL, nodSym(OXDOT, ptr, meth), nil)
call.List.Set(callargs) call.List.Set(callargs)
call.SetIsddd(ddd) call.SetIsddd(ddd)
if t0.Results().NumFields() == 0 { if t0.NumResults() == 0 {
body = append(body, call) body = append(body, call)
} else { } else {
n := nod(OAS2, nil, nil) n := nod(OAS2, nil, nil)

View File

@ -848,7 +848,7 @@ func (e *EscState) esc(n *Node, parent *Node) {
case ORETURN: case ORETURN:
retList := n.List retList := n.List
if retList.Len() == 1 && Curfn.Type.Results().NumFields() > 1 { if retList.Len() == 1 && Curfn.Type.NumResults() > 1 {
// OAS2FUNC in disguise // OAS2FUNC in disguise
// esccall already done on n.List.First() // esccall already done on n.List.First()
// tie e.nodeEscState(n.List.First()).Retval to Curfn.Func.Dcl PPARAMOUT's // tie e.nodeEscState(n.List.First()).Retval to Curfn.Func.Dcl PPARAMOUT's

View File

@ -814,7 +814,7 @@ func typefmt(t *types.Type, flag FmtFlag, mode fmtMode, depth int) string {
} }
buf = append(buf, tmodeString(t.Params(), mode, depth)...) buf = append(buf, tmodeString(t.Params(), mode, depth)...)
switch t.Results().NumFields() { switch t.NumResults() {
case 0: case 0:
// nothing to do // nothing to do

View File

@ -208,8 +208,7 @@ func fninit(n []*Node) {
} }
func (n *Node) checkInitFuncSignature() { func (n *Node) checkInitFuncSignature() {
ft := n.Type.FuncType() if n.Type.NumRecvs()+n.Type.NumParams()+n.Type.NumResults() > 0 {
if ft.Receiver.Fields().Len()+ft.Params.Fields().Len()+ft.Results.Fields().Len() > 0 {
Fatalf("init function cannot have receiver, params, or results: %v (%v)", n, n.Type) Fatalf("init function cannot have receiver, params, or results: %v (%v)", n, n.Type)
} }
} }

View File

@ -346,14 +346,14 @@ func ismulticall(l Nodes) bool {
} }
// call must return multiple values // 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, // Copyret emits t1, t2, ... = n, where n is a function call,
// and then returns the list t1, t2, .... // and then returns the list t1, t2, ....
func copyret(n *Node, order *Order) []*Node { func copyret(n *Node, order *Order) []*Node {
if !n.Type.IsFuncArgStruct() { 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 var l1 []*Node

View File

@ -37,7 +37,7 @@ func emitptrargsmap() {
nptr := int(Curfn.Type.ArgWidth() / int64(Widthptr)) nptr := int(Curfn.Type.ArgWidth() / int64(Widthptr))
bv := bvalloc(int32(nptr) * 2) bv := bvalloc(int32(nptr) * 2)
nbitmap := 1 nbitmap := 1
if Curfn.Type.Results().NumFields() > 0 { if Curfn.Type.NumResults() > 0 {
nbitmap = 2 nbitmap = 2
} }
off := duint32(lsym, 0, uint32(nbitmap)) off := duint32(lsym, 0, uint32(nbitmap))
@ -48,13 +48,13 @@ func emitptrargsmap() {
onebitwalktype1(Curfn.Type.Recvs(), &xoffset, bv) onebitwalktype1(Curfn.Type.Recvs(), &xoffset, bv)
} }
if Curfn.Type.Params().NumFields() > 0 { if Curfn.Type.NumParams() > 0 {
xoffset = 0 xoffset = 0
onebitwalktype1(Curfn.Type.Params(), &xoffset, bv) onebitwalktype1(Curfn.Type.Params(), &xoffset, bv)
} }
off = dbvec(lsym, off, bv) off = dbvec(lsym, off, bv)
if Curfn.Type.Results().NumFields() > 0 { if Curfn.Type.NumResults() > 0 {
xoffset = 0 xoffset = 0
onebitwalktype1(Curfn.Type.Results(), &xoffset, bv) onebitwalktype1(Curfn.Type.Results(), &xoffset, bv)
off = dbvec(lsym, off, bv) off = dbvec(lsym, off, bv)

View File

@ -1187,8 +1187,8 @@ ok:
} }
ot = dcommontype(lsym, ot, t) ot = dcommontype(lsym, ot, t)
inCount := t.Recvs().NumFields() + t.Params().NumFields() inCount := t.NumRecvs() + t.NumParams()
outCount := t.Results().NumFields() outCount := t.NumResults()
if isddd { if isddd {
outCount |= 1 << 15 outCount |= 1 << 15
} }
@ -1198,7 +1198,7 @@ ok:
ot += 4 // align for *rtype ot += 4 // align for *rtype
} }
dataAdd := (inCount + t.Results().NumFields()) * Widthptr dataAdd := (inCount + t.NumResults()) * Widthptr
ot = dextratype(lsym, ot, t, dataAdd) ot = dextratype(lsym, ot, t, dataAdd)
// Array of rtype pointers follows funcType. // Array of rtype pointers follows funcType.

View File

@ -1756,7 +1756,7 @@ func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym, iface
call := nod(OCALL, dot, nil) call := nod(OCALL, dot, nil)
call.List.Set(args) call.List.Set(args)
call.SetIsddd(isddd) call.SetIsddd(isddd)
if method.Type.Results().NumFields() > 0 { if method.Type.NumResults() > 0 {
n := nod(ORETURN, nil, nil) n := nod(ORETURN, nil, nil)
n.List.Set1(call) n.List.Set1(call)
call = n call = n

View File

@ -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) }) typecheckaste(OCALL, n.Left, n.Isddd(), t.Params(), n.List, func() string { return fmt.Sprintf("argument to %v", n.Left) })
ok |= Etop ok |= Etop
if t.Results().NumFields() == 0 { if t.NumResults() == 0 {
break OpSwitch break OpSwitch
} }
ok |= Erv ok |= Erv
if t.Results().NumFields() == 1 { if t.NumResults() == 1 {
n.Type = l.Type.Results().Field(0).Type 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" { 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. // Bail. This error will be reported elsewhere.
return n return n
} }
if t.Results().NumFields() != 2 { if t.NumResults() != 2 {
yyerror("invalid operation: complex expects two arguments, %v returns %d results", n.List.First(), t.Results().NumFields()) yyerror("invalid operation: complex expects two arguments, %v returns %d results", n.List.First(), t.NumResults())
n.Type = nil n.Type = nil
return n return n
} }
@ -4001,7 +4001,7 @@ func (n *Node) isterminating() bool {
// checkreturn makes sure that fn terminates appropriately. // checkreturn makes sure that fn terminates appropriately.
func checkreturn(fn *Node) { 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) markbreaklist(fn.Nbody, nil)
if !fn.Nbody.isterminating() { if !fn.Nbody.isterminating() {
yyerrorl(fn.Func.Endlineno, "missing return at end of function") yyerrorl(fn.Func.Endlineno, "missing return at end of function")

View File

@ -647,7 +647,7 @@ opswitch:
// Update type of OCALLFUNC node. // Update type of OCALLFUNC node.
// Output arguments had not changed, but their offsets could. // 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 n.Type = n.Left.Type.Results().Field(0).Type
} else { } else {
n.Type = n.Left.Type.Results() 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) Fatalf("mkcall %v %v", fn, fn.Type)
} }
n := fn.Type.Params().NumFields() n := fn.Type.NumParams()
if n != len(va) { if n != len(va) {
Fatalf("vmkcall %v needs %v args got %v", fn, n, len(va)) Fatalf("vmkcall %v needs %v args got %v", fn, n, len(va))
} }
r := nod(OCALL, fn, nil) r := nod(OCALL, fn, nil)
r.List.Set(va) r.List.Set(va)
if fn.Type.Results().NumFields() > 0 { if fn.Type.NumResults() > 0 {
r = typecheck(r, Erv|Efnstruct) r = typecheck(r, Erv|Efnstruct)
} else { } else {
r = typecheck(r, Etop) r = typecheck(r, Etop)
@ -3706,16 +3706,16 @@ func usemethod(n *Node) {
// //
// TODO(crawshaw): improve precision of match by working out // TODO(crawshaw): improve precision of match by working out
// how to check the method name. // how to check the method name.
if n := t.Params().NumFields(); n != 1 { if n := t.NumParams(); n != 1 {
return return
} }
if n := t.Results().NumFields(); n != 1 && n != 2 { if n := t.NumResults(); n != 1 && n != 2 {
return return
} }
p0 := t.Params().Field(0) p0 := t.Params().Field(0)
res0 := t.Results().Field(0) res0 := t.Results().Field(0)
var res1 *types.Field var res1 *types.Field
if t.Results().NumFields() == 2 { if t.NumResults() == 2 {
res1 = t.Results().Field(1) res1 = t.Results().Field(1)
} }

View File

@ -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) Params() *Type { return t.FuncType().Params }
func (t *Type) Results() *Type { return t.FuncType().Results } 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. // Recv returns the receiver of function type t, if any.
func (t *Type) Recv() *Field { func (t *Type) Recv() *Field {
s := t.Recvs() s := t.Recvs()