示例#1
0
 public override Microsoft.Boogie.Type VisitType(Microsoft.Boogie.Type node)
 {
     Log.Out(Log.Normal, "Type " + node);
     return(base.VisitType(node));
 }
示例#2
0
        public LinearDomain(Program program, string domainName, Type elementType)
        {
            this.elementType = elementType;
            this.axioms = new List<Axiom>();

            MapType mapTypeBool = new MapType(Token.NoToken, new List<TypeVariable>(), new List<Type> { this.elementType }, Type.Bool);
            MapType mapTypeInt = new MapType(Token.NoToken, new List<TypeVariable>(), new List<Type> { this.elementType }, Type.Int);
            this.mapOrBool = new Function(Token.NoToken, "linear_" + domainName + "_MapOr",
                                          new List<Variable> { new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "a", mapTypeBool), true),
                                                          new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "b", mapTypeBool), true) },
                                          new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "c", mapTypeBool), false));
            if (CommandLineOptions.Clo.UseArrayTheory)
            {
                this.mapOrBool.AddAttribute("builtin", "MapOr");
            }
            else
            {
                BoundVariable a = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "a", mapTypeBool));
                IdentifierExpr aie = new IdentifierExpr(Token.NoToken, a);
                BoundVariable b = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "b", mapTypeBool));
                IdentifierExpr bie = new IdentifierExpr(Token.NoToken, b);
                BoundVariable x = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "x", elementType));
                IdentifierExpr xie = new IdentifierExpr(Token.NoToken, x);
                var mapApplTerm = new NAryExpr(Token.NoToken, new FunctionCall(mapOrBool), new List<Expr> { aie, bie } );
                var lhsTerm = new NAryExpr(Token.NoToken, new MapSelect(Token.NoToken, 1), new List<Expr> { mapApplTerm, xie } );
                var rhsTerm = Expr.Binary(BinaryOperator.Opcode.Or,
                                          new NAryExpr(Token.NoToken, new MapSelect(Token.NoToken, 1), new List<Expr> { aie, xie } ),
                                          new NAryExpr(Token.NoToken, new MapSelect(Token.NoToken, 1), new List<Expr> { bie, xie} ));
                var axiomExpr = new ForallExpr(Token.NoToken, new List<TypeVariable>(), new List<Variable> { a, b }, null,
                                               new Trigger(Token.NoToken, true, new List<Expr> { mapApplTerm }),
                                               new ForallExpr(Token.NoToken, new List<Variable> { x }, Expr.Binary(BinaryOperator.Opcode.Eq, lhsTerm, rhsTerm)));
                axiomExpr.Typecheck(new TypecheckingContext(null));
                axioms.Add(new Axiom(Token.NoToken, axiomExpr));
            }

            this.mapImpBool = new Function(Token.NoToken, "linear_" + domainName + "_MapImp",
                                              new List<Variable> { new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "a", mapTypeBool), true),
                                                              new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "b", mapTypeBool), true) },
                                              new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "c", mapTypeBool), false));
            if (CommandLineOptions.Clo.UseArrayTheory)
            {
                this.mapImpBool.AddAttribute("builtin", "MapImp");
            }
            else
            {
                BoundVariable a = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "a", mapTypeBool));
                IdentifierExpr aie = new IdentifierExpr(Token.NoToken, a);
                BoundVariable b = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "b", mapTypeBool));
                IdentifierExpr bie = new IdentifierExpr(Token.NoToken, b);
                BoundVariable x = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "x", elementType));
                IdentifierExpr xie = new IdentifierExpr(Token.NoToken, x);
                var mapApplTerm = new NAryExpr(Token.NoToken, new FunctionCall(mapImpBool), new List<Expr> { aie, bie });
                var lhsTerm = new NAryExpr(Token.NoToken, new MapSelect(Token.NoToken, 1), new List<Expr> { mapApplTerm, xie });
                var rhsTerm = Expr.Binary(BinaryOperator.Opcode.Imp,
                                          new NAryExpr(Token.NoToken, new MapSelect(Token.NoToken, 1), new List<Expr> { aie, xie }),
                                          new NAryExpr(Token.NoToken, new MapSelect(Token.NoToken, 1), new List<Expr> { bie, xie }));
                var axiomExpr = new ForallExpr(Token.NoToken, new List<TypeVariable>(), new List<Variable> { a, b }, null,
                                               new Trigger(Token.NoToken, true, new List<Expr> { mapApplTerm }),
                                               new ForallExpr(Token.NoToken, new List<Variable> { x }, Expr.Binary(BinaryOperator.Opcode.Eq, lhsTerm, rhsTerm)));
                axiomExpr.Typecheck(new TypecheckingContext(null));
                axioms.Add(new Axiom(Token.NoToken, axiomExpr));
            }

            this.mapConstBool = new Function(Token.NoToken, "linear_" + domainName + "_MapConstBool",
                                              new List<Variable> { new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "b", Type.Bool), true) },
                                              new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "c", mapTypeBool), false));
            if (CommandLineOptions.Clo.UseArrayTheory)
            {
                this.mapConstBool.AddAttribute("builtin", "MapConst");
            }
            else
            {
                BoundVariable x = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "x", elementType));
                IdentifierExpr xie = new IdentifierExpr(Token.NoToken, x);
                var trueTerm = new NAryExpr(Token.NoToken, new MapSelect(Token.NoToken, 1),
                                           new List<Expr> { new NAryExpr(Token.NoToken, new FunctionCall(mapConstBool), new List<Expr> { Expr.True }), xie });
                var trueAxiomExpr = new ForallExpr(Token.NoToken, new List<Variable> { x }, trueTerm);
                trueAxiomExpr.Typecheck(new TypecheckingContext(null));
                axioms.Add(new Axiom(Token.NoToken, trueAxiomExpr));
                var falseTerm = new NAryExpr(Token.NoToken, new MapSelect(Token.NoToken, 1),
                                           new List<Expr> { new NAryExpr(Token.NoToken, new FunctionCall(mapConstBool), new List<Expr> { Expr.False }), xie });
                var falseAxiomExpr = new ForallExpr(Token.NoToken, new List<Variable> { x }, Expr.Unary(Token.NoToken, UnaryOperator.Opcode.Not, falseTerm));
                falseAxiomExpr.Typecheck(new TypecheckingContext(null));
                axioms.Add(new Axiom(Token.NoToken, falseAxiomExpr));
            }

            this.mapEqInt = new Function(Token.NoToken, "linear_" + domainName + "_MapEq",
                                              new List<Variable> { new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "a", mapTypeInt), true),
                                                              new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "b", mapTypeInt), true) },
                                              new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "c", mapTypeBool), false));
            if (CommandLineOptions.Clo.UseArrayTheory)
            {
                this.mapEqInt.AddAttribute("builtin", "MapEq");
            }
            else
            {
                BoundVariable a = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "a", mapTypeInt));
                IdentifierExpr aie = new IdentifierExpr(Token.NoToken, a);
                BoundVariable b = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "b", mapTypeInt));
                IdentifierExpr bie = new IdentifierExpr(Token.NoToken, b);
                BoundVariable x = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "x", elementType));
                IdentifierExpr xie = new IdentifierExpr(Token.NoToken, x);
                var mapApplTerm = new NAryExpr(Token.NoToken, new FunctionCall(mapEqInt), new List<Expr> { aie, bie });
                var lhsTerm = new NAryExpr(Token.NoToken, new MapSelect(Token.NoToken, 1), new List<Expr> { mapApplTerm, xie });
                var rhsTerm = Expr.Binary(BinaryOperator.Opcode.Eq,
                                          new NAryExpr(Token.NoToken, new MapSelect(Token.NoToken, 1), new List<Expr> { aie, xie }),
                                          new NAryExpr(Token.NoToken, new MapSelect(Token.NoToken, 1), new List<Expr> { bie, xie }));
                var axiomExpr = new ForallExpr(Token.NoToken, new List<TypeVariable>(), new List<Variable> { a, b }, null,
                                               new Trigger(Token.NoToken, true, new List<Expr> { mapApplTerm }),
                                               new ForallExpr(Token.NoToken, new List<Variable> { x }, Expr.Binary(BinaryOperator.Opcode.Eq, lhsTerm, rhsTerm)));
                axiomExpr.Typecheck(new TypecheckingContext(null));
                axioms.Add(new Axiom(Token.NoToken, axiomExpr));
            }

            this.mapConstInt = new Function(Token.NoToken, "linear_" + domainName + "_MapConstInt",
                                          new List<Variable> { new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "b", Type.Int), true) },
                                          new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "c", mapTypeInt), false));
            if (CommandLineOptions.Clo.UseArrayTheory)
            {
                this.mapConstInt.AddAttribute("builtin", "MapConst");
            }
            else
            {
                BoundVariable a = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "a", Type.Int));
                IdentifierExpr aie = new IdentifierExpr(Token.NoToken, a);
                BoundVariable x = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "x", elementType));
                IdentifierExpr xie = new IdentifierExpr(Token.NoToken, x);
                var lhsTerm = new NAryExpr(Token.NoToken, new MapSelect(Token.NoToken, 1), new List<Expr> { new NAryExpr(Token.NoToken, new FunctionCall(mapConstInt), new List<Expr> { aie }), xie });
                var axiomExpr = new ForallExpr(Token.NoToken, new List<Variable> { a, x }, Expr.Binary(BinaryOperator.Opcode.Eq, lhsTerm, aie));
                axiomExpr.Typecheck(new TypecheckingContext(null));
                axioms.Add(new Axiom(Token.NoToken, axiomExpr));
            }

            foreach (var axiom in axioms)
            {
                axiom.Expr.Resolve(new ResolutionContext(null));
                axiom.Expr.Typecheck(new TypecheckingContext(null));
            }
        }
 public Term ConstructValue(Term pureArg, Type boogieType)
 {
     arg          = pureArg;
     constructVal = true;
     return(Translate(boogieType));
 }
示例#4
0
        private void AddUpdateLocksetFunc(Microsoft.Boogie.Type type = null)
        {
            var str = "_UPDATE_CLS_$";

            var inParams  = new List <Variable>();
            var outParams = new List <Variable>();
            var in1       = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken,
                                                                            "lock", this.AC.MemoryModelType));
            var in2 = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken,
                                                                      "isLocked", Microsoft.Boogie.Type.Bool));

            if (type != null)
            {
                str += type.ToString() + "$";
                outParams.Add(new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken,
                                                                              "$r", type)));
            }

            inParams.Add(in1);
            inParams.Add(in2);

            Procedure proc = new Procedure(Token.NoToken,
                                           str + this.Thread.Name + "$" + this.Thread.Id,
                                           new List <TypeVariable>(), inParams, outParams,
                                           new List <Requires>(), new List <IdentifierExpr>(), new List <Ensures>());

            proc.AddAttribute("inline", new object[] { new LiteralExpr(Token.NoToken, BigNum.FromInt(1)) });

            foreach (var ls in this.AC.CurrentLocksets.Where(val => val.Thread.Equals(this.Thread)))
            {
                proc.Modifies.Add(new IdentifierExpr(ls.Id.tok, ls.Id));
            }

            this.AC.TopLevelDeclarations.Add(proc);
            this.AC.ResContext.AddProcedure(proc);

            Block b = new Block(Token.NoToken, "_UPDATE", new List <Cmd>(), new ReturnCmd(Token.NoToken));

            foreach (var ls in this.AC.CurrentLocksets.Where(val => val.Thread.Equals(this.Thread)))
            {
                List <AssignLhs> newLhss = new List <AssignLhs>();
                List <Expr>      newRhss = new List <Expr>();

                newLhss.Add(new SimpleAssignLhs(ls.Id.tok, new IdentifierExpr(ls.Id.tok, ls.Id)));
                newRhss.Add(new NAryExpr(Token.NoToken, new IfThenElse(Token.NoToken),
                                         new List <Expr>(new Expr[] { Expr.Eq(new IdentifierExpr(in1.tok, in1),
                                                                              new IdentifierExpr(ls.Lock.tok, ls.Lock)),
                                                                      new IdentifierExpr(in2.tok, in2), new IdentifierExpr(ls.Id.tok, ls.Id) })));

                var assign = new AssignCmd(Token.NoToken, newLhss, newRhss);
                b.Cmds.Add(assign);
            }

            Implementation impl = new Implementation(Token.NoToken,
                                                     str + this.Thread.Name + "$" + this.Thread.Id,
                                                     new List <TypeVariable>(), inParams, outParams,
                                                     new List <Variable>(), new List <Block>());

            if (type == Microsoft.Boogie.Type.Int)
            {
                var iVar = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken,
                                                                           "$i", type));
                var iVarId = new IdentifierExpr(Token.NoToken, iVar);
                impl.LocVars.Add(iVar);
                b.Cmds.Add(new HavocCmd(Token.NoToken, new List <IdentifierExpr> {
                    iVarId
                }));
                b.Cmds.Add(new AssignCmd(Token.NoToken,
                                         new List <AssignLhs> {
                    new SimpleAssignLhs(Token.NoToken,
                                        new IdentifierExpr(Token.NoToken, outParams[0]))
                },
                                         new List <Expr> {
                    iVarId
                }));
            }

            impl.Blocks.Add(b);
            impl.Proc = proc;
            impl.AddAttribute("inline", new object[] { new LiteralExpr(Token.NoToken, BigNum.FromInt(1)) });

            this.AC.TopLevelDeclarations.Add(impl);
        }
示例#5
0
 private IType makeType(Type type)
 {
     return(typeFactory.makeTypeI(type, new TypeFactory.Context()));
 }
示例#6
0
 static Bpl.Expr BplFormalVar(string name, Bpl.Type ty, bool incoming, List <Bpl.Variable> fvars)
 {
     Bpl.Expr e;
     fvars.Add(BplFormalVar(name, ty, incoming, out e));
     return(e);
 }
示例#7
0
 static Bpl.Expr BplLocalVar(string name, Bpl.Type ty, List <Bpl.Variable> lvars)
 {
     Bpl.Expr v;
     lvars.Add(BplLocalVar(name, ty, out v));
     return(v);
 }
示例#8
0
 public bool Initialize(Microsoft.Boogie.Type t)
 {
     return(Initialize(new Microsoft.Boogie.Type[Count].Stuff(t)));
 }
示例#9
0
 ////////////////////////////////////////////////////////////////////////////////////
 private IType makeType(Type type)
 {
     Debug.Assert(type != null);
     return(scope.typeFactory.makeTypeI(type, context)); //new TypeFactory.Context());
 }
 public Expr MakeZext(Expr expr, Microsoft.Boogie.Type resultType)
 {
     return(expr);
 }
示例#11
0
        // FIXME: move somewhere central
        public static Variable GetVariable(string name, BPLType type)
        {
            var v = new GlobalVariable(Token.NoToken, new TypedIdent(Token.NoToken, name, type));

            return(v);
        }
        private Expr MakeIntFunctionCall(string functionName, BinaryOperator.Opcode infixOp, Microsoft.Boogie.Type resultType, Expr lhs, Expr rhs)
        {
            Function f = verifier.GetOrCreateIntFunction(functionName, infixOp, resultType, lhs.Type, rhs.Type);
            var      e = new NAryExpr(Token.NoToken, new FunctionCall(f), new List <Expr> {
                lhs, rhs
            });

            e.Type = resultType;
            return(e);
        }
 private Expr MakeBitVectorUnaryBitVector(string suffix, string smtName, Expr expr, Microsoft.Boogie.Type resultType)
 {
     return(MakeBVFunctionCall("BV" + expr.Type.BvBits + "_" + suffix, smtName, resultType, expr));
 }
 public Term DestructValue(Term boogieValue, Type boogieType)
 {
     arg          = boogieValue;
     constructVal = false;
     return(Translate(boogieType));
 }
示例#15
0
 static Bpl.Expr BplBoundVar(string name, Bpl.Type ty, List <Bpl.Variable> bvars)
 {
     Bpl.Expr e;
     bvars.Add(BplBoundVar(name, ty, out e));
     return(e);
 }
示例#16
0
 /// <summary>
 /// Returns the (typed) BPL expression that corresponds to the value of the field
 /// <paramref name="f"/> belonging to the object <paramref name="o"/> (which must be non-null).
 /// </summary>
 /// <param name="o">The expression that represents the object to be dereferenced.
 /// </param>
 /// <param name="f">The field that is used to dereference the object <paramref name="o"/>.
 /// </param>
 public override Bpl.Expr ReadHeap(Bpl.Expr /*?*/ o, Bpl.Expr f, AccessType accessType, Bpl.Type unboxType)
 {
     if (accessType == AccessType.Struct || accessType == AccessType.Heap)
     {
         Bpl.IdentifierExpr field = f as Bpl.IdentifierExpr;
         Debug.Assert(field != null);
         return(Bpl.Expr.Select(field, o));
     }
     else
     {
         return(FromUnion(f.tok, unboxType, Bpl.Expr.Select(Bpl.Expr.Select(Bpl.Expr.Ident(ArrayContentsVariable), o), f), false));
     }
 }
示例#17
0
 // Makes a formal variable
 static Bpl.Formal BplFormalVar(string /*?*/ name, Bpl.Type ty, bool incoming)
 {
     Bpl.Expr _scratch;
     return(BplFormalVar(name, ty, incoming, out _scratch));
 }
示例#18
0
 /// <summary>
 /// Returns the BPL command that corresponds to assigning the value <paramref name="value"/>
 /// to the field <paramref name="f"/> of the object <paramref name="o"/> (which should be non-null).
 /// </summary>
 public override void WriteHeap(Bpl.IToken tok, Bpl.Expr /*?*/ o, Bpl.Expr f, Bpl.Expr value, AccessType accessType, Bpl.Type boxType, Bpl.StmtListBuilder builder)
 {
     Debug.Assert(o != null);
     Bpl.Cmd cmd;
     if (accessType == AccessType.Struct || accessType == AccessType.Heap)
     {
         Bpl.IdentifierExpr field = f as Bpl.IdentifierExpr;
         Debug.Assert(field != null);
         cmd = Bpl.Cmd.MapAssign(tok, field, o, value);
     }
     else
     {
         cmd = TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(ArrayContentsVariable), Bpl.Expr.Store(Bpl.Expr.Ident(ArrayContentsVariable), o, Bpl.Expr.Store(Bpl.Expr.Select(Bpl.Expr.Ident(ArrayContentsVariable), o), f, ToUnion(f.tok, boxType, value, false, builder))));
     }
     builder.Add(cmd);
 }
示例#19
0
        // The "typeInstantiation" argument is passed in to help construct the result type of the function.
        Bpl.NAryExpr FunctionCall(Bpl.IToken tok, BuiltinFunction f, Bpl.Type typeInstantiation, params Bpl.Expr[] args)
        {
            Contract.Requires(tok != null);
            Contract.Requires(args != null);
            Contract.Requires(predef != null);
            Contract.Ensures(Contract.Result <Bpl.NAryExpr>() != null);

            switch (f)
            {
            case BuiltinFunction.LitInt:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "LitInt", Bpl.Type.Int, args));

            case BuiltinFunction.LitReal:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "LitReal", Bpl.Type.Real, args));

            case BuiltinFunction.Lit:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "Lit", typeInstantiation, args));

            case BuiltinFunction.LayerSucc:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "$LS", predef.LayerType, args));

            case BuiltinFunction.AsFuelBottom:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "AsFuelBottom", predef.LayerType, args));

            case BuiltinFunction.CharFromInt:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "char#FromInt", predef.CharType, args));

            case BuiltinFunction.CharToInt:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "char#ToInt", predef.CharType, args));

            case BuiltinFunction.Is:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "$Is", Bpl.Type.Bool, args));

            case BuiltinFunction.IsBox:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "$IsBox", Bpl.Type.Bool, args));

            case BuiltinFunction.IsAlloc:
                Contract.Assert(args.Length == 3);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "$IsAlloc", Bpl.Type.Bool, args));

            case BuiltinFunction.IsAllocBox:
                Contract.Assert(args.Length == 3);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "$IsAllocBox", Bpl.Type.Bool, args));

            case BuiltinFunction.IsTraitParent:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "IsTraitParent", Bpl.Type.Bool, args));

            case BuiltinFunction.SetCard:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "Set#Card", Bpl.Type.Int, args));

            case BuiltinFunction.SetEmpty: {
                Contract.Assert(args.Length == 0);
                Contract.Assert(typeInstantiation != null);
                Bpl.Type resultType = predef.SetType(tok, true, typeInstantiation);
                return(Bpl.Expr.CoerceType(tok, FunctionCall(tok, "Set#Empty", resultType, args), resultType));
            }

            case BuiltinFunction.SetUnionOne:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "Set#UnionOne", predef.SetType(tok, true, typeInstantiation), args));

            case BuiltinFunction.SetUnion:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "Set#Union", predef.SetType(tok, true, typeInstantiation), args));

            case BuiltinFunction.SetIntersection:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "Set#Intersection", predef.SetType(tok, true, typeInstantiation), args));

            case BuiltinFunction.SetDifference:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "Set#Difference", predef.SetType(tok, true, typeInstantiation), args));

            case BuiltinFunction.SetEqual:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "Set#Equal", Bpl.Type.Bool, args));

            case BuiltinFunction.SetSubset:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "Set#Subset", Bpl.Type.Bool, args));

            case BuiltinFunction.SetDisjoint:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "Set#Disjoint", Bpl.Type.Bool, args));

            case BuiltinFunction.ISetEmpty: {
                Contract.Assert(args.Length == 0);
                Contract.Assert(typeInstantiation != null);
                Bpl.Type resultType = predef.SetType(tok, false, typeInstantiation);
                return(Bpl.Expr.CoerceType(tok, FunctionCall(tok, "ISet#Empty", resultType, args), resultType));
            }

            case BuiltinFunction.ISetUnionOne:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "ISet#UnionOne", predef.SetType(tok, false, typeInstantiation), args));

            case BuiltinFunction.ISetUnion:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "ISet#Union", predef.SetType(tok, false, typeInstantiation), args));

            case BuiltinFunction.ISetIntersection:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "ISet#Intersection", predef.SetType(tok, false, typeInstantiation), args));

            case BuiltinFunction.ISetDifference:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "ISet#Difference", predef.SetType(tok, false, typeInstantiation), args));

            case BuiltinFunction.ISetEqual:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "ISet#Equal", Bpl.Type.Bool, args));

            case BuiltinFunction.ISetSubset:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "ISet#Subset", Bpl.Type.Bool, args));

            case BuiltinFunction.ISetDisjoint:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "ISet#Disjoint", Bpl.Type.Bool, args));

            case BuiltinFunction.MultiSetCard:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "MultiSet#Card", Bpl.Type.Int, args));

            case BuiltinFunction.MultiSetEmpty: {
                Contract.Assert(args.Length == 0);
                Contract.Assert(typeInstantiation != null);
                Bpl.Type resultType = predef.MultiSetType(tok, typeInstantiation);
                return(Bpl.Expr.CoerceType(tok, FunctionCall(tok, "MultiSet#Empty", resultType, args), resultType));
            }

            case BuiltinFunction.MultiSetUnionOne:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "MultiSet#UnionOne", predef.MultiSetType(tok, typeInstantiation), args));

            case BuiltinFunction.MultiSetUnion:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "MultiSet#Union", predef.MultiSetType(tok, typeInstantiation), args));

            case BuiltinFunction.MultiSetIntersection:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "MultiSet#Intersection", predef.MultiSetType(tok, typeInstantiation), args));

            case BuiltinFunction.MultiSetDifference:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "MultiSet#Difference", predef.MultiSetType(tok, typeInstantiation), args));

            case BuiltinFunction.MultiSetEqual:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "MultiSet#Equal", Bpl.Type.Bool, args));

            case BuiltinFunction.MultiSetSubset:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "MultiSet#Subset", Bpl.Type.Bool, args));

            case BuiltinFunction.MultiSetDisjoint:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "MultiSet#Disjoint", Bpl.Type.Bool, args));

            case BuiltinFunction.MultiSetFromSet:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "MultiSet#FromSet", predef.MultiSetType(tok, typeInstantiation), args));

            case BuiltinFunction.MultiSetFromSeq:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "MultiSet#FromSeq", predef.MultiSetType(tok, typeInstantiation), args));

            case BuiltinFunction.IsGoodMultiSet:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "$IsGoodMultiSet", Bpl.Type.Bool, args));

            case BuiltinFunction.SeqLength:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "Seq#Length", Bpl.Type.Int, args));

            case BuiltinFunction.SeqEmpty: {
                Contract.Assert(args.Length == 0);
                Contract.Assert(typeInstantiation != null);
                Bpl.Type resultType = predef.SeqType(tok, typeInstantiation);
                return(Bpl.Expr.CoerceType(tok, FunctionCall(tok, "Seq#Empty", resultType, args), resultType));
            }

            case BuiltinFunction.SeqBuild:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "Seq#Build", predef.SeqType(tok, typeInstantiation), args));

            case BuiltinFunction.SeqAppend:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "Seq#Append", predef.SeqType(tok, typeInstantiation), args));

            case BuiltinFunction.SeqIndex:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "Seq#Index", typeInstantiation, args));

            case BuiltinFunction.SeqUpdate:
                Contract.Assert(args.Length == 3);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "Seq#Update", predef.SeqType(tok, typeInstantiation), args));

            case BuiltinFunction.SeqContains:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "Seq#Contains", Bpl.Type.Bool, args));

            case BuiltinFunction.SeqDrop:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "Seq#Drop", predef.SeqType(tok, typeInstantiation), args));

            case BuiltinFunction.SeqTake:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "Seq#Take", predef.SeqType(tok, typeInstantiation), args));

            case BuiltinFunction.SeqEqual:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "Seq#Equal", Bpl.Type.Bool, args));

            case BuiltinFunction.SeqSameUntil:
                Contract.Assert(args.Length == 3);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "Seq#SameUntil", Bpl.Type.Bool, args));

            case BuiltinFunction.SeqFromArray:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "Seq#FromArray", typeInstantiation, args));

            case BuiltinFunction.SeqRank:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "Seq#Rank", Bpl.Type.Int, args));

            case BuiltinFunction.MapEmpty: {
                Contract.Assert(args.Length == 0);
                Contract.Assert(typeInstantiation != null);
                Bpl.Type resultType = predef.MapType(tok, true, typeInstantiation, typeInstantiation); // use 'typeInstantiation' (which is really always just BoxType anyway) as both type arguments
                return(Bpl.Expr.CoerceType(tok, FunctionCall(tok, "Map#Empty", resultType, args), resultType));
            }

            case BuiltinFunction.MapCard:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "Map#Card", Bpl.Type.Int, args));

            case BuiltinFunction.MapDomain:
                Contract.Assert(args.Length == 1);
                return(FunctionCall(tok, "Map#Domain", typeInstantiation, args));

            case BuiltinFunction.MapElements:
                Contract.Assert(args.Length == 1);
                return(FunctionCall(tok, "Map#Elements", typeInstantiation, args));

            case BuiltinFunction.MapGlue:
                Contract.Assert(args.Length == 3);
                return(FunctionCall(tok, "Map#Glue", predef.MapType(tok, true, predef.BoxType, predef.BoxType), args));

            case BuiltinFunction.MapEqual:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "Map#Equal", Bpl.Type.Bool, args));

            case BuiltinFunction.MapDisjoint:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "Map#Disjoint", Bpl.Type.Bool, args));

            case BuiltinFunction.MapUnion:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "Map#Disjoint", typeInstantiation, args));

            case BuiltinFunction.IMapEmpty: {
                Contract.Assert(args.Length == 0);
                Contract.Assert(typeInstantiation != null);
                Bpl.Type resultType = predef.MapType(tok, false, typeInstantiation, typeInstantiation); // use 'typeInstantiation' (which is really always just BoxType anyway) as both type arguments
                return(Bpl.Expr.CoerceType(tok, FunctionCall(tok, "IMap#Empty", resultType, args), resultType));
            }

            case BuiltinFunction.IMapDomain:
                Contract.Assert(args.Length == 1);
                return(FunctionCall(tok, "IMap#Domain", typeInstantiation, args));

            case BuiltinFunction.IMapElements:
                Contract.Assert(args.Length == 1);
                return(FunctionCall(tok, "IMap#Elements", typeInstantiation, args));

            case BuiltinFunction.IMapGlue:
                Contract.Assert(args.Length == 3);
                return(FunctionCall(tok, "IMap#Glue", predef.MapType(tok, false, predef.BoxType, predef.BoxType), args));

            case BuiltinFunction.IMapEqual:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "IMap#Equal", Bpl.Type.Bool, args));

            case BuiltinFunction.IndexField:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "IndexField", predef.FieldName(tok, predef.BoxType), args));

            case BuiltinFunction.MultiIndexField:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "MultiIndexField", predef.FieldName(tok, predef.BoxType), args));

            case BuiltinFunction.Box:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "$Box", predef.BoxType, args));

            case BuiltinFunction.Unbox:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation != null);
                return(Bpl.Expr.CoerceType(tok, FunctionCall(tok, "$Unbox", typeInstantiation, args), typeInstantiation));

            case BuiltinFunction.RealToInt:
                Contract.Assume(args.Length == 1);
                Contract.Assume(typeInstantiation == null);
                return(FunctionCall(tok, "Int", Bpl.Type.Int, args));

            case BuiltinFunction.IntToReal:
                Contract.Assume(args.Length == 1);
                Contract.Assume(typeInstantiation == null);
                return(FunctionCall(tok, "Real", Bpl.Type.Real, args));

            case BuiltinFunction.IsGoodHeap:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "$IsGoodHeap", Bpl.Type.Bool, args));

            case BuiltinFunction.IsHeapAnchor:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "$IsHeapAnchor", Bpl.Type.Bool, args));

            case BuiltinFunction.HeapSucc:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "$HeapSucc", Bpl.Type.Bool, args));

            case BuiltinFunction.HeapSuccGhost:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "$HeapSuccGhost", Bpl.Type.Bool, args));

            case BuiltinFunction.DynamicType:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "dtype", predef.ClassNameType, args));

            case BuiltinFunction.TypeTuple:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "TypeTuple", predef.ClassNameType, args));

            case BuiltinFunction.DeclType:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "DeclType", predef.ClassNameType, args));

            case BuiltinFunction.FieldOfDecl:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "FieldOfDecl", predef.FieldName(tok, typeInstantiation), args));

            case BuiltinFunction.FDim:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "FDim", Bpl.Type.Int, args));

            case BuiltinFunction.IsGhostField:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "$IsGhostField", Bpl.Type.Bool, args));

            case BuiltinFunction.DatatypeCtorId:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "DatatypeCtorId", predef.DtCtorId, args));

            case BuiltinFunction.DtRank:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "DtRank", Bpl.Type.Int, args));

            case BuiltinFunction.BoxRank:
                Contract.Assert(args.Length == 1);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "BoxRank", Bpl.Type.Int, args));

            case BuiltinFunction.GenericAlloc:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation == null);
                return(FunctionCall(tok, "GenericAlloc", Bpl.Type.Bool, args));

            case BuiltinFunction.AtLayer:
                Contract.Assert(args.Length == 2);
                Contract.Assert(typeInstantiation != null);
                return(FunctionCall(tok, "AtLayer", typeInstantiation, args));

            default:
                Contract.Assert(false); throw new cce.UnreachableException(); // unexpected built-in function
            }
        }
示例#20
0
        /// <summary>
        /// Returns the (typed) BPL expression that corresponds to the value of the field
        /// <paramref name="f"/> belonging to the object <paramref name="o"/> (which must be non-null).
        /// </summary>
        /// <param name="o">The expression that represents the object to be dereferenced.
        /// </param>
        /// <param name="f">The field that is used to dereference the object <paramref name="o"/>.
        /// </param>
        public override Bpl.Expr ReadHeap(Bpl.Expr /*?*/ o, Bpl.Expr f, AccessType accessType, Bpl.Type unboxType)
        {
            Debug.Assert(o != null);

            Bpl.NAryExpr callRead;
            if (accessType == AccessType.Struct || accessType == AccessType.Heap)
            {
                callRead = new Bpl.NAryExpr(f.tok, new Bpl.FunctionCall(this.Read), new List <Bpl.Expr>(new Bpl.Expr[] { new Bpl.IdentifierExpr(f.tok, this.HeapVariable), o, f }));
            }
            else
            {
                callRead = Bpl.Expr.Select(Bpl.Expr.Select(Bpl.Expr.Ident(ArrayContentsVariable), o), f);
            }

            // wrap it in the right conversion function
            var callExpr = FromUnion(f.tok, unboxType, callRead, false);

            return(callExpr);
        }
示例#21
0
        public static string GetSMTLIBType(Microsoft.Boogie.Type T)
        {
            Microsoft.Boogie.Type theType = null;

            // Handle type synonyms. E.g. ``type arrayId = bv2``
            // Perhaps we should run a pass in the program to remove
            // type synonyms?
            theType = T;
            while (theType is TypeSynonymAnnotation)
            {
                theType = (theType as TypeSynonymAnnotation).ExpandedType;
            }

            if (theType is BvType)
            {
                var BVT = theType as BvType;
                return("(_ BitVec " + BVT.Bits + ")");
            }
            else if (theType is BasicType)
            {
                var ST = (theType as BasicType).T;
                switch (ST)
                {
                case SimpleType.Bool:
                    return("Bool");

                case SimpleType.Int:
                    return("Int");

                case SimpleType.Real:
                    return("Real");

                default:
                    throw new NotImplementedException("Unsupported SimpleType " + ST.ToString());
                }
            }
            else if (theType is MapType)
            {
                var MT = theType as MapType;
                // We are using Z3's Native ArrayTheory (allows for Arrays of Arrays) here. I don't know if other Solvers support this.
                Debug.Assert(MT.Arguments.Count >= 1, "MapType has too few arguments");
                string mapTypeAsString = "";
                foreach (var domainType in MT.Arguments)
                {
                    mapTypeAsString += "(Array " + GetSMTLIBType(domainType) + " ";
                }

                // Now print the final result from the map (the codomain)
                mapTypeAsString += GetSMTLIBType(MT.Result) + " ";

                // Now add closing braces
                for (int index = 0; index < MT.Arguments.Count; ++index)
                {
                    mapTypeAsString += ")";
                }
                return(mapTypeAsString);
            }
            else if (theType is CtorType)
            {
                var CT = theType as CtorType;
                return(GetCustomSortName(CT.Decl));
            }
            else
            {
                throw new NotImplementedException("The type " + theType.ToString() + " is not supported");
            }
        }
示例#22
0
        /// <summary>
        /// Returns the BPL command that corresponds to assigning the value <paramref name="value"/>
        /// to the field <paramref name="f"/> of the object <paramref name="o"/> (which should be non-null).
        /// </summary>
        public override void WriteHeap(Bpl.IToken tok, Bpl.Expr /*?*/ o, Bpl.Expr f, Bpl.Expr value, AccessType accessType, Bpl.Type boxType, Bpl.StmtListBuilder builder)
        {
            Debug.Assert(o != null);

            Bpl.IdentifierExpr h;
            Bpl.NAryExpr       callWrite;
            var callConversion = ToUnion(f.tok, boxType, value, false, builder);

            if (accessType == AccessType.Struct || accessType == AccessType.Heap)
            {
                h         = Bpl.Expr.Ident(HeapVariable);
                callWrite = new Bpl.NAryExpr(f.tok, new Bpl.FunctionCall(this.Write), new List <Bpl.Expr>(new Bpl.Expr[] { h, o, f, callConversion }));
            }
            else
            {
                h         = Bpl.Expr.Ident(ArrayContentsVariable);
                callWrite = Bpl.Expr.Store(Bpl.Expr.Ident(ArrayContentsVariable), o, Bpl.Expr.Store(Bpl.Expr.Select(Bpl.Expr.Ident(ArrayContentsVariable), o), f, callConversion));
            }
            builder.Add(Bpl.Cmd.SimpleAssign(f.tok, h, callWrite));
        }
 //not implemented
 public override Type VisitType(Type type)
 {
     throw new NotImplementedException();
 }
 public abstract Bpl.Expr ReadHeap(Bpl.Expr o, Bpl.Expr f, AccessType accessType, Bpl.Type unboxType);
示例#25
0
 public override Microsoft.Boogie.Type VisitType(Microsoft.Boogie.Type node)
 {
     add(node);
     return(base.VisitType(node));
 }
 public abstract void WriteHeap(Bpl.IToken tok, Bpl.Expr o, Bpl.Expr f, Bpl.Expr value, AccessType accessType, Bpl.Type boxType, Bpl.StmtListBuilder builder);
示例#27
0
文件: Parser.cs 项目: qunyanm/boogie
public Parser(Scanner/*!*/ scanner, Errors/*!*/ errors, bool disambiguation)
 : this(scanner, errors)
{
  // initialize readonly fields
  Pgm = new Program();
  dummyExpr = new LiteralExpr(Token.NoToken, false);
  dummyCmd = new AssumeCmd(Token.NoToken, dummyExpr);
  dummyBlock = new Block(Token.NoToken, "dummyBlock", new List<Cmd>(), new ReturnCmd(Token.NoToken));
  dummyType = new BasicType(Token.NoToken, SimpleType.Bool);
  dummyExprSeq = new List<Expr> ();
  dummyTransferCmd = new ReturnCmd(Token.NoToken);
  dummyStructuredCmd = new BreakCmd(Token.NoToken, null);
}
示例#28
0
 public ScalarSymbolNode(string symbol, Microsoft.Boogie.Type type)
 {
     this.symbol           = symbol;
     this.type             = type;
     this.isOffsetVariable = RegularExpressions.OFFSET_VARIABLE.IsMatch(symbol);
 }