1
0
mirror of https://github.com/golang/go synced 2024-11-24 00:50:10 -07:00

cmd/compile: move haspointers to type.go

100% code movement.

Change-Id: Idb51c61b7363229258a3b48045e901bea68c7a85
Reviewed-on: https://go-review.googlesource.com/38911
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2017-03-29 21:03:09 -07:00
parent 371aa23d10
commit 944d56d763
2 changed files with 43 additions and 43 deletions

View File

@ -718,49 +718,6 @@ var kinds = []int{
TUNSAFEPTR: obj.KindUnsafePointer,
}
func haspointers(t *Type) bool {
switch t.Etype {
case TINT, TUINT, TINT8, TUINT8, TINT16, TUINT16, TINT32, TUINT32, TINT64,
TUINT64, TUINTPTR, TFLOAT32, TFLOAT64, TCOMPLEX64, TCOMPLEX128, TBOOL:
return false
case TSLICE:
return true
case TARRAY:
at := t.Extra.(*ArrayType)
if at.Haspointers != 0 {
return at.Haspointers-1 != 0
}
ret := false
if t.NumElem() != 0 { // non-empty array
ret = haspointers(t.Elem())
}
at.Haspointers = 1 + uint8(obj.Bool2int(ret))
return ret
case TSTRUCT:
st := t.StructType()
if st.Haspointers != 0 {
return st.Haspointers-1 != 0
}
ret := false
for _, t1 := range t.Fields().Slice() {
if haspointers(t1.Type) {
ret = true
break
}
}
st.Haspointers = 1 + uint8(obj.Bool2int(ret))
return ret
}
return true
}
// typeptrdata returns the length in bytes of the prefix of t
// containing pointer data. Anything after this offset is scalar data.
func typeptrdata(t *Type) int64 {

View File

@ -1309,6 +1309,49 @@ func (t *Type) IsUntyped() bool {
return false
}
func haspointers(t *Type) bool {
switch t.Etype {
case TINT, TUINT, TINT8, TUINT8, TINT16, TUINT16, TINT32, TUINT32, TINT64,
TUINT64, TUINTPTR, TFLOAT32, TFLOAT64, TCOMPLEX64, TCOMPLEX128, TBOOL:
return false
case TSLICE:
return true
case TARRAY:
at := t.Extra.(*ArrayType)
if at.Haspointers != 0 {
return at.Haspointers-1 != 0
}
ret := false
if t.NumElem() != 0 { // non-empty array
ret = haspointers(t.Elem())
}
at.Haspointers = 1 + uint8(obj.Bool2int(ret))
return ret
case TSTRUCT:
st := t.StructType()
if st.Haspointers != 0 {
return st.Haspointers-1 != 0
}
ret := false
for _, t1 := range t.Fields().Slice() {
if haspointers(t1.Type) {
ret = true
break
}
}
st.Haspointers = 1 + uint8(obj.Bool2int(ret))
return ret
}
return true
}
// HasPointer returns whether t contains heap pointer.
// This is used for write barrier insertion, so we ignore
// pointers to go:notinheap types.