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>
case TCHAN:
p.tag(chanTag)
- p.int(int(t.Chan))
+ p.int(int(t.ChanDir()))
p.typ(t.Elem())
default:
return "[]" + t.Elem().String()
case TCHAN:
- switch t.Chan {
+ switch t.ChanDir() {
case Crecv:
return "<-chan " + t.Elem().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()
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))
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
}
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:
}
case TCHAN:
- if t1.Chan != t2.Chan {
+ if t1.ChanDir() != t2.ChanDir() {
return false
}
// 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
}
}
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:
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 }
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
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
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