예제 #1
0
        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));
        }
예제 #2
0
        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)}.");
        }
예제 #3
0
        public bool HasConstraint(SymbolicValue symbolicValue, SymbolicValueConstraint constraint)
        {
            SymbolicValueConstraints constraints;

            return(Constraints.TryGetValue(symbolicValue, out constraints) &&
                   constraints.HasConstraint(constraint));
        }
예제 #4
0
        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));
        }
예제 #5
0
        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));
        }
예제 #6
0
        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));
        }
예제 #7
0
        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)}.");
        }
예제 #8
0
 public virtual IEnumerable <ProgramState> TrySetOppositeConstraint(SymbolicValueConstraint constraint,
                                                                    ProgramState programState)
 {
     return(TrySetConstraint(constraint?.OppositeForLogicalNot, programState));
 }