示例#1
0
        public override string VisitTermQuantifier(TermQuantifier t)
        {
            var qIsa = GetStringFromQuantifier(t.Quantifier);
            var sb   = new StringBuilder();

            sb.Append("(");
            sb.Append(qIsa);
            sb.Append(" ");

            IEnumerable <string> boundVarsTranslated;

            if (t.BoundVarTypes != null)
            {
                boundVarsTranslated = t.BoundVars.Zip(t.BoundVarTypes, (id, ty) =>
                                                      H.Parenthesis(GetStringFromIdentifier(id) + "::" + typePrettyPrinter.Visit(ty))
                                                      );
            }
            else
            {
                boundVarsTranslated = t.BoundVars.Select(GetStringFromIdentifier);
            }

            sb.Append(boundVarsTranslated.SpaceAggregate());
            sb.Append(".");

            sb.Append(" ");
            sb.Append(t.Term.Dispatch(this));
            sb.Append(")");

            return(sb.ToString());
        }
示例#2
0
 public static Term Let(Identifier boundVar, Term termSubst, Term body)
 {
     return(new TermApp(
                new TermApp(new TermIdent(new SimpleIdentifier("Let")), termSubst),
                TermQuantifier.Lambda(new List <Identifier> {
         boundVar
     }, null, body)
                ));
 }
示例#3
0
        public static Term ClosednessAssumption(Term absValTyMap)
        {
            Identifier boundVar = new SimpleIdentifier("v");

            return(TermQuantifier.MetaAll(new List <Identifier> {
                boundVar
            },
                                          null,
                                          IsaBoogieTerm.IsClosedType(IsaBoogieTerm.TypeToVal(absValTyMap, new TermIdent(boundVar)))
                                          ));
        }
示例#4
0
        private static Term ConclusionBlock(
            IEnumerable <Block> b_successors,
            Term normalInitState,
            Term finalState,
            IDictionary <NamedDeclaration, Term> declToVCMapping,
            VCInstantiation <Block> vcinst,
            bool useMagicFinalState = false)
        {
            if (useMagicFinalState)
            {
                return(new TermBinary(finalState, IsaBoogieTerm.Magic(), TermBinary.BinaryOpCode.Eq));
            }

            Term nonFailureConclusion =
                new TermBinary(finalState, IsaBoogieTerm.Failure(), TermBinary.BinaryOpCode.Neq);

            var normalFinalState = IsaCommonTerms.TermIdentFromName("n_s'");

            Term ifNormalConclusionLhs = new TermBinary(finalState, IsaBoogieTerm.Normal(normalFinalState),
                                                        TermBinary.BinaryOpCode.Eq);

            Term ifNormalConclusionRhs1 = new TermBinary(normalFinalState, normalInitState, TermBinary.BinaryOpCode.Eq);

            var ifNormalConclusionRhs =
                !b_successors.Any()
                    ? ifNormalConclusionRhs1
                    : new TermBinary(
                    ifNormalConclusionRhs1,
                    LemmaHelper.ConjunctionOfSuccessorBlocks(b_successors, declToVCMapping, vcinst),
                    TermBinary.BinaryOpCode.And);

            Term ifNormalConclusion =
                new TermQuantifier(
                    TermQuantifier.QuantifierKind.ALL,
                    new List <Identifier> {
                normalFinalState.Id
            },
                    new TermBinary(
                        ifNormalConclusionLhs,
                        ifNormalConclusionRhs,
                        TermBinary.BinaryOpCode.Implies)
                    );

            return(new TermBinary(nonFailureConclusion, ifNormalConclusion, TermBinary.BinaryOpCode.And));
        }
示例#5
0
        public static Term NonEmptyTypesAssumption(Term absValTyMap)
        {
            Identifier bvType      = new SimpleIdentifier("t");
            Term       bvTypeTerm  = new TermIdent(bvType);
            Identifier bvValue     = new SimpleIdentifier("v");
            Term       bvValueTerm = new TermIdent(bvValue);

            return(TermQuantifier.MetaAll(new List <Identifier> {
                bvType
            },
                                          null,
                                          TermBinary.MetaImplies(IsaBoogieTerm.IsClosedType(bvTypeTerm),
                                                                 TermQuantifier.Exists(new List <Identifier> {
                bvValue
            },
                                                                                       null,
                                                                                       TermBinary.Eq(IsaBoogieTerm.TypeToVal(absValTyMap, bvValueTerm), bvTypeTerm)
                                                                                       ))));
        }
        public static Term ProcedureIsCorrect(Term funDecls, Term constantDecls, Term globalDecls, Term axioms,
                                              Term procedure)
        {
            var typeInterpId = new SimpleIdentifier("A");

            return
                (TermQuantifier.MetaAll(
                     new List <Identifier> {
                typeInterpId
            },
                     null,
                     new TermApp(
                         IsaCommonTerms.TermIdentFromName("proc_is_correct"),
                         //TODO: here assuming that we use "'a" for the abstract value type carrier t --> make t a parameter somewhere
                         new TermWithExplicitType(new TermIdent(typeInterpId), IsaBoogieType.AbstractValueTyFunType(new VarType("a"))),
                         funDecls,
                         constantDecls,
                         globalDecls,
                         axioms,
                         procedure)));
        }
示例#7
0
        //if blockToNewVars is non-null, then the mapped variables are universally quantified for the corresponding block definition
        public IDictionary <Block, DefDecl> IsaDefsFromVC(IDictionary <Block, VCExpr> blockToVC,
                                                          IDictionary <Block, IList <VCExprVar> > blockToActiveVars,
                                                          CFGRepr cfg,
                                                          IDictionary <Block, IList <VCExprVar> > blockToNewVars = null)
        {
            Contract.Ensures(Contract.Result <IDictionary <Block, DefDecl> >().Count == cfg.NumOfBlocks());

            IDictionary <Block, DefDecl> blockToDefVC = new Dictionary <Block, DefDecl>();

            var vcExprIsaVisitor = new VCExprToIsaTranslator(uniqueNamer, blockToDefVC, blockToActiveVars);

            foreach (var block in cfg.GetBlocksBackwards())
            {
                // might be more efficient to hand over this:
                // IEnumerable<Tuple<Block, DefDecl>> successorDefs = cfg.outgoingBlocks[block].Select(b => new Tuple<Block, DefDecl>(b, blockToDefVC[b]));

                var term = vcExprIsaVisitor.Translate(blockToVC[block]);

                if (blockToNewVars != null && blockToNewVars.TryGetValue(block, out var newVars) && newVars != null &&
                    newVars.Any())
                {
                    IList <Identifier> boundVars = newVars
                                                   .Select(v => (Identifier) new SimpleIdentifier(uniqueNamer.GetName(v, v.Name))).ToList();
                    IList <TypeIsa> boundVarsTypes =
                        newVars.Select(v => pureTyIsaTransformer.Translate(v.Type)).ToList();

                    term = new TermQuantifier(TermQuantifier.QuantifierKind.ALL, boundVars, boundVarsTypes, term);
                }

                IList <Term> args = blockToActiveVars[block].Select(v => vcExprIsaVisitor.Translate(v)).ToList();

                var def = new DefDecl(GetVCDefName(block), new Tuple <IList <Term>, Term>(args, term));

                Contract.Assert(!blockToDefVC.ContainsKey(block));
                blockToDefVC.Add(block, def);
            }

            return(blockToDefVC);
        }