Ejemplo n.º 1
0
        public static Term VarContextTypeAssumption(Variable v, Term varContext, TypeIsaVisitor typeIsaVisitor)
        {
            Term left  = new TermApp(varContext, new StringConst(v.Name));
            var  right = IsaCommonTerms.SomeOption(typeIsaVisitor.Translate(v.TypedIdent.Type));

            return(new TermBinary(left, right, TermBinary.BinaryOpCode.Eq));
        }
Ejemplo n.º 2
0
        public static Term VariableTypeAssumption(
            Variable v,
            Term vcVar,
            TypeIsaVisitor typeIsaVisitor,
            Term absValTyMap)
        {
            var left  = IsaBoogieTerm.TypeToVal(absValTyMap, vcVar);
            var right = typeIsaVisitor.Translate(v.TypedIdent.Type);

            return(TermBinary.Eq(left, right));
        }
        private void AddHint(IDictionary <TypeVariable, Type> unifier)
        {
            var typeIsaVisitor = new TypeIsaVisitor(tyVarTranslation);
            IDictionary <int, Term> indexToType = new Dictionary <int, Term>();

            foreach (var entry in unifier)
            {
                if (tyVarTranslation.TryTranslateVariableId(entry.Key, out var idTerm, out _) &&
                    idTerm is NatConst idNat)
                {
                    indexToType.Add(idNat.Val, typeIsaVisitor.Translate(entry.Value));
                }
Ejemplo n.º 4
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);
        }