/// <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; } }
/// <inheritdoc /> public override void VisitIntegerValue(IntegerValue value) { if (isIncrement) { if (value.Value < int.MaxValue) { result = OutSet.CreateInt(value.Value + 1); } else { result = OutSet.CreateDouble(TypeConversion.ToFloat(value.Value) + 1.0); } } else { if (value.Value > int.MinValue) { result = OutSet.CreateInt(value.Value - 1); } else { result = OutSet.CreateDouble(TypeConversion.ToFloat(value.Value) - 1.0); } } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { // When comparing, both operands are converted to boolean switch (operation) { case Operations.Equal: case Operations.LessThanOrEqual: result = OutSet.CreateBool(!TypeConversion.ToBoolean(leftOperand.Value)); break; case Operations.NotEqual: case Operations.GreaterThan: case Operations.Or: case Operations.Xor: result = TypeConversion.ToBoolean(OutSet, leftOperand); break; case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = leftOperand; break; case Operations.Mul: result = OutSet.CreateInt(0); break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { // When comparing, both operands are converted to boolean switch (operation) { case Operations.Identical: case Operations.LessThan: case Operations.And: result = OutSet.CreateBool(false); break; case Operations.NotIdentical: case Operations.GreaterThanOrEqual: result = OutSet.CreateBool(true); break; case Operations.Equal: case Operations.LessThanOrEqual: bool convertedValue; if (TypeConversion.TryConvertToBoolean(leftOperand, out convertedValue)) { result = OutSet.CreateBool(!convertedValue); } else { result = OutSet.AnyBooleanValue; } break; case Operations.NotEqual: case Operations.GreaterThan: case Operations.Or: case Operations.Xor: result = TypeConversion.ToBoolean(OutSet, leftOperand); break; case Operations.Add: case Operations.Sub: result = leftOperand; 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; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { int integerValue; double floatValue; bool isInteger; switch (operation) { case Operations.Or: case Operations.Xor: result = TypeConversion.ToBoolean(OutSet, leftOperand); break; case Operations.Add: case Operations.Sub: TypeConversion.TryConvertToNumber(leftOperand.Value, true, out integerValue, out floatValue, out isInteger); if (isInteger) { result = OutSet.CreateInt(integerValue); } else { result = OutSet.CreateDouble(floatValue); } break; case Operations.Mul: TypeConversion.TryConvertToNumber(leftOperand.Value, true, out integerValue, out floatValue, out isInteger); if (isInteger) { result = OutSet.CreateInt(0); } else { result = OutSet.CreateDouble(0.0); } break; case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = TypeConversion.ToInteger(OutSet, leftOperand); break; default: result = Comparison.Compare(OutSet, operation, leftOperand.Value, string.Empty); if (result != null) { break; } base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitAssociativeArray(AssociativeArray value) { switch (operation) { case Operations.Equal: case Operations.GreaterThanOrEqual: result = OutSet.CreateBool(!TypeConversion.ToNativeBoolean(Snapshot, value)); break; case Operations.NotEqual: case Operations.LessThan: case Operations.Or: case Operations.Xor: result = TypeConversion.ToBoolean(Snapshot, value); break; case Operations.BitAnd: case Operations.ShiftLeft: case Operations.ShiftRight: result = OutSet.CreateInt(0); break; case Operations.BitOr: case Operations.BitXor: result = TypeConversion.ToInteger(Snapshot, value); break; case Operations.Mod: if (TypeConversion.ToNativeBoolean(Snapshot, value)) { // 0 (null) divided or modulo by anything is always 0 result = OutSet.CreateInt(0); } else { SetWarning("Division by zero (converted from array)", AnalysisWarningCause.DIVISION_BY_ZERO); // Division or modulo by zero returns false boolean value result = OutSet.CreateBool(false); } break; default: if (ArithmeticOperation.IsArithmetic(operation)) { // TODO: This must be fatal error SetWarning("Unsupported operand type: Arithmetic of array and null type"); result = OutSet.AnyValue; break; } base.VisitAssociativeArray(value); break; } }
/// <inheritdoc /> public override void VisitGenericIntervalValue <T>(IntervalValue <T> value) { // When comparing, both operands are converted to boolean switch (operation) { case Operations.Identical: case Operations.GreaterThan: case Operations.And: result = OutSet.CreateBool(false); break; case Operations.NotIdentical: case Operations.LessThanOrEqual: result = OutSet.CreateBool(true); break; case Operations.Equal: case Operations.GreaterThanOrEqual: bool booleanValue; if (TypeConversion.TryConvertToBoolean(value, out booleanValue)) { result = OutSet.CreateBool(!booleanValue); } else { result = OutSet.AnyBooleanValue; } break; case Operations.NotEqual: case Operations.LessThan: case Operations.Or: case Operations.Xor: BooleanValue convertedValue; if (TypeConversion.TryConvertToBoolean(OutSet, value, out convertedValue)) { result = convertedValue; } else { result = OutSet.AnyBooleanValue; } break; case Operations.BitAnd: case Operations.ShiftLeft: case Operations.ShiftRight: result = OutSet.CreateInt(0); break; default: base.VisitGenericIntervalValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { if (isIncrement) { result = OutSet.CreateInt(1); } else { result = value; } }
private MemoryEntry sub(MemoryEntry left, MemoryEntry right) { if (left.Count != 1 || right.Count != 1) { throw new NotImplementedException(); } var leftValue = left.PossibleValues.First() as IntegerValue; var rightValue = right.PossibleValues.First() as IntegerValue; return(new MemoryEntry(OutSet.CreateInt(leftValue.Value - rightValue.Value))); }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.Identical: case Operations.LessThan: case Operations.And: result = OutSet.CreateBool(false); break; case Operations.NotIdentical: case Operations.GreaterThanOrEqual: result = OutSet.CreateBool(true); break; case Operations.Equal: case Operations.LessThanOrEqual: result = OutSet.CreateBool(!TypeConversion.ToNativeBoolean(Snapshot, leftOperand)); break; case Operations.NotEqual: case Operations.GreaterThan: case Operations.Or: case Operations.Xor: result = TypeConversion.ToBoolean(Snapshot, leftOperand); break; case Operations.BitAnd: result = OutSet.CreateInt(0); break; case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = TypeConversion.ToInteger(Snapshot, leftOperand); break; case Operations.Div: result = ArithmeticOperation.DivisionByNull(flow); break; case Operations.Mod: result = ModuloOperation.ModuloByNull(flow); break; default: base.VisitUndefinedValue(value); break; } }
/// <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; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.Identical: case Operations.Equal: case Operations.LessThan: case Operations.LessThanOrEqual: case Operations.And: result = OutSet.CreateBool(false); break; case Operations.NotIdentical: case Operations.NotEqual: case Operations.GreaterThan: case Operations.GreaterThanOrEqual: case Operations.Or: case Operations.Xor: result = OutSet.CreateBool(true); break; case Operations.Add: case Operations.Sub: case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = OutSet.AnyIntegerValue; break; case Operations.Mul: 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; } }
/// <inheritdoc /> public override void VisitAnyResourceValue(AnyResourceValue value) { // Resource is always greater than null 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: result = OutSet.CreateInt(0); break; case Operations.Add: case Operations.Sub: case Operations.BitOr: case Operations.BitXor: result = OutSet.AnyIntegerValue; break; case Operations.Div: case Operations.Mod: // We can assume that resource is not zero, because it is always true result = OutSet.CreateInt(0); break; default: if (PerformCommonAnyOperandOperations()) { break; } base.VisitAnyResourceValue(value); break; } }
/// <inheritdoc /> public override void VisitFloatValue(FloatValue value) { switch (operation) { case Operations.Plus: result = value; break; case Operations.Minus: result = OutSet.CreateDouble(-value.Value); break; case Operations.BitNegation: int nativeIntegerValue; if (TypeConversion.TryConvertToInteger(value.Value, out nativeIntegerValue)) { result = OutSet.CreateInt(~nativeIntegerValue); } else { result = OutSet.AnyIntegerValue; } break; case Operations.Int32Cast: IntegerValue integerValue; if (TypeConversion.TryConvertToInteger(OutSet, value, out integerValue)) { result = integerValue; } else { result = OutSet.AnyIntegerValue; } break; case Operations.FloatCast: case Operations.DoubleCast: result = value; break; default: base.VisitFloatValue(value); break; } }
/// <inheritdoc /> public override void VisitAnyBooleanValue(AnyBooleanValue value) { switch (operation) { case Operations.Equal: case Operations.NotEqual: case Operations.GreaterThanOrEqual: case Operations.LessThan: case Operations.Or: case Operations.Xor: result = value; break; case Operations.Add: case Operations.BitOr: case Operations.BitXor: result = TypeConversion.AnyBooleanToIntegerInterval(OutSet); break; case Operations.Sub: var booleanInterval = TypeConversion.AnyBooleanToIntegerInterval(OutSet); result = OutSet.CreateIntegerInterval(-booleanInterval.End, -booleanInterval.Start); break; case Operations.Mul: result = OutSet.CreateInt(0); break; case Operations.Div: SetWarning("Possible division by zero (converted from boolean false)", AnalysisWarningCause.DIVISION_BY_ZERO); // Division or modulo by false returns false boolean value result = OutSet.AnyValue; break; case Operations.Mod: result = ModuloOperation.ModuloByAnyBooleanValue(flow); break; default: base.VisitAnyBooleanValue(value); break; } }
/// <inheritdoc /> public override void VisitIntervalIntegerValue(IntegerIntervalValue value) { if (value.Start == value.End) { VisitIntegerValue(OutSet.CreateInt(value.Start)); return; } switch (operation) { case Operations.Minus: // Result of arithmetic negation can overflow if ((value.Start == 0) || ((-value.Start) != 0)) { result = OutSet.CreateIntegerInterval(-value.End, -value.Start); } else { // <seealso cref="UnaryOperationEvaluator.VisitIntegerValue" /> result = OutSet.CreateFloatInterval(-TypeConversion.ToFloat(value.End), -TypeConversion.ToFloat(value.Start)); } break; case Operations.BitNegation: result = OutSet.CreateIntegerInterval(~value.End, ~value.Start); break; case Operations.Int32Cast: result = value; break; case Operations.FloatCast: case Operations.DoubleCast: result = OutSet.CreateFloatInterval(TypeConversion.ToFloat(value.Start), TypeConversion.ToFloat(value.End)); break; default: base.VisitIntervalIntegerValue(value); break; } }
/// <inheritdoc /> public override void VisitIntegerValue(IntegerValue value) { switch (operation) { case Operations.Plus: result = value; break; case Operations.Minus: // Result of arithmetic negation can overflow if ((value.Value == 0) || ((-value.Value) != 0)) { result = OutSet.CreateInt(-value.Value); } else { // If the number has the lowest value (the most important bit is 1, others are 0 // in binary), arithmetic negation of it is zero. PHP behaves differently. // It converts the number to the same positive value, but that cause overflow. // Then integer value is converted to appropriate float value result = OutSet.CreateDouble(-TypeConversion.ToFloat(value.Value)); } break; case Operations.BitNegation: result = OutSet.CreateInt(~value.Value); break; case Operations.Int32Cast: result = value; break; case Operations.FloatCast: case Operations.DoubleCast: result = OutSet.CreateDouble(value.Value); break; default: base.VisitIntegerValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.LessThan: result = OutSet.CreateBool(false); break; case Operations.GreaterThanOrEqual: result = OutSet.CreateBool(true); break; case Operations.Equal: case Operations.LessThanOrEqual: result = OutSet.CreateBool(!leftOperand.Value); break; case Operations.NotEqual: case Operations.GreaterThan: case Operations.Or: case Operations.Xor: result = leftOperand; break; case Operations.Add: case Operations.Sub: case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = TypeConversion.ToInteger(OutSet, leftOperand); break; case Operations.Mul: result = OutSet.CreateInt(0); break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { // When comparing, both operands are converted to boolean switch (operation) { case Operations.Identical: case Operations.LessThan: case Operations.And: result = OutSet.CreateBool(false); break; case Operations.NotIdentical: case Operations.GreaterThanOrEqual: result = OutSet.CreateBool(true); break; case Operations.Equal: case Operations.NotEqual: case Operations.GreaterThan: case Operations.LessThanOrEqual: case Operations.Or: case Operations.Xor: result = OutSet.AnyBooleanValue; 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; } }
/// <inheritdoc /> public override void VisitAnyScalarValue(AnyScalarValue value) { switch (operation) { case Operations.BitAnd: case Operations.ShiftLeft: case Operations.ShiftRight: result = OutSet.CreateInt(0); break; default: if (PerformCommonAnyOperandOperations()) { break; } base.VisitAnyScalarValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = leftOperand; break; case Operations.Mul: result = OutSet.CreateInt(0); break; default: base.VisitUndefinedValue(value); break; } }
public override MemoryEntry IncDecEx(IncDecEx operation, MemoryEntry incrementedValue) { var inc = operation.Inc ? 1 : -1; var values = new List <Value>(); foreach (var incremented in incrementedValue.PossibleValues) { var integer = incremented as IntegerValue; if (integer == null) { return(new MemoryEntry(OutSet.AnyValue)); } var result = OutSet.CreateInt(integer.Value + inc); values.Add(result); } return(new MemoryEntry(values)); }
/// <inheritdoc /> public override void VisitAnyArrayValue(AnyArrayValue value) { switch (operation) { case Operations.Equal: case Operations.NotEqual: case Operations.LessThan: case Operations.GreaterThanOrEqual: case Operations.Or: case Operations.Xor: result = OutSet.AnyBooleanValue; break; case Operations.BitAnd: case Operations.ShiftLeft: case Operations.ShiftRight: result = OutSet.CreateInt(0); break; case Operations.BitOr: case Operations.BitXor: result = TypeConversion.AnyArrayToIntegerInterval(OutSet); break; case Operations.Mod: result = ModuloOperation.AbstractModulo(flow); break; default: if (ArithmeticOperation.IsArithmetic(operation)) { // TODO: This must be fatal error SetWarning("Unsupported operand type: Arithmetic of array and null type"); result = OutSet.AnyValue; break; } base.VisitAnyArrayValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { // When comparing, both operands are converted to boolean switch (operation) { case Operations.Equal: case Operations.LessThanOrEqual: result = OutSet.CreateBool(!TypeConversion.ToBoolean(leftOperand.Value)); break; case Operations.NotEqual: case Operations.GreaterThan: case Operations.Or: case Operations.Xor: result = TypeConversion.ToBoolean(OutSet, leftOperand); break; case Operations.Mul: result = OutSet.CreateDouble(0.0); break; case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: int leftInteger; if (TypeConversion.TryConvertToInteger(leftOperand.Value, out leftInteger)) { result = OutSet.CreateInt(leftInteger); } else { result = OutSet.AnyIntegerValue; } break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { // When comparing, both operands are converted to boolean switch (operation) { case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = leftOperand; break; case Operations.Mul: result = OutSet.CreateInt(0); break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.Add: case Operations.Sub: case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = TypeConversion.AnyBooleanToIntegerInterval(OutSet); break; case Operations.Mul: result = OutSet.CreateInt(0); break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> protected override void flowThrough() { switch (_partial.Type) { case PseudoConstUse.Types.Line: Value = OutSet.CreateSnapshotEntry(new MemoryEntry(OutSet.CreateInt(_partial.Position.FirstLine))); return; case PseudoConstUse.Types.File: Value = OutSet.CreateSnapshotEntry(new MemoryEntry(OutSet.CreateString(OwningScriptFullName))); return; case PseudoConstUse.Types.Dir: Value = OutSet.CreateSnapshotEntry(new MemoryEntry(OutSet.CreateString(OwningScript.Directory.FullName))); return; case PseudoConstUse.Types.Function: if (OwningPPGraph.FunctionName == null) { Value = OutSet.CreateSnapshotEntry(new MemoryEntry(OutSet.UndefinedValue)); } else { Value = OutSet.CreateSnapshotEntry(new MemoryEntry(OutSet.CreateString(OwningPPGraph.FunctionName))); } return; case PseudoConstUse.Types.Method: case PseudoConstUse.Types.Class: case PseudoConstUse.Types.Namespace: Value = OutSet.CreateSnapshotEntry(new MemoryEntry(OutSet.AnyStringValue)); return; default: Value = OutSet.CreateSnapshotEntry(new MemoryEntry(OutSet.AnyValue)); return; } }
/// <inheritdoc /> public override void VisitBooleanValue(BooleanValue value) { switch (operation) { case Operations.Plus: result = TypeConversion.ToInteger(OutSet, value); break; case Operations.Minus: result = OutSet.CreateInt(value.Value ? -1 : 0); break; case Operations.LogicNegation: result = OutSet.CreateBool(!value.Value); break; case Operations.BitNegation: // TODO: This must be fatal error SetWarning("Unsupported operand types: Bit negation of boolean value"); result = OutSet.AnyValue; break; case Operations.Int32Cast: result = TypeConversion.ToInteger(OutSet, value); break; case Operations.FloatCast: case Operations.DoubleCast: result = TypeConversion.ToFloat(Snapshot, value); break; default: base.VisitBooleanValue(value); break; } }
/// <inheritdoc /> public override void VisitScalarValue(ScalarValue 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: case Operations.ShiftLeft: case Operations.ShiftRight: result = OutSet.CreateInt(0); break; default: base.VisitScalarValue(value); break; } }
/// <summary> /// Create integer representation of given literal /// </summary> /// <param name="x">Literal value</param> /// <returns>Created literal value representation</returns> public virtual MemoryEntry IntLiteral(IntLiteral x) { return(new MemoryEntry(OutSet.CreateInt((int)x.Value))); }