private static Value Modulo(ISnapshotReadWrite snapshot, IntervalValue <int> leftOperand, int rightOperand) { IntervalValue <int> result; if (leftOperand.Start >= 0) { result = PositiveDividendModulo(snapshot, leftOperand.Start, leftOperand.End, rightOperand); } else { if (leftOperand.End <= 0) { result = NegativeDividendModulo(snapshot, leftOperand.Start, leftOperand.End, rightOperand); } else { var negative = NegativeDividendModulo(snapshot, leftOperand.Start, 0, rightOperand); var positive = PositiveDividendModulo(snapshot, 0, leftOperand.End, rightOperand); result = snapshot.CreateIntegerInterval(negative.Start, positive.End); } } if (result.Start < result.End) { return(result); } else { return(snapshot.CreateInt(result.Start)); } }
/// <summary> /// Perform bitwise operation for given integer operands. /// </summary> /// <param name="snapshot">Read-write memory snapshot used for fix-point analysis.</param> /// <param name="operation">Operation to be performed, only the bitwise one gives a result.</param> /// <param name="leftOperand">Left integer operand of bitwise operation.</param> /// <param name="rightOperand">Right integer operand of bitwise operation.</param> /// <returns>If operation is bitwise, it returns integer result, otherwise <c>null</c>.</returns> public static IntegerValue Bitwise(ISnapshotReadWrite snapshot, Operations operation, int leftOperand, int rightOperand) { switch (operation) { case Operations.BitAnd: return(snapshot.CreateInt(leftOperand & rightOperand)); case Operations.BitOr: return(snapshot.CreateInt(leftOperand | rightOperand)); case Operations.BitXor: return(snapshot.CreateInt(leftOperand ^ rightOperand)); case Operations.ShiftLeft: return(snapshot.CreateInt(leftOperand << rightOperand)); case Operations.ShiftRight: return(snapshot.CreateInt(leftOperand >> rightOperand)); default: return(null); } }