mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 00:47:28 +01:00
Add a slice.length method.
This commit is contained in:
1 parent
fda696bf95
commit
51f2b183a2
7 files changed
+57
-6
No files matched your search
@@ -144,6 +144,21 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if isLength(g.tm, n) {
|
||||
if pp == parenthesesMandatory {
|
||||
b.writeb('(')
|
||||
}
|
||||
b.writes("(uint64_t)(")
|
||||
x := n.LHS().Expr().LHS().Expr()
|
||||
if err := g.writeExpr(b, x, rp, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(".len)")
|
||||
if pp == parenthesesMandatory {
|
||||
b.writeb(')')
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// TODO.
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
|
||||
@@ -196,11 +196,6 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
b.writeb('0')
|
||||
}
|
||||
b.writes(";\n")
|
||||
|
||||
// TODO: remove this.
|
||||
if n.XType().Decorator().Key() == t.KeyColon {
|
||||
b.printf("PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(%s%s);\n", vPrefix, n.Name().String(g.tm))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -782,3 +777,11 @@ func isDecode(tm *t.Map, n *a.Expr) bool {
|
||||
n = n.LHS().Expr()
|
||||
return n.ID0().Key() == t.KeyDot && n.ID1() == tm.ByName("decode")
|
||||
}
|
||||
|
||||
func isLength(tm *t.Map, n *a.Expr) bool {
|
||||
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() || len(n.Args()) != 0 {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.ID0().Key() == t.KeyDot && n.ID1().Key() == t.KeyLength
|
||||
}
|
||||
Reference in new issue
Block a user