TODO: consider exposing a way to configure a limit for the max visit depth. It's possible that we could want to configure this on the NewExprVisitor() and through MatchDescendents() / MaxID().
(expr Expr, visitor Visitor, order visitOrder, depth, maxDepth int)
| 192 | // It's possible that we could want to configure this on the NewExprVisitor() |
| 193 | // and through MatchDescendents() / MaxID(). |
| 194 | func visit(expr Expr, visitor Visitor, order visitOrder, depth, maxDepth int) { |
| 195 | if maxDepth > 0 && depth == maxDepth { |
| 196 | return |
| 197 | } |
| 198 | if order == preOrder { |
| 199 | visitor.VisitExpr(expr) |
| 200 | } |
| 201 | switch expr.Kind() { |
| 202 | case CallKind: |
| 203 | c := expr.AsCall() |
| 204 | if c.IsMemberFunction() { |
| 205 | visit(c.Target(), visitor, order, depth+1, maxDepth) |
| 206 | } |
| 207 | for _, arg := range c.Args() { |
| 208 | visit(arg, visitor, order, depth+1, maxDepth) |
| 209 | } |
| 210 | case ComprehensionKind: |
| 211 | c := expr.AsComprehension() |
| 212 | visit(c.IterRange(), visitor, order, depth+1, maxDepth) |
| 213 | visit(c.AccuInit(), visitor, order, depth+1, maxDepth) |
| 214 | visit(c.LoopCondition(), visitor, order, depth+1, maxDepth) |
| 215 | visit(c.LoopStep(), visitor, order, depth+1, maxDepth) |
| 216 | visit(c.Result(), visitor, order, depth+1, maxDepth) |
| 217 | case ListKind: |
| 218 | l := expr.AsList() |
| 219 | for _, elem := range l.Elements() { |
| 220 | visit(elem, visitor, order, depth+1, maxDepth) |
| 221 | } |
| 222 | case MapKind: |
| 223 | m := expr.AsMap() |
| 224 | for _, e := range m.Entries() { |
| 225 | if order == preOrder { |
| 226 | visitor.VisitEntryExpr(e) |
| 227 | } |
| 228 | entry := e.AsMapEntry() |
| 229 | visit(entry.Key(), visitor, order, depth+1, maxDepth) |
| 230 | visit(entry.Value(), visitor, order, depth+1, maxDepth) |
| 231 | if order == postOrder { |
| 232 | visitor.VisitEntryExpr(e) |
| 233 | } |
| 234 | } |
| 235 | case SelectKind: |
| 236 | visit(expr.AsSelect().Operand(), visitor, order, depth+1, maxDepth) |
| 237 | case StructKind: |
| 238 | s := expr.AsStruct() |
| 239 | for _, f := range s.Fields() { |
| 240 | if order == preOrder { |
| 241 | visitor.VisitEntryExpr(f) |
| 242 | } |
| 243 | visit(f.AsStructField().Value(), visitor, order, depth+1, maxDepth) |
| 244 | if order == postOrder { |
| 245 | visitor.VisitEntryExpr(f) |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | if order == postOrder { |
| 250 | visitor.VisitExpr(expr) |
| 251 | } |
no test coverage detected