Пример #1
0
        ////////////////////////////////////////////////////////////////////////////////////
        //TODO: Old semantics - go to arguments?
        private Expression makeExpression(BvConcatExpr bce, bool old)
        {
            var arguments = new ExpressionList(makeExpression(bce.E0, old), makeExpression(bce.E1, old));

            return(new BoogieFunctionApplicationExpression(bce, BoogieBitVectorConcatenationFunction.make(bce),
                                                           arguments));
        }
Пример #2
0
        public void CachedHashCodeBvConcatExpr()
        {
            var literalBv = new LiteralExpr(Token.NoToken, Microsoft.BaseTypes.BigNum.FromInt(0), 4, /*immutable=*/ true);
            var bvConcat  = new BvConcatExpr(Token.NoToken, literalBv, literalBv, /*immutable=*/ true);

            Assert.AreEqual(bvConcat.ComputeHashCode(), bvConcat.GetHashCode());
        }
Пример #3
0
 public virtual BvConcatExpr VisitBvConcatExpr(BvConcatExpr node)
 {
     Contract.Requires(node != null);
     Contract.Ensures(Contract.Result <BvConcatExpr>() != null);
     node.E0 = this.VisitExpr(node.E0);
     node.E1 = this.VisitExpr(node.E1);
     return(node);
 }
Пример #4
0
 public void ProtectedBvConcatExprRhs()
 {
   var lhs = new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(0), 32, /*immutable=*/true);
   var rhs = new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(1), 32, /*immutable=*/true);
   var concat = new BvConcatExpr(Token.NoToken, lhs, rhs, /* immutable=*/true);
   Assert.IsTrue(concat.Immutable);
   Assert.Throws(typeof(InvalidOperationException), () => concat.E1 = lhs);
 }
Пример #5
0
        ////////////////////////////////////////////////////////////////////////////////////
        //TODO: Old semantics - go to arguments?
        private Term makeExpression(BvConcatExpr bce, bool old)
        {
            ExpressionList arguments = new ExpressionList();

            arguments.append(makeExpression(bce.E0, old));
            arguments.append(makeExpression(bce.E1, old));

            return(new Programs.Terms.Boogie.BoogieFunctionApplication(bce, new Logic.Boogie.BoogieFunction(new BoogieBitVectorConcatenation(bce)), arguments));
        }
Пример #6
0
    public void BVConcatExpr() {
      var bv1_8 = new LiteralExpr(Token.NoToken, BigNum.FromInt(1), 8);
      var bv2_8 = new LiteralExpr(Token.NoToken, BigNum.FromInt(2), 8);
      var A = new BvConcatExpr(Token.NoToken, bv1_8, bv2_8);
      var B = d.Visit(A);

      // The duplicator should ensure we get new BVConcatExprs
      Assert.AreNotSame(A, B);
    }
Пример #7
0
        public void ProtectedBvConcatExprRhs()
        {
            var lhs    = new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(0), 32, /*immutable=*/ true);
            var rhs    = new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(1), 32, /*immutable=*/ true);
            var concat = new BvConcatExpr(Token.NoToken, lhs, rhs, /* immutable=*/ true);

            Assert.IsTrue(concat.Immutable);
            concat.E1 = lhs; // Should throw
        }
Пример #8
0
        public void BVConcatExpr()
        {
            var bv1_8 = new LiteralExpr(Token.NoToken, BigNum.FromInt(1), 8);
            var bv2_8 = new LiteralExpr(Token.NoToken, BigNum.FromInt(2), 8);
            var A     = new BvConcatExpr(Token.NoToken, bv1_8, bv2_8);
            var B     = d.Visit(A);

            // The duplicator should ensure we get new BVConcatExprs
            Assert.AreNotSame(A, B);
        }
        public static BoogieBitVectorConcatenationFunction make(BvConcatExpr bce)
        {
            Debug.Assert(bce != null);
            Debug.Assert(bce.E0.Type.IsBv);
            Debug.Assert(bce.E1.Type.IsBv);
            int w0 = (bce.E0.Type as BvType).Bits;
            int w1 = (bce.E1.Type as BvType).Bits;

            return(new BoogieBitVectorConcatenationFunction(bce, w0, w1));
        }
Пример #10
0
        public override Expr VisitBvConcatExpr(BvConcatExpr node)
        {
            var MSBCopy = this.Visit(node.E0) as Expr;
            var LSBCopy = this.Visit(node.E1) as Expr;
            var newNode = Builder.BVCONCAT(MSBCopy, LSBCopy);

            Debug.Assert(MSBCopy != null);
            Debug.Assert(LSBCopy != null);
            Debug.Assert(newNode != null);
            return(newNode);
        }
Пример #11
0
 public Expr VisitBvConcatExpr(BvConcatExpr e)
 {
     TW.Write("(concat");
     PushIndent();
     PrintSeperator();
     PrintExpr(e.E0);
     PrintSeperator();
     PrintExpr(e.E1);
     PopIndent();
     PrintSeperator();
     TW.Write(")");
     return(e);
 }
Пример #12
0
        public static Expr GetChild(this BvConcatExpr e, int number)
        {
            switch (number)
            {
            case 0:
                return(e.E0);    // Most significant bytes

            case 1:
                return(e.E1);   // Least significant bytes

            default:
                throw new InvalidOperationException("BvConcat only has two children");
            }
        }
 private BoogieBitVectorConcatenationFunction(BvConcatExpr bce, int w0, int w1)
     : base(
         "++",//bce."++",//FunctionSymbol.ToString(),
         BitVectorType.makeBitVectorType(w0 + w1),
         new IType[2]
 {
     BitVectorType.makeBitVectorType(w0),
     BitVectorType.makeBitVectorType(w1)
 }
         )
 {
     boogieExpression = bce;
     this.w0          = w0;
     this.w1          = w1;
     typeArguments    = TypeTuple.make();
 }
Пример #14
0
        public static void SetChild(this BvConcatExpr e, int number, Expr NewChild)
        {
            switch (number)
            {
            case 0:
                e.E0 = NewChild;     // Most significant bytes
                return;

            case 1:
                e.E1 = NewChild;     // Least significant bytes
                return;

            default:
                throw new InvalidOperationException("BvConcat only has two children");
            }
        }
Пример #15
0
        public Expr BVCONCAT(Expr MSB, Expr LSB)
        {
            if (!MSB.Type.IsBv)
            {
                throw new ExprTypeCheckException("MSB must be BvType");
            }

            if (!LSB.Type.IsBv)
            {
                throw new ExprTypeCheckException("MSB must be BvType");
            }

            var result = new BvConcatExpr(Token.NoToken, MSB, LSB, Immutable);

            result.Type = result.ShallowType;
            return(result);
        }
Пример #16
0
        public void SimpleBVConcat()
        {
            var variable = new GlobalVariable(Token.NoToken, new TypedIdent(Token.NoToken, "foo", Microsoft.Boogie.Type.GetBvType(8)));
            var id       = new IdentifierExpr(Token.NoToken, variable);
            var constant = new LiteralExpr(Token.NoToken, BigNum.FromInt(5), 8); // 5bv8;
            var concat   = new BvConcatExpr(Token.NoToken, id, constant);

            // Don't trust the Boogie duplicator here. Do it ourselves
            var constant2 = new LiteralExpr(Token.NoToken, BigNum.FromInt(5), 8); // 5bv8;
            // We don't duplicate the variable because that is not an Expr and we require reference equality.
            var id2     = new IdentifierExpr(Token.NoToken, variable);
            var concat2 = new BvConcatExpr(Token.NoToken, id2, constant2);

            Assert.AreNotSame(concat, concat2);                           // These are different references

            Assert.IsTrue(concat.Equals(concat2));                        // These are "structurally equal"
            Assert.AreEqual(concat.GetHashCode(), concat2.GetHashCode()); // If the .Equals() is true then hash codes must be the same
        }
Пример #17
0
        public static Expr substituteForIdentifierExpr(Expr original, IdentifierExpr id, Expr replacement)
        {
            if (original is IdentifierExpr)
            {
                return(((original as IdentifierExpr).Name.Equals(id.Name)) ? replacement : original);
            }
            else if (original is LiteralExpr)
            {
                return(original);
            }
            else if (original is BvExtractExpr)
            {
                BvExtractExpr tmp = (original as BvExtractExpr);
                return(new BvExtractExpr(Token.NoToken, substituteForIdentifierExpr(tmp.Bitvector, id, replacement), tmp.End, tmp.Start));
            }
            else if (original is BvConcatExpr)
            {
                BvConcatExpr tmp = (original as BvConcatExpr);
                return(new BvConcatExpr(Token.NoToken,
                                        substituteForIdentifierExpr(tmp.E0, id, replacement),
                                        substituteForIdentifierExpr(tmp.E1, id, replacement)));
            }
            else if (original is NAryExpr)
            {
                NAryExpr    tmp      = (original as NAryExpr);
                List <Expr> new_args = new List <Expr>();
                foreach (Expr e in tmp.Args)
                {
                    new_args.Add(substituteForIdentifierExpr(e, id, replacement));
                }
                return(new NAryExpr(Token.NoToken, tmp.Fun, new_args));
            }

            Utils.Assert(false, "should not get here: " + original);
            return(original);
        }
Пример #18
0
 public override Expr VisitBvConcatExpr(BvConcatExpr node)
 {
     return(base.VisitBvConcatExpr((BvConcatExpr)node.Clone()));
 }
Пример #19
0
 public override Expr VisitBvConcatExpr(BvConcatExpr node)
 {
     Contract.Ensures(Contract.Result<Expr>() == node);
     this.VisitExpr(node.E0);
     this.VisitExpr(node.E1);
     return node;
 }
Пример #20
0
 public virtual Expr VisitBvConcatExpr(BvConcatExpr node) {
   Contract.Requires(node != null);
   Contract.Ensures(Contract.Result<Expr>() != null);
   node.E0 = this.VisitExpr(node.E0);
   node.E1 = this.VisitExpr(node.E1);
   return node;
 }
Пример #21
0
	void BvTerm(out Expr/*!*/ e0) {
		Contract.Ensures(Contract.ValueAtReturn(out e0) != null); IToken/*!*/ x; Expr/*!*/ e1; 
		Term(out e0);
		while (la.kind == 74) {
			Get();
			x = t; 
			Term(out e1);
			e0 = new BvConcatExpr(x, e0, e1); 
		}
	}
Пример #22
0
 public override Expr VisitBvConcatExpr(BvConcatExpr node) {
   // don't recurse on subexpression
   return node;
 }
Пример #23
0
 //not implemented exprs
 public override Expr VisitBvConcatExpr(BvConcatExpr node)
 {
     throw new NotImplementedException();
 }
Пример #24
0
 public void ProtectedBvConcatExprRhs()
 {
     var lhs = new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(0), 32, /*immutable=*/true);
     var rhs = new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(1), 32, /*immutable=*/true);
     var concat = new BvConcatExpr(Token.NoToken, lhs, rhs,/* immutable=*/true);
     Assert.IsTrue(concat.Immutable);
     concat.E1 = lhs; // Should throw
 }
Пример #25
0
 // BvConcatExpr
 public static int GetNumberOfChildren(this BvConcatExpr e)
 {
     return(2);
 }
Пример #26
0
 public override Expr VisitBvConcatExpr(BvConcatExpr node)
 {
     problematicNode = node;
     return(node);
 }
Пример #27
0
 public override Expr VisitBvConcatExpr (BvConcatExpr node) {
   Contract.Ensures(Contract.Result<Expr>() != null);
   return base.VisitBvConcatExpr((BvConcatExpr) node.Clone());
 }
Пример #28
0
 public void CachedHashCodeBvConcatExpr()
 {
     var literalBv = new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(0), 4, /*immutable=*/true);
     var bvConcat = new BvConcatExpr(Token.NoToken, literalBv, literalBv, /*immutable=*/true);
     Assert.AreEqual(bvConcat.ComputeHashCode(), bvConcat.GetHashCode());
 }
Пример #29
0
 public override Expr VisitBvConcatExpr(BvConcatExpr node)
 {
     Contract.Ensures(Contract.Result <Expr>() != null);
     return(base.VisitBvConcatExpr((BvConcatExpr)node.Clone()));
 }
Пример #30
0
        public static Node CreateFromExpr(Expr expr)
        {
            if (expr is NAryExpr)
            {
                NAryExpr nary = expr as NAryExpr;
                if (nary.Fun is IfThenElse)
                {
                    Node one    = CreateFromExpr(nary.Args[0]);
                    Node two    = CreateFromExpr(nary.Args[1]);
                    Node three  = CreateFromExpr(nary.Args[2]);
                    Node parent = new TernaryNode(nary.Fun.FunctionName, one, two, three);
                    one.parent   = parent;
                    two.parent   = parent;
                    three.parent = parent;
                    return(parent);
                }
                else if (nary.Fun is BinaryOperator)
                {
                    Node one    = CreateFromExpr(nary.Args[0]);
                    Node two    = CreateFromExpr(nary.Args[1]);
                    Node parent = new BinaryNode(nary.Fun.FunctionName, one, two);
                    one.parent = parent;
                    two.parent = parent;
                    return(parent);
                }
                else if (nary.Fun is UnaryOperator)
                {
                    Node      one    = CreateFromExpr(nary.Args[0]);
                    UnaryNode parent = new UnaryNode(nary.Fun.FunctionName, one);
                    one.parent = parent;
                    return(parent);
                }
                else if (nary.Fun is FunctionCall)
                {
                    FunctionCall call = nary.Fun as FunctionCall;
                    if (nary.Args.Count == 1)
                    {
                        Node      one    = CreateFromExpr(nary.Args[0]);
                        UnaryNode parent = new UnaryNode(nary.Fun.FunctionName, one);
                        one.parent = parent;
                        return(parent);
                    }
                    else if (nary.Args.Count == 2)
                    {
                        Node one    = CreateFromExpr(nary.Args[0]);
                        Node two    = CreateFromExpr(nary.Args[1]);
                        Node parent = new BinaryNode(call.FunctionName, one, two);
                        one.parent = parent;
                        two.parent = parent;
                        return(parent);
                    }
                    else
                    {
                        Print.ExitMessage("Unhandled number of arguments in Boogie function call with function: " + nary.Fun.FunctionName);
                    }
                }
                else if (nary.Fun is MapSelect)
                {
                    List <Expr> indices = new List <Expr>();
                    while (true)
                    {
                        NAryExpr nary2 = nary.Args[0] as NAryExpr;
                        Print.ConditionalExitMessage(nary.Args.Count == 2, "Map select has more than two arguments");
                        indices.Insert(0, nary.Args[1]);
                        if (nary2 == null)
                        {
                            break;
                        }
                        else
                        {
                            nary = nary2;
                        }
                    }

                    IdentifierExpr identifier = nary.Args[0] as IdentifierExpr;
                    Node           parent     = new MapSymbolNode(identifier.Name);
                    foreach (Expr index in indices)
                    {
                        Node child = CreateFromExpr(index);
                        parent.Children.Add(child);
                        child.parent = parent;
                    }

                    return(parent);
                }
                else
                {
                    Print.ExitMessage("Unhandled Nary expression: " + nary.Fun.GetType().ToString());
                }
            }
            else if (expr is IdentifierExpr)
            {
                IdentifierExpr identifier = expr as IdentifierExpr;
                return(new ScalarSymbolNode(identifier.Name, identifier.Type));
            }
            else if (expr is LiteralExpr)
            {
                LiteralExpr literal = expr as LiteralExpr;
                if (literal.Val is BvConst)
                {
                    BvConst bv = (BvConst)literal.Val;
                    return(new LiteralNode(new BitVector(bv)));
                }
                else if (literal.Val is BigNum)
                {
                    BigNum num = (BigNum)literal.Val;
                    return(new LiteralNode(new BitVector(num.ToInt)));
                }
                else if (literal.Val is bool)
                {
                    bool boolean = (bool)literal.Val;
                    if (boolean)
                    {
                        return(new LiteralNode(BitVector.True));
                    }
                    else
                    {
                        return(new LiteralNode(BitVector.False));
                    }
                }
                else
                {
                    Print.ExitMessage("Unhandled literal expression: " + literal.ToString());
                }
            }
            else if (expr is BvExtractExpr)
            {
                BvExtractExpr bvExtract = expr as BvExtractExpr;
                Node          child     = CreateFromExpr(bvExtract.Bitvector);
                Node          parent    = new BVExtractNode(child, bvExtract.End, bvExtract.Start);
                child.parent = parent;
                return(parent);
            }
            else if (expr is BvConcatExpr)
            {
                BvConcatExpr bvConcat = expr as BvConcatExpr;
                Node         one      = CreateFromExpr(bvConcat.E0);
                Node         two      = CreateFromExpr(bvConcat.E1);
                Node         parent   = new BVConcatenationNode(one, two);
                one.parent = parent;
                two.parent = parent;
                return(parent);
            }
            else if (expr is ForallExpr)
            {
                ForallExpr forall = expr as ForallExpr;
                Node       one    = CreateFromExpr(forall._Body);
                Node       parent = new ForAllNode(one);
                one.parent = parent;
                return(parent);
            }

            Print.ExitMessage("Unhandled expression tree: " + expr.ToString() + " " + expr.Type.ToString());
            return(null);
        }
Пример #31
0
    public void SimpleBVConcat() {
      var variable = new GlobalVariable(Token.NoToken, new TypedIdent(Token.NoToken, "foo", Microsoft.Boogie.Type.GetBvType(8)));
      var id = new IdentifierExpr(Token.NoToken, variable);
      var constant = new LiteralExpr(Token.NoToken, BigNum.FromInt(5), 8); // 5bv8;
      var concat = new BvConcatExpr(Token.NoToken, id, constant);

      // Don't trust the Boogie duplicator here. Do it ourselves
      var constant2 = new LiteralExpr(Token.NoToken, BigNum.FromInt(5), 8); // 5bv8;
      // We don't duplicate the variable because that is not an Expr and we require reference equality.
      var id2 = new IdentifierExpr(Token.NoToken, variable);
      var concat2 = new BvConcatExpr(Token.NoToken, id2, constant2);

      Assert.AreNotSame(concat, concat2); // These are different references

      Assert.IsTrue(concat.Equals(concat2)); // These are "structurally equal"
      Assert.AreEqual(concat.GetHashCode(), concat2.GetHashCode()); // If the .Equals() is true then hash codes must be the same
    }