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

+8 -5
View File
@@ -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
}