Exemplo n.º 1
0
        public void ModelOperation(IModellingContext context, IMethodSymbol method, IEnumerable <ITypeModel> arguments)
        {
            Contract.Requires(context != null);
            Contract.Requires(method != null);
            Contract.Requires(arguments != null);
            Contract.Requires(arguments.Count() == method.Parameters.Length);

            if (method.MethodKind != MethodKind.BuiltinOperator ||
                method.Parameters.Length == 0 ||
                !this.IsTypeSupported(method.ReturnType))
            {
                // This might be the case of static methods etc.
                context.SetUnsupported();
                return;
            }

            BoolHandle boolResult = GetOperationResult(method, arguments);

            if (boolResult.Expression != null)
            {
                Contract.Assert(this.IsTypeSupported(method.ReturnType));
                var resultModel = new BooleanModel(this, method.ReturnType, boolResult);

                context.SetResultValue(resultModel);
            }
            else
            {
                context.SetUnsupported();
            }
        }
Exemplo n.º 2
0
        internal BooleanModel(BooleanModelFactory factory, ITypeSymbol type, BoolHandle value)
        {
            Contract.Requires <ArgumentNullException>(factory != null, nameof(factory));
            Contract.Requires <ArgumentException>(value.Expression != null, nameof(value));

            this.Factory = factory;
            this.Type    = type;
            this.Value   = value;
        }
Exemplo n.º 3
0
        internal InnerFlowEdge(InnerFlowEdgeId id, FlowNode from, FlowNode to, BoolHandle condition)
            : base(from, to)
        {
            Contract.Requires(id.IsValid);
            Contract.Requires(from.Graph == to.Graph);
            Contract.Requires(condition.Expression != null);

            this.Graph     = from.Graph;
            this.Id        = id;
            this.Condition = condition;
        }
Exemplo n.º 4
0
        public InnerFlowEdge AddEdge(FlowNode from, FlowNode to, BoolHandle condition)
        {
            Contract.Requires <InvalidOperationException>(this.Graph != null);
            Contract.Requires <ArgumentNullException>(from != null, nameof(from));
            Contract.Requires <ArgumentNullException>(to != null, nameof(to));
            Contract.Requires <ArgumentException>(from.Graph == this.Graph, nameof(from));
            Contract.Requires <ArgumentException>(to.Graph == this.Graph, nameof(to));

            var edgeId = this.edgeIdProvider.GenerateNewId();
            var edge   = new InnerFlowEdge(edgeId, from, to, condition);

            this.Graph.MutableEdges.Add(edge);
            Contract.Assert(edgeId.Value == this.Graph.MutableEdges.IndexOf(edge));

            edge.From.MutableOutgoingEdges.Add(edge);
            edge.To.MutableIngoingEdges.Add(edge);

            return(edge);
        }
Exemplo n.º 5
0
        public void InterpretationConstructedProperly()
        {
            var trueVal = new BoolHandle(true);

            ExpressionTestHelper.CheckExpression(
                trueVal.Expression,
                ExpressionKind.Interpretation,
                Sort.Bool,
                true.ToString(),
                0);
            Assert.AreEqual(ExpressionFactory.True, trueVal.Expression);

            BoolHandle falseVal = false;

            ExpressionTestHelper.CheckExpression(
                falseVal.Expression,
                ExpressionKind.Interpretation,
                Sort.Bool,
                false.ToString(),
                0);
            Assert.AreEqual(ExpressionFactory.False, falseVal.Expression);
        }
Exemplo n.º 6
0
        private void GetOperationResult(
            IModellingContext context,
            IMethodSymbol method,
            IEnumerable <ITypeModel> arguments,
            out IntHandle intResult,
            out BoolHandle boolResult)
        {
            var first = ((IntegerModel)arguments.First()).Value;

            if (method.Parameters.Length == 1)
            {
                if (method.Name == "op_UnaryNegation")
                {
                    intResult = -first;
                }
                else if (method.Name == "op_UnaryPlus")
                {
                    intResult = first;
                }
            }
            else
            {
                Contract.Assert(method.Parameters.Length == 2);
                var second = ((IntegerModel)arguments.ElementAt(1)).Value;

                if (BooleanModelFactory.Instance.IsTypeSupported(method.ReturnType))
                {
                    switch (method.Name)
                    {
                    case "op_Equality":
                        boolResult = (first == second);
                        break;

                    case "op_Inequality":
                        boolResult = (first != second);
                        break;

                    case "op_GreaterThan":
                        boolResult = (first > second);
                        break;

                    case "op_LessThan":
                        boolResult = (first < second);
                        break;

                    case "op_GreaterThanOrEqual":
                        boolResult = (first >= second);
                        break;

                    case "op_LessThanOrEqual":
                        boolResult = (first <= second);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    Contract.Assert(this.IsTypeSupported(method.ReturnType));

                    switch (method.Name)
                    {
                    case "op_Addition":
                        intResult = first + second;
                        break;

                    case "op_Subtraction":
                        intResult = first - second;
                        break;

                    case "op_Division":
                        // TODO: Set the exception if the right is zero
                        intResult = first / second;
                        break;

                    case "op_Modulus":
                        intResult = first % second;
                        break;

                    case "op_Multiply":
                        intResult = first * second;
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Exemplo n.º 7
0
 public BoolHandleTest()
 {
     this.a = (BoolHandle)ExpressionFactory.NamedVariable(Sort.Bool, "a");
     this.b = (BoolHandle)ExpressionFactory.NamedVariable(Sort.Bool, "b");
     this.c = (BoolHandle)ExpressionFactory.NamedVariable(Sort.Bool, "c");
 }
Exemplo n.º 8
0
 public ArrayHandleTest()
 {
     this.a = (ArrayHandle <IntHandle, BoolHandle>)ExpressionFactory.NamedVariable(arraySort, "a");
     this.k = (IntHandle)ExpressionFactory.NamedVariable(Sort.Int, "k");
     this.v = (BoolHandle)ExpressionFactory.NamedVariable(Sort.Bool, "v");
 }
 protected override void OnConditionAsserted(BoolHandle condition)
 {
     this.smtSolver.AddAssertion(this.NameProvider, condition);
 }
Exemplo n.º 10
0
 public void AddAssertion(BoolHandle assertion)
 {
     this.owner.smtSolver.AddAssertion(this.owner.pathConditionHandler.NameProvider, assertion);
 }
Exemplo n.º 11
0
 public void AddExceptionThrow(BoolHandle condition, Type exceptionType)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 12
0
        public void AddAssertion <TVariable>(INameProvider <TVariable> varNameProvider, BoolHandle assertion)
            where TVariable : Variable
        {
            // It is expected to be reused by multiple solvers
            var converter = this.context.ExpressionConverter;

            var expr = (BoolExpr)converter.Convert(assertion, varNameProvider);

            this.solver.Assert(expr);
        }
Exemplo n.º 13
0
 public void AddAssertion(BoolHandle assertion) => this.AddAssertion((INameProvider <Variable>)null, assertion);
Exemplo n.º 14
0
 public bool GetValue(BoolHandle handle)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
 internal BooleanValueModel(BooleanModelFactory factory, ITypeSymbol type, BoolHandle value)
     : base(factory, type, value)
 {
     Contract.Requires(value.Expression.Kind == ExpressionKind.Interpretation);
 }