MCPcopy
hub / github.com/google/go-jsonnet / clone

Function clone

ast/clone.go:74–295  ·  view source on GitHub ↗

Updates *astPtr to point to a deep clone of what it originally pointed at.

(astPtr *Node)

Source from the content-addressed store, hash-verified

72
73// Updates *astPtr to point to a deep clone of what it originally pointed at.
74func clone(astPtr *Node) {
75 node := *astPtr
76 if node == nil {
77 return
78 }
79
80 switch node := node.(type) {
81 case *Apply:
82 r := new(Apply)
83 *astPtr = r
84 *r = *node
85 clone(&r.Target)
86 r.Arguments.Positional = cloneCommaSeparatedExprs(r.Arguments.Positional)
87 r.Arguments.Named = append(make([]NamedArgument, 0), r.Arguments.Named...)
88 for i := range r.Arguments.Named {
89 clone(&r.Arguments.Named[i].Arg)
90 }
91
92 case *ApplyBrace:
93 r := new(ApplyBrace)
94 *astPtr = r
95 *r = *node
96 clone(&r.Left)
97 clone(&r.Right)
98
99 case *Array:
100 r := new(Array)
101 *astPtr = r
102 *r = *node
103 r.Elements = cloneCommaSeparatedExprs(r.Elements)
104
105 case *ArrayComp:
106 r := new(ArrayComp)
107 *astPtr = r
108 *r = *node
109 clone(&r.Body)
110 cloneForSpec(&r.Spec)
111
112 case *Assert:
113 r := new(Assert)
114 *astPtr = r
115 *r = *node
116 clone(&r.Cond)
117 clone(&r.Message)
118 clone(&r.Rest)
119
120 case *Binary:
121 r := new(Binary)
122 *astPtr = r
123 *r = *node
124 clone(&r.Left)
125 clone(&r.Right)
126
127 case *Conditional:
128 r := new(Conditional)
129 *astPtr = r
130 *r = *node
131 clone(&r.Cond)

Callers 5

cloneForSpecFunction · 0.85
cloneFieldFunction · 0.85
cloneDesugaredFieldFunction · 0.85
cloneCommaSeparatedExprsFunction · 0.85
CloneFunction · 0.85

Calls 6

cloneCommaSeparatedExprsFunction · 0.85
cloneForSpecFunction · 0.85
CloneFunction · 0.85
cloneFieldFunction · 0.85
cloneDesugaredFieldFunction · 0.85
cloneNodeBaseFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…