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>
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
// 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 {
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()
if src.Etype == TNIL {
switch dst.Etype {
case TARRAY:
- if dst.Bound != -100 { // not slice
+ if !dst.IsSlice() {
break
}
fallthrough
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:
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
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
n.Type = t
n.Left = nil
n.Right = nil
- if t.Bound != -100 {
+ if !t.isDDDArray() {
checkwidth(t)
}
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)
}
l.Right = assignconv(r, t.Type, "array or slice literal")
}
- if t.Bound == -100 {
+ if t.isDDDArray() {
t.Bound = length
}
if t.Bound < 0 {