Add a slice.length method.

This commit is contained in:
Nigel Tao committed 2017-09-22 12:37:07 +10:00
1 parent fda696bf95
commit 51f2b183a2
7 files changed
+57 -6

No files matched your search

+15
View File
@@ -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: