(expr ast.Expr, info *ast.SourceInfo)
| 176 | } |
| 177 | |
| 178 | func 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. |
| 210 | func newIDGenerator(seed int64) *idGenerator { |
no test coverage detected