MCPcopy Index your code
hub / github.com/expr-lang/expr / Visit

Method Visit

optimizer/in_range.go:11–43  ·  view source on GitHub ↗
(node *Node)

Source from the content-addressed store, hash-verified

9type inRange struct{}
10
11func (*inRange) Visit(node *Node) {
12 switch n := (*node).(type) {
13 case *BinaryNode:
14 if n.Operator == "in" {
15 t := n.Left.Type()
16 if t == nil {
17 return
18 }
19 if t.Kind() != reflect.Int {
20 return
21 }
22 if rangeOp, ok := n.Right.(*BinaryNode); ok && rangeOp.Operator == ".." {
23 if from, ok := rangeOp.Left.(*IntegerNode); ok {
24 if to, ok := rangeOp.Right.(*IntegerNode); ok {
25 patchCopyType(node, &BinaryNode{
26 Operator: "and",
27 Left: &BinaryNode{
28 Operator: ">=",
29 Left: n.Left,
30 Right: from,
31 },
32 Right: &BinaryNode{
33 Operator: "<=",
34 Left: n.Left,
35 Right: to,
36 },
37 })
38 }
39 }
40 }
41 }
42 }
43}

Callers

nothing calls this directly

Calls 2

patchCopyTypeFunction · 0.85
TypeMethod · 0.65

Tested by

no test coverage detected