Exemple #1
0
 internal Bpl.Expr BplBvLiteralExpr(Bpl.IToken tok, BaseTypes.BigNum n, int width)
 {
     Contract.Requires(tok != null);
     Contract.Requires(0 <= width);
     if (width == 0)
     {
         // see comment in BplBvType
         Contract.Assert(n.IsZero);
         return(Bpl.Expr.Literal(0));
     }
     else if (n.IsNegative)
     {
         // This can only happen if some error is reported elsewhere. Nevertheless, we do need to
         // generate a Boogie expression and Boogie would crash if we pass a negative number to
         // Bpl.LiteralExpr for a bitvector.
         var zero  = new Bpl.LiteralExpr(tok, BaseTypes.BigNum.ZERO, width);
         var absN  = new Bpl.LiteralExpr(tok, -n, width);
         var etran = new ExpressionTranslator(this, predef, tok);
         return(etran.TrToFunctionCall(tok, "sub_bv" + width, BplBvType(width), zero, absN, false));
     }
     else
     {
         return(new Bpl.LiteralExpr(tok, n, width));
     }
 }
        public Bpl.AssignCmd createBoogieNavigationUpdateCmd(Sink sink)
        {
            // the block is a potential page changer
            List <Bpl.AssignLhs> lhs = new List <Bpl.AssignLhs>();
            List <Bpl.Expr>      rhs = new List <Bpl.Expr>();

            Bpl.Expr value = new Bpl.LiteralExpr(Bpl.Token.NoToken, false);
            rhs.Add(value);
            Bpl.SimpleAssignLhs assignee =
                new Bpl.SimpleAssignLhs(Bpl.Token.NoToken,
                                        new Bpl.IdentifierExpr(Bpl.Token.NoToken,
                                                               sink.FindOrCreateGlobalVariable(PhoneCodeHelper.BOOGIE_CONTINUE_ON_PAGE_VARIABLE, Bpl.Type.Bool)));
            lhs.Add(assignee);
            Bpl.AssignCmd assignCmd = new Bpl.AssignCmd(Bpl.Token.NoToken, lhs, rhs);
            return(assignCmd);
        }
        private void _PositiveBV(int decimalValue, int width, string expectedString)
        {
            Assert.IsTrue(decimalValue >= 0);
            var builder = GetSimpleBuilder();
            // Test both versions of the API
            var constants = new Microsoft.Boogie.LiteralExpr[] {
                builder.ConstantBV(decimalValue, width),
                builder.ConstantBV(new BigInteger(decimalValue), width)
            };

            foreach (var constant in constants)
            {
                Assert.AreEqual(expectedString, constant.ToString());
                CheckType(constant, t => t.IsBv);
                Assert.AreEqual(width, constant.asBvConst.Bits);
                Assert.AreEqual(width, constant.Type.BvBits);
                Assert.AreEqual(decimalValue, constant.asBvConst.Value.ToInt);
            }
        }
        public void _NegativeBV(int decimalValue, int width, string expectedString)
        {
            Assert.IsTrue(decimalValue <= 0);
            var builder = GetSimpleBuilder();
            // Test both versions of the API
            var constants = new Microsoft.Boogie.LiteralExpr[] {
                builder.ConstantBV(decimalValue, width),
                builder.ConstantBV(new BigInteger(decimalValue), width)
            };

            foreach (var constant in constants)
            {
                Assert.AreEqual(expectedString, constant.ToString());
                CheckType(constant, t => t.IsBv);
                Assert.AreEqual(width, constant.asBvConst.Bits);
                Assert.AreEqual(width, constant.Type.BvBits);

                // Compute decimal representation of two's complement bv
                var MaxValuePlusOne = BigInteger.Pow(2, width);
                var expectedValue   = (MaxValuePlusOne + decimalValue) % MaxValuePlusOne;

                Assert.AreEqual(expectedValue, constant.asBvConst.Value.ToBigInteger);
            }
        }
 public Bpl.AssignCmd createBoogieNavigationUpdateCmd(Sink sink) {
   // the block is a potential page changer
   List<Bpl.AssignLhs> lhs = new List<Bpl.AssignLhs>();
   List<Bpl.Expr> rhs = new List<Bpl.Expr>();
   Bpl.Expr value = new Bpl.LiteralExpr(Bpl.Token.NoToken, false);
   rhs.Add(value);
   Bpl.SimpleAssignLhs assignee =
     new Bpl.SimpleAssignLhs(Bpl.Token.NoToken,
                             new Bpl.IdentifierExpr(Bpl.Token.NoToken,
                                                    sink.FindOrCreateGlobalVariable(PhoneCodeHelper.BOOGIE_CONTINUE_ON_PAGE_VARIABLE, Bpl.Type.Bool)));
   lhs.Add(assignee);
   Bpl.AssignCmd assignCmd = new Bpl.AssignCmd(Bpl.Token.NoToken, lhs, rhs);
   return assignCmd;
 }