Commit 331f9625 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: use IsSlice and IsArray instead of checking Bound

Changes generated by eg and manually checked.

Isfixedarray, Isslice, and many other
Type-related functions in subr.go should
either be deleted or moved to type.go.
Later, though; the game now is cleanup via encapsulation.

Passes toolstash -cmp.

Change-Id: I83dd8816f6263b74367d23c2719a08c362e330f9
Reviewed-on: https://go-review.googlesource.com/21303Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent d7f7ea6e
......@@ -240,7 +240,7 @@ func dowidth(t *Type) {
if t.Type == nil {
break
}
if t.Bound >= 0 {
if t.IsArray() {
dowidth(t.Type)
if t.Type.Width != 0 {
cap := (uint64(Thearch.MAXWIDTH) - 1) / uint64(t.Type.Width)
......
......@@ -506,7 +506,7 @@ func (p *exporter) typ(t *Type) {
if t.isDDDArray() {
Fatalf("array bounds should be known at export time: %v", t)
}
if t.Bound >= 0 {
if t.IsArray() {
p.tag(arrayTag)
p.int64(t.Bound)
} else {
......
......@@ -586,7 +586,7 @@ func typefmt(t *Type, flag FmtFlag) string {
return "*" + t.Type.String()
case TARRAY:
if t.Bound >= 0 {
if t.IsArray() {
return fmt.Sprintf("[%d]%v", t.Bound, t.Type)
}
if t.isDDDArray() {
......
......@@ -674,7 +674,7 @@ func haspointers(t *Type) bool {
ret = false
case TARRAY:
if t.Bound < 0 { // slice
if t.IsSlice() {
ret = true
break
}
......@@ -835,7 +835,7 @@ func dcommontype(s *Sym, ot int, t *Type) int {
ot = duint8(s, ot, t.Align) // fieldAlign
i = kinds[t.Etype]
if t.Etype == TARRAY && t.Bound < 0 {
if t.IsSlice() {
i = obj.KindSlice
}
if !haspointers(t) {
......@@ -1114,7 +1114,7 @@ ok:
ot = dextratype(s, ot, t, 0)
case TARRAY:
if t.Bound >= 0 {
if t.IsArray() {
// ../../../../runtime/type.go:/arrayType
s1 := dtypesym(t.Type)
t2 := typSlice(t.Type)
......
......@@ -540,7 +540,7 @@ func getdyn(n *Node, top int) initGenType {
return initDynamic
case OARRAYLIT:
if top == 0 && n.Type.Bound < 0 {
if top == 0 && n.Type.IsSlice() {
return initDynamic
}
......@@ -568,7 +568,7 @@ func structlit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
switch value.Op {
case OARRAYLIT:
if value.Type.Bound < 0 {
if value.Type.IsSlice() {
if pass == 1 && ctxt != 0 {
a := NodSym(ODOT, var_, index.Sym)
slicelit(ctxt, value, a, init)
......@@ -630,7 +630,7 @@ func arraylit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
switch value.Op {
case OARRAYLIT:
if value.Type.Bound < 0 {
if value.Type.IsSlice() {
if pass == 1 && ctxt != 0 {
a := Nod(OINDEX, var_, index)
slicelit(ctxt, value, a, init)
......@@ -804,7 +804,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init *Nodes) {
switch value.Op {
case OARRAYLIT:
if value.Type.Bound < 0 {
if value.Type.IsSlice() {
break
}
arraylit(ctxt, 2, value, a, init)
......@@ -1076,7 +1076,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
if t.Etype != TARRAY {
Fatalf("anylit: not array")
}
if t.Bound < 0 {
if t.IsSlice() {
slicelit(ctxt, n, var_, init)
break
}
......@@ -1195,7 +1195,7 @@ func stataddr(nam *Node, n *Node) bool {
return true
case OINDEX:
if n.Left.Type.Bound < 0 {
if n.Left.Type.IsSlice() {
break
}
if !stataddr(nam, n.Left) {
......@@ -1384,7 +1384,7 @@ func genAsInitNoCheck(n *Node, reportOnly bool) bool {
}
// nr is the array being converted to a slice
if nr.Type == nil || nr.Type.Etype != TARRAY || nr.Type.Bound < 0 {
if nr.Type == nil || nr.Type.Etype != TARRAY || nr.Type.IsSlice() {
return false
}
......
......@@ -583,11 +583,11 @@ func Istype(t *Type, et EType) bool {
}
func Isfixedarray(t *Type) bool {
return t != nil && t.Etype == TARRAY && t.Bound >= 0
return t != nil && t.IsArray()
}
func Isslice(t *Type) bool {
return t != nil && t.Etype == TARRAY && t.Bound < 0
return t != nil && t.IsSlice()
}
func isblank(n *Node) bool {
......
......@@ -789,6 +789,7 @@ func (t *Type) IsChan() bool {
}
func (t *Type) IsSlice() bool {
// TODO(josharian): Change this to t.Bound == -1.
return t.Etype == TARRAY && t.Bound < 0
}
......
......@@ -375,7 +375,7 @@ OpSwitch:
Yyerror("array bound is too large")
n.Type = nil
return n
} else if t.Bound < 0 {
} else if t.IsSlice() {
Yyerror("array bound must be non-negative")
n.Type = nil
return n
......@@ -1412,7 +1412,7 @@ OpSwitch:
}
case TARRAY:
if t.Bound < 0 { // slice
if t.IsSlice() {
break
}
if callrecv(l) { // has call or receive
......@@ -2974,7 +2974,7 @@ func typecheckcomplit(n *Node) *Node {
i++
if int64(i) > length {
length = int64(i)
if t.Bound >= 0 && length > t.Bound {
if t.IsArray() && length > t.Bound {
setlineno(l)
Yyerror("array index %d out of bounds [0:%d]", length-1, t.Bound)
t.Bound = -1 // no more errors
......@@ -2991,7 +2991,7 @@ func typecheckcomplit(n *Node) *Node {
if t.isDDDArray() {
t.Bound = length
}
if t.Bound < 0 {
if t.IsSlice() {
n.Right = Nodintconst(length)
}
n.Op = OARRAYLIT
......
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