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

Method VisitExpr

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

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