Add a writer1.length method.

This commit is contained in:
Nigel Tao committed 2017-10-06 14:17:01 +11:00
1 parent e9df25d599
commit d30d4c3dad
3 files changed
+16 -4

No files matched your search

+12 -4
View File
@@ -171,12 +171,20 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
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
if typ := x.MType(); typ.Decorator() == 0 && typ.Name().Key() == t.KeyWriter1 {
// TODO: don't hard-code dst.
const wName = "dst"
b.printf("(uint64_t)(%swptr_%s - %swstart_%s)", bPrefix, wName, bPrefix, wName)
} else {
b.writes("(uint64_t)(")
if err := g.writeExpr(b, x, rp, parenthesesMandatory, depth); err != nil {
return err
}
b.writes(".len)")
}
b.writes(".len)")
if pp == parenthesesMandatory {
b.writeb(')')
}