Commit 272df158 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: clean up ... Bound marker

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/21235Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent fcd2a06a
...@@ -256,7 +256,7 @@ func dowidth(t *Type) { ...@@ -256,7 +256,7 @@ func dowidth(t *Type) {
w = int64(sizeof_Array) w = int64(sizeof_Array)
checkwidth(t.Type) checkwidth(t.Type)
t.Align = uint8(Widthptr) t.Align = uint8(Widthptr)
} else if t.Bound == -100 { } else if t.isDDDArray() {
if !t.Broke { if !t.Broke {
Yyerror("use of [...] array outside of array literal") Yyerror("use of [...] array outside of array literal")
t.Broke = true t.Broke = true
......
...@@ -503,8 +503,10 @@ func (p *exporter) typ(t *Type) { ...@@ -503,8 +503,10 @@ func (p *exporter) typ(t *Type) {
// otherwise we have a type literal // otherwise we have a type literal
switch t.Etype { switch t.Etype {
case TARRAY: case TARRAY:
// TODO(gri) define named constant for the -100 if t.isDDDArray() {
if t.Bound >= 0 || t.Bound == -100 { Fatalf("array bounds should be known at export time: %v", t)
}
if t.Bound >= 0 {
p.tag(arrayTag) p.tag(arrayTag)
p.int64(t.Bound) p.int64(t.Bound)
} else { } else {
......
...@@ -589,7 +589,7 @@ func typefmt(t *Type, flag FmtFlag) string { ...@@ -589,7 +589,7 @@ func typefmt(t *Type, flag FmtFlag) string {
if t.Bound >= 0 { if t.Bound >= 0 {
return fmt.Sprintf("[%d]%v", t.Bound, t.Type) return fmt.Sprintf("[%d]%v", t.Bound, t.Type)
} }
if t.Bound == -100 { if t.isDDDArray() {
return "[...]" + t.Type.String() return "[...]" + t.Type.String()
} }
return "[]" + t.Type.String() return "[]" + t.Type.String()
......
...@@ -897,7 +897,7 @@ func assignop(src *Type, dst *Type, why *string) Op { ...@@ -897,7 +897,7 @@ func assignop(src *Type, dst *Type, why *string) Op {
if src.Etype == TNIL { if src.Etype == TNIL {
switch dst.Etype { switch dst.Etype {
case TARRAY: case TARRAY:
if dst.Bound != -100 { // not slice if !dst.IsSlice() {
break break
} }
fallthrough fallthrough
......
...@@ -70,6 +70,8 @@ const ( ...@@ -70,6 +70,8 @@ const (
NTYPE NTYPE
) )
const dddBound = -100 // arrays declared as [...]T start life with Bound=dddBound
// Types stores pointers to predeclared named types. // Types stores pointers to predeclared named types.
// //
// It also stores pointers to several special types: // It also stores pointers to several special types:
...@@ -373,6 +375,13 @@ func (t *Type) SetFields(fields []*Field) { ...@@ -373,6 +375,13 @@ func (t *Type) SetFields(fields []*Field) {
t.Fields().Set(fields) t.Fields().Set(fields)
} }
func (t *Type) isDDDArray() bool {
if t.Etype != TARRAY {
return false
}
return t.Bound == dddBound
}
func (t *Type) Size() int64 { func (t *Type) Size() int64 {
dowidth(t) dowidth(t)
return t.Width return t.Width
......
...@@ -336,7 +336,7 @@ OpSwitch: ...@@ -336,7 +336,7 @@ OpSwitch:
if l == nil { if l == nil {
t.Bound = -1 // slice t.Bound = -1 // slice
} else if l.Op == ODDD { } 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 { if top&Ecomplit == 0 && n.Diag == 0 {
t.Broke = true t.Broke = true
n.Diag = 1 n.Diag = 1
...@@ -385,7 +385,7 @@ OpSwitch: ...@@ -385,7 +385,7 @@ OpSwitch:
n.Type = t n.Type = t
n.Left = nil n.Left = nil
n.Right = nil n.Right = nil
if t.Bound != -100 { if !t.isDDDArray() {
checkwidth(t) checkwidth(t)
} }
...@@ -1267,7 +1267,7 @@ OpSwitch: ...@@ -1267,7 +1267,7 @@ OpSwitch:
n.Left = defaultlit(n.Left, nil) n.Left = defaultlit(n.Left, nil)
l = n.Left l = n.Left
if l.Op == OTYPE { if l.Op == OTYPE {
if n.Isddd || l.Type.Bound == -100 { if n.Isddd || l.Type.isDDDArray() {
if !l.Type.Broke { if !l.Type.Broke {
Yyerror("invalid use of ... in type conversion to %v", l.Type) Yyerror("invalid use of ... in type conversion to %v", l.Type)
} }
...@@ -2991,7 +2991,7 @@ func typecheckcomplit(n *Node) *Node { ...@@ -2991,7 +2991,7 @@ func typecheckcomplit(n *Node) *Node {
l.Right = assignconv(r, t.Type, "array or slice literal") l.Right = assignconv(r, t.Type, "array or slice literal")
} }
if t.Bound == -100 { if t.isDDDArray() {
t.Bound = length t.Bound = length
} }
if t.Bound < 0 { if t.Bound < 0 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment