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) {
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
......
......@@ -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 {
......
......@@ -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()
......
......@@ -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
......
......@@ -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
......
......@@ -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 {
......
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