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 override SimpleDisequalities <Variable, Expression> VisitEqual(Expression left, Expression right, Expression original, SimpleDisequalities <Variable, Expression> data) { evalConstant.Visit(right); Variable leftVar = Decoder.UnderlyingVariable(left); if (data.ContainsKey(leftVar) && data[leftVar].IsNormal() && evalConstant.HasValue) { foreach (Rational r in data[leftVar].Values) { // we know left != r, so we want that intvForRight != r if (r == evalConstant.Result) { return(data.Bottom); } } } evalConstant.Visit(left); Variable rightVar = Decoder.UnderlyingVariable(right); if (data.ContainsKey(rightVar) && data[rightVar].IsNormal() && evalConstant.HasValue) { foreach (Rational r in data[rightVar].Values) { // we know right != r, so we want that intvForLeft != r if (r == evalConstant.Result) { return(data.Bottom); } } } // At this point we know that we do not have simple contraddictions. // Now we can say that left and right have the same inequalities SetOfConstraints <Rational> unionOfConstraints = data[leftVar].Meet(data[rightVar]); if (!unionOfConstraints.IsTop) { data[leftVar] = unionOfConstraints; data[rightVar] = unionOfConstraints; } return(data); }
private static string SaltKey(Expression expression) { ConstantVisitor constantVisitor = new ConstantVisitor(); constantVisitor.Visit(expression); var saltKey = constantVisitor.ValueBuilder.ToString(); saltKey = $"{XxHashUnsafe.ComputeHash(saltKey):X}"; return(saltKey); }
public async Task Should_parameterize_value() { List <EntityDto> dtos; string username; using (var db = new ClientContext()) { username = "******"; var query = ProjectTo <EntityDto>(db.Entities, new { username }); dtos = await query.ToListAsync(); var constantVisitor = new ConstantVisitor(); constantVisitor.Visit(query.Expression); constantVisitor.HasConstant.ShouldBeFalse(); dtos.All(dto => dto.UserName == username).ShouldBeTrue(); username = "******"; query = ProjectTo <EntityDto>( db.Entities, new Dictionary <string, object> { { "username", username } } ); dtos = await query.ToListAsync(); constantVisitor = new ConstantVisitor(); constantVisitor.Visit(query.Expression); constantVisitor.HasConstant.ShouldBeTrue(); dtos.All(dto => dto.UserName == username).ShouldBeTrue(); username = "******"; query = db.Entities.Select( e => new EntityDto { Id = e.Id, Value = e.Value, UserName = username } ); dtos = await query.ToListAsync(); dtos.All(dto => dto.UserName == username).ShouldBeTrue(); constantVisitor = new ConstantVisitor(); constantVisitor.Visit(query.Expression); constantVisitor.HasConstant.ShouldBeFalse(); } }
/// <summary> /// Visits the children of the <see cref="T:System.Linq.Expressions.BinaryExpression"/>. /// </summary> /// <param name="node">The expression to visit.</param> /// <returns> /// The modified expression, if it or any subexpression was modified; otherwise, returns the original expression. /// </returns> protected override Expression VisitBinary(BinaryExpression node) { LeftPartVisitor lv=new LeftPartVisitor(); lv.Visit(node.Left); ConstantVisitor cv=new ConstantVisitor(); cv.Visit(node.Right); if(!cv.Visited) throw new ArgumentException("Cannot evaluate:"+node.Right); Action<Operation, object> setAction; if(_simplePropertySetters.TryGetValue(lv.Member.Name,out setAction)) { setAction.Invoke(TranslateOperation(node.NodeType),cv.Value); } return node; }