]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use IsSlice and IsArray instead of checking Bound
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 29 Mar 2016 16:14:19 +0000 (09:14 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Wed, 30 Mar 2016 17:18:29 +0000 (17:18 +0000)
Changes generated by eg and manually checked.

Isfixedarray, Isslice, and many other
Type-related functions in subr.go should
either be deleted or moved to type.go.
Later, though; the game now is cleanup via encapsulation.

Passes toolstash -cmp.

Change-Id: I83dd8816f6263b74367d23c2719a08c362e330f9
Reviewed-on: https://go-review.googlesource.com/21303
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/align.go
src/cmd/compile/internal/gc/bexport.go
src/cmd/compile/internal/gc/fmt.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/sinit.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/type.go
src/cmd/compile/internal/gc/typecheck.go

index e852c0b1226e8d436a7e0e69d4008e79e78f5559..1ca7dd4d20b1cb32a27b7dd4a9ddb9e792f8e158 100644 (file)
@@ -240,7 +240,7 @@ func dowidth(t *Type) {
                if t.Type == nil {
                        break
                }
-               if t.Bound >= 0 {
+               if t.IsArray() {
                        dowidth(t.Type)
                        if t.Type.Width != 0 {
                                cap := (uint64(Thearch.MAXWIDTH) - 1) / uint64(t.Type.Width)
index dd1af1c0f82fd213690b8770b56df78dbfa5ecf4..f47d7bb06ec154aeda6f8bae84bbf8624ce9cd3a 100644 (file)
@@ -506,7 +506,7 @@ func (p *exporter) typ(t *Type) {
                if t.isDDDArray() {
                        Fatalf("array bounds should be known at export time: %v", t)
                }
-               if t.Bound >= 0 {
+               if t.IsArray() {
                        p.tag(arrayTag)
                        p.int64(t.Bound)
                } else {
index 11122a4741888db0829c47c0c44b4b3cc56f857b..79d64a10be7c5d65bfb8a40f2f20f05f3491b34b 100644 (file)
@@ -586,7 +586,7 @@ func typefmt(t *Type, flag FmtFlag) string {
                return "*" + t.Type.String()
 
        case TARRAY:
-               if t.Bound >= 0 {
+               if t.IsArray() {
                        return fmt.Sprintf("[%d]%v", t.Bound, t.Type)
                }
                if t.isDDDArray() {
index c05ee3cdd11dad7ad5d08c2af0a61e67934d95c3..92f8285fa8393d5c984427b92245feef60656642 100644 (file)
@@ -674,7 +674,7 @@ func haspointers(t *Type) bool {
                ret = false
 
        case TARRAY:
-               if t.Bound < 0 { // slice
+               if t.IsSlice() {
                        ret = true
                        break
                }
@@ -835,7 +835,7 @@ func dcommontype(s *Sym, ot int, t *Type) int {
        ot = duint8(s, ot, t.Align) // fieldAlign
 
        i = kinds[t.Etype]
-       if t.Etype == TARRAY && t.Bound < 0 {
+       if t.IsSlice() {
                i = obj.KindSlice
        }
        if !haspointers(t) {
@@ -1114,7 +1114,7 @@ ok:
                ot = dextratype(s, ot, t, 0)
 
        case TARRAY:
-               if t.Bound >= 0 {
+               if t.IsArray() {
                        // ../../../../runtime/type.go:/arrayType
                        s1 := dtypesym(t.Type)
                        t2 := typSlice(t.Type)
index 9782673892e49a4b5d76f5fc45e6ee3ec27af7ae..06776121532d1c4774583fe9779c37fd4c10d400 100644 (file)
@@ -540,7 +540,7 @@ func getdyn(n *Node, top int) initGenType {
                return initDynamic
 
        case OARRAYLIT:
-               if top == 0 && n.Type.Bound < 0 {
+               if top == 0 && n.Type.IsSlice() {
                        return initDynamic
                }
 
@@ -568,7 +568,7 @@ func structlit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
 
                switch value.Op {
                case OARRAYLIT:
-                       if value.Type.Bound < 0 {
+                       if value.Type.IsSlice() {
                                if pass == 1 && ctxt != 0 {
                                        a := NodSym(ODOT, var_, index.Sym)
                                        slicelit(ctxt, value, a, init)
@@ -630,7 +630,7 @@ func arraylit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
 
                switch value.Op {
                case OARRAYLIT:
-                       if value.Type.Bound < 0 {
+                       if value.Type.IsSlice() {
                                if pass == 1 && ctxt != 0 {
                                        a := Nod(OINDEX, var_, index)
                                        slicelit(ctxt, value, a, init)
@@ -804,7 +804,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init *Nodes) {
 
                switch value.Op {
                case OARRAYLIT:
-                       if value.Type.Bound < 0 {
+                       if value.Type.IsSlice() {
                                break
                        }
                        arraylit(ctxt, 2, value, a, init)
@@ -1076,7 +1076,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
                if t.Etype != TARRAY {
                        Fatalf("anylit: not array")
                }
-               if t.Bound < 0 {
+               if t.IsSlice() {
                        slicelit(ctxt, n, var_, init)
                        break
                }
@@ -1195,7 +1195,7 @@ func stataddr(nam *Node, n *Node) bool {
                return true
 
        case OINDEX:
-               if n.Left.Type.Bound < 0 {
+               if n.Left.Type.IsSlice() {
                        break
                }
                if !stataddr(nam, n.Left) {
@@ -1384,7 +1384,7 @@ func genAsInitNoCheck(n *Node, reportOnly bool) bool {
                }
 
                // nr is the array being converted to a slice
-               if nr.Type == nil || nr.Type.Etype != TARRAY || nr.Type.Bound < 0 {
+               if nr.Type == nil || nr.Type.Etype != TARRAY || nr.Type.IsSlice() {
                        return false
                }
 
index d4f2f83a7ff9dfff4bc49c41b44abdced0416a5a..96fe21968661bd6eab02afc37e92f56863239886 100644 (file)
@@ -583,11 +583,11 @@ func Istype(t *Type, et EType) bool {
 }
 
 func Isfixedarray(t *Type) bool {
-       return t != nil && t.Etype == TARRAY && t.Bound >= 0
+       return t != nil && t.IsArray()
 }
 
 func Isslice(t *Type) bool {
-       return t != nil && t.Etype == TARRAY && t.Bound < 0
+       return t != nil && t.IsSlice()
 }
 
 func isblank(n *Node) bool {
index 26bcd8f1cb86fd7c8938863ba96fdca26eb4af44..6f40b00bc094b4cf33345e04d9b27d45b448622f 100644 (file)
@@ -789,6 +789,7 @@ func (t *Type) IsChan() bool {
 }
 
 func (t *Type) IsSlice() bool {
+       // TODO(josharian): Change this to t.Bound == -1.
        return t.Etype == TARRAY && t.Bound < 0
 }
 
index f6f13c485c0273c0417f196cd04c77143d7406cb..ffd885671e866fead988d17c3a30b6cf116353f8 100644 (file)
@@ -375,7 +375,7 @@ OpSwitch:
                                Yyerror("array bound is too large")
                                n.Type = nil
                                return n
-                       } else if t.Bound < 0 {
+                       } else if t.IsSlice() {
                                Yyerror("array bound must be non-negative")
                                n.Type = nil
                                return n
@@ -1412,7 +1412,7 @@ OpSwitch:
                        }
 
                case TARRAY:
-                       if t.Bound < 0 { // slice
+                       if t.IsSlice() {
                                break
                        }
                        if callrecv(l) { // has call or receive
@@ -2974,7 +2974,7 @@ func typecheckcomplit(n *Node) *Node {
                        i++
                        if int64(i) > length {
                                length = int64(i)
-                               if t.Bound >= 0 && length > t.Bound {
+                               if t.IsArray() && length > t.Bound {
                                        setlineno(l)
                                        Yyerror("array index %d out of bounds [0:%d]", length-1, t.Bound)
                                        t.Bound = -1 // no more errors
@@ -2991,7 +2991,7 @@ func typecheckcomplit(n *Node) *Node {
                if t.isDDDArray() {
                        t.Bound = length
                }
-               if t.Bound < 0 {
+               if t.IsSlice() {
                        n.Right = Nodintconst(length)
                }
                n.Op = OARRAYLIT