示例#1
0
 //returns PureTyIsaTransformer that instantiates U and T with the concrete instantiations
 public static PureTyIsaTransformer ConretePureTyIsaTransformer(TypeIsa abstractValueType)
 {
     //instantiate type in VC representing Boogie values with Boogie value type
     //instantiate type in VC representing Boogie types with Boogie closed type
     return(new PureTyIsaTransformer(IsaBoogieType.ValType(abstractValueType), IsaBoogieVC.BoogieClosedType()));
 }
示例#2
0
        public static Term FunctionVcCorresAssm(
            Function f,
            IDictionary <Function, TermIdent> funInterpMapping,
            IDictionary <NamedDeclaration, Term> declToVCMapping,
            BoogieContextIsa boogieContext
            )
        {
            var converter = new PureToBoogieValConverter();

            //TODO: unique naming scheme
            var boundParamVars = GetNames("farg", f.InParams.Count);

            TypeUtil.SplitTypeParams(f.TypeParameters, f.InParams.Select(v => v.TypedIdent.Type),
                                     out var explicitTypeVars, out var implicitTypeVars);


            var boundTypeVars = GetNames("targ", f.TypeParameters.Count);

            IDictionary <TypeVariable, Term> substitution = new Dictionary <TypeVariable, Term>();
            var i = 0;

            foreach (var tv in f.TypeParameters)
            {
                substitution.Add(tv, new TermIdent(boundTypeVars[i]));
                i++;
            }

            var varSubstitution = new SimpleVarSubstitution <TypeVariable>(substitution);
            var typeIsaVisitor  = new TypeIsaVisitor(varSubstitution);

            IEnumerable <Term> valueArgConstraints =
                f.InParams
                .Select((v, idx) =>
                        !TypeUtil.IsPrimitive(v.TypedIdent.Type)
                            ? TermBinary.Eq(
                            IsaBoogieTerm.TypeToVal(boogieContext.absValTyMap, new TermIdent(boundParamVars[idx])),
                            typeIsaVisitor.Translate(v.TypedIdent.Type))
                            : null)
                .Where(t => t != null);

            var boogieFunTyArgs = boundTypeVars.Select(id => (Term) new TermIdent(id)).ToList();
            var vcFunTyArgs     = new List <Term>();

            f.TypeParameters.ZipDo(boogieFunTyArgs, (tv, tvTerm) =>
            {
                if (explicitTypeVars.Contains(tv))
                {
                    vcFunTyArgs.Add(IsaBoogieVC.TyToClosed(tvTerm));
                }
            });

            var boogieFunValArgs =
                f.InParams.Select(
                    (v, idx) => converter.ConvertToBoogieVal(v.TypedIdent.Type, new TermIdent(boundParamVars[idx]))
                    ).ToList();

            Term left = new TermApp(funInterpMapping[f], new List <Term>
            {
                new TermList(boogieFunTyArgs),
                new TermList(boogieFunValArgs)
            });

            Term vcFunApp =
                new TermApp(declToVCMapping[f],
                            vcFunTyArgs.Union(
                                boundParamVars.Select(bv => (Term) new TermIdent(bv)).ToList()
                                ).ToList());

            var outputType = f.OutParams.First().TypedIdent.Type;

            var right = IsaCommonTerms.SomeOption(
                converter.ConvertToBoogieVal(outputType,
                                             vcFunApp)
                );

            Term equation = TermBinary.Eq(left, right);

            Term conclusion;

            if (!TypeUtil.IsPrimitive(outputType))
            {
                //if type is not primitive, then the type information is not yet included

                conclusion = TermBinary.And(equation,
                                            TermBinary.Eq(
                                                IsaBoogieTerm.TypeToVal(boogieContext.absValTyMap, vcFunApp),
                                                typeIsaVisitor.Translate(outputType)
                                                ));
            }
            else
            {
                conclusion = equation;
            }

            if (valueArgConstraints.Any())
            {
                conclusion = TermBinary.MetaImplies(valueArgConstraints.Aggregate((t1, t2) => TermBinary.And(t2, t1)), conclusion);
            }

            if (boogieFunTyArgs.Any())
            {
                var closednessAssms = boogieFunTyArgs.Select(t1 => IsaBoogieTerm.IsClosedType(t1))
                                      .Aggregate((t1, t2) => TermBinary.And(t2, t1));
                conclusion = TermBinary.MetaImplies(closednessAssms, conclusion);
            }

            if (boundParamVars.Any())
            {
                return(new TermQuantifier(TermQuantifier.QuantifierKind.META_ALL,
                                          boundParamVars.Union(boundTypeVars).ToList(), conclusion));
            }

            return(conclusion);
        }
示例#3
0
 public override Term TypeConstructorInverse(string constrName, int index, Function func)
 {
     return(IsaBoogieVC.VCInv(index));
 }
示例#4
0
 public override Term TypeConstructor(string constrName, Function func)
 {
     return(IsaBoogieVC.VCTypeConstructor(constrName, func.InParams.Count));
 }
示例#5
0
 public override Term Type(Function func)
 {
     return(IsaBoogieVC.VCType(_boogieContextIsa.absValTyMap));
 }
示例#6
0
 public override Term IntType(Function func)
 {
     return(IsaBoogieVC.PrimTypeClosed(IsaBoogieType.IntType()));
 }