public override bool Understands(IFunctionSymbol /*!*/ f, IList /*!*/ args) { //Contract.Requires(args != null); //Contract.Requires(f != null); return(f.Equals(Prop.And) || f.Equals(Value.Eq) || microLattice.Understands(f, args)); }
public override bool Understands(IFunctionSymbol /*!*/ f, IList /*<IExpr!>*//*!*/ args) { //Contract.Requires(args != null); //Contract.Requires(f != null); bool isEq = f.Equals(Microsoft.AbstractInterpretationFramework.Value.Eq); if (isEq || f.Equals(Microsoft.AbstractInterpretationFramework.Value.Subtype)) { Contract.Assert(args.Count == 2); IExpr /*!*/ arg0 = (IExpr /*!*/)cce.NonNull(args[0]); IExpr /*!*/ arg1 = (IExpr /*!*/)cce.NonNull(args[1]); // Look for $typeof(var) == t or t == $typeof(var) or $typeof(var) <: t if (isEq && factory.IsTypeConstant(arg0)) { // swap the arguments IExpr /*!*/ tmp = arg0; arg0 = arg1; arg1 = tmp; } else if (!factory.IsTypeConstant(arg1)) { return(false); } IFunApp typeofExpr = arg0 as IFunApp; if (typeofExpr != null && typeofExpr.FunctionSymbol.Equals(Microsoft.AbstractInterpretationFramework.Value.Typeof)) { Contract.Assert(typeofExpr.Arguments.Count == 1); if (typeofExpr.Arguments[0] is IVariable) { // we have a match return(true); } } } return(false); }
public override bool Understands(IFunctionSymbol /*!*/ f, IList /*<IExpr!>*//*!*/ args) { //Contract.Requires(args != null); //Contract.Requires(f != null); if (f.Equals(Microsoft.AbstractInterpretationFramework.Value.Eq) || f.Equals(Microsoft.AbstractInterpretationFramework.Value.Neq)) { Contract.Assert(args.Count == 2); IExpr /*!*/ arg0 = (IExpr /*!*/)cce.NonNull(args[0]); IExpr /*!*/ arg1 = (IExpr /*!*/)cce.NonNull(args[1]); // Look for "x OP null" or "null OP x" where OP is "==" or "!=". if (arg0 is IVariable && arg1 is IFunApp && ((IFunApp)arg1).FunctionSymbol == Ref.Null) { return(true); } else if (arg1 is IVariable && arg0 is IFunApp && ((IFunApp)arg0).FunctionSymbol == Ref.Null) { return(true); } } return(false); }
public override bool Understands(IFunctionSymbol/*!*/ f, IList/*<IExpr!>*//*!*/ args) { //Contract.Requires(args != null); //Contract.Requires(f != null); bool isEq = f.Equals(Microsoft.AbstractInterpretationFramework.Value.Eq); if (isEq || f.Equals(Microsoft.AbstractInterpretationFramework.Value.Subtype)) { Contract.Assert(args.Count == 2); IExpr/*!*/ arg0 = (IExpr/*!*/)cce.NonNull(args[0]); IExpr/*!*/ arg1 = (IExpr/*!*/)cce.NonNull(args[1]); // Look for $typeof(var) == t or t == $typeof(var) or $typeof(var) <: t if (isEq && factory.IsTypeConstant(arg0)) { // swap the arguments IExpr/*!*/ tmp = arg0; arg0 = arg1; arg1 = tmp; } else if (!factory.IsTypeConstant(arg1)) { return false; } IFunApp typeofExpr = arg0 as IFunApp; if (typeofExpr != null && typeofExpr.FunctionSymbol.Equals(Microsoft.AbstractInterpretationFramework.Value.Typeof)) { Contract.Assert(typeofExpr.Arguments.Count == 1); if (typeofExpr.Arguments[0] is IVariable) { // we have a match return true; } } } return false; }
/// <summary> /// For the moment consider just equalities. Other case must be considered /// </summary> public override bool Understands(IFunctionSymbol/*!*/ f, IList /*<IExpr*//*!*/ args) { //Contract.Requires(args != null); //Contract.Requires(f != null); return f.Equals(Microsoft.AbstractInterpretationFramework.Value.Eq); }
/// <summary> /// For the moment consider just equalities. Other case must be considered /// </summary> public override bool Understands(IFunctionSymbol /*!*/ f, IList /*<IExpr*//*!*/ args) { //Contract.Requires(args != null); //Contract.Requires(f != null); return(f.Equals(Microsoft.AbstractInterpretationFramework.Value.Eq)); }
public override bool Understands(IFunctionSymbol/*!*/ f, IList/*!*/ args) { //Contract.Requires(args != null); //Contract.Requires(f != null); return f.Equals(Prop.And) || f.Equals(Value.Eq) || microLattice.Understands(f, args); }
/// <summary> /// Builds a linear expression from "e", if possible; returns null if not possible. /// </summary> /// <param name="e"></param> /// <returns></returns> public static /*maybe null*/ LinearExpr AsExpr(IExpr /*!*/ e) /* throws ArithmeticException */ { Contract.Requires(e != null); if (e is IVariable) { // Note, without a type for the variable, we don't know if the identifier is intended to hold an integer value. // However, it seems that no harm can be caused by here treating the identifier as if it held an // integer value, because other parts of this method will reject the expression as a linear expression // if non-numeric operations other than equality are applied to the identifier. return(new LinearExpr((IVariable)e)); } else if (e is IFunApp) { IFunApp /*!*/ funapp = (IFunApp)e; Contract.Assert(funapp != null); IFunctionSymbol /*!*/ s = funapp.FunctionSymbol; Contract.Assert(s != null); if (s is IntSymbol) { return(new LinearExpr(((IntSymbol)s).Value)); } else if (s.Equals(Int.Negate)) { Contract.Assert(funapp.Arguments.Count == 1); LinearExpr le = AsExpr((IExpr /*!*/)cce.NonNull(funapp.Arguments[0])); if (le != null) { le.Negate(); return(le); } } else if (s.Equals(Int.Add) || s.Equals(Int.Sub) || s.Equals(Int.Mul)) { Contract.Assert(funapp.Arguments.Count == 2); IExpr /*!*/ arg0 = (IExpr /*!*/)cce.NonNull(funapp.Arguments[0]); IExpr /*!*/ arg1 = (IExpr /*!*/)cce.NonNull(funapp.Arguments[1]); LinearExpr le0 = AsExpr(arg0); if (le0 == null) { return(null); } LinearExpr le1 = AsExpr(arg1); if (le1 == null) { return(null); } if (s.Equals(Int.Add)) { le0.Add(le1); return(le0); } else if (s.Equals(Int.Sub)) { le1.Negate(); le0.Add(le1); return(le0); } else if (s.Equals(Int.Mul)) { BigNum x; if (le0.AsConstant(out x)) { le1.Multiply(x); return(le1); } else if (le1.AsConstant(out x)) { le0.Multiply(x); return(le0); } } } } return(null); }
static /*maybe null*/ LinearCondition GetCond(IExpr e, bool positive) /* throws ArithmeticException */ { IFunApp funapp = e as IFunApp; if (funapp == null) { return(null); } IFunctionSymbol /*!*/ s = funapp.FunctionSymbol; Contract.Assert(s != null); if ((positive && s.Equals(Prop.False)) || (!positive && s.Equals(Prop.True))) { return(new LCBottom()); } else if (s.Equals(Prop.Not)) { Contract.Assert(funapp.Arguments.Count == 1); return(GetCond((IExpr /*!*/)cce.NonNull(funapp.Arguments[0]), !positive)); } else if (funapp.Arguments.Count == 2) { IExpr /*!*/ arg0 = (IExpr /*!*/)cce.NonNull(funapp.Arguments[0]); IExpr /*!*/ arg1 = (IExpr /*!*/)cce.NonNull(funapp.Arguments[1]); LinearExpr le0 = AsExpr(arg0); if (le0 == null) { return(null); } LinearExpr le1 = AsExpr(arg1); if (le1 == null) { return(null); } LinearConstraint constraint = null; bool sense = true; if ((positive && s.Equals(Int.Less)) || (!positive && s.Equals(Int.AtLeast))) { constraint = MakeConstraint(le0, le1, LinearConstraint.ConstraintRelation.LE, BigNum.ONE); } else if ((positive && s.Equals(Int.AtMost)) || (!positive && s.Equals(Int.Greater))) { constraint = MakeConstraint(le0, le1, LinearConstraint.ConstraintRelation.LE, BigNum.ZERO); } else if ((positive && s.Equals(Int.AtLeast)) || (!positive && s.Equals(Int.Less))) { constraint = MakeConstraint(le1, le0, LinearConstraint.ConstraintRelation.LE, BigNum.ZERO); } else if ((positive && s.Equals(Int.Greater)) || (!positive && s.Equals(Int.AtMost))) { constraint = MakeConstraint(le1, le0, LinearConstraint.ConstraintRelation.LE, BigNum.ONE); } else if (s.Equals(Int.Eq)) { constraint = MakeConstraint(le0, le1, LinearConstraint.ConstraintRelation.EQ, BigNum.ZERO); sense = positive; } else if (s.Equals(Int.Neq)) { constraint = MakeConstraint(le0, le1, LinearConstraint.ConstraintRelation.EQ, BigNum.ZERO); sense = !positive; } if (constraint != null) { if (constraint.coefficients.Count != 0) { return(new LinearConditionLiteral(sense, constraint)); } else if (constraint.IsConstantSatisfiable()) { return(null); } else { return(new LCBottom()); } } } return(null); }
public override bool Understands(IFunctionSymbol /*!*/ f, IList /*<IExpr!>*//*!*/ args) { //Contract.Requires(args != null); //Contract.Requires(f != null); return(f is IntSymbol || f.Equals(Int.Add) || f.Equals(Int.Sub) || f.Equals(Int.Negate) || f.Equals(Int.Mul) || f.Equals(Int.Eq) || f.Equals(Int.Neq) || f.Equals(Prop.Not) || f.Equals(Int.AtMost) || f.Equals(Int.Less) || f.Equals(Int.Greater) || f.Equals(Int.AtLeast)); }
/// <summary> /// Is this a boolean field that monotonically goes from false to true? /// </summary> public static bool IsBooleanMonotonicallyWeakening(IFunctionSymbol/*!*/ f) { Contract.Requires(f != null); return f.Equals(Allocated); }
public override bool Understands(IFunctionSymbol/*!*/ f, IList/*<IExpr!>*//*!*/ args) { //Contract.Requires(args != null); //Contract.Requires(f != null); if (f.Equals(Microsoft.AbstractInterpretationFramework.Value.Eq) || f.Equals(Microsoft.AbstractInterpretationFramework.Value.Neq)) { Contract.Assert(args.Count == 2); IExpr/*!*/ arg0 = (IExpr/*!*/)cce.NonNull(args[0]); IExpr/*!*/ arg1 = (IExpr/*!*/)cce.NonNull(args[1]); // Look for "x OP null" or "null OP x" where OP is "==" or "!=". if (arg0 is IVariable && arg1 is IFunApp && ((IFunApp)arg1).FunctionSymbol == Ref.Null) { return true; } else if (arg1 is IVariable && arg0 is IFunApp && ((IFunApp)arg0).FunctionSymbol == Ref.Null) { return true; } } return false; }
public override bool Understands(IFunctionSymbol/*!*/ f, IList/*<IExpr!>*//*!*/ args) { //Contract.Requires(args != null); //Contract.Requires(f != null); return f is IntSymbol || f.Equals(Int.Add) || f.Equals(Int.Sub) || f.Equals(Int.Negate) || f.Equals(Int.Mul) || f.Equals(Int.Eq) || f.Equals(Int.Neq) || f.Equals(Prop.Not) || f.Equals(Int.AtMost) || f.Equals(Int.Less) || f.Equals(Int.Greater) || f.Equals(Int.AtLeast); }