Call initializers for out-of-pkg struct fields

This commit is contained in:
Nigel Tao committed 2017-12-03 14:22:49 +11:00
1 parent 6fec22c6d7
commit 7e73a5ac5f
4 files changed
+43 -32

No files matched your search

+11 -4
View File
@@ -696,12 +696,19 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
// TODO: arrays of sub-structs.
continue
}
if g.structMap[x.Name()] == nil {
prefix := g.pkgPrefix
if otherPkgID := x.Decorator(); otherPkgID != 0 {
// See gen.writeCTypeName for a related TODO with otherPkg.
otherPkg := g.tm.ByID(otherPkgID)
prefix = "wuffs_" + otherPkg + "__"
} else if g.structMap[x.Name()] == nil {
// Skip field types like u32 and bool.
continue
}
b.printf("%s%s__initialize(&self->private_impl.%s%s,"+
"WUFFS_VERSION, WUFFS_BASE__ALREADY_ZEROED);\n",
g.pkgPrefix, x.Name().Str(g.tm), fPrefix, f.Name().Str(g.tm))
b.printf("%s%s__initialize(&self->private_impl.%s%s, WUFFS_VERSION, WUFFS_BASE__ALREADY_ZEROED);\n",
prefix, x.Name().Str(g.tm), fPrefix, f.Name().Str(g.tm))
}
b.writes("}\n\n")
+2
View File
@@ -574,6 +574,8 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
// to generating "wuffs_bar__qux".
//
// TODO: sanitize or validate otherPkg, e.g. that it's ASCII only?
//
// See gen.writeInitializerImpl for a similar use of otherPkg.
prefix = "wuffs_" + otherPkg + "__"
}
b.printf("%s%s", prefix, innermost.Name().Str(g.tm))