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)); }
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)); } }