public ValueInterval([NotNull] OrderedLiteralBase from, [NotNull] OrderedLiteralBase to, bool fromInclusive = true, bool toInclusive = true) { From = from ?? throw new ArgumentNullException(nameof(from)); To = to ?? throw new ArgumentNullException(nameof(to)); FromInclusive = fromInclusive; ToInclusive = toInclusive; if (Comparer <OrderedLiteralBase> .Default.Compare(from, to) > 0) { throw new ArgumentException(nameof(from)); } }
public override (IValue from, IValue to) Apply(IValue value, IValue operand) { switch (value) { case OrderedLiteralBase orderedLiteralValue: { switch (operand) { case OrderedLiteralBase orderedLiteralOperand: var literal = OrderedLiteralBase.BitRightShift(orderedLiteralValue, orderedLiteralOperand); return(literal, literal); default: throw new ArgumentOutOfRangeException(nameof(operand)); } } default: throw new ArgumentOutOfRangeException(nameof(value)); } }
public static ValueInterval Single(OrderedLiteralBase value) { return(new ValueInterval(value, value)); }
public static ValueInterval ToInterval([NotNull] AnalysisContext context, [NotNull] LogicExpressionBase expression, [NotNull] ILValue lValue) { switch (expression) { case BinaryLogicExpression binaryLogicExpression: if (binaryLogicExpression.Left is OrderedLiteralBase && binaryLogicExpression.Right is Variable) { binaryLogicExpression = binaryLogicExpression.Flip(); } var left = binaryLogicExpression.Left; var right = context[binaryLogicExpression.Right]; if (right == null) { return(null); } ILValue variant = null; OrderedLiteralBase literal = null; switch (left) { case ILValue valueVariantBase: variant = valueVariantBase; break; case OrderedLiteralBase orderedLiteralBase: literal = orderedLiteralBase; break; default: throw new ArgumentOutOfRangeException(nameof(left)); } switch (right) { case ILValue valueVariantBase: variant = valueVariantBase; break; case OrderedLiteralBase orderedLiteralBase: literal = orderedLiteralBase; break; default: throw new ArgumentOutOfRangeException(nameof(right)); } if (variant == null || literal == null) { return(null); } if (Equals(lValue, variant) || variant is IVariantWithStorageVariable variantWithStorage && Equals(variantWithStorage.StorageVariable, lValue)) { return(OperatorToInterval(binaryLogicExpression.Operator, literal, variant.TypeRef)); } else { return(null); }