mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 08:47:28 +01:00
Use "T[..inclMax]" instead of "T[:exclMax]".
This commit is contained in:
1 parent
d3eba13223
commit
9184e2682e
9 files changed
+53
-44
No files matched your search
+7
-7
@@ -400,8 +400,8 @@ const MaxTypeExprDepth = 63
|
||||
//
|
||||
// Other ID0 values mean a (possibly package-qualified) type like "pkg.foo" or
|
||||
// "foo". ID0 is the "pkg" or zero, ID1 is the "foo". Such a type can be
|
||||
// refined as "foo[LHS:MHS]". LHS and MHS are Expr's, possibly nil. For
|
||||
// example, the MHS for "u32[:4096]" is nil.
|
||||
// refined as "foo[LHS..MHS]". LHS and MHS are Expr's, possibly nil. For
|
||||
// example, the LHS for "u32[..4095]" is nil.
|
||||
type TypeExpr Node
|
||||
|
||||
func (n *TypeExpr) Node() *Node { return (*Node)(n) }
|
||||
@@ -413,17 +413,17 @@ func (n *TypeExpr) PackageOrDecorator() t.ID { return n.id0 }
|
||||
func (n *TypeExpr) Name() t.ID { return n.id1 }
|
||||
func (n *TypeExpr) ArrayLength() *Expr { return n.lhs.Expr() }
|
||||
func (n *TypeExpr) Bounds() [2]*Expr { return [2]*Expr{n.lhs.Expr(), n.mhs.Expr()} }
|
||||
func (n *TypeExpr) InclMin() *Expr { return n.lhs.Expr() }
|
||||
func (n *TypeExpr) ExclMax() *Expr { return n.mhs.Expr() }
|
||||
func (n *TypeExpr) Min() *Expr { return n.lhs.Expr() }
|
||||
func (n *TypeExpr) Max() *Expr { return n.mhs.Expr() }
|
||||
func (n *TypeExpr) Inner() *TypeExpr { return n.rhs.TypeExpr() }
|
||||
|
||||
func NewTypeExpr(pkgOrDec t.ID, name t.ID, arrayLengthInclMin *Expr, exclMax *Expr, inner *TypeExpr) *TypeExpr {
|
||||
func NewTypeExpr(pkgOrDec t.ID, name t.ID, arrayLengthMin *Expr, max *Expr, inner *TypeExpr) *TypeExpr {
|
||||
return &TypeExpr{
|
||||
kind: KTypeExpr,
|
||||
id0: pkgOrDec,
|
||||
id1: name,
|
||||
lhs: arrayLengthInclMin.Node(),
|
||||
mhs: exclMax.Node(),
|
||||
lhs: arrayLengthMin.Node(),
|
||||
mhs: max.Node(),
|
||||
rhs: inner.Node(),
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -145,7 +145,7 @@ func (n *TypeExpr) String(m *t.IDMap) string {
|
||||
if n == nil {
|
||||
return ""
|
||||
}
|
||||
if n.PackageOrDecorator() == 0 && n.InclMin() == nil && n.ExclMax() == nil {
|
||||
if n.PackageOrDecorator() == 0 && n.Min() == nil && n.Max() == nil {
|
||||
return m.ByID(n.Name())
|
||||
}
|
||||
return string(n.appendString(nil, m, 0))
|
||||
@@ -176,11 +176,11 @@ func (n *TypeExpr) appendString(buf []byte, m *t.IDMap, depth uint32) []byte {
|
||||
buf = append(buf, '.')
|
||||
buf = append(buf, m.ByID(n.Name())...)
|
||||
}
|
||||
if n.InclMin() != nil || n.ExclMax() != nil {
|
||||
if n.Min() != nil || n.Max() != nil {
|
||||
buf = append(buf, '[')
|
||||
buf = n.InclMin().appendString(buf, m, false, 0)
|
||||
buf = append(buf, ':')
|
||||
buf = n.ExclMax().appendString(buf, m, false, 0)
|
||||
buf = n.Min().appendString(buf, m, false, 0)
|
||||
buf = append(buf, ".."...)
|
||||
buf = n.Max().appendString(buf, m, false, 0)
|
||||
buf = append(buf, ']')
|
||||
}
|
||||
return buf
|
||||
|
||||
@@ -50,13 +50,13 @@ func TestString(t *testing.T) {
|
||||
"x as u32",
|
||||
"x as T",
|
||||
"x as T",
|
||||
"x as T[i:]",
|
||||
"x as T[:j]",
|
||||
"x as T[i:j]",
|
||||
"x as T[i..]",
|
||||
"x as T[..j]",
|
||||
"x as T[i..j]",
|
||||
"x as pkg.T",
|
||||
"x as ptr T",
|
||||
"x as [4] T",
|
||||
"x as [8 + (2 * N)] ptr [4] ptr pkg.T[i:j]",
|
||||
"x as [8 + (2 * N)] ptr [4] ptr pkg.T[i..j]",
|
||||
}
|
||||
|
||||
idMap := &token.IDMap{}
|
||||
|
||||
Reference in new issue
Block a user