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

Method inlineExpr

cel/inlining.go:136–148  ·  view source on GitHub ↗

inlineExpr replaces the current expression with the inlined one, unless the location of the inlining happens within a presence test, e.g. has(a.b.c) -> inline alpha for a.b.c in which case an attempt is made to determine whether the inlined value can be presence or existence tested.

(ctx *OptimizerContext, prev ast.NavigableExpr, inlined ast.Expr, inlinedType *Type)

Source from the content-addressed store, hash-verified

134// happens within a presence test, e.g. has(a.b.c) -> inline alpha for a.b.c in which case an attempt is
135// made to determine whether the inlined value can be presence or existence tested.
136func (opt *inliningOptimizer) inlineExpr(ctx *OptimizerContext, prev ast.NavigableExpr, inlined ast.Expr, inlinedType *Type) {
137 switch prev.Kind() {
138 case ast.SelectKind:
139 sel := prev.AsSelect()
140 if !sel.IsTestOnly() {
141 ctx.UpdateExpr(prev, inlined)
142 return
143 }
144 opt.rewritePresenceExpr(ctx, prev, inlined, inlinedType)
145 default:
146 ctx.UpdateExpr(prev, inlined)
147 }
148}
149
150// rewritePresenceExpr converts the inlined expression, when it occurs within a has() macro, to type-safe
151// expression appropriate for the inlined type, if possible.

Callers 1

OptimizeMethod · 0.95

Calls 5

rewritePresenceExprMethod · 0.95
UpdateExprMethod · 0.80
KindMethod · 0.65
AsSelectMethod · 0.65
IsTestOnlyMethod · 0.65

Tested by

no test coverage detected