if n2.Isddd && !n.Isddd {
// Introduce ODDDARG node to represent ... allocation.
src = Nod(ODDDARG, nil, nil)
- src.Type = typ(TARRAY)
- src.Type.Type = n2.Type.Type
- src.Type.Bound = int64(len(lls))
- src.Type = Ptrto(src.Type) // make pointer so it will be tracked
+ arr := typArray(n2.Type.Type, int64(len(lls)))
+ src.Type = Ptrto(arr) // make pointer so it will be tracked
src.Lineno = n.Lineno
e.track(src)
n.Right = src
// Introduce ODDDARG node to represent ... allocation.
src = Nod(ODDDARG, nil, nil)
src.Lineno = n.Lineno
- src.Type = typ(TARRAY)
- src.Type.Type = t.Type.Type
- src.Type.Bound = int64(len(lls) - i)
- src.Type = Ptrto(src.Type) // make pointer so it will be tracked
+ arr := typArray(t.Type.Type, int64(len(lls)-i))
+ src.Type = Ptrto(arr) // make pointer so it will be tracked
e.track(src)
n.Right = src
}
as.Right = nodnil()
as.Right.Type = varargtype
} else {
- vararrtype := typ(TARRAY)
- vararrtype.Type = varargtype.Type
- vararrtype.Bound = int64(varargcount)
-
- as.Right = Nod(OCOMPLIT, nil, typenod(varargtype))
+ vararrtype := typArray(varargtype.Type, int64(varargcount))
+ as.Right = Nod(OCOMPLIT, nil, typenod(vararrtype))
as.Right.List.Set(varargs)
as.Right = Nod(OSLICE, as.Right, Nod(OKEY, nil, nil))
}
orderexprlist(n.List, order)
if n.List.Len() > 5 {
- t := typ(TARRAY)
- t.Bound = int64(n.List.Len())
- t.Type = Types[TSTRING]
+ t := typArray(Types[TSTRING], int64(n.List.Len()))
prealloc[n] = ordertemp(t, order, false)
}
s3 := p.hidden_type()
s4 := p.oliteral()
- t := typ(TARRAY)
- t.Bound = -1
- t.Type = s3
+ t := typSlice(s3)
ss := Nod(ODCLFIELD, nil, typenod(t))
if s1 != nil {
}
// The first field is: uint8 topbits[BUCKETSIZE].
- arr := typ(TARRAY)
-
- arr.Type = Types[TUINT8]
- arr.Bound = BUCKETSIZE
+ arr := typArray(Types[TUINT8], BUCKETSIZE)
field := make([]*Field, 0, 5)
field = append(field, makefield("topbits", arr))
- arr = typ(TARRAY)
- arr.Type = keytype
- arr.Bound = BUCKETSIZE
+ arr = typArray(keytype, BUCKETSIZE)
field = append(field, makefield("keys", arr))
- arr = typ(TARRAY)
- arr.Type = valtype
- arr.Bound = BUCKETSIZE
+ arr = typArray(valtype, BUCKETSIZE)
field = append(field, makefield("values", arr))
// Make sure the overflow pointer is the last memory in the struct,
if t.Bound >= 0 {
// ../../../../runtime/type.go:/arrayType
s1 := dtypesym(t.Type)
-
- t2 := typ(TARRAY)
- t2.Type = t.Type
- t2.Bound = -1 // slice
+ t2 := typSlice(t.Type)
s2 := dtypesym(t2)
ot = dcommontype(s, ot, t)
ot = dsymptr(s, ot, s1, 0)
initplan(r)
if Isslice(r.Type) {
// Init slice.
- ta := typ(TARRAY)
-
- ta.Type = r.Type.Type
- ta.Bound = r.Right.Val().U.(*Mpint).Int64()
+ bound := r.Right.Val().U.(*Mpint).Int64()
+ ta := typArray(r.Type.Type, bound)
a := staticname(ta, 1)
inittemps[r] = a
n := *l
tstruct := typ(TSTRUCT)
tstruct.SetFields(fields[:])
- tarr := typ(TARRAY)
- tarr.Bound = int64(b)
- tarr.Type = tstruct
+ tarr := typArray(tstruct, int64(b))
// TODO(josharian): suppress alg generation for these types?
dowidth(tarr)
}
func aindex(b *Node, t *Type) *Type {
- bound := int64(-1) // open bound
+ hasbound := false
+ var bound int64
b = typecheck(b, Erv)
if b != nil {
switch consttype(b) {
Yyerror("array bound must be an integer expression")
case CTINT, CTRUNE:
+ hasbound = true
bound = b.Val().U.(*Mpint).Int64()
if bound < 0 {
Yyerror("array bound must be non negative")
}
}
- // fixed array
- r := typ(TARRAY)
-
- r.Type = t
- r.Bound = bound
- return r
+ if !hasbound {
+ return typSlice(t)
+ }
+ return typArray(t, bound)
}
// treecopy recursively copies n, with the exception of
// that the interface call will pass in.
// Add a dummy padding argument after the
// receiver to make up the difference.
- tpad := typ(TARRAY)
-
- tpad.Type = Types[TUINT8]
- tpad.Bound = Types[Tptr].Width - rcvr.Width
+ tpad := typArray(Types[TUINT8], Types[Tptr].Width-rcvr.Width)
pad := Nod(ODCLFIELD, newname(Lookup(".pad")), typenod(tpad))
l = append(l, pad)
}
return t
}
+// typArray returns a new fixed-length array Type.
+func typArray(elem *Type, bound int64) *Type {
+ t := typ(TARRAY)
+ t.Type = elem
+ t.Bound = bound
+ return t
+}
+
+// typSlice returns a new slice Type.
+func typSlice(elem *Type) *Type {
+ t := typ(TARRAY)
+ t.Type = elem
+ t.Bound = -1
+ return t
+}
+
+// typeDDDArray returns a new [...]T array Type.
+func typeDDDArray(elem *Type) *Type {
+ t := typ(TARRAY)
+ t.Type = elem
+ t.Bound = dddBound
+ return t
+}
+
func newField() *Field {
return &Field{
Offset: BADWIDTH,
case OTARRAY:
ok |= Etype
- t := typ(TARRAY)
+ var t *Type
l := n.Left
r := n.Right
+ r = typecheck(r, Etype)
+ if r.Type == nil {
+ n.Type = nil
+ return n
+ }
+
if l == nil {
- t.Bound = -1 // slice
+ t = typSlice(r.Type)
} else if l.Op == ODDD {
- t.Bound = dddBound // to be filled in
+ t = typeDDDArray(r.Type)
if top&Ecomplit == 0 && n.Diag == 0 {
t.Broke = true
n.Diag = 1
return n
}
- t.Bound = v.U.(*Mpint).Int64()
+ t = typArray(r.Type, v.U.(*Mpint).Int64())
+
if doesoverflow(v, Types[TINT]) {
Yyerror("array bound is too large")
n.Type = nil
}
}
- r = typecheck(r, Etype)
- if r.Type == nil {
- n.Type = nil
- return n
- }
- t.Type = r.Type
n.Op = OTYPE
n.Type = t
n.Left = nil
n.Op = OSLICESTR
} else if Isptr[t.Etype] && Isfixedarray(t.Type) {
tp = t.Type
- n.Type = typ(TARRAY)
- n.Type.Type = tp.Type
- n.Type.Bound = -1
+ n.Type = typSlice(tp.Type)
dowidth(n.Type)
n.Op = OSLICEARR
} else if Isslice(t) {
var tp *Type
if Isptr[t.Etype] && Isfixedarray(t.Type) {
tp = t.Type
- n.Type = typ(TARRAY)
- n.Type.Type = tp.Type
- n.Type.Bound = -1
+ n.Type = typSlice(tp.Type)
dowidth(n.Type)
n.Op = OSLICE3ARR
} else if Isslice(t) {
esc = ddd.Esc
}
- tslice := typ(TARRAY)
- tslice.Type = l.Type.Type
- tslice.Bound = -1
+ tslice := typSlice(l.Type.Type)
var n *Node
if len(lr0) == 0 {
// large numbers of strings are passed to the runtime as a slice.
fn = "concatstrings"
- t := typ(TARRAY)
- t.Type = Types[TSTRING]
- t.Bound = -1
+ t := typSlice(Types[TSTRING])
slice := Nod(OCOMPLIT, nil, typenod(t))
if prealloc[n] != nil {
prealloc[slice] = prealloc[n]