MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Copy

Function Copy

common/ast/ast.go:133–150  ·  view source on GitHub ↗

Copy creates a deep copy of the Expr and SourceInfo values in the input AST. Copies of the Expr value are generated using an internal default ExprFactory.

(a *AST)

Source from the content-addressed store, hash-verified

131//
132// Copies of the Expr value are generated using an internal default ExprFactory.
133func Copy(a *AST) *AST {
134 if a == nil {
135 return nil
136 }
137 e := defaultFactory.CopyExpr(a.expr)
138 if !a.IsChecked() {
139 return NewAST(e, CopySourceInfo(a.SourceInfo()))
140 }
141 typesCopy := make(map[int64]*types.Type, len(a.typeMap))
142 for id, t := range a.typeMap {
143 typesCopy[id] = t
144 }
145 refsCopy := make(map[int64]*ReferenceInfo, len(a.refMap))
146 for id, r := range a.refMap {
147 refsCopy[id] = r
148 }
149 return NewCheckedAST(NewAST(e, CopySourceInfo(a.SourceInfo())), typesCopy, refsCopy)
150}
151
152// MaxID returns the upper-bound, non-inclusive, of ids present within the AST's Expr value.
153func MaxID(a *AST) int64 {

Callers 4

OptimizeMethod · 0.92
TestASTCopyFunction · 0.92
TestASTJsonNamesFunction · 0.92
TestASTNilSafetyFunction · 0.92

Calls 6

NewASTFunction · 0.85
CopySourceInfoFunction · 0.85
NewCheckedASTFunction · 0.85
CopyExprMethod · 0.65
IsCheckedMethod · 0.45
SourceInfoMethod · 0.45

Tested by 3

TestASTCopyFunction · 0.74
TestASTJsonNamesFunction · 0.74
TestASTNilSafetyFunction · 0.74