(v *NormalizeVisitor)
| 115 | } |
| 116 | |
| 117 | func (expr *BinaryExpr) normalize(v *NormalizeVisitor) TypedExpr { |
| 118 | left := expr.TypedLeft() |
| 119 | right := expr.TypedRight() |
| 120 | expectedType := expr.ResolvedType() |
| 121 | |
| 122 | if !expr.fn.NullableArgs && (left == DNull || right == DNull) { |
| 123 | return DNull |
| 124 | } |
| 125 | |
| 126 | var final TypedExpr |
| 127 | |
| 128 | switch expr.Operator { |
| 129 | case Plus: |
| 130 | if v.isNumericZero(right) { |
| 131 | final = ReType(left, expectedType) |
| 132 | break |
| 133 | } |
| 134 | if v.isNumericZero(left) { |
| 135 | final = ReType(right, expectedType) |
| 136 | break |
| 137 | } |
| 138 | case Minus: |
| 139 | if types.IsAdditiveType(left.ResolvedType()) && v.isNumericZero(right) { |
| 140 | final = ReType(left, expectedType) |
| 141 | break |
| 142 | } |
| 143 | case Mult: |
| 144 | if v.isNumericOne(right) { |
| 145 | final = ReType(left, expectedType) |
| 146 | break |
| 147 | } |
| 148 | if v.isNumericOne(left) { |
| 149 | final = ReType(right, expectedType) |
| 150 | break |
| 151 | } |
| 152 | // We can't simplify multiplication by zero to zero, |
| 153 | // because if the other operand is NULL during evaluation |
| 154 | // the result must be NULL. |
| 155 | case Div, FloorDiv: |
| 156 | if v.isNumericOne(right) { |
| 157 | final = ReType(left, expectedType) |
| 158 | break |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | if final == nil { |
| 163 | return expr |
| 164 | } |
| 165 | return final |
| 166 | } |
| 167 | |
| 168 | func (expr *AndExpr) normalize(v *NormalizeVisitor) TypedExpr { |
| 169 | left := expr.TypedLeft() |
nothing calls this directly
no test coverage detected