private IEnumerable <ProgramState> TrySetConstraint(ObjectConstraint objectConstraint,
                                                            SymbolicValueConstraints oldConstraints, ProgramState currentProgramState)
        {
            var oldBoolConstraint = oldConstraints.GetConstraintOrDefault <BoolConstraint>();

            if (oldBoolConstraint != null)
            {
                if (objectConstraint == ObjectConstraint.Null)
                {
                    return(Enumerable.Empty <ProgramState>());
                }

                return(new[] { currentProgramState });
            }

            var oldObjectConstraint = oldConstraints.GetConstraintOrDefault <ObjectConstraint>();

            if (oldObjectConstraint != null)
            {
                if (oldObjectConstraint != objectConstraint)
                {
                    return(Enumerable.Empty <ProgramState>());
                }

                return(new[] { SetConstraint(objectConstraint, currentProgramState) });
            }

            throw new NotSupportedException($"Neither {nameof(BoolConstraint)}, nor {nameof(ObjectConstraint)}");
        }
        private ImmutableDictionary <SymbolicValue, SymbolicValueConstraints> AddConstraintForSymbolicValue(SymbolicValue symbolicValue,
                                                                                                            SymbolicValueConstraint constraint, ImmutableDictionary <SymbolicValue, SymbolicValueConstraints> constraintMap)
        {
            var constraints = constraintMap.GetValueOrDefault(symbolicValue);

            var updatedConstraints = constraints != null
                ? constraints.WithConstraint(constraint)
                : SymbolicValueConstraints.Create(constraint);

            return(constraintMap.SetItem(symbolicValue, updatedConstraints));
        }
        internal override IEnumerable <ProgramState> SetConstraint(BoolConstraint boolConstraint,
                                                                   SymbolicValueConstraints leftConstraints, SymbolicValueConstraints rightConstraints,
                                                                   ProgramState programState)
        {
            if (boolConstraint == BoolConstraint.False)
            {
                return(RightOperand.TrySetConstraints(leftConstraints, programState)
                       .SelectMany(ps => LeftOperand.TrySetConstraints(rightConstraints, ps)));
            }

            return(RightOperand.TrySetOppositeConstraints(leftConstraints, programState)
                   .SelectMany(ps => LeftOperand.TrySetOppositeConstraints(rightConstraints, ps)));
        }
        private IEnumerable <ProgramState> TrySetConstraint(BoolConstraint boolConstraint,
                                                            SymbolicValueConstraints oldConstraints, ProgramState currentProgramState)
        {
            if (oldConstraints.HasConstraint(ObjectConstraint.Null))
            {
                // It was null, and now it should be true or false
                return(Enumerable.Empty <ProgramState>());
            }

            var oldBoolConstraint = oldConstraints.GetConstraintOrDefault <BoolConstraint>();

            if (oldBoolConstraint != null &&
                oldBoolConstraint != boolConstraint)
            {
                return(Enumerable.Empty <ProgramState>());
            }

            // Either same bool constraint, or previously not null, and now a bool constraint
            return(new[] { SetConstraint(boolConstraint, currentProgramState) });
        }
        private IEnumerable <ProgramState> TrySetConstraints(SymbolicValueConstraints constraints,
                                                             ProgramState programState, bool isOppositeConstraints)
        {
            IEnumerable <ProgramState> programStates = new [] { programState };

            if (constraints == null)
            {
                return(programStates);
            }

            foreach (var constraint in constraints.GetConstraints())
            {
                programStates = programStates.SelectMany(ps =>
                                                         isOppositeConstraints
                    ? TrySetOppositeConstraint(constraint, ps)
                    : TrySetConstraint(constraint, ps));
            }

            return(programStates);
        }
 public IEnumerable <ProgramState> TrySetOppositeConstraints(SymbolicValueConstraints constraints,
                                                             ProgramState programState)
 {
     return(TrySetConstraints(constraints, programState, true));
 }
 public bool TryGetConstraints(ProgramState programState, out SymbolicValueConstraints constraints)
 {
     return(programState.Constraints.TryGetValue(this, out constraints));
 }
Exemple #8
0
 internal abstract IEnumerable <ProgramState> SetConstraint(BoolConstraint boolConstraint,
                                                            SymbolicValueConstraints leftConstraints, SymbolicValueConstraints rightConstraints,
                                                            ProgramState programState);