diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-12-02 10:57:36 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-12-11 15:22:17 +0000 |
| commit | 2f981ae0154bd9e967e046692984f0b6e2423a32 (patch) | |
| tree | ef9cfb66e60160880add82e2db356a152e977ee4 /pkg/declextract | |
| parent | b2c5a234aeb69e981c6e7ad120b49d37a86c6cae (diff) | |
pkg/declextract: rename generated names for consistency
Currently we append "$auto", or "$auto_record", or prepend "auto_",
or insert "auto" somewhere in the middle.
Use more consistent naming: always append "$auto".
Diffstat (limited to 'pkg/declextract')
| -rw-r--r-- | pkg/declextract/declextract.go | 21 | ||||
| -rw-r--r-- | pkg/declextract/netlink.go | 24 |
2 files changed, 18 insertions, 27 deletions
diff --git a/pkg/declextract/declextract.go b/pkg/declextract/declextract.go index dd54bf79c..49a515ddb 100644 --- a/pkg/declextract/declextract.go +++ b/pkg/declextract/declextract.go @@ -67,9 +67,7 @@ func (ctx *context) processIncludes() { func (ctx *context) processEnums() { for _, enum := range ctx.Enums { - // TODO: change for consistency: - // enum.Name += autoSuffix - enum.Name = "auto_" + enum.Name + enum.Name += autoSuffix } } @@ -110,9 +108,7 @@ func (ctx *context) processIouring() { func (ctx *context) processStructs() { for _, str := range ctx.Structs { - // TODO: change for consistency: - // str.Name += autoSuffix - str.Name += "$auto_record" + str.Name += autoSuffix ctx.structs[str.Name] = str } ctx.Structs = slices.DeleteFunc(ctx.Structs, func(str *Struct) bool { @@ -196,9 +192,7 @@ func (ctx *context) fieldTypeInt(f, counts *Field, needBase bool) string { return unusedType } if t.Enum != "" { - // TODO: change for consistency: - // t.Enum += autoSuffix - t.Enum = "auto_" + t.Enum + t.Enum += autoSuffix return fmt.Sprintf("flags[%v %v]", t.Enum, maybeBaseType(baseType, needBase)) } if counts != nil { @@ -288,7 +282,7 @@ func (ctx *context) fieldTypePtr(f, counts *Field, parent string) string { // Use an opt pointer if the direct parent is the same as this node, or if the field name is next. // Looking at the field name is a hack, but it's enough to avoid some recursion cases, // e.g. for struct adf_user_cfg_section. - if f.Name == "next" || parent != "" && parent == t.Elem.Struct+"$auto_record" { + if f.Name == "next" || parent != "" && parent == t.Elem.Struct+autoSuffix { opt = ", opt" } elem := &Field{ @@ -336,9 +330,7 @@ func (ctx *context) fieldTypeBuffer(f *Field) string { } func (ctx *context) fieldTypeStruct(f *Field) string { - // TODO: change for consistency: - // f.Type.Struct += autoSuffix - f.Type.Struct += "$auto_record" + f.Type.Struct += autoSuffix if ctx.structs[f.Type.Struct].ByteSize == 0 { return "void" } @@ -372,11 +364,10 @@ func fixIdentifier(name string) string { } func stringIdentifier(name string) string { - // TODO: make the identifier lower case. for _, bad := range []string{" ", ".", "-"} { name = strings.ReplaceAll(name, bad, "_") } - return name + return strings.ToLower(name) } func maybeBaseType(baseType string, needBase bool) string { diff --git a/pkg/declextract/netlink.go b/pkg/declextract/netlink.go index de60ae30e..ad80122dc 100644 --- a/pkg/declextract/netlink.go +++ b/pkg/declextract/netlink.go @@ -15,7 +15,7 @@ func (ctx *context) fabricateNetlinkPolicies() { continue } str := &Struct{ - Name: pol.Name, + Name: pol.Name + autoSuffix, IsUnion: true, isVarlen: true, } @@ -36,19 +36,19 @@ func (ctx *context) emitNetlinkTypes() { continue } id := stringIdentifier(fam.Name) - ctx.fmt("resource genl_%v_family_id_auto[int16]\n", id) + ctx.fmt("resource genl_%v_family_id%v[int16]\n", id, autoSuffix) } for _, fam := range ctx.NetlinkFamilies { if isEmptyFamily(fam) { continue } id := stringIdentifier(fam.Name) - ctx.fmt("type msghdr_%v_auto[CMD, POLICY] msghdr_netlink[netlink_msg_t"+ - "[genl_%v_family_id_auto, genlmsghdr_t[CMD], POLICY]]\n", id, id) + ctx.fmt("type msghdr_%v%v[CMD, POLICY] msghdr_netlink[netlink_msg_t"+ + "[genl_%v_family_id%v, genlmsghdr_t[CMD], POLICY]]\n", id, autoSuffix, id, autoSuffix) } for _, pol := range ctx.NetlinkPolicies { if len(pol.Attrs) == 0 { - ctx.fmt("type %v auto_todo\n", pol.Name) + ctx.fmt("type %v auto_todo\n", pol.Name+autoSuffix) } } } @@ -59,8 +59,8 @@ func (ctx *context) emitNetlinkGetFamily() { continue } id := stringIdentifier(fam.Name) - ctx.fmt("syz_genetlink_get_family_id$auto_%v(name ptr[in, string[\"%v\"]],"+ - " fd sock_nl_generic) genl_%v_family_id_auto\n", id, fam.Name, id) + ctx.fmt("syz_genetlink_get_family_id%v_%v(name ptr[in, string[\"%v\"]],"+ + " fd sock_nl_generic) genl_%v_family_id%v\n", autoSuffix, id, fam.Name, id, autoSuffix) } } @@ -80,9 +80,9 @@ func (ctx *context) emitNetlinkSendmsgs() { continue } dedup[op.Name] = true - syscalls = append(syscalls, fmt.Sprintf("sendmsg$auto_%v(fd sock_nl_generic,"+ - " msg ptr[in, msghdr_%v_auto[%v, %v]], f flags[send_flags])\n", - op.Name, id, op.Name, op.Policy)) + syscalls = append(syscalls, fmt.Sprintf("sendmsg%v_%v(fd sock_nl_generic,"+ + " msg ptr[in, msghdr_%v%v[%v, %v]], f flags[send_flags])\n", + autoSuffix, op.Name, id, autoSuffix, op.Name, op.Policy+autoSuffix)) ctx.noteInterface(&Interface{ Type: IfaceNetlinkOp, @@ -124,7 +124,7 @@ func (ctx *context) nlattrType(attr *NetlinkAttr) string { nlattr = "nlnest" policy := "nl_generic_attr" if attr.NestedPolicy != "" { - policy = attr.NestedPolicy + policy = attr.NestedPolicy + autoSuffix } typ = fmt.Sprintf("array[%v]", policy) if attr.Kind == "NLA_NESTED_ARRAY" { @@ -181,7 +181,7 @@ func (ctx *context) netlinkType(attr *NetlinkAttr) *Type { case attr.Elem.Int != nil: elemSize = attr.Elem.Int.ByteSize case attr.Elem.Struct != "": - if str := ctx.structs[attr.Elem.Struct+"$auto_record"]; str != nil { + if str := ctx.structs[attr.Elem.Struct+autoSuffix]; str != nil { elemSize = str.ByteSize } else { ctx.error("binary nlattr %v referenced non-existing struct %v", |
