Add a TypeExpr.HasPointers method.

This commit is contained in:
Nigel Tao committed 2017-09-28 11:41:01 +10:00
1 parent 7b6f7384d1
commit 95391533b3
3 files changed
+18 -25

No files matched your search

-9
View File
@@ -384,15 +384,6 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
return nil
}
var builtInPointerTypes = [...]bool{
t.KeyBuf1: true,
t.KeyBuf1Mark: true,
// TODO: uncomment, after figuring out how limit's should really work.
// t.KeyReader1: true,
t.KeyWriter1: true,
t.KeyBuf2: true,
}
var cTypeNames = [...]string{
t.KeyI8: "int8_t",
t.KeyI16: "int16_t",
+2 -16
View File
@@ -232,7 +232,7 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, prefix string, suspend bo
local := fmt.Sprintf("%s%s", prefix, n.Name().String(g.tm))
// TODO: explicitly handle prefix == lPrefix?
if typ := n.XType(); prefix == vPrefix && typeHasPointers(typ) {
if typ := n.XType(); prefix == vPrefix && typ.HasPointers() {
if suspend {
return nil
}
@@ -297,7 +297,7 @@ func (g *gen) writeVars(b *buffer, block []*a.Node, skipPointerTypes bool) error
if v := n.Value(); v != nil && v.ID0().Key() == t.KeyLimit {
b.printf("uint64_t %s%v;\n", lPrefix, n.Name().String(g.tm))
}
if skipPointerTypes && typeHasPointers(n.XType()) {
if skipPointerTypes && n.XType().HasPointers() {
return nil
}
if err := g.writeCTypeName(b, n.XType(), vPrefix, n.Name().String(g.tm)); err != nil {
@@ -307,17 +307,3 @@ func (g *gen) writeVars(b *buffer, block []*a.Node, skipPointerTypes bool) error
return nil
})
}
func typeHasPointers(typ *a.TypeExpr) bool {
for ; typ != nil; typ = typ.Inner() {
switch typ.Decorator().Key() {
case 0:
if key := typ.Name().Key(); key < t.Key(len(builtInPointerTypes)) && builtInPointerTypes[key] {
return true
}
case t.KeyPtr, t.KeyColon:
return true
}
}
return false
}