예제 #1
0
        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)}");
        }
예제 #2
0
        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)));
        }
예제 #4
0
        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) });
        }
예제 #5
0
        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);
        }
예제 #6
0
 public IEnumerable <ProgramState> TrySetOppositeConstraints(SymbolicValueConstraints constraints,
                                                             ProgramState programState)
 {
     return(TrySetConstraints(constraints, programState, true));
 }
예제 #7
0
 public bool TryGetConstraints(ProgramState programState, out SymbolicValueConstraints constraints)
 {
     return(programState.Constraints.TryGetValue(this, out constraints));
 }
예제 #8
0
 internal abstract IEnumerable <ProgramState> SetConstraint(BoolConstraint boolConstraint,
                                                            SymbolicValueConstraints leftConstraints, SymbolicValueConstraints rightConstraints,
                                                            ProgramState programState);