Author: Elliot Levin (elliot@aanet.com.au)
Inheritance: use trait Storm\Core\Helpers\Type
Esempio n. 1
0
 public function MapBinaryOperationExpression(CoreExpression $LeftOperandExpression, $BinaryOperator, CoreExpression $RightOperandExpression)
 {
     if ($LeftOperandExpression instanceof E\BinaryOperationExpression) {
         $NestedOperand = $LeftOperandExpression->GetLeftOperandExpression();
         if ($NestedOperand instanceof E\FunctionCallExpression && $NestedOperand->GetName() === 'LOCATE') {
             if ($RightOperandExpression instanceof EE\ConstantExpression && $RightOperandExpression->GetValue() === false) {
                 $RightOperandExpression = Expression::Constant(-1);
             }
         }
     }
     switch ($BinaryOperator) {
         case O\Binary::Concatenation:
             return new E\FunctionCallExpression('CONCAT', Expression::ValueList([$LeftOperandExpression, $RightOperandExpression]));
         case O\Binary::Power:
             return new E\FunctionCallExpression('POW', Expression::ValueList([$LeftOperandExpression, $RightOperandExpression]));
         case O\Binary::NullSafeInequality:
             return Expression::UnaryOperation(O\Unary::Not, Expression::BinaryOperation($LeftOperandExpression, O\Binary::NullSafeEquality, $RightOperandExpression));
         default:
             return new E\BinaryOperationExpression($LeftOperandExpression, $BinaryOperator, $RightOperandExpression);
     }
 }
Esempio n. 2
0
 protected final function IsExpressionConstant(CoreExpression $Expression)
 {
     switch (true) {
         case $Expression instanceof ConstantExpression:
             return true;
         case $Expression instanceof ColumnExpression:
             return false;
         case $Expression instanceof UnaryOperationExpression:
             return $this->IsExpressionConstant($Expression->GetOperandExpression());
         case $Expression instanceof BinaryOperationExpression:
             return $this->IsExpressionConstant($Expression->GetLeftOperandExpression()) && $this->IsExpressionConstant($Expression->GetRightOperandExpression());
         case $Expression instanceof CompoundBooleanExpression:
             return $this->AreExpressionsConstant($Expression->GetBooleanExpressions());
         case $Expression instanceof FunctionCallExpression:
             return $this->AreExpressionsConstant($Expression->GetArgumentValueListExpression()->GetValueExpressions());
         default:
             return false;
     }
 }