public override bool Visit(VCExprNAry node, bool arg)
        {
            Contract.Requires(node != null);

            if (node.Op is VCExprStoreOp)
            {
                RegisterStore(node);
            }
            else if (node.Op is VCExprSelectOp)
            {
                RegisterSelect(node);
            }
            else
            {
                VCExprBoogieFunctionOp op = node.Op as VCExprBoogieFunctionOp;
                if (op != null &&
                    !(op.Func is DatatypeConstructor) && !(op.Func is DatatypeMembership) && !(op.Func is DatatypeSelector) &&
                    !KnownFunctions.Contains(op.Func))
                {
                    Function f = op.Func;
                    Contract.Assert(f != null);

                    var builtin = SMTLibExprLineariser.ExtractBuiltin(f);
                    if (builtin == null)
                    {
                        string printedName = Namer.GetQuotedName(f, f.Name);
                        Contract.Assert(printedName != null);

                        Contract.Assert(f.OutParams.Count == 1);
                        var    argTypes = f.InParams.Cast <Variable>().MapConcat(p => TypeToStringReg(p.TypedIdent.Type), " ");
                        string decl;
                        if (RegisteredRelations.Contains(op.Func))
                        {
                            decl = "(declare-rel " + printedName + " (" + argTypes + ") " + ")";
                        }
                        else
                        {
                            decl = "(declare-fun " + printedName + " (" + argTypes + ") " + TypeToStringReg(f.OutParams[0].TypedIdent.Type) + ")";
                        }
                        AddDeclaration(decl);
                    }
                    KnownFunctions.Add(f);
                }
                else
                {
                    var lab = node.Op as VCExprLabelOp;
                    if (lab != null && !KnownLBL.Contains(lab.label))
                    {
                        KnownLBL.Add(lab.label);
                        var name = SMTLibNamer.QuoteId(SMTLibNamer.LabelVar(lab.label));
                        AddDeclaration("(declare-fun " + name + " () Bool)");
                    }
                }
            }

            return(base.Visit(node, arg));
        }
示例#2
0
        public override bool Visit(VCExprNAry node, bool arg)
        {
            Contract.Requires(node != null);

            if (node.Op is VCExprStoreOp)
            {
                RegisterStore(node);
            }
            else if (node.Op is VCExprSelectOp)
            {
                RegisterSelect(node);
            }
            else if (node.Op is VCExprSoftOp)
            {
                var exprVar = node[0] as VCExprVar;
                AddDeclaration(string.Format("(declare-fun {0} () Bool)", exprVar.Name));
                AddDeclaration(string.Format("(assert-soft {0} :weight {1})", exprVar.Name, ((VCExprSoftOp)node.Op).Weight));
            }
            else if (node.Op.Equals(VCExpressionGenerator.NamedAssumeOp))
            {
                var exprVar = node[0] as VCExprVar;
                AddDeclaration(string.Format("(declare-fun {0} () Bool)", exprVar.Name));
                if (CommandLineOptions.Clo.PrintNecessaryAssumes)
                {
                    AddDeclaration(string.Format("(assert (! {0} :named {1}))", exprVar.Name, "aux$$" + exprVar.Name));
                }
            }
            else
            {
                VCExprBoogieFunctionOp op = node.Op as VCExprBoogieFunctionOp;
                if (op != null &&
                    !(op.Func is DatatypeConstructor) && !(op.Func is DatatypeMembership) && !(op.Func is DatatypeSelector) &&
                    !KnownFunctions.Contains(op.Func))
                {
                    Function f = op.Func;
                    Contract.Assert(f != null);

                    var builtin = SMTLibExprLineariser.ExtractBuiltin(f);
                    if (builtin == null)
                    {
                        string printedName = Namer.GetQuotedName(f, f.Name);
                        Contract.Assert(printedName != null);

                        Contract.Assert(f.OutParams.Count == 1);
                        var    argTypes = f.InParams.Cast <Variable>().MapConcat(p => TypeToStringReg(p.TypedIdent.Type), " ");
                        string decl;
                        if (RegisteredRelations.Contains(op.Func))
                        {
                            decl = "(declare-rel " + printedName + " (" + argTypes + ") " + ")";
                        }
                        else
                        {
                            decl = "(declare-fun " + printedName + " (" + argTypes + ") " + TypeToStringReg(f.OutParams[0].TypedIdent.Type) + ")";
                        }
                        AddDeclaration(decl);
                        if (declHandler != null)
                        {
                            declHandler.FuncDecl(f);
                        }
                    }
                    KnownFunctions.Add(f);
                }
                else
                {
                    var lab = node.Op as VCExprLabelOp;
                    if (lab != null && !KnownLBL.Contains(lab.label))
                    {
                        KnownLBL.Add(lab.label);
                        var name = SMTLibNamer.QuoteId(Namer.LabelVar(lab.label));
                        AddDeclaration("(declare-fun " + name + " () Bool)");
                    }
                }
            }

            return(base.Visit(node, arg));
        }