Commit 77456008 authored by Dr. Stefan Schimanski's avatar Dr. Stefan Schimanski

bump(k8s.io/gengo): 712a17394a0980fabbcf3d968972e185d80c0fa4

parent 0d88afa1
...@@ -2231,7 +2231,6 @@ ...@@ -2231,7 +2231,6 @@
}, },
{ {
"ImportPath": "github.com/pelletier/go-buffruneio", "ImportPath": "github.com/pelletier/go-buffruneio",
"Comment": "v0.1.0",
"Rev": "df1e16fde7fc330a0ca68167c23bf7ed6ac31d6d" "Rev": "df1e16fde7fc330a0ca68167c23bf7ed6ac31d6d"
}, },
{ {
...@@ -2985,43 +2984,43 @@ ...@@ -2985,43 +2984,43 @@
}, },
{ {
"ImportPath": "k8s.io/gengo/args", "ImportPath": "k8s.io/gengo/args",
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30" "Rev": "712a17394a0980fabbcf3d968972e185d80c0fa4"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators", "ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators",
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30" "Rev": "712a17394a0980fabbcf3d968972e185d80c0fa4"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators", "ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators",
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30" "Rev": "712a17394a0980fabbcf3d968972e185d80c0fa4"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/import-boss/generators", "ImportPath": "k8s.io/gengo/examples/import-boss/generators",
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30" "Rev": "712a17394a0980fabbcf3d968972e185d80c0fa4"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/set-gen/generators", "ImportPath": "k8s.io/gengo/examples/set-gen/generators",
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30" "Rev": "712a17394a0980fabbcf3d968972e185d80c0fa4"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/set-gen/sets", "ImportPath": "k8s.io/gengo/examples/set-gen/sets",
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30" "Rev": "712a17394a0980fabbcf3d968972e185d80c0fa4"
}, },
{ {
"ImportPath": "k8s.io/gengo/generator", "ImportPath": "k8s.io/gengo/generator",
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30" "Rev": "712a17394a0980fabbcf3d968972e185d80c0fa4"
}, },
{ {
"ImportPath": "k8s.io/gengo/namer", "ImportPath": "k8s.io/gengo/namer",
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30" "Rev": "712a17394a0980fabbcf3d968972e185d80c0fa4"
}, },
{ {
"ImportPath": "k8s.io/gengo/parser", "ImportPath": "k8s.io/gengo/parser",
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30" "Rev": "712a17394a0980fabbcf3d968972e185d80c0fa4"
}, },
{ {
"ImportPath": "k8s.io/gengo/types", "ImportPath": "k8s.io/gengo/types",
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30" "Rev": "712a17394a0980fabbcf3d968972e185d80c0fa4"
}, },
{ {
"ImportPath": "k8s.io/heapster/metrics/api/v1/types", "ImportPath": "k8s.io/heapster/metrics/api/v1/types",
......
...@@ -320,7 +320,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat ...@@ -320,7 +320,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
if d.object != nil { if d.object != nil {
continue continue
} }
if buildCallTreeForType(t, true, existingDefaulters, newDefaulters) != nil { if newCallTreeForType(existingDefaulters, newDefaulters).build(t, true) != nil {
args := defaultingArgsFromType(t) args := defaultingArgsFromType(t)
sw.Do("$.inType|objectdefaultfn$", args) sw.Do("$.inType|objectdefaultfn$", args)
newDefaulters[t] = defaults{ newDefaulters[t] = defaults{
...@@ -387,7 +387,22 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat ...@@ -387,7 +387,22 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
return packages return packages
} }
// buildCallTreeForType creates a tree of paths to fields (based on how they would be accessed in Go - pointer, elem, // callTreeForType contains fields necessary to build a tree for types.
type callTreeForType struct {
existingDefaulters defaulterFuncMap
newDefaulters defaulterFuncMap
currentlyBuildingTypes map[*types.Type]bool
}
func newCallTreeForType(existingDefaulters, newDefaulters defaulterFuncMap) *callTreeForType {
return &callTreeForType{
existingDefaulters: existingDefaulters,
newDefaulters: newDefaulters,
currentlyBuildingTypes: make(map[*types.Type]bool),
}
}
// build creates a tree of paths to fields (based on how they would be accessed in Go - pointer, elem,
// slice, or key) and the functions that should be invoked on each field. An in-order traversal of the resulting tree // slice, or key) and the functions that should be invoked on each field. An in-order traversal of the resulting tree
// can be used to generate a Go function that invokes each nested function on the appropriate type. The return // can be used to generate a Go function that invokes each nested function on the appropriate type. The return
// value may be nil if there are no functions to call on type or the type is a primitive (Defaulters can only be // value may be nil if there are no functions to call on type or the type is a primitive (Defaulters can only be
...@@ -396,7 +411,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat ...@@ -396,7 +411,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
// that could be or will be generated. If newDefaulters has an entry for a type, but the 'object' field is nil, // that could be or will be generated. If newDefaulters has an entry for a type, but the 'object' field is nil,
// this function skips adding that defaulter - this allows us to avoid generating object defaulter functions for // this function skips adding that defaulter - this allows us to avoid generating object defaulter functions for
// list types that call empty defaulters. // list types that call empty defaulters.
func buildCallTreeForType(t *types.Type, root bool, existingDefaulters, newDefaulters defaulterFuncMap) *callNode { func (c *callTreeForType) build(t *types.Type, root bool) *callNode {
parent := &callNode{} parent := &callNode{}
if root { if root {
...@@ -404,8 +419,8 @@ func buildCallTreeForType(t *types.Type, root bool, existingDefaulters, newDefau ...@@ -404,8 +419,8 @@ func buildCallTreeForType(t *types.Type, root bool, existingDefaulters, newDefau
parent.elem = true parent.elem = true
} }
defaults, _ := existingDefaulters[t] defaults, _ := c.existingDefaulters[t]
newDefaults, generated := newDefaulters[t] newDefaults, generated := c.newDefaulters[t]
switch { switch {
case !root && generated && newDefaults.object != nil: case !root && generated && newDefaults.object != nil:
parent.call = append(parent.call, newDefaults.object) parent.call = append(parent.call, newDefaults.object)
...@@ -432,19 +447,33 @@ func buildCallTreeForType(t *types.Type, root bool, existingDefaulters, newDefau ...@@ -432,19 +447,33 @@ func buildCallTreeForType(t *types.Type, root bool, existingDefaulters, newDefau
// base has been added already, now add any additional defaulters defined for this object // base has been added already, now add any additional defaulters defined for this object
parent.call = append(parent.call, defaults.additional...) parent.call = append(parent.call, defaults.additional...)
// if the type already exists, don't build the tree for it and don't generate anything.
// This is used to avoid recursion for nested recursive types.
if c.currentlyBuildingTypes[t] {
return nil
}
// if type doesn't exist, mark it as existing
c.currentlyBuildingTypes[t] = true
defer func() {
// The type will now acts as a parent, not a nested recursive type.
// We can now build the tree for it safely.
c.currentlyBuildingTypes[t] = false
}()
switch t.Kind { switch t.Kind {
case types.Pointer: case types.Pointer:
if child := buildCallTreeForType(t.Elem, false, existingDefaulters, newDefaulters); child != nil { if child := c.build(t.Elem, false); child != nil {
child.elem = true child.elem = true
parent.children = append(parent.children, *child) parent.children = append(parent.children, *child)
} }
case types.Slice, types.Array: case types.Slice, types.Array:
if child := buildCallTreeForType(t.Elem, false, existingDefaulters, newDefaulters); child != nil { if child := c.build(t.Elem, false); child != nil {
child.index = true child.index = true
parent.children = append(parent.children, *child) parent.children = append(parent.children, *child)
} }
case types.Map: case types.Map:
if child := buildCallTreeForType(t.Elem, false, existingDefaulters, newDefaulters); child != nil { if child := c.build(t.Elem, false); child != nil {
child.key = true child.key = true
parent.children = append(parent.children, *child) parent.children = append(parent.children, *child)
} }
...@@ -458,13 +487,13 @@ func buildCallTreeForType(t *types.Type, root bool, existingDefaulters, newDefau ...@@ -458,13 +487,13 @@ func buildCallTreeForType(t *types.Type, root bool, existingDefaulters, newDefau
name = field.Type.Name.Name name = field.Type.Name.Name
} }
} }
if child := buildCallTreeForType(field.Type, false, existingDefaulters, newDefaulters); child != nil { if child := c.build(field.Type, false); child != nil {
child.field = name child.field = name
parent.children = append(parent.children, *child) parent.children = append(parent.children, *child)
} }
} }
case types.Alias: case types.Alias:
if child := buildCallTreeForType(t.Underlying, false, existingDefaulters, newDefaulters); child != nil { if child := c.build(t.Underlying, false); child != nil {
parent.children = append(parent.children, *child) parent.children = append(parent.children, *child)
} }
} }
...@@ -571,7 +600,7 @@ func (g *genDefaulter) GenerateType(c *generator.Context, t *types.Type, w io.Wr ...@@ -571,7 +600,7 @@ func (g *genDefaulter) GenerateType(c *generator.Context, t *types.Type, w io.Wr
glog.V(5).Infof("generating for type %v", t) glog.V(5).Infof("generating for type %v", t)
callTree := buildCallTreeForType(t, true, g.existingDefaulters, g.newDefaulters) callTree := newCallTreeForType(g.existingDefaulters, g.newDefaulters).build(t, true)
if callTree == nil { if callTree == nil {
glog.V(5).Infof(" no defaulters defined") glog.V(5).Infof(" no defaulters defined")
return nil return nil
......
...@@ -16,6 +16,8 @@ limitations under the License. ...@@ -16,6 +16,8 @@ limitations under the License.
package types package types
import "strings"
// Ref makes a reference to the given type. It can only be used for e.g. // Ref makes a reference to the given type. It can only be used for e.g.
// passing to namers. // passing to namers.
func Ref(packageName, typeName string) *Type { func Ref(packageName, typeName string) *Type {
...@@ -44,6 +46,19 @@ func (n Name) String() string { ...@@ -44,6 +46,19 @@ func (n Name) String() string {
return n.Package + "." + n.Name return n.Package + "." + n.Name
} }
// ParseFullyQualifiedName parses a name like k8s.io/kubernetes/pkg/api.Pod into a Name.
func ParseFullyQualifiedName(fqn string) Name {
cs := strings.Split(fqn, ".")
pkg := ""
if len(cs) > 1 {
pkg = strings.Join(cs[0:len(cs) - 1], ".")
}
return Name{
Name: cs[len(cs) - 1],
Package: pkg,
}
}
// The possible classes of types. // The possible classes of types.
type Kind string type Kind string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment