]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add Type.NumResults and friends
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 2 May 2017 16:16:22 +0000 (09:16 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 28 Aug 2017 22:42:57 +0000 (22:42 +0000)
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>
src/cmd/compile/internal/gc/closure.go
src/cmd/compile/internal/gc/esc.go
src/cmd/compile/internal/gc/fmt.go
src/cmd/compile/internal/gc/init.go
src/cmd/compile/internal/gc/order.go
src/cmd/compile/internal/gc/pgen.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/walk.go
src/cmd/compile/internal/types/type.go

index c6e94cc4b32ee2d745b6fc70fd244b5d7161f28c..afb6805337704046c3e4411389008e0a8a42674b 100644 (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.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)
index afe1e5a7e5b0b478fabbb30ed1a898abe8392219..0160c613579444b109b3c87d3a017ad8aa754c94 100644 (file)
@@ -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
index 8cd67ec203bf22c0d8e0d22a30aa18af92cacf9a..21f5e9d9b965557459635fd795e1f9a0052819ef 100644 (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)...)
 
-               switch t.Results().NumFields() {
+               switch t.NumResults() {
                case 0:
                        // nothing to do
 
index fcdec06ae766f25b58a38f171863fba65e5d3fd9..180cbcfda2b09742f8b0ce7c5477c447cc08a6f8 100644 (file)
@@ -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)
        }
 }
index cdda2f3486eb7dbd8642dd77f63156b87e04b0f5..297db503333a26f98df5f72fa743c0605a9404de 100644 (file)
@@ -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
index 5029b479b2efd41ef04a73475ad7786c686a3ae1..25bb0ae683224479be095cced5d5dcbf16c90a6e 100644 (file)
@@ -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)
index 68083b7fe994e6ce224f7006a74268e93145772b..845f7a6e317feb7252a8f0ff23b4d4f6e809614c 100644 (file)
@@ -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.
index b7b27d64d86f0289e2f9e09ce11f9eab736d76af..647694d68a43f7bfd770466bd5e016ca10e63a58 100644 (file)
@@ -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
index 0bef396da237538f4a57180058ba23e4849db223..465f317b5e14296aabec11e79558821238443996 100644 (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) })
                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")
index 971a670e9d3a178fab3e59e16270497c27613e19..e85e4ba8f5d573783d09c5681d2985a0668bb4bc 100644 (file)
@@ -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)
        }
 
index 3e12cc026c53dc808f42396a36b884135907d55b..d485e9cab15272a8aa0cb4743231cf89cb323c46 100644 (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) 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()