mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Remove typeExprPlaceholder
This commit is contained in:
1 parent
ba0db5b4d1
commit
c479907bff
4 files changed
+23
-24
No files matched your search
@@ -69,6 +69,8 @@ var Types = []string{
|
||||
"u16",
|
||||
"u32",
|
||||
"u64",
|
||||
|
||||
"empty_struct",
|
||||
"bool",
|
||||
"status",
|
||||
"io_reader",
|
||||
|
||||
@@ -38,10 +38,12 @@ var (
|
||||
typeExprIdeal = a.NewTypeExpr(0, t.IDBase, t.IDDoubleZ, nil, nil, nil)
|
||||
typeExprList = a.NewTypeExpr(0, t.IDBase, t.IDDollar, nil, nil, nil)
|
||||
|
||||
typeExprU8 = a.NewTypeExpr(0, t.IDBase, t.IDU8, nil, nil, nil)
|
||||
typeExprU16 = a.NewTypeExpr(0, t.IDBase, t.IDU16, nil, nil, nil)
|
||||
typeExprU32 = a.NewTypeExpr(0, t.IDBase, t.IDU32, nil, nil, nil)
|
||||
typeExprU64 = a.NewTypeExpr(0, t.IDBase, t.IDU64, nil, nil, nil)
|
||||
typeExprU8 = a.NewTypeExpr(0, t.IDBase, t.IDU8, nil, nil, nil)
|
||||
typeExprU16 = a.NewTypeExpr(0, t.IDBase, t.IDU16, nil, nil, nil)
|
||||
typeExprU32 = a.NewTypeExpr(0, t.IDBase, t.IDU32, nil, nil, nil)
|
||||
typeExprU64 = a.NewTypeExpr(0, t.IDBase, t.IDU64, nil, nil, nil)
|
||||
|
||||
typeExprEmptyStruct = a.NewTypeExpr(0, t.IDBase, t.IDEmptyStruct, nil, nil, nil)
|
||||
typeExprBool = a.NewTypeExpr(0, t.IDBase, t.IDBool, nil, nil, nil)
|
||||
typeExprStatus = a.NewTypeExpr(0, t.IDBase, t.IDStatus, nil, nil, nil)
|
||||
typeExprIOReader = a.NewTypeExpr(0, t.IDBase, t.IDIOReader, nil, nil, nil)
|
||||
@@ -49,11 +51,6 @@ var (
|
||||
typeExprImageConfig = a.NewTypeExpr(0, t.IDBase, t.IDImageConfig, nil, nil, nil)
|
||||
|
||||
typeExprSliceU8 = a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, typeExprU8)
|
||||
|
||||
// TODO: delete this.
|
||||
typeExprPlaceholder = a.NewTypeExpr(0, t.IDBase, t.IDU8, nil, nil, nil)
|
||||
typeExprPlaceholder16 = a.NewTypeExpr(0, t.IDBase, t.IDU16, nil, nil, nil)
|
||||
typeExprPlaceholder32 = a.NewTypeExpr(0, t.IDBase, t.IDU32, nil, nil, nil)
|
||||
)
|
||||
|
||||
// typeMap maps from variable names (as token IDs) to types.
|
||||
|
||||
+7
-9
@@ -429,24 +429,23 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
// require a TypeExpr being able to express function and method types.
|
||||
|
||||
// TODO: delete this hack that only matches "foo.decode(etc)".
|
||||
if isThatMethod(q.tm, n, q.tm.ByName("decode"), 3) {
|
||||
if idDecode := q.tm.ByName("decode"); isThatMethod(q.tm, n, idDecode, 3) {
|
||||
foo := n.LHS().Expr().LHS().Expr()
|
||||
if err := q.tcheckExpr(foo, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
n.LHS().SetTypeChecked()
|
||||
n.LHS().Expr().SetMType(typeExprPlaceholder) // HACK.
|
||||
n.LHS().Expr().SetMType(a.NewTypeExpr(t.IDFunc, 0, idDecode, foo.MType().Node(), nil, nil))
|
||||
for _, o := range n.Args() {
|
||||
if err := q.tcheckArg(o.Arg(), nil, nil, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if n.Operator() == t.IDTry {
|
||||
// TODO: be more principled about inferring "try etc"'s type.
|
||||
n.SetMType(typeExprStatus)
|
||||
} else {
|
||||
n.SetMType(typeExprPlaceholder) // HACK.
|
||||
if n.Operator() != t.IDTry {
|
||||
return fmt.Errorf("TODO: foo.decode(etc) outside of a try statement")
|
||||
}
|
||||
// TODO: be more principled about inferring "try etc"'s type.
|
||||
n.SetMType(typeExprStatus)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -600,8 +599,7 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
|
||||
// *ast.Struct, to an *ast.TypeExpr we can pass to n.SetMType.
|
||||
return fmt.Errorf("TODO: translate an *ast.Struct to an *ast.TypeExpr")
|
||||
case 0:
|
||||
// TODO: use a "unit", "void" or "empty struct" type.
|
||||
n.SetMType(typeExprPlaceholder)
|
||||
n.SetMType(typeExprEmptyStruct)
|
||||
case 1:
|
||||
oTyp := outFields[0].Field().XType()
|
||||
if genericType != nil && oTyp.Eq(typeExprGeneric) {
|
||||
|
||||
+8
-6
@@ -366,11 +366,12 @@ const (
|
||||
IDSLICE = ID(0xA6)
|
||||
IDBase = ID(0xA7)
|
||||
|
||||
IDBool = ID(0xA8)
|
||||
IDIOReader = ID(0xA9)
|
||||
IDIOWriter = ID(0xAA)
|
||||
IDStatus = ID(0xAB)
|
||||
IDImageConfig = ID(0xAC)
|
||||
IDEmptyStruct = ID(0xA8)
|
||||
IDBool = ID(0xA9)
|
||||
IDStatus = ID(0xAA)
|
||||
IDIOReader = ID(0xAB)
|
||||
IDIOWriter = ID(0xAC)
|
||||
IDImageConfig = ID(0xAD)
|
||||
|
||||
IDMark = ID(0xB0)
|
||||
IDReadU8 = ID(0xB1)
|
||||
@@ -534,10 +535,11 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
IDSLICE: "SLICE",
|
||||
IDBase: "base",
|
||||
|
||||
IDEmptyStruct: "empty_struct",
|
||||
IDBool: "bool",
|
||||
IDStatus: "status",
|
||||
IDIOReader: "io_reader",
|
||||
IDIOWriter: "io_writer",
|
||||
IDStatus: "status",
|
||||
IDImageConfig: "image_config",
|
||||
|
||||
IDMark: "mark",
|
||||
|
||||
Reference in new issue
Block a user