Example #1
0
    public StratifiedCallSite(CallSite cs, SubstitutingVCExprVisitor substVisitor, VCExprSubstitution subst)
    {
      callSite = cs;
      interfaceExprs = new List<VCExpr>();
      foreach (VCExpr v in cs.interfaceExprs)
      {
        interfaceExprs.Add(substVisitor.Mutate(v, subst));
      }

      if (callSite.callSiteVar != null)
        callSiteExpr = substVisitor.Mutate(callSite.callSiteVar, subst);
    }
        private void InstantiateQuantifierAtInstance(VCExprQuantifier quantifierExpr, List <VCExpr> instance)
        {
            var quantifierInstantiationInfo = this.quantifierInstantiationInfo[quantifierExpr];

            if (quantifierInstantiationInfo.instances.ContainsKey(instance))
            {
                return;
            }
            var subst = new VCExprSubstitution(
                Enumerable.Range(0, quantifierExpr.BoundVars.Count).ToDictionary(
                    x => quantifierExpr.BoundVars[x],
                    x => instance[x]), new Dictionary <TypeVariable, Type>());
            var substituter   = new SubstitutingVCExprVisitor(vcExprGen);
            var instantiation = substituter.Mutate(quantifierExpr.Body, subst);

            quantifierInstantiationInfo.instances[new List <VCExpr>(instance)] =
                Skolemizer.Skolemize(this, quantifierExpr.Quan == Quantifier.ALL ? Polarity.Positive : Polarity.Negative,
                                     instantiation);
        }
Example #3
0
    public VCExpr Attach(StratifiedVC svc)
    {
      Contract.Assert(interfaceExprs.Count == svc.interfaceExprVars.Count);
      StratifiedInliningInfo info = svc.info;
      ProverInterface prover = info.vcgen.prover;
      VCExpressionGenerator gen = prover.VCExprGen;

      Dictionary<VCExprVar, VCExpr> substDict = new Dictionary<VCExprVar, VCExpr>();
      for (int i = 0; i < svc.interfaceExprVars.Count; i++)
      {
        VCExprVar v = svc.interfaceExprVars[i];
        substDict.Add(v, interfaceExprs[i]);
      }

      VCExprSubstitution subst =
        new VCExprSubstitution(substDict, new Dictionary<TypeVariable, Microsoft.Boogie.Type>());
      SubstitutingVCExprVisitor substVisitor = new SubstitutingVCExprVisitor(prover.VCExprGen);
      svc.vcexpr = substVisitor.Mutate(svc.vcexpr, subst);
      foreach (StratifiedCallSite scs in svc.CallSites)
      {
        List<VCExpr> newInterfaceExprs = new List<VCExpr>();
        foreach (VCExpr expr in scs.interfaceExprs)
        {
          newInterfaceExprs.Add(substVisitor.Mutate(expr, subst));
        }

        scs.interfaceExprs = newInterfaceExprs;
      }

      foreach (StratifiedCallSite scs in svc.RecordProcCallSites)
      {
        List<VCExpr> newInterfaceExprs = new List<VCExpr>();
        foreach (VCExpr expr in scs.interfaceExprs)
        {
          newInterfaceExprs.Add(substVisitor.Mutate(expr, subst));
        }

        scs.interfaceExprs = newInterfaceExprs;
      }

      //return gen.Implies(callSiteExpr, svc.vcexpr);
      return svc.vcexpr;
    }
        /*!*/
        private VCExpr GenTypePremisses(List<VCExprVar/*!*/>/*!*/ oldBoundVars,
            List<VCExprVar/*!*/>/*!*/ newBoundVars,
            IDictionary<TypeVariable/*!*/, VCExpr/*!*/>/*!*/
            typeVarTranslation,
            List<VCExprLetBinding/*!*/>/*!*/ typeVarBindings,
            out List<VCTrigger/*!*/>/*!*/ triggers)
        {
            Contract.Requires(cce.NonNullElements(oldBoundVars));
              Contract.Requires(cce.NonNullElements(newBoundVars));
              Contract.Requires(cce.NonNullDictionaryAndValues(typeVarTranslation));
              Contract.Requires(cce.NonNullElements(typeVarBindings));
              Contract.Ensures(cce.NonNullElements(Contract.ValueAtReturn(out triggers)));
              Contract.Ensures(Contract.Result<VCExpr>() != null);

              // build a substitution of the type variables that it can be checked
              // whether type premisses are trivial
              VCExprSubstitution/*!*/ typeParamSubstitution = new VCExprSubstitution();
              foreach (VCExprLetBinding/*!*/ binding in typeVarBindings) {
            Contract.Assert(binding != null);
            typeParamSubstitution[binding.V] = binding.E;
              }
              SubstitutingVCExprVisitor/*!*/ substituter = new SubstitutingVCExprVisitor(Gen);
              Contract.Assert(substituter != null);

              List<VCExpr/*!*/>/*!*/ typePremisses = new List<VCExpr/*!*/>(newBoundVars.Count);
              triggers = new List<VCTrigger/*!*/>(newBoundVars.Count);

              for (int i = 0; i < newBoundVars.Count; ++i) {
            VCExprVar/*!*/ oldVar = oldBoundVars[i];
            Contract.Assert(oldVar != null);
            VCExprVar/*!*/ newVar = newBoundVars[i];
            Contract.Assert(newVar != null);

            VCExpr/*!*/ typePremiss =
              AxBuilderPremisses.GenVarTypeAxiom(newVar, oldVar.Type,
                                             typeVarTranslation);
            Contract.Assert(typePremiss != null);
            if (!IsTriviallyTrue(substituter.Mutate(typePremiss,
                                                typeParamSubstitution))) {
              typePremisses.Add(typePremiss);
              // generate a negative trigger for the variable occurrence
              // in the type premiss
              triggers.Add(Gen.Trigger(false,
                         HelperFuns.ToList(AxBuilderPremisses.TypeOf(newVar))));
            }
              }

              typePremisses.TrimExcess();
              triggers.TrimExcess();

              return Gen.NAry(VCExpressionGenerator.AndOp, typePremisses);
        }
Example #5
0
    public StratifiedVC(StratifiedInliningInfo siInfo, HashSet<string> procCalls)
    {
      info = siInfo;
      info.GenerateVC();
      var vcgen = info.vcgen;
      var prover = vcgen.prover;
      VCExpressionGenerator gen = prover.VCExprGen;
      var bet = prover.Context.BoogieExprTranslator;

      vcexpr = info.vcexpr;
      id = vcgen.CreateNewId();
      interfaceExprVars = new List<VCExprVar>();
      Dictionary<VCExprVar, VCExpr> substDict = new Dictionary<VCExprVar, VCExpr>();
      foreach (VCExprVar v in info.interfaceExprVars)
      {
        VCExprVar newVar = vcgen.CreateNewVar(v.Type);
        interfaceExprVars.Add(newVar);
        substDict.Add(v, newVar);
      }

      foreach (VCExprVar v in info.privateExprVars)
      {
        substDict.Add(v, vcgen.CreateNewVar(v.Type));
      }

      if (info.controlFlowVariable != null)
        substDict.Add(bet.LookupVariable(info.controlFlowVariable), gen.Integer(BigNum.FromInt(id)));
      VCExprSubstitution subst =
        new VCExprSubstitution(substDict, new Dictionary<TypeVariable, Microsoft.Boogie.Type>());
      SubstitutingVCExprVisitor substVisitor = new SubstitutingVCExprVisitor(prover.VCExprGen);
      vcexpr = substVisitor.Mutate(vcexpr, subst);

      // For BoolControlVC generation
      if (info.blockToControlVar != null)
      {
        blockToControlVar = new Dictionary<Block, VCExpr>();
        foreach (var tup in info.blockToControlVar)
          blockToControlVar.Add(tup.Key, substDict[tup.Value]);
      }

      if (procCalls != null)
        vcexpr = RemoveProcedureCalls.Apply(vcexpr, info.vcgen.prover.VCExprGen, procCalls);

      callSites = new Dictionary<Block, List<StratifiedCallSite>>();
      foreach (Block b in info.callSites.Keys)
      {
        callSites[b] = new List<StratifiedCallSite>();
        foreach (CallSite cs in info.callSites[b])
        {
          callSites[b].Add(new StratifiedCallSite(cs, substVisitor, subst));
        }
      }

      recordProcCallSites = new Dictionary<Block, List<StratifiedCallSite>>();
      foreach (Block b in info.recordProcCallSites.Keys)
      {
        recordProcCallSites[b] = new List<StratifiedCallSite>();
        foreach (CallSite cs in info.recordProcCallSites[b])
        {
          recordProcCallSites[b].Add(new StratifiedCallSite(cs, substVisitor, subst));
        }
      }
    }