/// <summary>
        /// Returns the properties associated with <paramref name="v"/> in its variable declaration.
        /// The first element of the result tuple is the type and the second element is the where clause.
        /// </summary>
        public static Tuple <Term, Term> VarDeclTuple(Variable v, TypeIsaVisitor typeIsaVisitor, Func <Absy, Term> boogieToIsa)
        {
            var vType        = typeIsaVisitor.Translate(v.TypedIdent.Type);
            var vWhereClause = v.TypedIdent.WhereExpr != null
                ? IsaCommonTerms.SomeOption(boogieToIsa(v.TypedIdent.WhereExpr))
                : IsaCommonTerms.NoneOption();

            return(Tuple.Create(vType, vWhereClause));
        }
Exemple #2
0
        public override QuantifierExpr VisitQuantifierExpr(QuantifierExpr node)
        {
            if (!(node is ForallExpr || node is ExistsExpr))
            {
                throw new ProofGenUnexpectedStateException(GetType(), "can only handle forall and exists quantifiers");
            }

            var isForall = IsForall(node);

            //Quantifers with multiple bound variables are desugared into multiple quantifiers expressions with single variables
            foreach (var boundVar in node.Dummies)
            {
                boogieVarTranslation.VarTranslation.AddBoundVariable(boundVar);
            }
            foreach (var boundTyVar in node.TypeParameters)
            {
                boogieVarTranslation.TypeVarTranslation.AddBoundVariable(boundTyVar);
            }

            var numValVarBefore = boogieVarTranslation.VarTranslation.NumBoundVariables();
            var numTyVarBefore  = boogieVarTranslation.TypeVarTranslation.NumBoundVariables();

            var result = Translate(node.Body);

            if (numValVarBefore != boogieVarTranslation.VarTranslation.NumBoundVariables() ||
                numTyVarBefore != boogieVarTranslation.TypeVarTranslation.NumBoundVariables())
            {
                throw new ProofGenUnexpectedStateException(GetType(),
                                                           "quantifier levels not the same before and after");
            }

            for (var i = node.Dummies.Count - 1; i >= 0; i--)
            {
                boogieVarTranslation.VarTranslation.DropLastBoundVariable();
                var boundVar     = node.Dummies[i];
                var boundVarType = typeIsaVisitor.Translate(boundVar.TypedIdent.Type);
                result = IsaBoogieTerm.Quantifier(isForall, boundVarType, result);
            }

            for (var i = node.TypeParameters.Count - 1; i >= 0; i--)
            {
                boogieVarTranslation.TypeVarTranslation.DropLastBoundVariable();
                result = IsaBoogieTerm.TypeQuantifier(isForall, result);
            }

            ReturnResult(result);
            return(node);
        }
        public Term Visit(FunctionCall functionCall)
        {
            if (_args.Count != functionCall.ArgumentCount)
            {
                throw new ExprArgException();
            }

            var typeInstIsa = new List <Term>();

            foreach (var typeVar in _typeInst.FormalTypeParams)
            {
                var t = typeIsaVisitor.Translate(_typeInst[typeVar]);
                typeInstIsa.Add(t);
            }

            return(IsaBoogieTerm.FunCall(functionCall.FunctionName, typeInstIsa, _args));
        }