]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add Type.ChanDir
authorJosh Bleecher Snyder <josharian@gmail.com>
Sat, 2 Apr 2016 23:26:30 +0000 (16:26 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sun, 3 Apr 2016 01:50:04 +0000 (01:50 +0000)
Generated with eg.

Passes toolstash -cmp.

Change-Id: I3af35191e73a558080f777a4eed93bcec7dfe1f5
Reviewed-on: https://go-review.googlesource.com/21469
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/bexport.go
src/cmd/compile/internal/gc/fmt.go
src/cmd/compile/internal/gc/range.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/type.go
src/cmd/compile/internal/gc/typecheck.go

index bfa5a501a0ae9b0e29b576e9160c581f337cef36..a63f615267e0fa0b529ea25932f90d2a3f63a98e 100644 (file)
@@ -547,7 +547,7 @@ func (p *exporter) typ(t *Type) {
 
        case TCHAN:
                p.tag(chanTag)
-               p.int(int(t.Chan))
+               p.int(int(t.ChanDir()))
                p.typ(t.Elem())
 
        default:
index 72e1bc31424f4587c1e0bbf721e14965358e3e8f..94805594c7dd093533af9ec5c900c17e2d03220d 100644 (file)
@@ -596,7 +596,7 @@ func typefmt(t *Type, flag FmtFlag) string {
                return "[]" + t.Elem().String()
 
        case TCHAN:
-               switch t.Chan {
+               switch t.ChanDir() {
                case Crecv:
                        return "<-chan " + t.Elem().String()
 
@@ -604,7 +604,7 @@ func typefmt(t *Type, flag FmtFlag) string {
                        return "chan<- " + t.Elem().String()
                }
 
-               if t.Elem() != nil && t.Elem().IsChan() && t.Elem().Sym == nil && t.Elem().Chan == Crecv {
+               if t.Elem() != nil && t.Elem().IsChan() && t.Elem().Sym == nil && t.Elem().ChanDir() == Crecv {
                        return "chan (" + t.Elem().String() + ")"
                }
                return "chan " + t.Elem().String()
@@ -1102,7 +1102,7 @@ func exprfmt(n *Node, prec int) string {
                if n.Type != nil && n.Type.Etype != TIDEAL && n.Type.Etype != TNIL && n.Type != idealbool && n.Type != idealstring {
                        // Need parens when type begins with what might
                        // be misinterpreted as a unary operator: * or <-.
-                       if n.Type.IsPtr() || (n.Type.IsChan() && n.Type.Chan == Crecv) {
+                       if n.Type.IsPtr() || (n.Type.IsChan() && n.Type.ChanDir() == Crecv) {
                                return fmt.Sprintf("(%v)(%v)", n.Type, Vconv(n.Val(), 0))
                        } else {
                                return fmt.Sprintf("%v(%v)", n.Type, Vconv(n.Val(), 0))
index e97a628ce3131c9b5e596029d034a52c83f2d8ee..6a28c3ceb5e582a050c2b960238694eaa448948c 100644 (file)
@@ -58,7 +58,7 @@ func typecheckrange(n *Node) {
                t2 = t.Val()
 
        case TCHAN:
-               if t.Chan&Crecv == 0 {
+               if t.ChanDir()&Crecv == 0 {
                        Yyerror("invalid operation: range %v (receive from send-only type %v)", n.Right, n.Right.Type)
                        goto out
                }
index 95e5214a430946a2d496b5f6a37a55cedc1fc9e3..11bcd4cdc6de0f8084de8ae1926502f8ae6a6b5e 100644 (file)
@@ -1143,7 +1143,7 @@ ok:
 
                ot = dcommontype(s, ot, t)
                ot = dsymptr(s, ot, s1, 0)
-               ot = duintptr(s, ot, uint64(t.Chan))
+               ot = duintptr(s, ot, uint64(t.ChanDir()))
                ot = dextratype(s, ot, t, 0)
 
        case TFUNC:
index 2447bccb5c847724a5e38b8e132ac6a4665262bd..a61b8bcd271f0719820da15e5287f2f2e947e395 100644 (file)
@@ -721,7 +721,7 @@ func eqtype1(t1, t2 *Type, assumedEqual map[typePair]struct{}) bool {
                }
 
        case TCHAN:
-               if t1.Chan != t2.Chan {
+               if t1.ChanDir() != t2.ChanDir() {
                        return false
                }
 
@@ -844,7 +844,7 @@ func assignop(src *Type, dst *Type, why *string) Op {
        // 4. src is a bidirectional channel value, dst is a channel type,
        // src and dst have identical element types, and
        // either src or dst is not a named type.
-       if src.IsChan() && src.Chan == Cboth && dst.IsChan() {
+       if src.IsChan() && src.ChanDir() == Cboth && dst.IsChan() {
                if Eqtype(src.Elem(), dst.Elem()) && (src.Sym == nil || dst.Sym == nil) {
                        return OCONVNOP
                }
index 1aefc9cf245423efcfaf7caca72b2b59fdbba034..d207a046d74a28c4c9a497e8ed0ab8919f6ce351 100644 (file)
@@ -817,8 +817,8 @@ func (t *Type) cmp(x *Type) ssa.Cmp {
                }
 
        case TCHAN:
-               if t.Chan != x.Chan {
-                       return cmpForNe(t.Chan < x.Chan)
+               if t.ChanDir() != x.ChanDir() {
+                       return cmpForNe(t.ChanDir() < x.ChanDir())
                }
 
        default:
@@ -955,6 +955,13 @@ func (t *Type) SetNumElem(n int64) {
        t.Bound = n
 }
 
+// ChanDir returns the direction of a channel type t.
+// The direction will be one of Crecv, Csend, or Cboth.
+func (t *Type) ChanDir() uint8 {
+       t.wantEtype(TCHAN)
+       return t.Chan
+}
+
 func (t *Type) IsMemory() bool { return false }
 func (t *Type) IsFlags() bool  { return false }
 func (t *Type) IsVoid() bool   { return false }
index 828f5bae97a394fd8506370a081e8a8204540908..6b566210d78188cf4376e1869069f4ce73692659 100644 (file)
@@ -1048,7 +1048,7 @@ OpSwitch:
                        return n
                }
 
-               if t.Chan&Crecv == 0 {
+               if t.ChanDir()&Crecv == 0 {
                        Yyerror("invalid operation: %v (receive from send-only type %v)", n, t)
                        n.Type = nil
                        return n
@@ -1075,7 +1075,7 @@ OpSwitch:
                        return n
                }
 
-               if t.Chan&Csend == 0 {
+               if t.ChanDir()&Csend == 0 {
                        Yyerror("invalid operation: %v (send to receive-only type %v)", n, t)
                        n.Type = nil
                        return n
@@ -1528,7 +1528,7 @@ OpSwitch:
                        return n
                }
 
-               if t.Chan&Csend == 0 {
+               if t.ChanDir()&Csend == 0 {
                        Yyerror("invalid operation: %v (cannot close receive-only channel)", n)
                        n.Type = nil
                        return n