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

Method VisitExpr

common/ast/ast.go:608–637  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

606//
607// Identifiers and literals are treated as having a height of zero.
608func (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.
640func (hv heightVisitor) VisitEntryExpr(e EntryExpr) {

Callers

nothing calls this directly

Calls 15

maxHeightMethod · 0.95
maxEntryHeightMethod · 0.95
IDMethod · 0.65
KindMethod · 0.65
OperandMethod · 0.65
AsSelectMethod · 0.65
AsCallMethod · 0.65
ArgsMethod · 0.65
IsMemberFunctionMethod · 0.65
TargetMethod · 0.65
AsListMethod · 0.65
ElementsMethod · 0.65

Tested by

no test coverage detected