]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: clean up ... Bound marker
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 28 Mar 2016 00:57:42 +0000 (17:57 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 28 Mar 2016 23:33:30 +0000 (23:33 +0000)
This mostly a mechanical change.
However, the change in assignop (subr.go) is a bug fix.
The code didn’t match the comment,
and the comment was correct.
Nevertheless, this CL passes toolstash -cmp.

The last direct reference to dddBound outside
type.go (in typecheck.go) will go away
in a future CL.

Change-Id: Ifb1691e0a07f906712c18c4a4cd23060807a5da5
Reviewed-on: https://go-review.googlesource.com/21235
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
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/subr.go
src/cmd/compile/internal/gc/type.go
src/cmd/compile/internal/gc/typecheck.go

index dd508a508f9cbac51856fe74058911d35c2df161..61a33943371ed5dd548e9e1851439a5e9a36b885 100644 (file)
@@ -256,7 +256,7 @@ func dowidth(t *Type) {
                        w = int64(sizeof_Array)
                        checkwidth(t.Type)
                        t.Align = uint8(Widthptr)
-               } else if t.Bound == -100 {
+               } else if t.isDDDArray() {
                        if !t.Broke {
                                Yyerror("use of [...] array outside of array literal")
                                t.Broke = true
index 03f2cf48dfd323027cfb15125829d2a1d8259bb5..518666c767a8808a1e28907ee3c9a50ddeb34eec 100644 (file)
@@ -503,8 +503,10 @@ func (p *exporter) typ(t *Type) {
        // otherwise we have a type literal
        switch t.Etype {
        case TARRAY:
-               // TODO(gri) define named constant for the -100
-               if t.Bound >= 0 || t.Bound == -100 {
+               if t.isDDDArray() {
+                       Fatalf("array bounds should be known at export time: %v", t)
+               }
+               if t.Bound >= 0 {
                        p.tag(arrayTag)
                        p.int64(t.Bound)
                } else {
index 6199abec8ab959804d0ba56c09e069bf64e6f45f..8f809c82eedd9b64605f161bc9f10e620477cca3 100644 (file)
@@ -589,7 +589,7 @@ func typefmt(t *Type, flag FmtFlag) string {
                if t.Bound >= 0 {
                        return fmt.Sprintf("[%d]%v", t.Bound, t.Type)
                }
-               if t.Bound == -100 {
+               if t.isDDDArray() {
                        return "[...]" + t.Type.String()
                }
                return "[]" + t.Type.String()
index f72ea61ebbaf4732aaa9866ac0278da19e1a9183..e827464bde98e73cf51f1187988b3a284b5d4562 100644 (file)
@@ -897,7 +897,7 @@ func assignop(src *Type, dst *Type, why *string) Op {
        if src.Etype == TNIL {
                switch dst.Etype {
                case TARRAY:
-                       if dst.Bound != -100 { // not slice
+                       if !dst.IsSlice() {
                                break
                        }
                        fallthrough
index f8a436c65540161714cae17e6ba33934273a4173..ac870483ac876e4f3836f9bedb9a172ebadefd1b 100644 (file)
@@ -70,6 +70,8 @@ const (
        NTYPE
 )
 
+const dddBound = -100 // arrays declared as [...]T start life with Bound=dddBound
+
 // Types stores pointers to predeclared named types.
 //
 // It also stores pointers to several special types:
@@ -373,6 +375,13 @@ func (t *Type) SetFields(fields []*Field) {
        t.Fields().Set(fields)
 }
 
+func (t *Type) isDDDArray() bool {
+       if t.Etype != TARRAY {
+               return false
+       }
+       return t.Bound == dddBound
+}
+
 func (t *Type) Size() int64 {
        dowidth(t)
        return t.Width
index 1851bcc3c0189f5ad8d16dea5bdc7db16f17a460..4e575d0df0b0e2f594897b361b65a1a99a60ff2c 100644 (file)
@@ -336,7 +336,7 @@ OpSwitch:
                if l == nil {
                        t.Bound = -1 // slice
                } else if l.Op == ODDD {
-                       t.Bound = -100 // to be filled in
+                       t.Bound = dddBound // to be filled in
                        if top&Ecomplit == 0 && n.Diag == 0 {
                                t.Broke = true
                                n.Diag = 1
@@ -385,7 +385,7 @@ OpSwitch:
                n.Type = t
                n.Left = nil
                n.Right = nil
-               if t.Bound != -100 {
+               if !t.isDDDArray() {
                        checkwidth(t)
                }
 
@@ -1267,7 +1267,7 @@ OpSwitch:
                n.Left = defaultlit(n.Left, nil)
                l = n.Left
                if l.Op == OTYPE {
-                       if n.Isddd || l.Type.Bound == -100 {
+                       if n.Isddd || l.Type.isDDDArray() {
                                if !l.Type.Broke {
                                        Yyerror("invalid use of ... in type conversion to %v", l.Type)
                                }
@@ -2991,7 +2991,7 @@ func typecheckcomplit(n *Node) *Node {
                        l.Right = assignconv(r, t.Type, "array or slice literal")
                }
 
-               if t.Bound == -100 {
+               if t.isDDDArray() {
                        t.Bound = length
                }
                if t.Bound < 0 {