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

Method buildMacroCallArg

parser/helper.go:197–227  ·  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

195// buildMacroCallArg iterates the expression and returns a new expression
196// where all macros have been replaced by their IDs in MacroCalls
197func (p *parserHelper) buildMacroCallArg(expr ast.Expr) ast.Expr {
198 if _, found := p.sourceInfo.GetMacroCall(expr.ID()); found {
199 return p.exprFactory.NewUnspecifiedExpr(expr.ID())
200 }
201
202 switch expr.Kind() {
203 case ast.CallKind:
204 // Iterate the AST from `expr` recursively looking for macros. Because we are at most
205 // starting from the top level macro, this recursion is bounded by the size of the AST. This
206 // means that the depth check on the AST during parsing will catch recursion overflows
207 // before we get to here.
208 call := expr.AsCall()
209 macroArgs := make([]ast.Expr, len(call.Args()))
210 for index, arg := range call.Args() {
211 macroArgs[index] = p.buildMacroCallArg(arg)
212 }
213 if !call.IsMemberFunction() {
214 return p.exprFactory.NewCall(expr.ID(), call.FunctionName(), macroArgs...)
215 }
216 macroTarget := p.buildMacroCallArg(call.Target())
217 return p.exprFactory.NewMemberCall(expr.ID(), call.FunctionName(), macroTarget, macroArgs...)
218 case ast.ListKind:
219 list := expr.AsList()
220 macroListArgs := make([]ast.Expr, list.Size())
221 for i, elem := range list.Elements() {
222 macroListArgs[i] = p.buildMacroCallArg(elem)
223 }
224 return p.exprFactory.NewList(expr.ID(), macroListArgs, list.OptionalIndices())
225 }
226 return expr
227}
228
229// addMacroCall adds the macro the the MacroCalls map in source info. If a macro has args/subargs/target
230// 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