Exemplo n.º 1
0
        /// <inheritdoc />
        public override void VisitStringValue(StringValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                result = ModuloOperation.Modulo(flow,
                                                TypeConversion.ToNativeInteger(Snapshot, leftOperand), value.Value);
                break;

            default:
                result = Comparison.LeftAlwaysGreater(OutSet, operation);
                if (result != null)
                {
                    break;
                }

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

                result = BitwiseOperation.Bitwise(OutSet, operation,
                                                  TypeConversion.ToNativeInteger(Snapshot, leftOperand), value.Value);
                if (result == null)
                {
                    base.VisitStringValue(value);
                }

                break;
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public override void VisitStringValue(StringValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

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

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

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

                base.VisitStringValue(value);
                break;
            }
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public override void VisitAnyResourceValue(AnyResourceValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

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

            case Operations.Mod:
                result = ModuloOperation.AbstractModulo(flow);
                break;

            default:
                result = BitwiseOperation.Bitwise(OutSet, operation);
                if (result != null)
                {
                    // Bitwise operation with resource can give any integer
                    break;
                }

                base.VisitAnyResourceValue(value);
                break;
            }
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public override void VisitBooleanValue(BooleanValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                // Ommitted warning message that object cannot be converted to integer
                result = ModuloOperation.ModuloByBooleanValue(flow, value.Value);
                break;

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

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

                base.VisitBooleanValue(value);
                break;
            }
        }
Exemplo n.º 6
0
        /// <inheritdoc />
        public override void VisitStringValue(StringValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                result = ModuloOperation.AbstractModulo(flow, value.Value);
                break;

            default:
                result = Comparison.LeftAlwaysGreater(OutSet, operation);
                if (result != null)
                {
                    break;
                }

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

                base.VisitStringValue(value);
                break;
            }
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        public override void VisitAnyValue(AnyValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
            case Operations.NotIdentical:
                result = OutSet.AnyBooleanValue;
                break;

            case Operations.Mod:
                // Ommitted warning message that object cannot be converted to integer
                result = ModuloOperation.AbstractModulo(flow);
                break;

            default:
                result = ArithmeticOperation.AbstractFloatArithmetic(Snapshot, operation);
                if (result != null)
                {
                    // Ommitted warning message that object cannot be converted to integer
                    // Ommitted error report that array is unsupported operand in arithmetic operation
                    break;
                }

                result = BitwiseOperation.Bitwise(OutSet, operation);
                if (result != null)
                {
                    // Ommitted warning message that object cannot be converted to integer
                    break;
                }

                base.VisitAnyValue(value);
                break;
            }
        }
Exemplo n.º 8
0
        /// <inheritdoc />
        public override void VisitAnyBooleanValue(AnyBooleanValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

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

            case Operations.Mod:
                result = ModuloOperation.ModuloByAnyBooleanValue(flow);
                break;

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

                base.VisitAnyBooleanValue(value);
                break;
            }
        }
Exemplo n.º 9
0
        /// <inheritdoc />
        public override void VisitAnyStringValue(AnyStringValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

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

            case Operations.Mod:
                result = ModuloOperation.AbstractModulo(flow);
                break;

            default:
                result = Comparison.AbstractCompare(OutSet, operation);
                if (result != null)
                {
                    break;
                }

                result = ArithmeticOperation.AbstractFloatArithmetic(Snapshot, operation);
                if (result != null)
                {
                    // A string can be converted into floating point number too.
                    break;
                }

                base.VisitAnyStringValue(value);
                break;
            }
        }
Exemplo n.º 10
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;
            }
        }
Exemplo n.º 11
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;
            }
        }
Exemplo n.º 12
0
        /// <inheritdoc />
        public override void VisitIntervalFloatValue(FloatIntervalValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                result = ModuloOperation.AbstractModulo(flow, value);
                break;

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

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

                base.VisitIntervalFloatValue(value);
                break;
            }
        }
Exemplo n.º 13
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.LeftAbstractBooleanModulo(flow, value.Value);
                break;

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

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

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

                base.VisitFloatValue(value);
                break;
            }
        }
Exemplo n.º 14
0
        /// <inheritdoc />
        public override void VisitBooleanValue(BooleanValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                result = ModuloOperation.ModuloByBooleanValue(flow, value.Value);
                break;

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

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

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

                base.VisitBooleanValue(value);
                break;
            }
        }
Exemplo n.º 15
0
        /// <inheritdoc />
        public override void VisitAnyStringValue(AnyStringValue value)
        {
            switch (operation)
            {
            case Operations.Equal:
            case Operations.NotEqual:
            case Operations.GreaterThanOrEqual:
            case Operations.LessThan:
            case Operations.Or:
            case Operations.Xor:
                result = OutSet.AnyBooleanValue;
                break;

            case Operations.Mod:
                result = ModuloOperation.AbstractModulo(flow);
                break;

            case Operations.BitOr:
            case Operations.BitXor:
                result = OutSet.AnyIntegerValue;
                break;

            default:
                result = ArithmeticOperation.AbstractFloatArithmetic(Snapshot, operation);
                if (result != null)
                {
                    break;
                }

                base.VisitAnyStringValue(value);
                break;
            }
        }
Exemplo n.º 16
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;

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

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

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

                base.VisitBooleanValue(value);
                break;
            }
        }
Exemplo n.º 17
0
        /// <inheritdoc />
        public override void VisitBooleanValue(BooleanValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                result = ModuloOperation.ModuloByBooleanValue(flow, value.Value);
                break;

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

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

                base.VisitBooleanValue(value);
                break;
            }
        }
Exemplo n.º 18
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.AbstractModulo(flow, value);
                break;

            default:
                result = ArithmeticOperation.LeftAbstractArithmetic(flow, operation, value);
                if (result != null)
                {
                    break;
                }

                base.VisitIntervalFloatValue(value);
                break;
            }
        }
Exemplo n.º 19
0
        /// <inheritdoc />
        public override void VisitUndefinedValue(UndefinedValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
            case Operations.And:
                result = OutSet.CreateBool(false);
                break;

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

            case Operations.BitAnd:
                result = OutSet.CreateInt(0);
                break;

            case Operations.Div:
                result = ArithmeticOperation.DivisionByNull(flow);
                break;

            case Operations.Mod:
                result = ModuloOperation.ModuloByNull(flow);
                break;

            default:
                base.VisitUndefinedValue(value);
                break;
            }
        }
Exemplo n.º 20
0
        /// <inheritdoc />
        public override void VisitIntervalFloatValue(FloatIntervalValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                SetWarning("Object cannot be converted to integer by modulo operation",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                result = ModuloOperation.AbstractModulo(flow, value);
                break;

            default:
                result = ArithmeticOperation.LeftAbstractArithmetic(flow, operation, value);
                if (result != null)
                {
                    break;
                }

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

                base.VisitIntervalFloatValue(value);
                break;
            }
        }
Exemplo n.º 21
0
        /// <inheritdoc />
        public override void VisitAnyArrayValue(AnyArrayValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                result = ModuloOperation.AbstractModulo(flow);
                break;

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

                if (ArithmeticOperation.IsArithmetic(operation))
                {
                    // TODO: This must be fatal error
                    SetWarning("Unsupported operand type: Arithmetic of array and scalar type");
                    result = OutSet.AnyValue;
                    break;
                }

                base.VisitAnyArrayValue(value);
                break;
            }
        }
Exemplo n.º 22
0
        /// <inheritdoc />
        public override void VisitAnyBooleanValue(AnyBooleanValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                SetWarning("Object cannot be converted to integer by modulo operation",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                result = ModuloOperation.ModuloByAnyBooleanValue(flow);
                break;

            default:
                result = Comparison.RightAbstractBooleanCompare(OutSet, operation,
                                                                TypeConversion.ToBoolean(leftOperand));
                if (result != null)
                {
                    break;
                }

                result = ArithmeticOperation.RightAbstractBooleanArithmetic(flow, operation);
                if (result != null)
                {
                    SetWarning("Object cannot be converted to integer by arithmetic operation",
                               AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                    break;
                }

                base.VisitAnyBooleanValue(value);
                break;
            }
        }
Exemplo n.º 23
0
        /// <inheritdoc />
        public override void VisitStringValue(StringValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                // Ommitted warning message that object cannot be converted to integer
                result = ModuloOperation.AbstractModulo(flow, value.Value);
                break;

            default:
                result = Comparison.AbstractCompare(OutSet, operation);
                if (result != null)
                {
                    // Ommitted warning message that object cannot be converted to integer
                    break;
                }

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

                base.VisitStringValue(value);
                break;
            }
        }
Exemplo n.º 24
0
        /// <inheritdoc />
        public override void VisitAnyStringValue(AnyStringValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                SetWarning("Object cannot be converted to integer by modulo operation",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                result = ModuloOperation.AbstractModulo(flow);
                break;

            default:
                if (Comparison.IsOperationComparison(operation))
                {
                    // TODO: The comparison of string with object depends upon whether the object has
                    // the "__toString" magic method implemented. If so, the string comparison is
                    // performed. Otherwise, the object is always greater than string.
                    result = OutSet.AnyBooleanValue;
                    break;
                }

                result = ArithmeticOperation.AbstractFloatArithmetic(Snapshot, operation);
                if (result != null)
                {
                    // A string can be converted into floating point number too.
                    break;
                }

                base.VisitAnyStringValue(value);
                break;
            }
        }
Exemplo n.º 25
0
        /// <inheritdoc />
        public override void VisitAssociativeArray(AssociativeArray value)
        {
            switch (operation)
            {
            case Operations.Mod:
                result = ModuloOperation.Modulo(flow, leftOperand.Value,
                                                TypeConversion.ToNativeInteger(Snapshot, value));
                break;

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

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

                base.VisitAssociativeArray(value);
                break;
            }
        }
Exemplo n.º 26
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;
            }
        }
Exemplo n.º 27
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;
            }
        }
Exemplo n.º 28
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;
            }
        }
Exemplo n.º 29
0
        /// <inheritdoc />
        public override void VisitAssociativeArray(AssociativeArray value)
        {
            switch (operation)
            {
            case Operations.Mod:
                result = ModuloOperation.AbstractModulo(flow,
                                                        TypeConversion.ToNativeInteger(Snapshot, value));
                break;

            default:
                result = Comparison.RightAlwaysGreater(OutSet, operation);
                if (result != null)
                {
                    break;
                }

                result = LogicalOperation.AbstractLogical(OutSet, operation,
                                                          TypeConversion.ToNativeBoolean(Snapshot, value));
                if (result != null)
                {
                    break;
                }

                base.VisitAssociativeArray(value);
                break;
            }
        }
Exemplo n.º 30
0
        /// <inheritdoc />
        public override void VisitBooleanValue(BooleanValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                result = ModuloOperation.ModuloByBooleanValue(flow, value.Value);
                break;

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

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

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

                base.VisitBooleanValue(value);
                break;
            }
        }