VisitExpr computes the height of a given node as the max height of its children plus one. Identifiers and literals are treated as having a height of zero.
(e Expr)
| 598 | // |
| 599 | // Identifiers and literals are treated as having a height of zero. |
| 600 | func (hv heightVisitor) VisitExpr(e Expr) { |
| 601 | // default includes IdentKind, LiteralKind |
| 602 | hv[e.ID()] = 0 |
| 603 | switch e.Kind() { |
| 604 | case SelectKind: |
| 605 | hv[e.ID()] = 1 + hv[e.AsSelect().Operand().ID()] |
| 606 | case CallKind: |
| 607 | c := e.AsCall() |
| 608 | height := hv.maxHeight(c.Args()...) |
| 609 | if c.IsMemberFunction() { |
| 610 | tHeight := hv[c.Target().ID()] |
| 611 | if tHeight > height { |
| 612 | height = tHeight |
| 613 | } |
| 614 | } |
| 615 | hv[e.ID()] = 1 + height |
| 616 | case ListKind: |
| 617 | l := e.AsList() |
| 618 | hv[e.ID()] = 1 + hv.maxHeight(l.Elements()...) |
| 619 | case MapKind: |
| 620 | m := e.AsMap() |
| 621 | hv[e.ID()] = 1 + hv.maxEntryHeight(m.Entries()...) |
| 622 | case StructKind: |
| 623 | s := e.AsStruct() |
| 624 | hv[e.ID()] = 1 + hv.maxEntryHeight(s.Fields()...) |
| 625 | case ComprehensionKind: |
| 626 | comp := e.AsComprehension() |
| 627 | hv[e.ID()] = 1 + hv.maxHeight(comp.IterRange(), comp.AccuInit(), comp.LoopCondition(), comp.LoopStep(), comp.Result()) |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | // VisitEntryExpr computes the max height of a map or struct entry and associates the height with the entry id. |
| 632 | func (hv heightVisitor) VisitEntryExpr(e EntryExpr) { |
nothing calls this directly
no test coverage detected