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

Function cleanupMacroRefs

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

Source from the content-addressed store, hash-verified

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