public override IEnumerable<ProgramState> TrySetConstraint(SymbolicValueConstraint constraint, ProgramState currentProgramState)
        {
            var boolConstraint = constraint as BoolConstraint;
            if (boolConstraint == null)
            {
                return new[] { currentProgramState };
            }

            SymbolicValueConstraint oldConstraint;
            if (TryGetConstraint(currentProgramState, out oldConstraint) &&
                oldConstraint != constraint)
            {
                return Enumerable.Empty<ProgramState>();
            }

            SymbolicValueConstraint leftConstraint;
            var leftHasConstraint = leftOperand.TryGetConstraint(currentProgramState, out leftConstraint);
            SymbolicValueConstraint rightConstraint;
            var rightHasConstraint = rightOperand.TryGetConstraint(currentProgramState, out rightConstraint);

            var relationship = GetRelationship(boolConstraint);

            var newProgramState = currentProgramState.TrySetRelationship(relationship);
            if (newProgramState == null)
            {
                return Enumerable.Empty<ProgramState>();
            }

            if (!rightHasConstraint && !leftHasConstraint)
            {
                return new[] { newProgramState };
            }

            return SetConstraint(boolConstraint, leftConstraint, rightConstraint, newProgramState);
        }
        public override IEnumerable<ProgramState> TrySetConstraint(SymbolicValueConstraint constraint, ProgramState currentProgramState)
        {
            var boolConstraint = constraint as BoolConstraint;
            if (boolConstraint == null)
            {
                return new[] { currentProgramState };
            }

            return Operand.TrySetConstraint(boolConstraint.OppositeForLogicalNot, currentProgramState);
        }
Beispiel #3
0
        public override IEnumerable <ProgramState> TrySetConstraint(SymbolicValueConstraint constraint, ProgramState currentProgramState)
        {
            var boolConstraint = constraint as BoolConstraint;

            if (boolConstraint == null)
            {
                return(new[] { currentProgramState });
            }

            return(Operand.TrySetConstraint(boolConstraint.OppositeForLogicalNot, currentProgramState));
        }
        internal override IEnumerable<ProgramState> SetConstraint(BoolConstraint boolConstraint,
            SymbolicValueConstraint leftConstraint, SymbolicValueConstraint rightConstraint,
            ProgramState programState)
        {
            if (boolConstraint == BoolConstraint.False)
            {
                return rightOperand.TrySetConstraint(leftConstraint, programState)
                    .SelectMany(ps => leftOperand.TrySetConstraint(rightConstraint, ps));
            }

            return rightOperand.TrySetConstraint(leftConstraint?.OppositeForLogicalNot, programState)
                .SelectMany(ps => leftOperand.TrySetConstraint(rightConstraint?.OppositeForLogicalNot, ps));
        }
Beispiel #5
0
        internal override IEnumerable <ProgramState> SetConstraint(BoolConstraint boolConstraint,
                                                                   SymbolicValueConstraint leftConstraint, SymbolicValueConstraint rightConstraint,
                                                                   ProgramState programState)
        {
            if (boolConstraint == BoolConstraint.False)
            {
                return(rightOperand.TrySetConstraint(leftConstraint, programState)
                       .SelectMany(ps => leftOperand.TrySetConstraint(rightConstraint, ps)));
            }

            return(rightOperand.TrySetConstraint(leftConstraint?.OppositeForLogicalNot, programState)
                   .SelectMany(ps => leftOperand.TrySetConstraint(rightConstraint?.OppositeForLogicalNot, ps)));
        }
        public override IEnumerable<ProgramState> TrySetConstraint(SymbolicValueConstraint constraint, ProgramState currentProgramState)
        {
            var boolConstraint = constraint as BoolConstraint;
            if (boolConstraint == null)
            {
                return new[] { currentProgramState };
            }

            var relationship = GetRelationship(boolConstraint);

            var newProgramState = currentProgramState.TrySetRelationship(relationship);
            if (newProgramState == null)
            {
                return Enumerable.Empty<ProgramState>();
            }

            return new[] { newProgramState };
        }
        public override IEnumerable <ProgramState> TrySetConstraint(SymbolicValueConstraint constraint, ProgramState currentProgramState)
        {
            var boolConstraint = constraint as BoolConstraint;

            if (boolConstraint == null)
            {
                return(new[] { currentProgramState });
            }

            var relationship = GetRelationship(boolConstraint);

            var newProgramState = currentProgramState.TrySetRelationship(relationship);

            if (newProgramState == null)
            {
                return(Enumerable.Empty <ProgramState>());
            }

            return(new[] { newProgramState });
        }
        public override IEnumerable<ProgramState> TrySetConstraint(SymbolicValueConstraint constraint, ProgramState currentProgramState)
        {
            var boolConstraint = constraint as BoolConstraint;
            if (boolConstraint == null)
            {
                return new[] { currentProgramState };
            }

            if (boolConstraint == BoolConstraint.False)
            {
                return leftOperand.TrySetConstraint(BoolConstraint.False, currentProgramState)
                    .SelectMany(ps => rightOperand.TrySetConstraint(BoolConstraint.False, ps));
            }

            return leftOperand.TrySetConstraint(BoolConstraint.True, currentProgramState)
                    .SelectMany(ps => rightOperand.TrySetConstraint(BoolConstraint.False, ps))
                .Union(leftOperand.TrySetConstraint(BoolConstraint.False, currentProgramState)
                    .SelectMany(ps => rightOperand.TrySetConstraint(BoolConstraint.True, ps)))
                .Union(leftOperand.TrySetConstraint(BoolConstraint.True, currentProgramState)
                    .SelectMany(ps => rightOperand.TrySetConstraint(BoolConstraint.True, ps)));
        }
        public override IEnumerable <ProgramState> TrySetConstraint(SymbolicValueConstraint constraint, ProgramState currentProgramState)
        {
            var boolConstraint = constraint as BoolConstraint;

            if (boolConstraint == null)
            {
                return(new[] { currentProgramState });
            }

            if (boolConstraint == BoolConstraint.True)
            {
                return(leftOperand.TrySetConstraint(BoolConstraint.True, currentProgramState)
                       .SelectMany(ps => rightOperand.TrySetConstraint(BoolConstraint.True, ps)));
            }

            return(leftOperand.TrySetConstraint(BoolConstraint.True, currentProgramState)
                   .SelectMany(ps => rightOperand.TrySetConstraint(BoolConstraint.False, ps))
                   .Union(leftOperand.TrySetConstraint(BoolConstraint.False, currentProgramState)
                          .SelectMany(ps => rightOperand.TrySetConstraint(BoolConstraint.True, ps)))
                   .Union(leftOperand.TrySetConstraint(BoolConstraint.False, currentProgramState)
                          .SelectMany(ps => rightOperand.TrySetConstraint(BoolConstraint.False, ps))));
        }
Beispiel #10
0
        public override IEnumerable <ProgramState> TrySetConstraint(SymbolicValueConstraint constraint, ProgramState currentProgramState)
        {
            var boolConstraint = constraint as BoolConstraint;

            if (boolConstraint == null)
            {
                return(new[] { currentProgramState });
            }

            SymbolicValueConstraint oldConstraint;

            if (TryGetConstraint(currentProgramState, out oldConstraint) &&
                oldConstraint != constraint)
            {
                return(Enumerable.Empty <ProgramState>());
            }

            SymbolicValueConstraint leftConstraint;
            var leftHasConstraint = leftOperand.TryGetConstraint(currentProgramState, out leftConstraint);
            SymbolicValueConstraint rightConstraint;
            var rightHasConstraint = rightOperand.TryGetConstraint(currentProgramState, out rightConstraint);

            var relationship = GetRelationship(boolConstraint);

            var newProgramState = currentProgramState.TrySetRelationship(relationship);

            if (newProgramState == null)
            {
                return(Enumerable.Empty <ProgramState>());
            }

            if (!rightHasConstraint && !leftHasConstraint)
            {
                return(new[] { newProgramState });
            }

            return(SetConstraint(boolConstraint, leftConstraint, rightConstraint, newProgramState));
        }
        internal ProgramState SetConstraint(SymbolicValueConstraint constraint, ProgramState programState)
        {
            if (constraint == null)
            {
                return(programState);
            }

            var newConstraints = programState.Constraints.SetItem(this, constraint);

            newConstraints = AddConstraintTo <EqualsRelationship>(constraint, programState, newConstraints);

            if (constraint is BoolConstraint)
            {
                newConstraints = AddConstraintTo <NotEqualsRelationship>(constraint.OppositeForLogicalNot, programState, newConstraints);
            }

            return(new ProgramState(
                       programState.Values,
                       newConstraints,
                       programState.ProgramPointVisitCounts,
                       programState.ExpressionStack,
                       programState.Relationships));
        }
        private ImmutableDictionary <SymbolicValue, SymbolicValueConstraint> AddConstraintTo <TRelationship>(SymbolicValueConstraint constraint,
                                                                                                             ProgramState programState, ImmutableDictionary <SymbolicValue, SymbolicValueConstraint> constraints)
            where TRelationship : BinaryRelationship
        {
            var newConstraints = constraints;
            var equalSymbols   = programState.Relationships
                                 .OfType <TRelationship>()
                                 .Select(r => GetOtherOperandFromMatchingRelationship(r))
                                 .Where(e => e != null);

            foreach (var equalSymbol in equalSymbols.Where(e => !e.HasConstraint(constraint, programState)))
            {
                newConstraints = newConstraints.SetItem(equalSymbol, constraint);
            }

            return(newConstraints);
        }
Beispiel #13
0
 internal abstract IEnumerable <ProgramState> SetConstraint(BoolConstraint boolConstraint,
                                                            SymbolicValueConstraint leftConstraint, SymbolicValueConstraint rightConstraint,
                                                            ProgramState programState);
            public override IEnumerable<ProgramState> TrySetConstraint(SymbolicValueConstraint constraint, ProgramState currentProgramState)
            {
                var boolConstraint = constraint as BoolConstraint;
                if (boolConstraint == null)
                {
                    return new[] { currentProgramState };
                }

                var nullabilityConstraint = boolConstraint == BoolConstraint.True
                    ? ObjectConstraint.NotNull
                    : ObjectConstraint.Null;

                return MemberExpression.TrySetConstraint(nullabilityConstraint, currentProgramState);
            }
 internal abstract IEnumerable<ProgramState> SetConstraint(BoolConstraint boolConstraint,
     SymbolicValueConstraint leftConstraint, SymbolicValueConstraint rightConstraint,
     ProgramState programState);
        private IEnumerable <ProgramState> TrySetConstraint(ObjectConstraint objectConstraint, SymbolicValueConstraint oldConstraint,
                                                            ProgramState currentProgramState)
        {
            var oldBoolConstraint = oldConstraint as BoolConstraint;

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

                return(new[] { currentProgramState });
            }

            var oldObjectConstraint = oldConstraint as 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 IEnumerable <ProgramState> TrySetConstraint(BoolConstraint boolConstraint, SymbolicValueConstraint oldConstraint,
                                                            ProgramState currentProgramState)
        {
            if (oldConstraint == ObjectConstraint.Null)
            {
                // It was null, and now it should be true or false
                return(Enumerable.Empty <ProgramState>());
            }

            var oldBoolConstraint = oldConstraint as 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) });
        }
 public bool TryGetConstraint(ProgramState programState, out SymbolicValueConstraint constraint)
 {
     return(programState.Constraints.TryGetValue(this, out constraint));
 }
        public static ProgramState SetConstraint(this ISymbol symbol, SymbolicValueConstraint constraint, ProgramState programState)
        {
            var symbolicValue = programState.GetSymbolValue(symbol);
            if (symbolicValue == null ||
                symbolicValue.HasConstraint(constraint, programState))
            {
                return programState;
            }

            return symbolicValue.SetConstraint(constraint, programState);
        }
 public bool HasConstraint(SymbolicValueConstraint constraint, ProgramState programState)
 {
     return(programState.Constraints.ContainsKey(this) &&
            programState.Constraints[this].Implies(constraint));
 }
        public static bool HasConstraint(this ISymbol symbol, SymbolicValueConstraint constraint, ProgramState programState)
        {
            var symbolicValue = programState.GetSymbolValue(symbol);
            if (symbolicValue == null)
            {
                return false;
            }

            return symbolicValue.HasConstraint(constraint, programState);
        }