mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 08:38:14 +01:00
Call initializers for out-of-pkg struct fields
This commit is contained in:
1 parent
6fec22c6d7
commit
7e73a5ac5f
4 files changed
+43
-32
No files matched your search
@@ -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")
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in new issue
Block a user