mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
Make an ast.TypeExpr's ID0 field more consistent
This commit is contained in:
1 parent
90a794c0b8
commit
4ddc2f0055
5 files changed
+11
-11
No files matched your search
+4
-4
@@ -618,7 +618,7 @@ const MaxTypeExprDepth = 63
|
|||||||
|
|
||||||
// TypeExpr is a type expression, such as "base.u32", "base.u32[..8]", "foo",
|
// TypeExpr is a type expression, such as "base.u32", "base.u32[..8]", "foo",
|
||||||
// "pkg.bar", "ptr T", "array[8] T" or "slice T":
|
// "pkg.bar", "ptr T", "array[8] T" or "slice T":
|
||||||
// - ID0: <0|IDPtr|IDArray|IDSlice|IDOpenParen>
|
// - ID0: <0|IDPtr|IDArray|IDSlice|IDFunc>
|
||||||
// - ID1: <0|pkg>
|
// - ID1: <0|pkg>
|
||||||
// - ID2: <0|type name>
|
// - ID2: <0|type name>
|
||||||
// - LHS: <nil|Expr>
|
// - LHS: <nil|Expr>
|
||||||
@@ -631,9 +631,9 @@ const MaxTypeExprDepth = 63
|
|||||||
//
|
//
|
||||||
// An IDSlice ID0 means "slice RHS". RHS is the inner type.
|
// An IDSlice ID0 means "slice RHS". RHS is the inner type.
|
||||||
//
|
//
|
||||||
// An IDOpenParen ID0 means "LHS.ID2", a function or method type. LHS is the
|
// An IDFunc ID0 means "func ID2" or "func (LHS).ID2", a function or method
|
||||||
// receiver type, which may be nil. If non-nil, it will be a pointee type: "T"
|
// type. LHS is the receiver type, which may be nil. If non-nil, it will be a
|
||||||
// instead of "ptr T", "ptr ptr T", etc.
|
// pointee type: "T" instead of "ptr T", "ptr ptr T", etc.
|
||||||
//
|
//
|
||||||
// TODO: method effects: "foo" vs "foo!" vs "foo?".
|
// TODO: method effects: "foo" vs "foo!" vs "foo?".
|
||||||
//
|
//
|
||||||
|
|||||||
+1
-1
@@ -223,7 +223,7 @@ func (n *TypeExpr) appendStr(buf []byte, tm *t.Map, depth uint32) []byte {
|
|||||||
case t.IDSlice:
|
case t.IDSlice:
|
||||||
buf = append(buf, "slice "...)
|
buf = append(buf, "slice "...)
|
||||||
return n.Inner().appendStr(buf, tm, depth)
|
return n.Inner().appendStr(buf, tm, depth)
|
||||||
case t.IDOpenParen:
|
case t.IDFunc:
|
||||||
buf = append(buf, "func "...)
|
buf = append(buf, "func "...)
|
||||||
if r := n.Receiver(); r != nil {
|
if r := n.Receiver(); r != nil {
|
||||||
buf = append(buf, '(')
|
buf = append(buf, '(')
|
||||||
|
|||||||
@@ -983,7 +983,7 @@ func (q *checker) bcheckExprCall(n *a.Expr, depth uint32) error {
|
|||||||
|
|
||||||
func makeSliceLengthExpr(slice *a.Expr) *a.Expr {
|
func makeSliceLengthExpr(slice *a.Expr) *a.Expr {
|
||||||
x := a.NewExpr(a.FlagsTypeChecked, t.IDDot, 0, t.IDLength, slice.Node(), nil, nil, nil)
|
x := a.NewExpr(a.FlagsTypeChecked, t.IDDot, 0, t.IDLength, slice.Node(), nil, nil, nil)
|
||||||
x.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, t.IDLength, slice.MType().Node(), nil, nil))
|
x.SetMType(a.NewTypeExpr(t.IDFunc, 0, t.IDLength, slice.MType().Node(), nil, nil))
|
||||||
x = a.NewExpr(a.FlagsTypeChecked, t.IDOpenParen, 0, 0, x.Node(), nil, nil, nil)
|
x = a.NewExpr(a.FlagsTypeChecked, t.IDOpenParen, 0, 0, x.Node(), nil, nil, nil)
|
||||||
x.SetMType(typeExprU64)
|
x.SetMType(typeExprU64)
|
||||||
return x
|
return x
|
||||||
@@ -1182,7 +1182,7 @@ func (q *checker) bcheckTypeExpr(typ *a.TypeExpr) (*big.Int, *big.Int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch typ.Decorator() {
|
switch typ.Decorator() {
|
||||||
// TODO: case t.IDOpenParen.
|
// TODO: case t.IDFunc.
|
||||||
case t.IDPtr, t.IDArray, t.IDSlice:
|
case t.IDPtr, t.IDArray, t.IDSlice:
|
||||||
return nil, nil, nil
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ func parseBuiltInFuncs(tm *t.Map, ss []string, generic bool) (map[t.QQID]*a.Func
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Checker) resolveFunc(typ *a.TypeExpr) (*a.Func, error) {
|
func (c *Checker) resolveFunc(typ *a.TypeExpr) (*a.Func, error) {
|
||||||
if typ.Decorator() != t.IDOpenParen {
|
if typ.Decorator() != t.IDFunc {
|
||||||
return nil, fmt.Errorf("check: resolveFunc cannot look up non-func TypeExpr %q", typ.Str(c.tm))
|
return nil, fmt.Errorf("check: resolveFunc cannot look up non-func TypeExpr %q", typ.Str(c.tm))
|
||||||
}
|
}
|
||||||
lTyp := typ.Receiver()
|
lTyp := typ.Receiver()
|
||||||
|
|||||||
+3
-3
@@ -695,7 +695,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
|||||||
} else if f == nil {
|
} else if f == nil {
|
||||||
return fmt.Errorf("check: no slice method %q", n.Ident().Str(q.tm))
|
return fmt.Errorf("check: no slice method %q", n.Ident().Str(q.tm))
|
||||||
}
|
}
|
||||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.Ident(), lTyp.Node(), nil, nil))
|
n.SetMType(a.NewTypeExpr(t.IDFunc, 0, n.Ident(), lTyp.Node(), nil, nil))
|
||||||
return nil
|
return nil
|
||||||
} else if lTyp.Decorator() != 0 {
|
} else if lTyp.Decorator() != 0 {
|
||||||
return fmt.Errorf("check: invalid type %q for dot-expression LHS %q", lTyp.Str(q.tm), lhs.Str(q.tm))
|
return fmt.Errorf("check: invalid type %q for dot-expression LHS %q", lTyp.Str(q.tm), lhs.Str(q.tm))
|
||||||
@@ -708,7 +708,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
|||||||
f = q.c.funcs[qqid]
|
f = q.c.funcs[qqid]
|
||||||
}
|
}
|
||||||
if f != nil {
|
if f != nil {
|
||||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.Ident(), lTyp.Node(), nil, nil))
|
n.SetMType(a.NewTypeExpr(t.IDFunc, 0, n.Ident(), lTyp.Node(), nil, nil))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1021,7 +1021,7 @@ func (q *checker) tcheckTypeExpr(typ *a.TypeExpr, depth uint32) error {
|
|||||||
|
|
||||||
swtch:
|
swtch:
|
||||||
switch typ.Decorator() {
|
switch typ.Decorator() {
|
||||||
// TODO: also check t.IDOpenParen.
|
// TODO: also check t.IDFunc.
|
||||||
case 0:
|
case 0:
|
||||||
qid := typ.QID()
|
qid := typ.QID()
|
||||||
if qid[0] == t.IDBase && qid[1].IsNumType() {
|
if qid[0] == t.IDBase && qid[1].IsNumType() {
|
||||||
|
|||||||
Reference in new issue
Block a user