mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Generate C code for "in.dst.write?(etc)".
This commit is contained in:
1 parent
88e2d4cf59
commit
f403d0faa8
8 files changed
+147
-29
No files matched your search
@@ -598,9 +598,8 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
// No-op.
|
||||
|
||||
case t.KeyOpenParen:
|
||||
// TODO: delete this hack that only matches "in.src.read_u8?()" and
|
||||
// "in.dst.write_u8?(x:bar)".
|
||||
if isInSrcReadU8(q.tm, n) || isInDstWriteU8(q.tm, n) {
|
||||
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
|
||||
if isInSrcReadU8(q.tm, n) || isInDst(q.tm, n, t.KeyWrite) || isInDst(q.tm, n, t.KeyWriteU8) {
|
||||
for _, o := range n.Args() {
|
||||
// TODO: check that the arg range at the caller and the
|
||||
// signature are compatible.
|
||||
|
||||
+4
-5
@@ -326,9 +326,8 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
|
||||
case t.KeyOpenParen:
|
||||
// n is a function call.
|
||||
// TODO: delete this hack that only matches "in.src.read_u8?()" and
|
||||
// "in.dst.write_u8?(x:bar)".
|
||||
if isInSrcReadU8(q.tm, n) || isInDstWriteU8(q.tm, n) {
|
||||
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
|
||||
if isInSrcReadU8(q.tm, n) || isInDst(q.tm, n, t.KeyWrite) || isInDst(q.tm, n, t.KeyWriteU8) {
|
||||
if err := q.tcheckExpr(n.LHS().Expr(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -406,13 +405,13 @@ func isInSrcReadU8(tm *t.Map, n *a.Expr) bool {
|
||||
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
||||
}
|
||||
|
||||
func isInDstWriteU8(tm *t.Map, n *a.Expr) bool {
|
||||
func isInDst(tm *t.Map, n *a.Expr, methodName t.Key) bool {
|
||||
// TODO: check that n.Args() is "(x:bar)".
|
||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 1 {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.ID0().Key() != t.KeyDot || n.ID1().Key() != t.KeyWriteU8 {
|
||||
if n.ID0().Key() != t.KeyDot || n.ID1().Key() != methodName {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
|
||||
@@ -241,6 +241,7 @@ const (
|
||||
KeyReadU32LE = Key(IDReadU32LE >> KeyShift)
|
||||
KeyReadU64BE = Key(IDReadU64BE >> KeyShift)
|
||||
KeyReadU64LE = Key(IDReadU64LE >> KeyShift)
|
||||
KeyWrite = Key(IDWrite >> KeyShift)
|
||||
KeyWriteU8 = Key(IDWriteU8 >> KeyShift)
|
||||
KeyWriteU16BE = Key(IDWriteU16BE >> KeyShift)
|
||||
KeyWriteU16LE = Key(IDWriteU16LE >> KeyShift)
|
||||
@@ -392,6 +393,7 @@ const (
|
||||
IDReadU32LE = ID(0xB5<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||
IDReadU64BE = ID(0xB6<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||
IDReadU64LE = ID(0xB7<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||
IDWrite = ID(0xB8<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||
IDWriteU8 = ID(0xB9<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||
IDWriteU16BE = ID(0xBA<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||
IDWriteU16LE = ID(0xBB<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||
@@ -565,6 +567,7 @@ var builtInsByKey = [nBuiltInKeys]struct {
|
||||
KeyReadU32LE: {"read_u32le", IDReadU32LE},
|
||||
KeyReadU64BE: {"read_u64be", IDReadU64BE},
|
||||
KeyReadU64LE: {"read_u64le", IDReadU64LE},
|
||||
KeyWrite: {"write", IDWrite},
|
||||
KeyWriteU8: {"write_u8", IDWriteU8},
|
||||
KeyWriteU16BE: {"write_u16be", IDWriteU16BE},
|
||||
KeyWriteU16LE: {"write_u16le", IDWriteU16LE},
|
||||
|
||||
Reference in new issue
Block a user