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

Method CopyAST

cel/optimizer.go:283–290  ·  view source on GitHub ↗

CopyAST creates a renumbered copy of `Expr` and `SourceInfo` values of the input AST, where the renumbering uses the same scheme as the core optimizer logic ensuring there are no collisions between copies. Use this method before attempting to merge the expression from AST into another.

(a *ast.AST)

Source from the content-addressed store, hash-verified

281//
282// Use this method before attempting to merge the expression from AST into another.
283func (opt *optimizerExprFactory) CopyAST(a *ast.AST) (ast.Expr, *ast.SourceInfo) {
284 idGen := newIDGenerator(opt.nextID())
285 defer func() { opt.seed = idGen.nextID() }()
286 copyExpr := opt.fac.CopyExpr(a.Expr())
287 copyInfo := ast.CopySourceInfo(a.SourceInfo())
288 normalizeIDs(idGen.renumberStable, copyExpr, copyInfo)
289 return copyExpr, copyInfo
290}
291
292// CopyASTAndMetadata copies the input AST and propagates the macro metadata into the AST being
293// optimized.

Callers 1

CopyASTAndMetadataMethod · 0.95

Calls 7

CopySourceInfoFunction · 0.92
newIDGeneratorFunction · 0.85
normalizeIDsFunction · 0.85
CopyExprMethod · 0.65
ExprMethod · 0.65
nextIDMethod · 0.45
SourceInfoMethod · 0.45

Tested by

no test coverage detected