cmd/compile: use NumElem instead of Type.Bound

This eliminates all direct reads of Type.Bound
outside type.go.

Change-Id: I0a9a72539f8f4c0de7f5e05e1821936bf7db5eb7
Reviewed-on: https://go-review.googlesource.com/21421
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2016-03-31 14:46:04 -07:00
parent 077902d1a6
commit 3a0783c504
14 changed files with 48 additions and 44 deletions

View file

@ -684,7 +684,7 @@ func haspointers(t *Type) bool {
break
}
if t.Bound == 0 { // empty array
if t.NumElem() == 0 { // empty array
ret = false
break
}
@ -747,8 +747,8 @@ func typeptrdata(t *Type) int64 {
// struct { byte *array; uintgo len; uintgo cap; }
return int64(Widthptr)
}
// haspointers already eliminated t.Bound == 0.
return (t.Bound-1)*t.Elem().Width + typeptrdata(t.Elem())
// haspointers already eliminated t.NumElem() == 0.
return (t.NumElem()-1)*t.Elem().Width + typeptrdata(t.Elem())
case TSTRUCT:
// Find the last field that has pointers.
@ -1127,7 +1127,7 @@ ok:
ot = dcommontype(s, ot, t)
ot = dsymptr(s, ot, s1, 0)
ot = dsymptr(s, ot, s2, 0)
ot = duintptr(s, ot, uint64(t.Bound))
ot = duintptr(s, ot, uint64(t.NumElem()))
} else {
// ../../../../runtime/type.go:/sliceType
s1 := dtypesym(t.Elem())
@ -1637,16 +1637,16 @@ func (p *GCProg) emit(t *Type, offset int64) {
p.w.Ptr(offset / int64(Widthptr))
return
}
if t.Bound == 0 {
if t.NumElem() == 0 {
// should have been handled by haspointers check above
Fatalf("GCProg.emit: empty array")
}
// Flatten array-of-array-of-array to just a big array by multiplying counts.
count := t.Bound
count := t.NumElem()
elem := t.Elem()
for elem.IsArray() {
count *= elem.Bound
count *= elem.NumElem()
elem = elem.Elem()
}