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

Function cleanupMacroRefs

cel/optimizer.go:179–208  ·  view source on GitHub ↗
(expr ast.Expr, info *ast.SourceInfo)

Source from the content-addressed store, hash-verified

177}
178
179func cleanupMacroRefs(expr ast.Expr, info *ast.SourceInfo) {
180 if len(info.MacroCalls()) == 0 {
181 return
182 }
183
184 // Sanitize the macro call references once the optimized expression has been computed
185 // and the ids normalized between the expression and the macros.
186 exprRefMap := make(map[int64]struct{})
187 ast.PostOrderVisit(expr, ast.NewExprVisitor(func(e ast.Expr) {
188 if e.ID() == 0 {
189 return
190 }
191 exprRefMap[e.ID()] = struct{}{}
192 }))
193 // Update the macro call id references to ensure that macro pointers are
194 // updated consistently across macros.
195 for _, call := range info.MacroCalls() {
196 ast.PostOrderVisit(call, ast.NewExprVisitor(func(e ast.Expr) {
197 if e.ID() == 0 {
198 return
199 }
200 exprRefMap[e.ID()] = struct{}{}
201 }))
202 }
203 for id := range info.MacroCalls() {
204 if _, found := exprRefMap[id]; !found {
205 info.ClearMacroCall(id)
206 }
207 }
208}
209
210// newIDGenerator ensures that new ids are only created the first time they are encountered.
211func newIDGenerator(seed int64) *idGenerator {

Callers 1

OptimizeMethod · 0.85

Calls 5

PostOrderVisitFunction · 0.92
NewExprVisitorFunction · 0.92
IDMethod · 0.65
MacroCallsMethod · 0.45
ClearMacroCallMethod · 0.45

Tested by

no test coverage detected