public override bool Visit(VCExprNAry node, bool arg) { Contract.Requires(node != null); VCExprBoogieFunctionOp op = node.Op as VCExprBoogieFunctionOp; if (op == null) { base.Visit(node, arg); return(false); } bool res = true; foreach (VCExpr subexpr in node) { Contract.Assert(subexpr != null); res &= this.Traverse(subexpr, arg); } if (res) { TermClustersSameHead clusters; if (!SubtermClusters.TryGetValue(op, out clusters)) { clusters = new TermClustersSameHead(op, GlobalVariables, Gen); SubtermClusters.Add(op, clusters); } cce.NonNull(clusters).AddExpr(node); } return(res); }
public bool VisitBoogieFunctionOp(VCExprNAry node, LineariserOptions options) { VCExprBoogieFunctionOp op = (VCExprBoogieFunctionOp)node.Op; Contract.Assert(op != null); string printedName; var builtin = ExtractBuiltin(op.Func); var datatype = ExtractDatatype(op.Func); if (builtin != null) { printedName = CheckMapApply(builtin, node); } else if (datatype != null) { printedName = datatype; } else { printedName = ExprLineariser.Namer.GetQuotedName(op.Func, op.Func.Name); } Contract.Assert(printedName != null); WriteApplication(printedName, node, options); return(true); }
public bool VisitBoogieFunctionOp(VCExprNAry node, TextWriter wr) { //Contract.Requires(wr != null); //Contract.Requires(node != null); VCExprBoogieFunctionOp /*!*/ op = (VCExprBoogieFunctionOp)node.Op; Contract.Assert(op != null); return(PrintNAry(op.Func.Name, node, wr)); }
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)); }
public bool VisitBoogieFunctionOp(VCExprNAry node, LineariserOptions options) { //Contract.Requires(options != null); //Contract.Requires(node != null); VCExprBoogieFunctionOp op = (VCExprBoogieFunctionOp)node.Op; Contract.Assert(op != null); string funcName = op.Func.Name; Contract.Assert(funcName != null); string bvzName = op.Func.FindStringAttribute("external"); string printedName = ExprLineariser.Namer.GetName(op.Func, funcName); Contract.Assert(printedName != null); if (bvzName != null) { printedName = bvzName; } if (options.UseTypes) { // we use term notation for arguments whose type is not bool, and // formula notation for boolean arguments wr.Write("("); ExprLineariser.WriteId(printedName); foreach (VCExpr e in node) { Contract.Assert(e != null); wr.Write(" "); ExprLineariser.Linearise(e, options.SetAsTerm(!e.Type.IsBool)); } wr.Write(")"); } else { // arguments are always terms WriteApplicationTermOnly(SimplifyLikeExprLineariser.MakeIdPrintable(printedName), node, options); } return(true); }
public bool VisitBoogieFunctionOp(VCExprNAry node, LineariserOptions options) { //Contract.Requires(node != null); //Contract.Requires(options != null); VCExprBoogieFunctionOp op = (VCExprBoogieFunctionOp)node.Op; Contract.Assert(op != null); string printedName = ExprLineariser.Namer.GetName(op.Func, Lowercase(op.Func.Name)); Contract.Assert(printedName != null); if (ExprLineariser.Options.UsePredicates && op.Func.OutParams[0].TypedIdent.Type.IsBool) { WriteApplication(printedName, node, options, true); } else { // arguments are always terms WriteApplicationTermOnly(printedName, node, options); } return(true); }
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); } } return(base.Visit(node, arg)); }
///////////////////////////////////////////////////////////////////////////////////// public Term Make(VCExprOp op, List <Term> children) { Context z3 = cm.z3; Term[] unwrapChildren = children.ToArray(); VCExprBoogieFunctionOp boogieFunctionOp = op as VCExprBoogieFunctionOp; if (boogieFunctionOp != null) { FuncDecl f = cm.GetFunction(boogieFunctionOp.Func.Name); return(z3.MkApp(f, unwrapChildren)); } VCExprDistinctOp distinctOp = op as VCExprDistinctOp; if (distinctOp != null) { return(z3.MkDistinct(unwrapChildren)); } if (op == VCExpressionGenerator.AndOp) { return(z3.MkAnd(unwrapChildren)); } if (op == VCExpressionGenerator.OrOp) { return(z3.MkOr(unwrapChildren)); } if (op == VCExpressionGenerator.ImpliesOp) { return(z3.MkImplies(unwrapChildren[0], unwrapChildren[1])); } if (op == VCExpressionGenerator.NotOp) { return(z3.MkNot(unwrapChildren[0])); } if (op == VCExpressionGenerator.EqOp) { return(z3.MkEq(unwrapChildren[0], unwrapChildren[1])); } if (op == VCExpressionGenerator.NeqOp) { return(z3.MkNot(z3.MkEq(unwrapChildren[0], unwrapChildren[1]))); } if (op == VCExpressionGenerator.LtOp) { return(z3.MkLt(unwrapChildren[0], unwrapChildren[1])); } if (op == VCExpressionGenerator.LeOp) { return(z3.MkLe(unwrapChildren[0], unwrapChildren[1])); } if (op == VCExpressionGenerator.GtOp) { return(z3.MkGt(unwrapChildren[0], unwrapChildren[1])); } if (op == VCExpressionGenerator.GeOp) { return(z3.MkGe(unwrapChildren[0], unwrapChildren[1])); } if (op == VCExpressionGenerator.AddOp) { return(z3.MkAdd(unwrapChildren)); } if (op == VCExpressionGenerator.SubOp) { return(z3.MkSub(unwrapChildren)); } if (op == VCExpressionGenerator.DivOp || op == VCExpressionGenerator.RealDivOp) { return(z3.MkDiv(unwrapChildren[0], unwrapChildren[1])); } if (op == VCExpressionGenerator.MulOp) { return(z3.MkMul(unwrapChildren)); } if (op == VCExpressionGenerator.ModOp) { return(z3.MkMod(unwrapChildren[0], unwrapChildren[1])); } if (op == VCExpressionGenerator.IfThenElseOp) { return(z3.MkIte(unwrapChildren[0], unwrapChildren[1], unwrapChildren[2])); } if (op == VCExpressionGenerator.ToIntOp) { return(z3.MkToInt(unwrapChildren[0])); } if (op == VCExpressionGenerator.ToRealOp) { return(z3.MkToReal(unwrapChildren[0])); } throw new Exception("unhandled boogie operator"); }