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

Method NewBindMacro

cel/optimizer.go:322–352  ·  view source on GitHub ↗

NewBindMacro creates an AST expression representing the expanded bind() macro, and a macro expression representing the unexpanded call signature to be inserted into the source info macro call metadata.

(macroID int64, varName string, varInit, remaining ast.Expr)

Source from the content-addressed store, hash-verified

320// NewBindMacro creates an AST expression representing the expanded bind() macro, and a macro expression
321// representing the unexpanded call signature to be inserted into the source info macro call metadata.
322func (opt *optimizerExprFactory) NewBindMacro(macroID int64, varName string, varInit, remaining ast.Expr) (astExpr, macroExpr ast.Expr) {
323 varID := opt.nextID()
324 remainingID := opt.nextID()
325 remaining = opt.fac.CopyExpr(remaining)
326 remaining.RenumberIDs(func(id int64) int64 {
327 if id == macroID {
328 return remainingID
329 }
330 return id
331 })
332 if call, exists := opt.sourceInfo.GetMacroCall(macroID); exists {
333 opt.SetMacroCall(remainingID, opt.fac.CopyExpr(call))
334 }
335
336 astExpr = opt.fac.NewComprehension(macroID,
337 opt.fac.NewList(opt.nextID(), []ast.Expr{}, []int32{}),
338 "#unused",
339 varName,
340 opt.fac.CopyExpr(varInit),
341 opt.fac.NewLiteral(opt.nextID(), types.False),
342 opt.fac.NewIdent(varID, varName),
343 remaining)
344
345 macroExpr = opt.fac.NewMemberCall(0, "bind",
346 opt.fac.NewIdent(opt.nextID(), "cel"),
347 opt.fac.NewIdent(varID, varName),
348 opt.fac.CopyExpr(varInit),
349 opt.fac.CopyExpr(remaining))
350 opt.sanitizeMacro(macroID, macroExpr)
351 return
352}
353
354// NewCall creates a global function call invocation expression.
355//

Callers 1

OptimizeMethod · 0.80

Calls 11

SetMacroCallMethod · 0.95
sanitizeMacroMethod · 0.95
GetMacroCallMethod · 0.80
CopyExprMethod · 0.65
RenumberIDsMethod · 0.65
NewComprehensionMethod · 0.65
NewListMethod · 0.65
NewLiteralMethod · 0.65
NewIdentMethod · 0.65
NewMemberCallMethod · 0.65
nextIDMethod · 0.45

Tested by

no test coverage detected