Esempio n. 1
0
 public bool VisitFloatEqOp(VCExprNAry node, TextWriter wr)
 {
     //Contract.Requires(wr != null);
     //Contract.Requires(node != null);
     return(PrintNAry("fp.eq", node, wr));
 }
Esempio n. 2
0
 public bool VisitGeOp(VCExprNAry node, LineariserOptions options)
 {
     WriteApplication(">=", node, options);
     return(true);
 }
        public override VCExpr VisitBoogieFunctionOp(VCExprNAry node, VariableBindings bindings)
        {
            Contract.Requires(bindings != null);
              Contract.Requires(node != null);
              Contract.Ensures(Contract.Result<VCExpr>() != null);
              Function/*!*/ oriFun = ((VCExprBoogieFunctionOp)node.Op).Func;
              Contract.Assert(oriFun != null);
              UntypedFunction untypedFun = AxBuilderPremisses.Typed2Untyped(oriFun);
              Contract.Assert(untypedFun.Fun.InParams.Count ==
             untypedFun.ExplicitTypeParams.Count + node.Arity);

              List<Type/*!*/>/*!*/ typeArgs =
            ExtractTypeArgs(node,
                        oriFun.TypeParameters, untypedFun.ExplicitTypeParams);
              return HandleFunctionOp(untypedFun.Fun, typeArgs, node, bindings);
        }
 public override VCExpr VisitStoreOp(VCExprNAry node, VariableBindings bindings)
 {
     Contract.Requires(bindings != null);
       Contract.Requires(node != null);
       Contract.Ensures(Contract.Result<VCExpr>() != null);
       List<Type>/*!*/ instantiations; // not used
       Function/*!*/ store =
     AxBuilder.MapTypeAbstracter.Store(node[0].Type.AsMap, out instantiations);
       Contract.Assert(store != null);
       return HandleFunctionOp(store,
     // the store function never has explicit
     // type parameters
                       new List<Type/*!*/>(),
                       node, bindings);
 }
    public override VCExpr VisitSubtypeOp(VCExprNAry node, VariableBindings bindings) {
Contract.Requires((bindings != null));
Contract.Requires((node != null));
Contract.Ensures(Contract.Result<VCExpr>() != null);
      // UGLY: the code for tracking polarities should be factored out
      int oldPolarity = Eraser.Polarity;
      Eraser.Polarity = 0;

      VCExpr/*!*/ res =
        Gen.Function(VCExpressionGenerator.Subtype3Op,
                     AxBuilder.Type2Term(node[0].Type,
                                         bindings.TypeVariableBindings),
                     AxBuilder.Cast(Eraser.Mutate(node[0], bindings),
                                    AxBuilder.U),
                     AxBuilder.Cast(Eraser.Mutate(node[1], bindings),
                                    AxBuilder.U));

      Eraser.Polarity = oldPolarity;
      return res;
    }
    private OpTypesPair TypesPairForSelectStore(VCExprNAry/*!*/ node, Function/*!*/ untypedOp,
      // instantiation of the abstract map type parameters
                                                List<Type>/*!*/ abstractionInstantiation) {
      Contract.Requires(node != null);
      Contract.Requires(untypedOp != null);
      Contract.Requires(abstractionInstantiation != null);

      List<Type/*!*/>/*!*/ inferredTypeArgs = new List<Type/*!*/> ();
      foreach (Type/*!*/ t in node.TypeArguments){Contract.Assert(t != null);
//        inferredTypeArgs.Add(AxBuilder.MapTypeAbstracter.AbstractMapTypeRecursively(t));
        inferredTypeArgs.Add(t);}
      foreach (Type/*!*/ t in abstractionInstantiation) {
        Contract.Assert(t != null);
        inferredTypeArgs.Add(t);}

      Contract.Assert(untypedOp.InParams.Count == inferredTypeArgs.Count + node.Arity);
      return new OpTypesPair (Gen.BoogieFunctionOp(untypedOp), inferredTypeArgs);
    }
Esempio n. 7
0
        /////////////////////////////////////////////////////////////////////////////////////

        public bool Visit(VCExprNAry node, LineariserOptions options)
        {
            VCExprOp op = node.Op;

            Contract.Assert(op != null);

            var booleanOps = new HashSet <VCExprOp>();

            booleanOps.Add(VCExpressionGenerator.NotOp);
            booleanOps.Add(VCExpressionGenerator.ImpliesOp);
            booleanOps.Add(VCExpressionGenerator.AndOp);
            booleanOps.Add(VCExpressionGenerator.OrOp);
            if (booleanOps.Contains(op))
            {
                Stack <VCExpr> exprs = new Stack <VCExpr>();
                exprs.Push(node);
                while (exprs.Count > 0)
                {
                    VCExpr expr = exprs.Pop();
                    if (expr == null)
                    {
                        wr.Write(")");
                        continue;
                    }

                    wr.Write(" ");
                    VCExprNAry naryExpr = expr as VCExprNAry;
                    if (naryExpr == null || !booleanOps.Contains(naryExpr.Op))
                    {
                        Linearise(expr, options);
                        continue;
                    }
                    else if (naryExpr.Op.Equals(VCExpressionGenerator.NotOp))
                    {
                        wr.Write("(not");
                    }
                    else if (naryExpr.Op.Equals(VCExpressionGenerator.ImpliesOp))
                    {
                        wr.Write("(=>");
                    }
                    else if (naryExpr.Op.Equals(VCExpressionGenerator.AndOp))
                    {
                        wr.Write("(and");
                    }
                    else
                    {
                        System.Diagnostics.Debug.Assert(naryExpr.Op.Equals(VCExpressionGenerator.OrOp));
                        wr.Write("(or");
                    }

                    exprs.Push(null);
                    for (int i = naryExpr.Arity - 1; i >= 0; i--)
                    {
                        exprs.Push(naryExpr[i]);
                    }
                }

                return(true);
            }

            if (OptimizationRequests != null &&
                (node.Op.Equals(VCExpressionGenerator.MinimizeOp) || node.Op.Equals(VCExpressionGenerator.MaximizeOp)))
            {
                string optOp = node.Op.Equals(VCExpressionGenerator.MinimizeOp) ? "minimize" : "maximize";
                OptimizationRequests.Add(string.Format("({0} {1})", optOp,
                                                       ToString(node[0], Namer, ProverOptions, NamedAssumes)));
                Linearise(node[1], options);
                return(true);
            }

            if (node.Op is VCExprSoftOp)
            {
                Linearise(node[1], options);
                return(true);
            }

            if (node.Op.Equals(VCExpressionGenerator.NamedAssumeOp))
            {
                var exprVar = node[0] as VCExprVar;
                NamedAssumes.Add(exprVar);
                Linearise(node[1], options);
                return(true);
            }

            return(node.Accept <bool, LineariserOptions /*!*/>(OpLineariser, options));
        }
    // for the time being, we store both the types of the arguments and the explicit
    // type parameters (for most operators, this is more than actually necessary)
    private OpTypesPair OriginalOpTypes(VCExprNAry node){
Contract.Requires(node != null);
      List<Type/*!*/>/*!*/ originalTypes = new List<Type/*!*/> ();
      foreach (VCExpr/*!*/ expr in node) {
        Contract.Assert(expr != null);
        originalTypes.Add(expr.Type);
      }
      originalTypes.AddRange(node.TypeArguments);
      return new OpTypesPair (node.Op, originalTypes);
    }
Esempio n. 9
0
 public bool VisitToRealOp(VCExprNAry node, TextWriter wr)
 {
     //Contract.Requires(wr != null);
     //Contract.Requires(node != null);
     return(PrintNAry("real", node, wr));
 }
Esempio n. 10
0
 private static string CheckMapApply(string name, VCExprNAry node)
 {
     if (name == "MapConst")
     {
         Type   type = node.Type;
         string s    = TypeToString(type);
         return("(as const " + s + ")");
     }
     else if (name == "MapAdd")
     {
         return("(_ map (+ (Int Int) Int))");
     }
     else if (name == "MapSub")
     {
         return("(_ map (- (Int Int) Int))");
     }
     else if (name == "MapMul")
     {
         return("(_ map (* (Int Int) Int))");
     }
     else if (name == "MapDiv")
     {
         return("(_ map (div (Int Int) Int))");
     }
     else if (name == "MapMod")
     {
         return("(_ map (mod (Int Int) Int))");
     }
     else if (name == "MapEq")
     {
         Type   type = ResultType(node[0].Type);
         string s    = TypeToString(type);
         return("(_ map (= (" + s + " " + s + ") Bool))");
     }
     else if (name == "MapIff")
     {
         return("(_ map (= (Bool Bool) Bool))");
     }
     else if (name == "MapGt")
     {
         return("(_ map (> (Int Int) Int))");
     }
     else if (name == "MapGe")
     {
         return("(_ map (>= (Int Int) Int))");
     }
     else if (name == "MapLt")
     {
         return("(_ map (< (Int Int) Int))");
     }
     else if (name == "MapLe")
     {
         return("(_ map (<= (Int Int) Int))");
     }
     else if (name == "MapOr")
     {
         return("(_ map or)");
     }
     else if (name == "MapAnd")
     {
         return("(_ map and)");
     }
     else if (name == "MapNot")
     {
         return("(_ map not)");
     }
     else if (name == "MapImp")
     {
         return("(_ map =>)");
     }
     else if (name == "MapIte")
     {
         Type   type = ResultType(node.Type);
         string s    = TypeToString(type);
         return("(_ map (ite (Bool " + s + " " + s + ") " + s + "))");
     }
     else
     {
         return(name);
     }
 }
Esempio n. 11
0
 public bool VisitSubtype3Op(VCExprNAry node, TextWriter wr)
 {
     //Contract.Requires(wr != null);
     //Contract.Requires(node != null);
     return(PrintNAry("<::", node, wr));
 }
Esempio n. 12
0
 public bool VisitIfThenElseOp(VCExprNAry node, TextWriter wr)
 {
     //Contract.Requires(wr != null);
     //Contract.Requires(node != null);
     return(PrintNAry("if-then-else", node, wr));
 }
Esempio n. 13
0
 public bool VisitBvConcatOp(VCExprNAry node, TextWriter wr)
 {
     //Contract.Requires(wr != null);
     //Contract.Requires(node != null);
     return(PrintNAry("BvConcat", node, wr));
 }
Esempio n. 14
0
 public bool VisitSubtype3Op(VCExprNAry node, LineariserOptions options)
 {
     WriteApplication("UOrdering3", node, options);
     return(true);
 }
Esempio n. 15
0
            ///////////////////////////////////////////////////////////////////////////////////

            public bool VisitNotOp(VCExprNAry node, LineariserOptions options)
            {
                WriteApplication("not", node, options); // arguments can be both terms and formulas
                return(true);
            }
Esempio n. 16
0
 public bool VisitToIntOp(VCExprNAry node, LineariserOptions options)
 {
     WriteApplication("to_int", node, options);
     return(true);
 }
Esempio n. 17
0
 public bool VisitEqOp(VCExprNAry node, LineariserOptions options)
 {
     return(PrintEq(node, options));
 }
Esempio n. 18
0
    public override VCExpr VisitNeqOp(VCExprNAry node, VariableBindings bindings) {
      Contract.Requires((bindings != null));
Contract.Requires((node != null));
Contract.Ensures(Contract.Result<VCExpr>() != null);
      // we also have to state that the types are (un)equal, because the
      // translation does not contain any information about the
      // relationship between values and types
      return Gen.OrSimp(base.VisitNeqOp(node, bindings),
                        Gen.Not(EqualTypes(node[0].Type, node[1].Type, bindings)));
    }
Esempio n. 19
0
 public bool VisitIfThenElseOp(VCExprNAry node, LineariserOptions options)
 {
     WriteApplication("ite", node, options);
     return(true);
 }
Esempio n. 20
0
    public override VCExpr VisitStoreOp(VCExprNAry node, VariableBindings bindings) {
Contract.Requires((bindings != null));
Contract.Requires((node != null));
Contract.Ensures(Contract.Result<VCExpr>() != null);
      OpTypesPair originalOpTypes = OriginalOpTypes(node);
      OpTypesPair newOpTypes;

      if (!NewOpCache.TryGetValue(originalOpTypes, out newOpTypes)) {
        MapType/*!*/ rawType = node[0].Type.AsMap;
        List<Type>/*!*/ abstractionInstantiation;
        Function/*!*/ store =
          AxBuilder.MapTypeAbstracter.Store(rawType, out abstractionInstantiation);

        newOpTypes = TypesPairForSelectStore(node, store, abstractionInstantiation);
        NewOpCache.Add(originalOpTypes, newOpTypes);
      }

      return AssembleOpExpression(newOpTypes, node, bindings);
    }
Esempio n. 21
0
 public bool VisitFloatEqOp(VCExprNAry node, LineariserOptions options)
 {
     WriteApplication("fp.eq", node, options);
     return(true);
 }
Esempio n. 22
0
    ///////////////////////////////////////////////////////////////////////////

    public override VCExpr VisitBoogieFunctionOp(VCExprNAry node, VariableBindings bindings) {
Contract.Requires((bindings != null));
Contract.Requires((node != null));
Contract.Ensures(Contract.Result<VCExpr>() != null);
      OpTypesPair originalOpTypes = OriginalOpTypes(node);
      OpTypesPair newOpTypes;

      if (!NewOpCache.TryGetValue(originalOpTypes, out newOpTypes)) {
        Function/*!*/ oriFun = ((VCExprBoogieFunctionOp)node.Op).Func;
        Contract.Assert(oriFun != null);
        List<Type/*!*/>/*!*/ inferredTypeArgs = new List<Type/*!*/> ();
        foreach (Type/*!*/ t in node.TypeArguments){Contract.Assert(t != null);
//          inferredTypeArgs.Add(AxBuilder.MapTypeAbstracter.AbstractMapTypeRecursively(t));
          inferredTypeArgs.Add(t);}

        VCExprOp/*!*/ newOp = Gen.BoogieFunctionOp(AxBuilderArguments.Typed2Untyped(oriFun));
        newOpTypes = new OpTypesPair (newOp, inferredTypeArgs);

        NewOpCache.Add(originalOpTypes, newOpTypes);
      }

      return AssembleOpExpression(newOpTypes, node, bindings);
    }
Esempio n. 23
0
 public bool VisitBvConcatOp(VCExprNAry node, LineariserOptions options)
 {
     WriteApplication("concat", node, options);
     return(true);
 }
Esempio n. 24
0
        /*!*/
        public override VCExpr VisitSelectOp(VCExprNAry/*!*/ node,
            VariableBindings/*!*/ bindings)
        {
            Contract.Requires(node != null); Contract.Requires(bindings != null);
              Contract.Ensures(Contract.Result<VCExpr>() != null);

              MapType/*!*/ mapType = node[0].Type.AsMap;
              Contract.Assert(mapType != null);
              List<Type>/*!*/ instantiations; // not used
              Function/*!*/ select =
            AxBuilder.MapTypeAbstracter.Select(mapType, out instantiations);
              Contract.Assert(select != null);

              List<int>/*!*/ explicitTypeParams =
            AxBuilderPremisses.MapTypeAbstracterPremisses
                          .ExplicitSelectTypeParams(mapType);
              Contract.Assert(select.InParams.Count == explicitTypeParams.Count + node.Arity);

              List<Type/*!*/>/*!*/ typeArgs = new List<Type/*!*/>(explicitTypeParams.Count);
              foreach (int i in explicitTypeParams)
            typeArgs.Add(node.TypeArguments[i]);
              return HandleFunctionOp(select, typeArgs, node, bindings);
        }
Esempio n. 25
0
 public bool VisitPowOp(VCExprNAry node, LineariserOptions options)
 {
     WriteApplication("real_pow", node, options);
     return(true);
 }
Esempio n. 26
0
 /*!*/
 private List<Type/*!*/> ExtractTypeArgs(VCExprNAry node, List<TypeVariable> allTypeParams, List<TypeVariable/*!*/>/*!*/ explicitTypeParams)
 {
     Contract.Requires(allTypeParams != null);
       Contract.Requires(node != null);
       Contract.Requires(cce.NonNullElements(explicitTypeParams));
       Contract.Ensures(cce.NonNullElements(Contract.Result<List<Type>>()));
       List<Type/*!*/>/*!*/ res = new List<Type/*!*/>(explicitTypeParams.Count);
       foreach (TypeVariable/*!*/ var in explicitTypeParams) {
     Contract.Assert(var != null);
     // this lookup could be optimised
     res.Add(node.TypeArguments[allTypeParams.IndexOf(var)]);
       }
       return res;
 }
Esempio n. 27
0
 public bool VisitImpliesOp(VCExprNAry node, TextWriter wr)
 {
     //Contract.Requires(wr != null);
     //Contract.Requires(node != null);
     return(PrintNAry("Implies", node, wr));
 }