Exemple #1
0
        /// <inheritdoc />
        public override void VisitIntervalFloatValue(FloatIntervalValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                result = ModuloOperation.Modulo(flow,
                                                TypeConversion.ToInteger(leftOperand.Value), value);
                break;

            default:
                var leftFloat = TypeConversion.ToFloat(leftOperand.Value);
                result = Comparison.IntervalCompare(OutSet, operation, leftFloat, value);
                if (result != null)
                {
                    break;
                }

                result = ArithmeticOperation.Arithmetic(flow, operation, leftFloat, value);
                if (result != null)
                {
                    break;
                }

                result = LogicalOperation.Logical(OutSet, operation, leftOperand.Value, value);
                if (result != null)
                {
                    break;
                }

                base.VisitIntervalFloatValue(value);
                break;
            }
        }
Exemple #2
0
        /// <inheritdoc />
        public override void VisitIntervalFloatValue(FloatIntervalValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            case Operations.Mod:
                result = ModuloOperation.Modulo(flow, leftOperand, value);
                break;

            default:
                var floatInterval = TypeConversion.ToFloatInterval(OutSet, leftOperand);
                result = Comparison.IntervalCompare(OutSet, operation, floatInterval, value);
                if (result != null)
                {
                    break;
                }

                result = ArithmeticOperation.Arithmetic(flow, operation, leftOperand, value);
                if (result != null)
                {
                    break;
                }

                base.VisitIntervalFloatValue(value);
                break;
            }
        }
Exemple #3
0
        /// <inheritdoc />
        public override void VisitIntervalFloatValue(FloatIntervalValue value)
        {
            // When comparing, both operands are converted to boolean
            switch (operation)
            {
            case Operations.BitOr:
            case Operations.BitXor:
                IntervalValue <int> integerInterval;
                if (TypeConversion.TryConvertToIntegerInterval(OutSet, value, out integerInterval))
                {
                    result = integerInterval;
                }
                else
                {
                    result = OutSet.AnyIntegerValue;
                }
                break;

            case Operations.Mod:
                result = ModuloOperation.Modulo(flow, TypeConversion.ToInteger(leftOperand), value);
                break;

            default:
                result = ArithmeticOperation.Arithmetic(flow, operation,
                                                        TypeConversion.ToFloat(leftOperand), value);
                if (result != null)
                {
                    break;
                }

                base.VisitIntervalFloatValue(value);
                break;
            }
        }
Exemple #4
0
        /// <inheritdoc />
        public override void VisitBooleanValue(BooleanValue value)
        {
            var leftBoolean = TypeConversion.ToBoolean(leftOperand.Value);

            result = Comparison.Compare(OutSet, operation, leftBoolean, value.Value);
            if (result != null)
            {
                return;
            }

            var rightInteger = TypeConversion.ToInteger(value.Value);

            result = ArithmeticOperation.Arithmetic(flow, operation,
                                                    leftOperand.Value, rightInteger);
            if (result != null)
            {
                return;
            }

            result = LogicalOperation.Logical(OutSet, operation, leftBoolean, value.Value);
            if (result != null)
            {
                return;
            }

            result = BitwiseOperation.Bitwise(OutSet, operation, leftOperand.Value, rightInteger);
            if (result != null)
            {
                return;
            }

            base.VisitBooleanValue(value);
        }
Exemple #5
0
        /// <inheritdoc />
        public override void VisitStringValue(StringValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                result = ModuloOperation.Modulo(flow, leftOperand, value.Value);
                break;

            default:
                int    integerValue;
                double floatValue;
                bool   isInteger;
                TypeConversion.TryConvertToNumber(value.Value, true,
                                                  out integerValue, out floatValue, out isInteger);

                result = Comparison.IntervalCompare(OutSet, operation, leftOperand, floatValue);
                if (result != null)
                {
                    break;
                }

                result = ArithmeticOperation.Arithmetic(flow, operation, leftOperand, floatValue);
                if (result != null)
                {
                    break;
                }

                base.VisitStringValue(value);
                break;
            }
        }
Exemple #6
0
        /// <inheritdoc />
        public override void VisitIntervalIntegerValue(IntegerIntervalValue value)
        {
            // When comparing, both operands are converted to boolean
            switch (operation)
            {
            case Operations.BitOr:
            case Operations.BitXor:
                result = value;
                break;

            case Operations.Mod:
                result = ModuloOperation.Modulo(flow, TypeConversion.ToInteger(leftOperand), value);
                break;

            default:
                result = ArithmeticOperation.Arithmetic(flow, operation,
                                                        TypeConversion.ToInteger(leftOperand), value);
                if (result != null)
                {
                    break;
                }

                base.VisitIntervalIntegerValue(value);
                break;
            }
        }
Exemple #7
0
        /// <inheritdoc />
        public override void VisitIntegerValue(IntegerValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = Comparison.Equal(OutSet, leftOperand, value.Value);
                break;

            case Operations.NotIdentical:
                result = Comparison.NotEqual(OutSet, leftOperand, value.Value);
                break;

            case Operations.Mod:
                result = ModuloOperation.Modulo(flow, leftOperand, value.Value);
                break;

            default:
                result = Comparison.IntervalCompare(OutSet, operation, leftOperand, value.Value);
                if (result != null)
                {
                    break;
                }

                result = ArithmeticOperation.Arithmetic(flow, operation, leftOperand, value.Value);
                if (result != null)
                {
                    break;
                }

                base.VisitIntegerValue(value);
                break;
            }
        }
Exemple #8
0
        /// <inheritdoc />
        public override void VisitIntervalIntegerValue(IntegerIntervalValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                result = ModuloOperation.Modulo(flow, leftOperand.Value, value);
                break;

            default:
                result = LogicalOperation.Logical(OutSet, operation,
                                                  TypeConversion.ToBoolean(leftOperand.Value), value);
                if (result != null)
                {
                    break;
                }

                int    integerValue;
                double floatValue;
                bool   isInteger;
                TypeConversion.TryConvertToNumber(leftOperand.Value, true,
                                                  out integerValue, out floatValue, out isInteger);

                if (isInteger)
                {
                    result = Comparison.IntervalCompare(OutSet, operation, integerValue, value);
                    if (result != null)
                    {
                        break;
                    }

                    result = ArithmeticOperation.Arithmetic(flow, operation, integerValue, value);
                    if (result != null)
                    {
                        break;
                    }
                }
                else
                {
                    var floatInterval = TypeConversion.ToFloatInterval(OutSet, value);
                    result = Comparison.IntervalCompare(OutSet, operation, floatValue, floatInterval);
                    if (result != null)
                    {
                        break;
                    }

                    result = ArithmeticOperation.Arithmetic(flow, operation, floatValue, floatInterval);
                    if (result != null)
                    {
                        break;
                    }
                }

                base.VisitIntervalIntegerValue(value);
                break;
            }
        }
Exemple #9
0
        /// <inheritdoc />
        public override void VisitBooleanValue(BooleanValue value)
        {
            result = ArithmeticOperation.Arithmetic(flow, operation, leftOperand,
                                                    TypeConversion.ToInteger(value.Value));
            if (result != null)
            {
                return;
            }

            base.VisitBooleanValue(value);
        }
Exemple #10
0
        /// <inheritdoc />
        public override void VisitFloatValue(FloatValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                SetWarning("Comparing floating-point numbers directly for equality");
                result = OutSet.CreateBool(leftOperand.Value == value.Value);
                break;

            case Operations.NotIdentical:
                SetWarning("Comparing floating-point numbers directly for non-equality");
                result = OutSet.CreateBool(leftOperand.Value != value.Value);
                break;

            case Operations.Mod:
                result = ModuloOperation.Modulo(flow, leftOperand.Value, value.Value);
                break;

            default:
                result = Comparison.Compare(OutSet, operation, leftOperand.Value, value.Value);
                if (result != null)
                {
                    break;
                }

                result = ArithmeticOperation.Arithmetic(flow, operation, leftOperand.Value, value.Value);
                if (result != null)
                {
                    break;
                }

                result = BitwiseOperation.Bitwise(OutSet, operation, leftOperand.Value, value.Value);
                if (result != null)
                {
                    break;
                }

                result = LogicalOperation.Logical(OutSet, operation,
                                                  TypeConversion.ToBoolean(leftOperand.Value), TypeConversion.ToBoolean(value.Value));
                if (result != null)
                {
                    break;
                }

                base.VisitFloatValue(value);
                break;
            }
        }
Exemple #11
0
        /// <inheritdoc />
        public override void VisitStringValue(StringValue value)
        {
            switch (operation)
            {
            case Operations.Or:
            case Operations.Xor:
                result = TypeConversion.ToBoolean(OutSet, value);
                break;

            case Operations.Mod:
                result = ModuloOperation.Modulo(flow,
                                                TypeConversion.ToInteger(leftOperand), value.Value);
                break;

            case Operations.BitOr:
            case Operations.BitXor:
                result = TypeConversion.ToInteger(OutSet, value);
                break;

            default:
                result = Comparison.Compare(OutSet, operation, string.Empty, value.Value);
                if (result != null)
                {
                    break;
                }

                int    integerValue;
                double floatValue;
                bool   isInteger;
                TypeConversion.TryConvertToNumber(value.Value, true, out integerValue,
                                                  out floatValue, out isInteger);

                var leftInteger = TypeConversion.ToInteger(leftOperand);
                result = isInteger
                        ? ArithmeticOperation.Arithmetic(flow, operation, leftInteger, integerValue)
                        : ArithmeticOperation.Arithmetic(flow, operation, leftInteger, floatValue);

                if (result != null)
                {
                    break;
                }

                base.VisitStringValue(value);
                break;
            }
        }
Exemple #12
0
        /// <inheritdoc />
        public override void VisitIntegerValue(IntegerValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(leftOperand.Value == value.Value);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(leftOperand.Value != value.Value);
                break;

            case Operations.Mod:
                result = ModuloOperation.Modulo(flow, leftOperand.Value, value.Value);
                break;

            default:
                result = Comparison.Compare(OutSet, operation, leftOperand.Value, value.Value);
                if (result != null)
                {
                    break;
                }

                result = ArithmeticOperation.Arithmetic(flow, operation, leftOperand.Value, value.Value);
                if (result != null)
                {
                    break;
                }

                result = BitwiseOperation.Bitwise(OutSet, operation, leftOperand.Value, value.Value);
                if (result != null)
                {
                    break;
                }

                result = LogicalOperation.Logical(OutSet, operation,
                                                  TypeConversion.ToBoolean(leftOperand.Value), TypeConversion.ToBoolean(value.Value));
                if (result != null)
                {
                    break;
                }

                base.VisitIntegerValue(value);
                break;
            }
        }
Exemple #13
0
        /// <inheritdoc />
        public override void VisitBooleanValue(BooleanValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(leftOperand.Value == value.Value);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(leftOperand.Value != value.Value);
                break;

            default:
                result = Comparison.Compare(OutSet, operation, leftOperand.Value, value.Value);
                if (result != null)
                {
                    break;
                }

                result = LogicalOperation.Logical(OutSet, operation, leftOperand.Value, value.Value);
                if (result != null)
                {
                    break;
                }

                var leftInteger  = TypeConversion.ToInteger(leftOperand.Value);
                var rightInteger = TypeConversion.ToInteger(value.Value);
                result = ArithmeticOperation.Arithmetic(flow, operation, leftInteger, rightInteger);
                if (result != null)
                {
                    break;
                }

                result = BitwiseOperation.Bitwise(OutSet, operation, leftInteger, rightInteger);
                if (result != null)
                {
                    break;
                }

                base.VisitBooleanValue(value);
                break;
            }
        }
Exemple #14
0
        /// <inheritdoc />
        public override void VisitFloatValue(FloatValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                // When dividend is true and divisor != +-1, result is 1, otherwise 0
                result = ModuloOperation.Modulo(flow,
                                                TypeConversion.ToInteger(leftOperand.Value), value.Value);
                break;

            default:
                var rightBoolean = TypeConversion.ToBoolean(value.Value);
                result = Comparison.Compare(OutSet, operation, leftOperand.Value, rightBoolean);
                if (result != null)
                {
                    break;
                }

                var leftInteger = TypeConversion.ToInteger(leftOperand.Value);
                result = ArithmeticOperation.Arithmetic(flow, operation, leftInteger, value.Value);
                if (result != null)
                {
                    break;
                }

                result = LogicalOperation.Logical(OutSet, operation, leftOperand.Value, rightBoolean);
                if (result != null)
                {
                    break;
                }

                result = BitwiseOperation.Bitwise(OutSet, operation, leftInteger, value.Value);
                if (result != null)
                {
                    break;
                }

                base.VisitFloatValue(value);
                break;
            }
        }
Exemple #15
0
        /// <inheritdoc />
        public override void VisitIntervalFloatValue(FloatIntervalValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = Comparison.Equal(OutSet, leftOperand.Value, value);
                break;

            case Operations.NotIdentical:
                result = Comparison.NotEqual(OutSet, leftOperand.Value, value);
                break;

            case Operations.Mod:
                result = ModuloOperation.Modulo(flow, leftOperand.Value, value);
                break;

            default:
                result = Comparison.IntervalCompare(OutSet, operation, leftOperand.Value, value);
                if (result != null)
                {
                    break;
                }

                result = ArithmeticOperation.Arithmetic(flow, operation, leftOperand.Value, value);
                if (result != null)
                {
                    break;
                }

                result = LogicalOperation.Logical(OutSet, operation,
                                                  TypeConversion.ToBoolean(leftOperand.Value), value);
                if (result != null)
                {
                    break;
                }

                base.VisitIntervalFloatValue(value);
                break;
            }
        }
Exemple #16
0
        /// <inheritdoc />
        public override void VisitStringValue(StringValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(string.Equals(leftOperand.Value, value.Value,
                                                         StringComparison.Ordinal));
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(!string.Equals(leftOperand.Value, value.Value,
                                                          StringComparison.Ordinal));
                break;

            case Operations.Mod:
                result = ModuloOperation.Modulo(flow, leftOperand.Value, value.Value);
                break;

            case Operations.BitAnd:
            case Operations.BitOr:
            case Operations.BitXor:
                // Bit operations are defined for every character, not for the entire string
                // TODO: PHP string is stored as array of bytes, but printed in UTF8 encoding
                result = OutSet.AnyStringValue;
                break;

            default:
                result = LogicalOperation.Logical(OutSet, operation,
                                                  TypeConversion.ToBoolean(leftOperand.Value), TypeConversion.ToBoolean(value.Value));
                if (result != null)
                {
                    break;
                }

                int    leftInteger;
                double leftFloat;
                bool   isLeftInteger;
                bool   isLeftHexadecimal;
                var    isLeftSuccessful = TypeConversion.TryConvertToNumber(leftOperand.Value, true,
                                                                            out leftInteger, out leftFloat, out isLeftInteger, out isLeftHexadecimal);

                int    rightInteger;
                double rightFloat;
                bool   isRightInteger;
                bool   isRightHexadecimal;
                var    isRightSuccessful = TypeConversion.TryConvertToNumber(value.Value, true,
                                                                             out rightInteger, out rightFloat, out isRightInteger, out isRightHexadecimal);

                // If both strings are convertible to number, they are conpared as numbers
                result = (isLeftSuccessful && isRightSuccessful)
                        ? ((isLeftInteger && isRightInteger)
                            ? Comparison.Compare(OutSet, operation, leftInteger, rightInteger)
                            : Comparison.Compare(OutSet, operation, leftFloat, rightFloat))
                        : Comparison.Compare(OutSet, operation, leftOperand.Value, value.Value);

                if (result != null)
                {
                    break;
                }

                result = (isLeftInteger && isRightInteger)
                        ? ArithmeticOperation.Arithmetic(flow, operation, leftInteger, rightInteger)
                        : ArithmeticOperation.Arithmetic(flow, operation, leftFloat, rightFloat);

                if (result != null)
                {
                    break;
                }

                // If string has hexadecimal format, the first zero is recognized.
                if (isLeftHexadecimal)
                {
                    leftInteger = 0;
                }

                if (isRightHexadecimal)
                {
                    rightInteger = 0;
                }

                // Only shifting operations can happen
                if ((isLeftInteger || (isLeftSuccessful &&
                                       TypeConversion.TryConvertToInteger(leftFloat, out leftInteger))) &&
                    (isRightInteger || (isRightSuccessful &&
                                        TypeConversion.TryConvertToInteger(rightFloat, out rightInteger))))
                {
                    result = BitwiseOperation.Bitwise(OutSet, operation, leftInteger, rightInteger);
                    if (result != null)
                    {
                        break;
                    }
                }
                else
                {
                    // If at least one operand can not be recognized, result can be any integer value.
                    result = BitwiseOperation.Bitwise(OutSet, operation);
                    if (result != null)
                    {
                        break;
                    }
                }

                base.VisitStringValue(value);
                break;
            }
        }
Exemple #17
0
        /// <inheritdoc />
        public override void VisitBooleanValue(BooleanValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            default:
                var leftBoolean = TypeConversion.ToBoolean(leftOperand.Value);
                result = Comparison.Compare(OutSet, operation, leftBoolean, value.Value);
                if (result != null)
                {
                    break;
                }

                result = LogicalOperation.Logical(OutSet, operation, leftBoolean, value.Value);
                if (result != null)
                {
                    break;
                }

                int    integerValue;
                double floatValue;
                bool   isInteger;
                bool   isHexadecimal;
                var    isSuccessful = TypeConversion.TryConvertToNumber(leftOperand.Value, true,
                                                                        out integerValue, out floatValue, out isInteger, out isHexadecimal);

                var rightInteger = TypeConversion.ToInteger(value.Value);

                result = isInteger
                        ? ArithmeticOperation.Arithmetic(flow, operation, integerValue, rightInteger)
                        : ArithmeticOperation.Arithmetic(flow, operation, floatValue, rightInteger);

                if (result != null)
                {
                    break;
                }

                // If string has hexadecimal format, the first zero is recognized.
                if (isHexadecimal)
                {
                    integerValue = 0;
                }

                if (isInteger || (isSuccessful &&
                                  TypeConversion.TryConvertToInteger(floatValue, out integerValue)))
                {
                    result = BitwiseOperation.Bitwise(OutSet, operation, integerValue, rightInteger);
                    if (result != null)
                    {
                        break;
                    }
                }
                else
                {
                    // If the left operand can not be recognized, result can be any integer value.
                    result = BitwiseOperation.Bitwise(OutSet, operation);
                    if (result != null)
                    {
                        break;
                    }
                }

                base.VisitBooleanValue(value);
                break;
            }
        }
Exemple #18
0
        /// <inheritdoc />
        public override void VisitStringValue(StringValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                result = ModuloOperation.Modulo(flow, leftOperand.Value, value.Value);
                break;

            default:
                result = LogicalOperation.Logical(OutSet, operation,
                                                  TypeConversion.ToBoolean(leftOperand.Value), TypeConversion.ToBoolean(value.Value));
                if (result != null)
                {
                    break;
                }

                int    integerValue;
                double floatValue;
                bool   isInteger;
                bool   isHexadecimal;
                var    isSuccessful = TypeConversion.TryConvertToNumber(value.Value, true,
                                                                        out integerValue, out floatValue, out isInteger, out isHexadecimal);

                if (isInteger)
                {
                    result = Comparison.Compare(OutSet, operation, leftOperand.Value, integerValue);
                    if (result != null)
                    {
                        break;
                    }

                    result = ArithmeticOperation.Arithmetic(flow, operation,
                                                            leftOperand.Value, integerValue);
                    if (result != null)
                    {
                        break;
                    }
                }
                else
                {
                    result = Comparison.Compare(OutSet, operation, leftOperand.Value, floatValue);
                    if (result != null)
                    {
                        break;
                    }

                    result = ArithmeticOperation.Arithmetic(flow, operation,
                                                            leftOperand.Value, floatValue);
                    if (result != null)
                    {
                        break;
                    }
                }

                // If string has hexadecimal format, the first zero is recognized.
                if (isHexadecimal)
                {
                    integerValue = 0;
                }

                if (isInteger || (isSuccessful &&
                                  TypeConversion.TryConvertToInteger(floatValue, out integerValue)))
                {
                    result = BitwiseOperation.Bitwise(OutSet, operation,
                                                      leftOperand.Value, integerValue);
                    if (result != null)
                    {
                        break;
                    }
                }
                else
                {
                    // If the right operand can not be recognized, result can be any integer value.
                    result = BitwiseOperation.Bitwise(OutSet, operation);
                    if (result != null)
                    {
                        break;
                    }
                }

                base.VisitStringValue(value);
                break;
            }
        }