/// <summary> /// Check if the expression <code>exp</code> is greater than zero /// </summary> public FlatAbstractDomain <bool> /*!*/ CheckIfGreaterEqualThanZero(Expression /*!*/ exp) { FlatAbstractDomain <bool> /*!*/ checkOnLeft = this.Left.CheckIfGreaterEqualThanZero(exp); FlatAbstractDomain <bool> /*!*/ checkOnRight = this.Right.CheckIfGreaterEqualThanZero(exp); return((FlatAbstractDomain <bool> /*!*/)checkOnLeft.Meet(checkOnRight)); }
/// <summary> /// Check if the expression <code>e1</code> is strictly smaller than <code>e2</code> /// </summary> public FlatAbstractDomain <bool> /*!*/ CheckIfLessThan(Expression /*!*/ e1, Expression /*!*/ e2) { FlatAbstractDomain <bool> /*!*/ checkOnLeft = this.Left.CheckIfLessThan(e1, e2); FlatAbstractDomain <bool> /*!*/ checkOnRight = this.Right.CheckIfLessThan(e1, e2, this.Left); return((FlatAbstractDomain <bool> /*!*/)checkOnLeft.Meet(checkOnRight)); }
/// <summary> /// left * right != 0 ?? /// </summary> public override FlatAbstractDomain <bool> VisitMultiplication(Expression left, Expression right, Expression original, FlatAbstractDomain <bool> data) { FlatAbstractDomain <bool> leftIsZero = IsNotZero(left); FlatAbstractDomain <bool> rightIsZero = IsNotZero(right); if (leftIsZero.IsNormal() && rightIsZero.IsNormal()) { // One of the two is zero ... if (leftIsZero.IsFalse() || rightIsZero.IsFalse()) { return(CheckOutcome.False); } // Both are non zero if (leftIsZero.IsTrue() && rightIsZero.IsTrue()) { return(CheckOutcome.True); } } if (leftIsZero.IsBottom || rightIsZero.IsBottom) { return(CheckOutcome.Bottom); } return(CheckOutcome.Top); }
Reduce(IntervalEnvironment < Rational, Expression> left, WeakUpperBounds <Expression, Rational> right) { ALog.BeginReduce("IntervalsWithSymbolicUpperBounds"); foreach (Expression x in left.Keys) { foreach (Expression y in left.Keys) { if (x.Equals(y)) { continue; } FlatAbstractDomain <bool> b = left.CheckIfLessThan(x, y); if (b.IsTop || b.IsBottom) { continue; } if (b.BoxedElement == true) { ALog.Message("Adding " + ExpressionPrinter <Expression> .ToString(x, this.decoder) + " < " + ExpressionPrinter <Expression> .ToString(y, this.decoder) + " as " + left.BoundsFor(x) + " < " + left.BoundsFor(y)); right.TestTrueLessThan(x, y); // Add the constraint x < y } } } ALog.EndReduce(); return(this.Factory(left, right)); }
private static ProofOutcome ProcessOutcome <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, LogOptions> ( FlatAbstractDomain <bool> result, BoxedExpression exp, IMethodDriver <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, LogOptions> mdriver, out BoxedExpression simplified ) where Expression : IEquatable <Expression> where Variable : IEquatable <Variable> where LogOptions : IFrameworkLogOptions where Type : IEquatable <Type> { if (result.IsTrue()) { simplified = BoxedExpression.Const(1, mdriver.MetaDataDecoder.System_Boolean, mdriver.MetaDataDecoder); return(ProofOutcome.True); } if (result.IsFalse()) { simplified = BoxedExpression.Const(0, mdriver.MetaDataDecoder.System_Boolean, mdriver.MetaDataDecoder); return(ProofOutcome.False); } simplified = exp; return(ProofOutcome.Top); }
/// <summary> /// Substitutes all the variables in <code>tobeRefined</code> with the expressions we've (if they are different from top) /// </summary> public Expression /*!*/ Refine(Expression /*!*/ tobeRefined) { Expression refined = tobeRefined; foreach (Expression /* is variable */ x in this.decoder.VariablesIn(tobeRefined)) { Debug.Assert(this.decoder.IsVariable(x)); // ^ assert this.decoder.IsVariable(x); FlatAbstractDomain <Expression> expForX = this.var2exp[x]; if (!expForX.IsTop) { if (expForX.IsBottom) { // If it is bottom, we just return the input return(tobeRefined); } else { // refined = refined.Substitute(x, expForX.BoxedElement); refined = this.encoder.Substitute(refined, x, expForX.BoxedElement); } } } return(refined); }
/// <summary> /// Check if exp != 0 /// </summary> public FlatAbstractDomain <bool> /*!*/ CheckIfNonZero(Expression /*!*/ exp) { FlatAbstractDomain <bool> /*!*/ checkLeft = this.Left.CheckIfNonZero(exp); FlatAbstractDomain <bool> /*!*/ checkRight = this.Right.CheckIfNonZero(exp); return(checkLeft.Meet(checkRight)); }
public FlatAbstractDomain <bool> /*!*/ StartsWith(IStringAbstraction /*!*/ param) { FlatAbstractDomain <bool> result; FlatAbstractDomain <bool> top = new FlatAbstractDomain <bool>(false).Top; if (this.IsTop || param.IsTop) { result = top; } else { StringAbstraction what = param as StringAbstraction; //^ assert what != null; Debug.Assert(what != null); if (content == ContentType.String && what.content == ContentType.String) { result = new FlatAbstractDomain <bool>(fullstring.StartsWith(what.fullstring)); } else if (content == ContentType.Prefix && what.content == ContentType.String) { result = new FlatAbstractDomain <bool>(prefix.StartsWith(what.fullstring)); } else { result = top; } } return(result); }
public FlatAbstractDomain <int> /*!*/ CompareTo(IStringAbstraction /*!*/ param) { FlatAbstractDomain <int> result; FlatAbstractDomain <int> top = (FlatAbstractDomain <int>) new FlatAbstractDomain <int>(1).Top; if (this.IsTop || param.IsTop) { return(top); } else { StringAbstraction who = param as StringAbstraction; //^ assert who != null; Debug.Assert(who != null); if (content == ContentType.String && who.content == ContentType.String) { result = new FlatAbstractDomain <int>(fullstring.CompareTo(who.fullstring)); } else { result = top; } } return(result); }
public FlatAbstractDomain <bool> /*!*/ CheckIfLessThan(Expression /*!*/ e1, Expression /*!*/ e2) { FlatAbstractDomain <bool> /*!*/ checkLeft = this.Left.CheckIfLessThan(e1, e2); FlatAbstractDomain <bool> /*!*/ checkRight = this.Right.CheckIfLessThan(e1, e2); FlatAbstractDomain <bool> result = (FlatAbstractDomain <bool> /*!*/)checkLeft.Meet(checkRight); if (result.Equals(result.Top) && !light) { //If we do not arrive to check the condition, we try to refine the information in the stripe domain with the state of the Karr domain LinearEqualitiesEnvironment <Variable, Expression> karrRefined = this.Right; var refined = this.Left.Right; if (strong) { //If we want to perform a precise but slow analysis, we refine the information for all the variables of the state of the Karr Domain var variables = this.ExtractVariable(e1); variables.AddRange(this.ExtractVariable(e2)); //foreach (var e in variables) // refined = refined.Refine(karrRefined, e); //foreach (var e in karrRefined.Variables) // refined = refined.Refine(karrRefined, e); } else {//Otherwise we refine only on the variables of the condition var variables = this.ExtractVariable(e1); variables.AddRange(this.ExtractVariable(e2)); //foreach (var e in variables) // refined = refined.Refine(karrRefined, e); } checkRight = refined.CheckIfLessThan(e1, e2 /*, this.Left.Left*/); result = checkLeft.Meet(checkRight); } return(result); }
public FlatAbstractDomain <bool> CheckIfHolds(Expression exp) { FlatAbstractDomain <bool> checkLeft = this.Left.CheckIfHolds(exp); FlatAbstractDomain <bool> checkRight = this.Right.CheckIfHolds(exp, this.left); FlatAbstractDomain <bool> result = (FlatAbstractDomain <bool>)checkLeft.Meet(checkRight); return(result); }
public ScalarFromArrayTracking( BoxedVariable <Variable> left, BoxedVariable <Variable> right, FlatAbstractDomain <bool> isUnmodifiedFromEntry, SymbolicExpressionTracker <BoxedVariable <Variable>, BoxedExpression> conditions) : this(new SetOfConstraints <BoxedVariable <Variable> >(left), new SetOfConstraints <BoxedVariable <Variable> >(right), isUnmodifiedFromEntry, conditions) { Contract.Requires(isUnmodifiedFromEntry != null); Contract.Requires(conditions != null); }
public ADictionary Update(Variable v, Type t) { var result = this.Clone() as ADictionary; Contract.Assume(result != null, "We miss the dynamic type static analysis"); result[new BoxedVariable <Variable>(v)] = new FlatAbstractDomain <Type>(t); return(result); }
protected override T To <T>(Variable d, FlatAbstractDomain <ConcreteFloat> c, IFactory <T> factory) { if (c.IsBottom) { return(factory.Constant(false)); } else { return(factory.IdentityForAnd); } }
public FlatAbstractDomain <bool> CheckIfNonZero(Expression e) { FlatAbstractDomain <bool> result = CheckOutcome.Bottom; for (int i = 0; i < disjuncts.Length; i++) { result = result.Join(disjuncts[i].CheckIfNonZero(e)); } return(result); }
public FlatAbstractDomain <bool> CheckIfEqualThan(Expression e1, Expression e2) { FlatAbstractDomain <bool> result = CheckOutcome.Bottom; for (int i = 0; i < this.disjuncts.Length; i++) { result = result.Join(this.disjuncts[i].CheckIfEqual(e1, e2)); } return(result); }
public FlatAbstractDomain <bool> CheckIfHolds(Expression exp) { FlatAbstractDomain <bool> result = CheckOutcome.Bottom; for (int i = 0; i < this.disjuncts.Length; i++) { result = result.Join(this.disjuncts[i].CheckIfHolds(exp)); } return(result); }
public FlatAbstractDomain <bool> CheckIfLessThan(Variable v1, Variable v2) { FlatAbstractDomain <bool> result = CheckOutcome.Bottom; for (int i = 0; i < this.disjuncts.Length; i++) { result = result.Join(this.disjuncts[i].CheckIfLessThan(v1, v2)); } return(result); }
public FlatAbstractDomain <bool> /*!*/ CheckIfLessThan(Expression /*!*/ e1, Expression /*!*/ e2) { FlatAbstractDomain <bool> /*!*/ checkLeft = this.Left.CheckIfLessThan(e1, e2); FlatAbstractDomain <bool> /*!*/ checkRight = this.Right.CheckIfLessThan(e1, e2 /*, this.Left*/); FlatAbstractDomain <bool> result = checkLeft.Meet(checkRight); if (result.Equals(result.Top)) { //If we do not arrive to check the condition, we try to refine the information in the stripe domain with the state of Interval domain and also internally StripeWithIntervals <Variable, Expression, MetaDataDecoder> refined = this.Right /*.Refine(this.Left).RefineInternally()*/; checkRight = refined.CheckIfLessThan(e1, e2 /*, this.Left*/); result = checkLeft.Meet(checkRight); } return(result); }
public override FlatAbstractDomain <bool> VisitNotEqual(Expression left, Expression right, Expression original, FlatAbstractDomain <bool> data) { if (left.Equals(right) && !Decoder.IsNaN(left) && !Decoder.IsNaN(right)) { return(CheckOutcome.False); } evalConstant.Visit(left); bool leftIsConstZero = evalConstant.HasValue && evalConstant.Result.IsZero; Variable rightVar = Decoder.UnderlyingVariable(right); if (evalConstant.HasValue && Domain.ContainsKey(rightVar) && Domain[rightVar].IsNormal()) { if (Domain[rightVar].Contains(evalConstant.Result)) { return(CheckOutcome.True); } } evalConstant.Visit(right); bool rightIsConstZero = evalConstant.HasValue && evalConstant.Result.IsZero; Variable leftVar = Decoder.UnderlyingVariable(left); if (evalConstant.HasValue && Domain.ContainsKey(leftVar) && Domain[leftVar].IsNormal()) { rightIsConstZero = evalConstant.Result.IsZero; if (Domain[leftVar].Contains(evalConstant.Result)) { return(CheckOutcome.True); } } if (leftIsConstZero) { return(Visit(right, data)); } if (rightIsConstZero) { return(Visit(left, data)); } return(CheckOutcome.Top); }
public ScalarFromArrayTracking( SetOfConstraints <BoxedVariable <Variable> > left, SetOfConstraints <BoxedVariable <Variable> > right, FlatAbstractDomain <bool> isUnmodifiedFromEntry, SymbolicExpressionTracker <BoxedVariable <Variable>, BoxedExpression> conditions) { Contract.Requires(left != null); Contract.Requires(right != null); Contract.Requires(isUnmodifiedFromEntry != null); Contract.Requires(conditions != null); this.left = left; this.right = right; this.isUnmodifiedFromEntry = isUnmodifiedFromEntry; this.conditions = conditions; }
public override FlatAbstractDomain <bool> VisitEqual(Expression left, Expression right, Expression original, FlatAbstractDomain <bool> data) { ExpressionType leftType = Decoder.TypeOf(left); ExpressionType rightType = Decoder.TypeOf(right); if (!leftType.IsFloatingPointType() && !rightType.IsFloatingPointType()) { if (left.Equals(right) && !Decoder.IsNaN(left) && !Decoder.IsNaN(right)) { return(CheckOutcome.True); } } evalConstant.Visit(left); Variable rightVar = Decoder.UnderlyingVariable(right); if (evalConstant.HasValue && Domain.ContainsKey(rightVar) && Domain[rightVar].IsNormal()) { if (Domain[rightVar].Contains(evalConstant.Result)) { return(CheckOutcome.False); } } evalConstant.Visit(right); Variable leftVar = Decoder.UnderlyingVariable(right); if (evalConstant.HasValue && Domain.ContainsKey(leftVar) && Domain[leftVar].IsNormal()) { if (Domain[leftVar].Contains(evalConstant.Result)) { return(CheckOutcome.False); } } return(CheckOutcome.Top); }
/// <summary> /// It checks for each dropped constraints if it can be validated by the intervals domain state /// </summary> private void addConstraints(IntervalsForUnsafeCode intervalsPrev, StripeForUnsafeCode thiscloned, StripeForUnsafeCode result) { StripeForUnsafeCode dropped = (StripeForUnsafeCode)this.Factory(); ExtractDroppedConstraints(thiscloned, result, dropped); foreach (BoxedExpression key in dropped.Keys) { foreach (AtMostTwoExpressions <BoxedExpression> constr in dropped[key].EmbeddedValues_Unsafe) { if (!constr.IsTop && !constr.IsBottom) { BoxedExpression toBeChecked = StripeWithIntervalsForUnsafeCode.MakeCondition(key, constr, this.mdDecoder); FlatAbstractDomain <bool> test = intervalsPrev.CheckIfHolds(toBeChecked); if (!test.IsBottom && !test.IsTop && test.BoxedElement == true) { result.AddConstraint(key, constr); } } } } }
public INumericalAbstractDomain <Variable, Expression> RemoveRedundanciesWith( INumericalAbstractDomain <Variable, Expression> oracle) { var result = new SimpleDisequalities <Variable, Expression>(decoder, encoder); if (encoder != null) { foreach (var x_pair in Elements) { SetOfConstraints <Rational> k = x_pair.Value; if (k.IsBottom || k.IsTop) { result[x_pair.Key] = k; } else { Expression xExp = encoder.VariableFor(x_pair.Key); foreach (Rational exp in k.Values) { Expression notEq = encoder.CompoundExpressionFor(ExpressionType.Bool, ExpressionOperator.NotEqual, xExp, exp.ToExpression(encoder)); FlatAbstractDomain <bool> check = oracle.CheckIfHolds(notEq); if (check.IsBottom || check.IsTop || !check.BoxedElement) { // If it is not implied by the oracle, we give up result = result.TestTrue(notEq); } } } } } return(result); }
public override FlatAbstractDomain <bool> VisitNotEqual(Expression left, Expression right, Expression original, FlatAbstractDomain <bool> data) { // Special case for the special semantics of NaN if (left.Equals(right) && !this.Decoder.IsNaN(left) && !this.Decoder.IsNaN(right)) { return(CheckOutcome.False); } var direct = base.VisitNotEqual(left, right, original, data); if (direct.IsNormal()) { return(direct); } var leftDis = Domain.Eval(left); var rightDis = Domain.Eval(right); if (leftDis.Meet(rightDis).IsBottom) { return(CheckOutcome.True); } return(CheckOutcome.Top); }
protected override string ToLogicalFormula(Variable d, FlatAbstractDomain <ConcreteFloat> c) { return(""); }
/// <summary> /// left % right != 0 ?? /// </summary> public override FlatAbstractDomain <bool> VisitModulus(Expression left, Expression right, Expression original, FlatAbstractDomain <bool> data) { // We do not check if left == k * right, for some k return(IsNotZero(left)); }
/// <summary> /// left / right != 0 ?? /// </summary> public override FlatAbstractDomain <bool> VisitDivision(Expression left, Expression right, Expression original, FlatAbstractDomain <bool> data) { return(IsNotZero(left)); }
public override FlatAbstractDomain <bool> VisitLessThan(Expression left, Expression right, Expression original, FlatAbstractDomain <bool> data) { return(Domain.CheckIfLessThan(left, right)); }
public override FlatAbstractDomain <bool> VisitEqual_Obj(Expression left, Expression right, Expression original, FlatAbstractDomain <bool> data) { return(VisitEqual(left, right, original, data)); }