mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 16:47:28 +01:00
Let fields have default values.
This commit is contained in:
1 parent
e66f1cb236
commit
99ff8e2487
8 files changed
+76
-17
No files matched your search
@@ -226,7 +226,13 @@ func writeCtorImpls(b *bytes.Buffer, pkgName string, m *t.IDMap, n *a.Struct) er
|
||||
"memset(self, 0, sizeof(*self)); }\n")
|
||||
b.WriteString("self->magic = PUFFS_MAGIC;\n")
|
||||
|
||||
// TODO: set any non-zero default values.
|
||||
for _, f := range n.Fields() {
|
||||
f := f.Field()
|
||||
if dv := f.DefaultValue(); dv != nil {
|
||||
// TODO: set default values for array types.
|
||||
fmt.Fprintf(b, "self->f_%s = %d;\n", f.Name().String(m), dv.ConstValue())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: call any ctor/dtors on sub-structures.
|
||||
|
||||
Reference in new issue
Block a user