Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        public override VCExpr VisitSelectOp(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;
                Contract.Assert(rawType != null);
                List <Type> /*!*/
                abstractionInstantiation;
                Function    /*!*/
                    select =
                    AxBuilder.MapTypeAbstracter.Select(rawType, out abstractionInstantiation);
                Contract.Assert(abstractionInstantiation != null);
                newOpTypes = TypesPairForSelectStore(node, select, abstractionInstantiation);
                NewOpCache.Add(originalOpTypes, newOpTypes);
            }

            return(AssembleOpExpression(newOpTypes, node, bindings));
        }
Exemplo n.º 3
0
        ////////////////////////////////////////////////////////////////////////////

        private VCExpr AssembleOpExpression(OpTypesPair opTypes, IEnumerable <VCExpr /*!*/> /*!*/ oldArgs, VariableBindings bindings)
        {
            Contract.Requires(bindings != null);
            Contract.Requires(cce.NonNullElements(oldArgs));
            Contract.Ensures(Contract.Result <VCExpr>() != null);
            // UGLY: the code for tracking polarities should be factored out
            int oldPolarity = Eraser.Polarity;

            Eraser.Polarity = 0;

            List <VCExpr /*!*/> /*!*/ newArgs = new List <VCExpr /*!*/> ();

            // explicit type parameters
            foreach (Type /*!*/ t in opTypes.Types)
            {
                Contract.Assert(newArgs != null);
                newArgs.Add(AxBuilder.Type2Term(t, bindings.TypeVariableBindings));
            }

            // and the actual value parameters
            Function /*!*/ newFun = ((VCExprBoogieFunctionOp)opTypes.Op).Func;
            // ^ we only allow this operator at this point
            int i = opTypes.Types.Count;

            foreach (VCExpr /*!*/ arg in oldArgs)
            {
                Contract.Assert(arg != null);
                newArgs.Add(AxBuilder.Cast(Eraser.Mutate(arg, bindings),
                                           cce.NonNull(newFun.InParams[i]).TypedIdent.Type));
                i = i + 1;
            }

            Eraser.Polarity = oldPolarity;
            return(Gen.Function(opTypes.Op, newArgs));
        }
Exemplo n.º 4
0
 public override bool Equals(object that)
 {
     if (that is OpTypesPair)
     {
         OpTypesPair thatPair = (OpTypesPair)that;
         return(this.Op.Equals(thatPair.Op) &&
                HFNS.SameElements(this.Types, thatPair.Types));
     }
     return(false);
 }
Exemplo n.º 5
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);
    }
Exemplo n.º 6
0
    ////////////////////////////////////////////////////////////////////////////

    private VCExpr AssembleOpExpression(OpTypesPair opTypes, IEnumerable<VCExpr/*!*/>/*!*/ oldArgs, VariableBindings bindings){
Contract.Requires(bindings != null);
Contract.Requires(cce.NonNullElements(oldArgs));
Contract.Ensures(Contract.Result<VCExpr>() != null);
      // UGLY: the code for tracking polarities should be factored out
      int oldPolarity = Eraser.Polarity;
      Eraser.Polarity = 0;

      List<VCExpr/*!*/>/*!*/ newArgs = new List<VCExpr/*!*/> ();
      // explicit type parameters
      foreach (Type/*!*/ t in opTypes.Types){
        Contract.Assert(newArgs != null);
        newArgs.Add(AxBuilder.Type2Term(t, bindings.TypeVariableBindings));}
      
      // and the actual value parameters
      Function/*!*/ newFun = ((VCExprBoogieFunctionOp)opTypes.Op).Func;
                              // ^ we only allow this operator at this point
      int i = opTypes.Types.Count;
      foreach (VCExpr/*!*/ arg in oldArgs) {
        Contract.Assert(arg != null);
        newArgs.Add(AxBuilder.Cast(Eraser.Mutate(arg, bindings),
                                   cce.NonNull(newFun.InParams[i]).TypedIdent.Type));
        i = i + 1;
      }

      Eraser.Polarity = oldPolarity;
      return Gen.Function(opTypes.Op, newArgs);
    }