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