private static bool IsConstantTrueOrFalse <Variable, Expression>( Expression e, bool t, IExpressionDecoder <Variable, Expression> decoder) { Contract.Requires(decoder != null); bool boolValue; Int32 intValue; if (decoder.IsConstant(e)) { if (decoder.TryValueOf <bool>(e, ExpressionType.Bool, out boolValue)) { return(boolValue == t); } else if (decoder.IsConstantInt(e, out intValue)) { return((intValue != 0) == t); } else { return(false); } } else { return(false); } }
protected virtual bool TryPolarity(Expr expr, In data, out bool shouldNegate) { if (Decoder.IsConstant(expr)) { int intValue; if (Decoder.TryValueOf(expr, ExpressionType.Int32, out intValue)) { return(true.With(intValue == 0, out shouldNegate)); } bool boolValue; if (Decoder.TryValueOf(expr, ExpressionType.Bool, out boolValue)) { return(true.With(boolValue, out shouldNegate)); } } return(false.Without(out shouldNegate)); }
static bool IsVariableEqConstant(Expression guard, IExpressionDecoder <Variable, Expression> decoder) { switch (decoder.OperatorFor(guard)) { case ExpressionOperator.Equal: case ExpressionOperator.Equal_Obj: Expression left = decoder.LeftExpressionFor(guard); Expression right = decoder.RightExpressionFor(guard); return((decoder.IsVariable(left) && decoder.IsConstant(right)) || (decoder.IsVariable(right) && decoder.IsConstant(right))); default: return(false); } }
public static bool IsNegativeInfinity <Variable, Expression>(this IExpressionDecoder <Variable, Expression> decoder, Expression exp) { Contract.Requires(decoder != null); Contract.Requires(exp != null); if (decoder.IsConstant(exp)) { var value = decoder.Constant(exp); if (value is Double) { return(Double.IsNegativeInfinity((Double)value)); } if (value is Single) { return(Single.IsNegativeInfinity((Single)value)); } } return(false); }
public void Insert(Expression /*!*/ target, Expression /*!*/ which, Expression /*!*/ where, Expression /*!*/ what) { if (decoder.IsConstant(where)) { Int32 index; if (decoder.TryValueOf <Int32>(where, ExpressionType.Int32, out index)) { var left = Eval(which); var right = Eval(what); this[decoder.UnderlyingVariable(target)] = left.Insert(index, right); } else { this.RemoveElement(decoder.UnderlyingVariable(target)); } } else { this.RemoveElement(decoder.UnderlyingVariable(target)); } }
public static bool IsAtomicExpression <Variable, Expression>(this IExpressionDecoder <Variable, Expression> decoder, Expression exp) { Contract.Requires(decoder != null); return(decoder.IsConstant(exp) || decoder.IsVariable(exp)); }