mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 16:47:28 +01:00
Generate a C placeholder for "in.src.read_u8?()".
This commit is contained in:
1 parent
0646f4472c
commit
1758637f89
7 files changed
+65
-8
No files matched your search
+28
-1
@@ -293,7 +293,14 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
|
||||
case t.KeyOpenParen:
|
||||
// n is a function call.
|
||||
// TODO.
|
||||
// TODO: delete this hack that only matches "in.src.read_u8?()".
|
||||
if isInSrcReadU8(q.idMap, n.LHS().Expr()) && len(n.Args()) == 0 {
|
||||
if err := q.tcheckExpr(n.LHS().Expr(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
n.SetMType(TypeExprU8)
|
||||
return nil
|
||||
}
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
// n is an index.
|
||||
@@ -309,6 +316,18 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprOther", n.ID0().Key())
|
||||
}
|
||||
|
||||
func isInSrcReadU8(m *t.IDMap, n *a.Expr) bool {
|
||||
if n.ID0().Key() != t.KeyDot || n.ID1().Key() != t.KeyReadU8 {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.ID0().Key() != t.KeyDot || n.ID1() != m.ByName("src") {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
||||
}
|
||||
|
||||
func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
lhs := n.LHS().Expr()
|
||||
if err := q.tcheckExpr(lhs, depth); err != nil {
|
||||
@@ -330,6 +349,14 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
s = q.f.Func.In()
|
||||
case t.KeyOut:
|
||||
s = q.f.Func.Out()
|
||||
case t.KeyBuf1:
|
||||
// TODO: remove this hack and be more principled about the built-in
|
||||
// buf1 type.
|
||||
//
|
||||
// Another hack is using TypeExprU8 until a TypeExpr can represent
|
||||
// function types.
|
||||
n.SetMType(TypeExprU8)
|
||||
return nil
|
||||
default:
|
||||
s = q.c.structs[name].Struct
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user