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

Method NewBindMacro

cel/optimizer.go:328–358  ·  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

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

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