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

Method buildMacroCallArg

parser/helper.go:234–264  ·  view source on GitHub ↗

buildMacroCallArg iterates the expression and returns a new expression where all macros have been replaced by their IDs in MacroCalls

(expr ast.Expr)

Source from the content-addressed store, hash-verified

232// buildMacroCallArg iterates the expression and returns a new expression
233// where all macros have been replaced by their IDs in MacroCalls
234func (p *parserHelper) buildMacroCallArg(expr ast.Expr) ast.Expr {
235 if _, found := p.sourceInfo.GetMacroCall(expr.ID()); found {
236 return p.exprFactory.NewUnspecifiedExpr(expr.ID())
237 }
238
239 switch expr.Kind() {
240 case ast.CallKind:
241 // Iterate the AST from `expr` recursively looking for macros. Because we are at most
242 // starting from the top level macro, this recursion is bounded by the size of the AST. This
243 // means that the depth check on the AST during parsing will catch recursion overflows
244 // before we get to here.
245 call := expr.AsCall()
246 macroArgs := make([]ast.Expr, len(call.Args()))
247 for index, arg := range call.Args() {
248 macroArgs[index] = p.buildMacroCallArg(arg)
249 }
250 if !call.IsMemberFunction() {
251 return p.exprFactory.NewCall(expr.ID(), call.FunctionName(), macroArgs...)
252 }
253 macroTarget := p.buildMacroCallArg(call.Target())
254 return p.exprFactory.NewMemberCall(expr.ID(), call.FunctionName(), macroTarget, macroArgs...)
255 case ast.ListKind:
256 list := expr.AsList()
257 macroListArgs := make([]ast.Expr, list.Size())
258 for i, elem := range list.Elements() {
259 macroListArgs[i] = p.buildMacroCallArg(elem)
260 }
261 return p.exprFactory.NewList(expr.ID(), macroListArgs, list.OptionalIndices())
262 }
263 return expr
264}
265
266// addMacroCall adds the macro the the MacroCalls map in source info. If a macro has args/subargs/target
267// that are macros, their ID will be stored instead for later self-lookups.

Callers 1

addMacroCallMethod · 0.95

Calls 15

GetMacroCallMethod · 0.80
IDMethod · 0.65
NewUnspecifiedExprMethod · 0.65
KindMethod · 0.65
AsCallMethod · 0.65
ArgsMethod · 0.65
IsMemberFunctionMethod · 0.65
NewCallMethod · 0.65
FunctionNameMethod · 0.65
TargetMethod · 0.65
NewMemberCallMethod · 0.65
AsListMethod · 0.65

Tested by

no test coverage detected