]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add typChan
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 29 Mar 2016 17:00:54 +0000 (10:00 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Wed, 30 Mar 2016 17:19:42 +0000 (17:19 +0000)
Passes toolstash -cmp.

Change-Id: I2c71882f957c44047c7ac83c78236dcc3dfa15a1
Reviewed-on: https://go-review.googlesource.com/21304
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/parser.go
src/cmd/compile/internal/gc/type.go
src/cmd/compile/internal/gc/typecheck.go

index cf2d3be9ef59b0ac7ce01a3c675a6fecbe8bcdf1..90be80154dcc15c878164e51dd6e287a0754a13c 100644 (file)
@@ -3050,9 +3050,7 @@ func (p *parser) hidden_type_misc() *Type {
                default:
                        // LCHAN hidden_type_non_recv_chan
                        s2 := p.hidden_type_non_recv_chan()
-                       ss := typ(TCHAN)
-                       ss.Type = s2
-                       ss.Chan = Cboth
+                       ss := typeChan(s2, Cboth)
                        return ss
 
                case '(':
@@ -3060,18 +3058,14 @@ func (p *parser) hidden_type_misc() *Type {
                        p.next()
                        s3 := p.hidden_type_recv_chan()
                        p.want(')')
-                       ss := typ(TCHAN)
-                       ss.Type = s3
-                       ss.Chan = Cboth
+                       ss := typeChan(s3, Cboth)
                        return ss
 
                case LCOMM:
                        // LCHAN hidden_type
                        p.next()
                        s3 := p.hidden_type()
-                       ss := typ(TCHAN)
-                       ss.Type = s3
-                       ss.Chan = Csend
+                       ss := typeChan(s3, Csend)
                        return ss
                }
 
@@ -3090,9 +3084,7 @@ func (p *parser) hidden_type_recv_chan() *Type {
        p.want(LCHAN)
        s3 := p.hidden_type()
 
-       ss := typ(TCHAN)
-       ss.Type = s3
-       ss.Chan = Crecv
+       ss := typeChan(s3, Crecv)
        return ss
 }
 
index 6f40b00bc094b4cf33345e04d9b27d45b448622f..6d0476eedb6d4ba1f464d0c60b897ec7e1790dfb 100644 (file)
@@ -259,6 +259,14 @@ func typeDDDArray(elem *Type) *Type {
        return t
 }
 
+// typeChan returns a new chan Type with direction dir.
+func typeChan(elem *Type, dir uint8) *Type {
+       t := typ(TCHAN)
+       t.Type = elem
+       t.Chan = dir
+       return t
+}
+
 func newField() *Field {
        return &Field{
                Offset: BADWIDTH,
index ffd885671e866fead988d17c3a30b6cf116353f8..b570d2dcd7bc76a505bcabe16f2180c851aa962d 100644 (file)
@@ -413,10 +413,7 @@ OpSwitch:
                        n.Type = nil
                        return n
                }
-               t := typ(TCHAN)
-               t.Type = l.Type
-               // TODO(marvin): Fix Node.EType type union.
-               t.Chan = uint8(n.Etype)
+               t := typeChan(l.Type, uint8(n.Etype)) // TODO(marvin): Fix Node.EType type union.
                n.Op = OTYPE
                n.Type = t
                n.Left = nil