mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Adjust conversion generator to new converter changes
This commit is contained in:
parent
2729b8e375
commit
7d5b96d5fc
@ -812,17 +812,23 @@ func (g *genConversion) doMap(inType, outType *types.Type, sw *generator.Snippet
|
||||
sw.Do("$.|raw$(val)\n", outType.Elem)
|
||||
}
|
||||
} else {
|
||||
sw.Do("newVal := new($.|raw$)\n", outType.Elem)
|
||||
conversionExists := true
|
||||
if function, ok := g.preexists(inType.Elem, outType.Elem); ok {
|
||||
sw.Do("newVal := new($.|raw$)\n", outType.Elem)
|
||||
sw.Do("if err := $.|raw$(&val, newVal, s); err != nil {\n", function)
|
||||
} else if g.convertibleOnlyWithinPackage(inType.Elem, outType.Elem) {
|
||||
sw.Do("newVal := new($.|raw$)\n", outType.Elem)
|
||||
sw.Do("if err := "+nameTmpl+"(&val, newVal, s); err != nil {\n", argsFromType(inType.Elem, outType.Elem))
|
||||
} else {
|
||||
sw.Do("// TODO: Inefficient conversion - can we improve it?\n", nil)
|
||||
sw.Do("if err := s.Convert(&val, newVal, 0); err != nil {\n", nil)
|
||||
args := argsFromType(inType.Elem, outType.Elem)
|
||||
sw.Do("// FIXME: Provide conversion function to convert $.inType|raw$ to $.outType|raw$\n", args)
|
||||
sw.Do("compileErrorOnMissingConversion()\n", nil)
|
||||
conversionExists = false
|
||||
}
|
||||
if conversionExists {
|
||||
sw.Do("return err\n", nil)
|
||||
sw.Do("}\n", nil)
|
||||
}
|
||||
if inType.Key == outType.Key {
|
||||
sw.Do("(*out)[key] = *newVal\n", nil)
|
||||
} else {
|
||||
@ -850,22 +856,22 @@ func (g *genConversion) doSlice(inType, outType *types.Type, sw *generator.Snipp
|
||||
sw.Do("(*out)[i] = $.|raw$((*in)[i])\n", outType.Elem)
|
||||
}
|
||||
} else {
|
||||
conversionExists := true
|
||||
if function, ok := g.preexists(inType.Elem, outType.Elem); ok {
|
||||
sw.Do("if err := $.|raw$(&(*in)[i], &(*out)[i], s); err != nil {\n", function)
|
||||
} else if g.convertibleOnlyWithinPackage(inType.Elem, outType.Elem) {
|
||||
sw.Do("if err := "+nameTmpl+"(&(*in)[i], &(*out)[i], s); err != nil {\n", argsFromType(inType.Elem, outType.Elem))
|
||||
} else {
|
||||
// TODO: This triggers on metav1.ObjectMeta <-> metav1.ObjectMeta and
|
||||
// similar because neither package is the target package, and
|
||||
// we really don't know which package will have the conversion
|
||||
// function defined. This fires on basically every object
|
||||
// conversion outside of pkg/api/v1.
|
||||
sw.Do("// TODO: Inefficient conversion - can we improve it?\n", nil)
|
||||
sw.Do("if err := s.Convert(&(*in)[i], &(*out)[i], 0); err != nil {\n", nil)
|
||||
args := argsFromType(inType.Elem, outType.Elem)
|
||||
sw.Do("// FIXME: Provide conversion function to convert $.inType|raw$ to $.outType|raw$\n", args)
|
||||
sw.Do("compileErrorOnMissingConversion()\n", nil)
|
||||
conversionExists = false
|
||||
}
|
||||
if conversionExists {
|
||||
sw.Do("return err\n", nil)
|
||||
sw.Do("}\n", nil)
|
||||
}
|
||||
}
|
||||
sw.Do("}\n", nil)
|
||||
}
|
||||
}
|
||||
@ -971,14 +977,19 @@ func (g *genConversion) doStruct(inType, outType *types.Type, sw *generator.Snip
|
||||
sw.Do("out.$.name$ = in.$.name$\n", args)
|
||||
continue
|
||||
}
|
||||
conversionExists := true
|
||||
if g.convertibleOnlyWithinPackage(inMemberType, outMemberType) {
|
||||
sw.Do("if err := "+nameTmpl+"(&in.$.name$, &out.$.name$, s); err != nil {\n", args)
|
||||
} else {
|
||||
sw.Do("// TODO: Inefficient conversion - can we improve it?\n", nil)
|
||||
sw.Do("if err := s.Convert(&in.$.name$, &out.$.name$, 0); err != nil {\n", args)
|
||||
args := argsFromType(inMemberType, outMemberType)
|
||||
sw.Do("// FIXME: Provide conversion function to convert $.inType|raw$ to $.outType|raw$\n", args)
|
||||
sw.Do("compileErrorOnMissingConversion()\n", nil)
|
||||
conversionExists = false
|
||||
}
|
||||
if conversionExists {
|
||||
sw.Do("return err\n", nil)
|
||||
sw.Do("}\n", nil)
|
||||
}
|
||||
case types.Alias:
|
||||
if isDirectlyAssignable(inMemberType, outMemberType) {
|
||||
if inMemberType == outMemberType {
|
||||
@ -987,27 +998,37 @@ func (g *genConversion) doStruct(inType, outType *types.Type, sw *generator.Snip
|
||||
sw.Do("out.$.name$ = $.outType|raw$(in.$.name$)\n", args)
|
||||
}
|
||||
} else {
|
||||
conversionExists := true
|
||||
if g.convertibleOnlyWithinPackage(inMemberType, outMemberType) {
|
||||
sw.Do("if err := "+nameTmpl+"(&in.$.name$, &out.$.name$, s); err != nil {\n", args)
|
||||
} else {
|
||||
sw.Do("// TODO: Inefficient conversion - can we improve it?\n", nil)
|
||||
sw.Do("if err := s.Convert(&in.$.name$, &out.$.name$, 0); err != nil {\n", args)
|
||||
args := argsFromType(inMemberType, outMemberType)
|
||||
sw.Do("// FIXME: Provide conversion function to convert $.inType|raw$ to $.outType|raw$\n", args)
|
||||
sw.Do("compileErrorOnMissingConversion()\n", nil)
|
||||
conversionExists = false
|
||||
}
|
||||
if conversionExists {
|
||||
sw.Do("return err\n", nil)
|
||||
sw.Do("}\n", nil)
|
||||
}
|
||||
}
|
||||
default:
|
||||
conversionExists := true
|
||||
if g.convertibleOnlyWithinPackage(inMemberType, outMemberType) {
|
||||
sw.Do("if err := "+nameTmpl+"(&in.$.name$, &out.$.name$, s); err != nil {\n", args)
|
||||
} else {
|
||||
sw.Do("// TODO: Inefficient conversion - can we improve it?\n", nil)
|
||||
sw.Do("if err := s.Convert(&in.$.name$, &out.$.name$, 0); err != nil {\n", args)
|
||||
args := argsFromType(inMemberType, outMemberType)
|
||||
sw.Do("// FIXME: Provide conversion function to convert $.inType|raw$ to $.outType|raw$\n", args)
|
||||
sw.Do("compileErrorOnMissingConversion()\n", nil)
|
||||
conversionExists = false
|
||||
}
|
||||
if conversionExists {
|
||||
sw.Do("return err\n", nil)
|
||||
sw.Do("}\n", nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *genConversion) isFastConversion(inType, outType *types.Type) bool {
|
||||
switch inType.Kind {
|
||||
@ -1033,18 +1054,23 @@ func (g *genConversion) doPointer(inType, outType *types.Type, sw *generator.Sni
|
||||
sw.Do("**out = $.|raw$(**in)\n", outType.Elem)
|
||||
}
|
||||
} else {
|
||||
conversionExists := true
|
||||
if function, ok := g.preexists(inType.Elem, outType.Elem); ok {
|
||||
sw.Do("if err := $.|raw$(*in, *out, s); err != nil {\n", function)
|
||||
} else if g.convertibleOnlyWithinPackage(inType.Elem, outType.Elem) {
|
||||
sw.Do("if err := "+nameTmpl+"(*in, *out, s); err != nil {\n", argsFromType(inType.Elem, outType.Elem))
|
||||
} else {
|
||||
sw.Do("// TODO: Inefficient conversion - can we improve it?\n", nil)
|
||||
sw.Do("if err := s.Convert(*in, *out, 0); err != nil {\n", nil)
|
||||
args := argsFromType(inType.Elem, outType.Elem)
|
||||
sw.Do("// FIXME: Provide conversion function to convert $.inType|raw$ to $.outType|raw$\n", args)
|
||||
sw.Do("compileErrorOnMissingConversion()\n", nil)
|
||||
conversionExists = false
|
||||
}
|
||||
if conversionExists {
|
||||
sw.Do("return err\n", nil)
|
||||
sw.Do("}\n", nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *genConversion) doAlias(inType, outType *types.Type, sw *generator.SnippetWriter) {
|
||||
// TODO: Add support for aliases.
|
||||
|
Loading…
Reference in New Issue
Block a user