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

Method VisitExpr

common/ast/ast.go:600–629  ·  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

598//
599// Identifiers and literals are treated as having a height of zero.
600func (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.
632func (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