Esempio n. 1
0
        /// <inheritdoc />
        public override void VisitAnyObjectValue(AnyObjectValue value)
        {
            if (Comparison.IsOperationComparison(operation))
            {
                // 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. Since we cannot
                // determine whether the abstract object has or has not the method,
                // we must return indeterminate boolean value.
                result = OutSet.AnyBooleanValue;
                return;
            }

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

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

            base.VisitAnyObjectValue(value);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public override void VisitAnyObjectValue(AnyObjectValue value)
        {
            var rightBoolean = TypeConversion.ToBoolean(value);

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

            result = ArithmeticOperation.RightAbstractArithmetic(flow, operation,
                                                                 TypeConversion.ToInteger(leftOperand.Value));
            if (result != null)
            {
                SetWarning("Object cannot be converted to integer by arithmetic operation",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                return;
            }

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

            base.VisitAnyObjectValue(value);
        }
Esempio n. 3
0
        /// <inheritdoc />
        protected override Value cloneValue()
        {
            AnyObjectValue value = new AnyObjectValue();

            value.setStorage(getStorage());
            return(value);
        }
Esempio n. 4
0
        /// <inheritdoc />
        public override void VisitAnyObjectValue(AnyObjectValue value)
        {
            switch (operation)
            {
            case Operations.Plus:
                SetWarning("Object cannot be converted to integer by unary plus operation",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                result = OutSet.AnyIntegerValue;
                break;

            case Operations.Minus:
                SetWarning("Object cannot be converted to integer by unary minus operation",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                result = OutSet.AnyIntegerValue;
                break;

            case Operations.LogicNegation:
                result = OutSet.CreateBool(!TypeConversion.ToBoolean(value));
                break;

            case Operations.Int32Cast:
                SetWarning("Object cannot be converted to integer",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                result = OutSet.AnyIntegerValue;
                break;

            case Operations.FloatCast:
            case Operations.DoubleCast:
                SetWarning("Object cannot be converted to float",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                result = OutSet.AnyFloatValue;
                break;

            case Operations.Print:
                // The operator convert value to string and print it. The string value is not used
                // to resolve the entire expression. Instead, the false value is returned.
                // TODO: This is a quest for tainted analysis
                result = OutSet.CreateBool(false);
                // TODO: Object can be converted only if it has __toString magic method implemented
                break;

            case Operations.Clone:
                // TODO: Object can be converted only if it has __clone magic method implemented
                result = OutSet.AnyObjectValue;
                break;

            case Operations.ObjectCast:
                result = value;
                break;

            case Operations.ArrayCast:
                result = OutSet.AnyArrayValue;
                break;

            default:
                base.VisitAnyObjectValue(value);
                break;
            }
        }
Esempio n. 5
0
        /// <inheritdoc />
        public override void VisitAnyObjectValue(AnyObjectValue value)
        {
            result = Comparison.AbstractCompare(OutSet, operation);
            if (result != null)
            {
                SetWarning("Object cannot be converted to integer by comparison",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                return;
            }

            base.VisitAnyObjectValue(value);
        }
Esempio n. 6
0
        /// <inheritdoc />
        public override void VisitAnyObjectValue(AnyObjectValue value)
        {
            result = ArithmeticOperation.RightAbstractArithmetic(flow, operation, leftOperand);
            if (result != null)
            {
                SetWarning("Object cannot be converted to integer by arithmetic operation",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                return;
            }

            base.VisitAnyObjectValue(value);
        }
Esempio n. 7
0
        /// <inheritdoc />
        public override void VisitAnyObjectValue(AnyObjectValue value)
        {
            // An object is always greater then null value
            switch (operation)
            {
            case Operations.Equal:
            case Operations.GreaterThanOrEqual:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotEqual:
            case Operations.LessThan:
            case Operations.Or:
            case Operations.Xor:
                result = OutSet.CreateBool(true);
                break;

            case Operations.Mul:
            case Operations.BitAnd:
            case Operations.ShiftLeft:
            case Operations.ShiftRight:
                SetWarning("Object cannot be converted to integer",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                result = OutSet.CreateInt(0);
                break;

            case Operations.Add:
            case Operations.Sub:
            case Operations.BitOr:
            case Operations.BitXor:
                SetWarning("Object cannot be converted to integer",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                result = OutSet.AnyIntegerValue;
                break;

            case Operations.Div:
            case Operations.Mod:
                SetWarning("Object cannot be converted to integer",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                // We can assume that object is not zero, because null is zero
                result = OutSet.CreateInt(0);
                break;

            default:
                base.VisitAnyObjectValue(value);
                break;
            }
        }
Esempio n. 8
0
        /// <inheritdoc />
        public override void VisitAnyObjectValue(AnyObjectValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

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

            case Operations.Mod:
                SetWarning("Object cannot be converted to integer by modulo operation",
                           AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                result = ModuloOperation.AbstractModulo(flow);
                break;

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

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

                result = BitwiseOperation.Bitwise(OutSet, operation);
                if (result != null)
                {
                    SetWarning("Object cannot be converted to integer by bitwise operation",
                               AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                    break;
                }

                base.VisitAnyObjectValue(value);
                break;
            }
        }
Esempio n. 9
0
        /// <inheritdoc />
        public override void VisitAnyObjectValue(AnyObjectValue value)
        {
            switch (operation)
            {
            case Operations.Mod:
                // Ommitted warning message that object cannot be converted to integer
                SetWarning("Object cannot be converted to integer by modulo operation",
                           AnalysisWarningCause.OBJECT_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
                    SetWarning("Object cannot be converted to integer by arithmetic operation",
                               AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                    break;
                }

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

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

                base.VisitAnyObjectValue(value);
                break;
            }
        }
Esempio n. 10
0
        /// <inheritdoc />
        public override void VisitAnyObjectValue(AnyObjectValue 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:
                result = Comparison.AbstractCompare(OutSet, operation);
                if (result != null)
                {
                    SetWarning("Object cannot be converted to integer by comparison",
                               AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                    break;
                }

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

                result = BitwiseOperation.Bitwise(OutSet, operation);
                if (result != null)
                {
                    SetWarning("Object cannot be converted to integer by bitwise operation",
                               AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                    break;
                }

                base.VisitAnyObjectValue(value);
                break;
            }
        }
Esempio n. 11
0
        /// <inheritdoc />
        public override void VisitAnyObjectValue(AnyObjectValue 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:
                result = BitwiseOperation.Bitwise(OutSet, operation);
                if (result != null)
                {
                    SetWarning("Object cannot be converted to integer by bitwise operation",
                               AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                    break;
                }

                base.VisitAnyObjectValue(value);
                break;
            }
        }
Esempio n. 12
0
 public override void VisitAnyObjectValue(AnyObjectValue value)
 {
     ContainsAnyValue = true;
     locations.Add(new ObjectAnyValueLocation(containingIndex, index, value));
 }
Esempio n. 13
0
 /// <inheritdoc />
 public override void VisitAnyObjectValue(AnyObjectValue value)
 {
     Result = StaticObjectVisitorResult.MULTIPLE_RESULTS;
 }
Esempio n. 14
0
 /// <inheritdoc />
 public override void VisitAnyObjectValue(AnyObjectValue value)
 {
     // TODO: Object can be converted only if it has __toString magic method implemented
     result         = null;
     abstractResult = OutSet.AnyStringValue;
 }
Esempio n. 15
0
 /// <inheritdoc />
 public override void VisitAnyObjectValue(AnyObjectValue value)
 {
     objectVisitor.SetLeftOperand(value);
     visitor = objectVisitor;
 }
Esempio n. 16
0
 /// <inheritdoc />
 public override void VisitAnyObjectValue(AnyObjectValue value)
 {
     result = TypeConversion.ToBoolean(snapshot, value);
 }
Esempio n. 17
0
 public override void VisitAnyObjectValue(AnyObjectValue value)
 {
     this.AddLocation(new ObjectAnyValueLocation(null, index, value));
 }