Generate a C placeholder for "in.src.read_u8?()".

This commit is contained in:
Nigel Tao committed 2017-06-03 12:25:31 +10:00
1 parent 0646f4472c
commit 1758637f89
7 files changed
+65 -8

No files matched your search

+19 -2
View File
@@ -673,8 +673,13 @@ func (g *gen) writeExprOther(n *a.Expr, depth uint32) error {
return nil
case t.KeyOpenParen:
// n is a function call.
// TODO.
// n is a function call.
// TODO: delete this hack that only matches "in.src.read_u8?()".
if isInSrcReadU8(g.idMap, n.LHS().Expr()) && len(n.Args()) == 0 {
// TODO.
g.writes("42")
return nil
}
case t.KeyOpenBracket:
// n is an index.
@@ -698,6 +703,18 @@ func (g *gen) writeExprOther(n *a.Expr, depth uint32) error {
return fmt.Errorf("unrecognized token.Key (0x%X) for writeExprOther", 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 (g *gen) writeExprUnaryOp(n *a.Expr, depth uint32) error {
// TODO.
return nil