util/codegen: support embedded fields

I noticed cmd/{cloner,viewer} didn't support structs with embedded
fields while working on a change in another repo. This adds support.

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2023-05-09 15:35:47 -07:00
committed by Brad Fitzpatrick
parent ea84fc9ad2
commit 4f454f4122
4 changed files with 89 additions and 4 deletions

View File

@@ -202,13 +202,18 @@ func AssertStructUnchanged(t *types.Struct, tname, ctx string, it *ImportTracker
w("var _%s%sNeedsRegeneration = %s(struct {", tname, ctx, tname)
for i := 0; i < t.NumFields(); i++ {
fname := t.Field(i).Name()
st := t.Field(i)
fname := st.Name()
ft := t.Field(i).Type()
if IsInvalid(ft) {
continue
}
qname := it.QualifiedName(ft)
w("\t%s %s", fname, qname)
if st.Anonymous() {
w("\t%s ", fname)
} else {
w("\t%s %s", fname, qname)
}
}
w("}{})\n")