public ProgramState SetConstraint(SymbolicValue symbolicValue, SymbolicValueConstraint constraint) { if (constraint == null) { return(this); } var updatedConstraintsMap = Constraints.AddConstraintForSymbolicValue(symbolicValue, constraint); updatedConstraintsMap = updatedConstraintsMap.AddConstraintTo <EqualsRelationship>(symbolicValue, constraint, this); if (constraint is BoolConstraint) { updatedConstraintsMap = updatedConstraintsMap.AddConstraintTo <NotEqualsRelationship>(symbolicValue, constraint.OppositeForLogicalNot, this); } return(new ProgramState( Values, updatedConstraintsMap, ProgramPointVisitCounts, ExpressionStack, Relationships)); }
public virtual IEnumerable <ProgramState> TrySetConstraint(SymbolicValueConstraint constraint, ProgramState programState) { if (constraint == null) { return(new[] { programState }); } if (!programState.Constraints.TryGetValue(this, out var oldConstraints)) { return(new[] { programState.SetConstraint(this, constraint) }); } if (constraint is BoolConstraint boolConstraint) { return(TrySetBoolConstraint(boolConstraint, oldConstraints, programState)); } if (constraint is ObjectConstraint objectConstraint) { return(TrySetObjectConstraint(objectConstraint, oldConstraints, programState)); } if (constraint is NullableValueConstraint || constraint is DisposableConstraint || constraint is CollectionCapacityConstraint) { return(new[] { programState }); } throw new NotSupportedException($"Neither one of {nameof(BoolConstraint)}, {nameof(ObjectConstraint)}, " + $"{nameof(ObjectConstraint)}, {nameof(DisposableConstraint)}, {nameof(CollectionCapacityConstraint)}."); }
public bool HasConstraint(SymbolicValue symbolicValue, SymbolicValueConstraint constraint) { SymbolicValueConstraints constraints; return(Constraints.TryGetValue(symbolicValue, out constraints) && constraints.HasConstraint(constraint)); }
public static bool HasConstraint(this ISymbol symbol, SymbolicValueConstraint constraint, ProgramState programState) { var symbolicValue = programState.GetSymbolValue(symbol); if (symbolicValue == null) { return(false); } return(programState.HasConstraint(symbolicValue, constraint)); }
public static ProgramState RemoveConstraint(this ISymbol symbol, SymbolicValueConstraint constraint, ProgramState programState) { var symbolicValue = programState.GetSymbolValue(symbol); if (symbolicValue == null || !programState.HasConstraint(symbolicValue, constraint)) { return(programState); } return(programState.RemoveConstraint(symbolicValue, constraint)); }
public ProgramState RemoveConstraint(SymbolicValue symbolicValue, SymbolicValueConstraint constraint) { if (constraint == null) { return(this); } var updatedConstraintsMap = Constraints.RemoveConstraintForSymbolicValue(symbolicValue, constraint); return(new ProgramState( Values, updatedConstraintsMap, ProgramPointVisitCounts, ExpressionStack, Relationships)); }
public virtual IEnumerable <ProgramState> TrySetConstraint(SymbolicValueConstraint constraint, ProgramState programState) { if (constraint == null) { return(new[] { programState }); } // This condition is added first because the way of setting string constraints // when the value doesnt exist is different than the other types of constraints if (constraint is StringConstraint stringConstraint) { return(TrySetStringConstraint(stringConstraint, programState)); } if (!programState.Constraints.TryGetValue(this, out var oldConstraints)) { return(new[] { programState.SetConstraint(this, constraint) }); } if (constraint is BoolConstraint boolConstraint) { return(TrySetBoolConstraint(boolConstraint, oldConstraints, programState)); } if (constraint is ObjectConstraint objectConstraint) { return(TrySetObjectConstraint(objectConstraint, oldConstraints, programState)); } if (constraint is NullableValueConstraint || constraint is DisposableConstraint || constraint is CollectionCapacityConstraint || constraint is SerializationConstraint) { return(new[] { programState }); } throw new NotSupportedException($"Neither one of {nameof(BoolConstraint)}, {nameof(ObjectConstraint)}, " + $"{nameof(ObjectConstraint)}, {nameof(DisposableConstraint)}, {nameof(CollectionCapacityConstraint)}," + $"{nameof(StringConstraint)} or {nameof(SerializationConstraint)}."); }
public virtual IEnumerable <ProgramState> TrySetOppositeConstraint(SymbolicValueConstraint constraint, ProgramState programState) { return(TrySetConstraint(constraint?.OppositeForLogicalNot, programState)); }