mirror of https://github.com/miguelmota/cointop
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
867 B
Go
42 lines
867 B
Go
package optimizer
|
|
|
|
import (
|
|
. "github.com/antonmedv/expr/ast"
|
|
)
|
|
|
|
type inRange struct{}
|
|
|
|
func (*inRange) Enter(*Node) {}
|
|
func (*inRange) Exit(node *Node) {
|
|
switch n := (*node).(type) {
|
|
case *BinaryNode:
|
|
if n.Operator == "in" || n.Operator == "not in" {
|
|
if rng, ok := n.Right.(*BinaryNode); ok && rng.Operator == ".." {
|
|
if from, ok := rng.Left.(*IntegerNode); ok {
|
|
if to, ok := rng.Right.(*IntegerNode); ok {
|
|
Patch(node, &BinaryNode{
|
|
Operator: "and",
|
|
Left: &BinaryNode{
|
|
Operator: ">=",
|
|
Left: n.Left,
|
|
Right: from,
|
|
},
|
|
Right: &BinaryNode{
|
|
Operator: "<=",
|
|
Left: n.Left,
|
|
Right: to,
|
|
},
|
|
})
|
|
if n.Operator == "not in" {
|
|
Patch(node, &UnaryNode{
|
|
Operator: "not",
|
|
Node: *node,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|