public ImmutableArray <BoolHandle> GetAssumptions()
                {
                    var refFieldHandles = this.fieldToVariableMap
                                          .Where(kvp => kvp.Key.IsReference())
                                          .Select(kvp => (ArrayHandle <IntHandle, IntHandle>)kvp.Value.Expression)
                                          .ToArray();

                    return(this.variableStates.Values
                           .Where(s => s.IsInput || s.IsInputDerived)
                           .Select((s) =>
                    {
                        // If there are no fields, only the object must be from the input heap
                        if (refFieldHandles.Length == 0)
                        {
                            if (s.CanBeNull)
                            {
                                return s.Representation <= VariableState.NullValue;
                            }
                            else
                            {
                                return s.Representation < VariableState.NullValue;
                            }
                        }

                        // Both the referenced object and all the objects referenced by it
                        // must be from the input heap (if not null)
                        var readConjuncts = new List <Expression>()
                        {
                            s.Representation < VariableState.NullValue
                        };

                        // TODO: Use only the fields present in the corresponding class
                        readConjuncts.AddRange(
                            refFieldHandles
                            .Select(h => (h.Select(s.Representation) <= VariableState.NullValue).Expression));

                        var readAnd = (BoolHandle)ExpressionFactory.And(readConjuncts.ToArray());

                        if (s.IsInputDerived)
                        {
                            return (s.Representation < VariableState.NullValue).Implies(readAnd);
                        }
                        else
                        {
                            if (s.CanBeNull)
                            {
                                return s.Representation == VariableState.NullValue || readAnd;
                            }
                            else
                            {
                                return readAnd;
                            }
                        }
                    })
                           .ToImmutableArray());
                }
Exemplo n.º 2
0
        public void And_SuccessfullyCreates_AndExpression_Test()
        {
            //Arrange
            var True          = _expressions.Bool(true);
            var TrueAndTrueEx = new And <IContext>(True, True);
            //Act
            var sut = _expressions.And(True, True);

            //Assert
            Assert.Equal(TrueAndTrueEx.Interpret(_context), sut.Interpret(_context));
        }
        /// <summary>
        /// 根据关键字段值列表创建表达式
        /// </summary>
        /// <param name="keyValue"></param>
        /// <param name="keyValues"></param>
        /// <returns></returns>
        protected IExpression GetKeysExpression(object keyValue, params object[] keyValues)
        {
            IExpression exp = ExpressionFactory.Eq(KeyItems[0].PropertyName, keyValue);;

            for (int i = 0; i < KeyItems.Count; i++)
            {
                if (exp == null)
                {
                    exp = ExpressionFactory.And(exp, ExpressionFactory.Eq(KeyItems[i].PropertyName, keyValues[i]));
                }
            }
            return(exp);
        }
Exemplo n.º 4
0
        public IInterpreter TraitFunctionCall()
        {
            var interpreter = new Interpreter.Interpreter();

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                    AllowInvalidMainResult = true,
                    DebugThrowOnError      = true
                }.SetMutability(mutability));
                var root_ns = env.Root;

                var main_func = root_ns.AddBuilder(FunctionBuilder.Create(
                                                       "main",
                                                       ExpressionReadMode.OptionalUse,
                                                       NameFactory.Int64NameReference(),
                                                       Block.CreateStatement(new IExpression[] {
                    // e &IEquatable = 3
                    VariableDeclaration.CreateStatement("e", NameFactory.ReferenceNameReference(NameFactory.IEquatableNameReference()),
                                                        Int64Literal.Create("3")),
                    // i Int = 7
                    VariableDeclaration.CreateStatement("i", NameFactory.Int64NameReference(), Int64Literal.Create("7")),
                    // if e!=i and i!=e then return 2
                    IfBranch.CreateIf(ExpressionFactory.And(ExpressionFactory.IsNotEqual("e", "i"), ExpressionFactory.IsNotEqual("e", "i")),
                                      new[] { Return.Create(Int64Literal.Create("2")) }),
                    // return 15
                    Return.Create(Int64Literal.Create("15"))
                })));

                ExecValue result = interpreter.TestRun(env);

                Assert.AreEqual(2L, result.RetValue.PlainValue);
            }

            return(interpreter);
        }
Exemplo n.º 5
0
 public static BoolHandle operator &(BoolHandle left, BoolHandle right)
 {
     return((BoolHandle)ExpressionFactory.And(left.Expression, right.Expression));
 }