public bool Visit(VCExprNAry node, TextWriter wr) { //Contract.Requires(wr != null); //Contract.Requires(node != null); VCExprOp /*!*/ op = node.Op; Contract.Assert(op != null); if (op.Equals(VCExpressionGenerator.AndOp) || op.Equals(VCExpressionGenerator.OrOp)) { // handle these operators without recursion wr.Write("({0}", op.Equals(VCExpressionGenerator.AndOp) ? "And" : "Or"); IEnumerator /*!*/ enumerator = new VCExprNAryUniformOpEnumerator(node); Contract.Assert(enumerator != null); while (enumerator.MoveNext()) { VCExprNAry naryExpr = enumerator.Current as VCExprNAry; if (naryExpr == null || !naryExpr.Op.Equals(op)) { wr.Write(" "); Print(cce.NonNull((VCExpr /*!*/)enumerator.Current), wr); } } wr.Write(")"); return(true); } return(node.Accept <bool, TextWriter /*!*/>(OpPrinter, wr)); }
///////////////////////////////////////////////////////////////////////////////////// public bool Visit(VCExprNAry node, LineariserOptions options) { //Contract.Requires(options != null); //Contract.Requires(node != null); VCExprOp op = node.Op; Contract.Assert(op != null); if (!options.AsTerm && (op.Equals(VCExpressionGenerator.AndOp) || op.Equals(VCExpressionGenerator.OrOp))) { // handle these operators without recursion wr.Write("({0}", op.Equals(VCExpressionGenerator.AndOp) ? andName : orName); IEnumerator enumerator = new VCExprNAryUniformOpEnumerator(node); Contract.Assert(enumerator != null); while (enumerator.MoveNext()) { VCExprNAry naryExpr = enumerator.Current as VCExprNAry; if (naryExpr == null || !naryExpr.Op.Equals(op)) { wr.Write(" "); Linearise(cce.NonNull((VCExpr)enumerator.Current), options); } } wr.Write(")"); return(true); } return(node.Accept <bool, LineariserOptions>(OpLineariser, options)); }
public Term Visit(VCExprNAry node, LineariserOptions options) { Contract.Requires(options != null); Contract.Requires(node != null); VCExprOp op = node.Op; Contract.Assert(op != null); if (op.Equals(VCExpressionGenerator.AndOp) || op.Equals(VCExpressionGenerator.OrOp)) { // handle these operators without recursion List <Term> asts = new List <Term>(); string opString = op.Equals(VCExpressionGenerator.AndOp) ? "AND" : "OR"; IEnumerator enumerator = new VCExprNAryUniformOpEnumerator(node); Contract.Assert(enumerator != null); while (enumerator.MoveNext()) { VCExprNAry naryExpr = enumerator.Current as VCExprNAry; if (naryExpr == null || !naryExpr.Op.Equals(op)) { asts.Add(Linearise(cce.NonNull((VCExpr)enumerator.Current), options)); } } return(Make(op, asts)); } return(node.Accept <Term, LineariserOptions>(OpLineariser, options)); }
///////////////////////////////////////////////////////////////////////////////////// public bool Visit(VCExprNAry node, LineariserOptions options) { //Contract.Requires(node != null); //Contract.Requires(options != null); VCExprOp op = node.Op; Contract.Assert(op != null); if (op.Equals(VCExpressionGenerator.AndOp) || op.Equals(VCExpressionGenerator.OrOp)) { // handle these operators without recursion wr.Write("({0}", op.Equals(VCExpressionGenerator.AndOp) ? "and" : "or"); foreach (var ch in node.UniformArguments) { wr.Write("\n"); Linearise(ch, options); } wr.Write(")"); return(true); } return(node.Accept <bool, LineariserOptions /*!*/>(OpLineariser, options)); }
///////////////////////////////////////////////////////////////////////////////////// public bool Visit(VCExprNAry node, LineariserOptions options) { VCExprOp op = node.Op; Contract.Assert(op != null); var booleanOps = new HashSet <VCExprOp>(); booleanOps.Add(VCExpressionGenerator.NotOp); booleanOps.Add(VCExpressionGenerator.ImpliesOp); booleanOps.Add(VCExpressionGenerator.AndOp); booleanOps.Add(VCExpressionGenerator.OrOp); if (booleanOps.Contains(op)) { Stack <VCExpr> exprs = new Stack <VCExpr>(); exprs.Push(node); while (exprs.Count > 0) { VCExpr expr = exprs.Pop(); if (expr == null) { wr.Write(")"); continue; } wr.Write(" "); VCExprNAry naryExpr = expr as VCExprNAry; if (naryExpr == null || !booleanOps.Contains(naryExpr.Op)) { Linearise(expr, options); continue; } else if (naryExpr.Op.Equals(VCExpressionGenerator.NotOp)) { wr.Write("(not"); } else if (naryExpr.Op.Equals(VCExpressionGenerator.ImpliesOp)) { wr.Write("(=>"); } else if (naryExpr.Op.Equals(VCExpressionGenerator.AndOp)) { wr.Write("(and"); } else { System.Diagnostics.Debug.Assert(naryExpr.Op.Equals(VCExpressionGenerator.OrOp)); wr.Write("(or"); } exprs.Push(null); for (int i = naryExpr.Arity - 1; i >= 0; i--) { exprs.Push(naryExpr[i]); } } return(true); } return(node.Accept <bool, LineariserOptions /*!*/>(OpLineariser, options)); }
///////////////////////////////////////////////////////////////////////////////////// public bool Visit(VCExprNAry node, LineariserOptions options) { VCExprOp op = node.Op; Contract.Assert(op != null); var booleanOps = new HashSet <VCExprOp>(); booleanOps.Add(VCExpressionGenerator.NotOp); booleanOps.Add(VCExpressionGenerator.ImpliesOp); booleanOps.Add(VCExpressionGenerator.AndOp); booleanOps.Add(VCExpressionGenerator.OrOp); if (booleanOps.Contains(op)) { Stack <VCExpr> exprs = new Stack <VCExpr>(); exprs.Push(node); while (exprs.Count > 0) { VCExpr expr = exprs.Pop(); if (expr == null) { wr.Write(")"); continue; } wr.Write(" "); VCExprNAry naryExpr = expr as VCExprNAry; if (naryExpr == null || !booleanOps.Contains(naryExpr.Op)) { Linearise(expr, options); continue; } else if (naryExpr.Op.Equals(VCExpressionGenerator.NotOp)) { wr.Write("(not"); } else if (naryExpr.Op.Equals(VCExpressionGenerator.ImpliesOp)) { wr.Write("(=>"); } else if (naryExpr.Op.Equals(VCExpressionGenerator.AndOp)) { wr.Write("(and"); } else { System.Diagnostics.Debug.Assert(naryExpr.Op.Equals(VCExpressionGenerator.OrOp)); wr.Write("(or"); } exprs.Push(null); for (int i = naryExpr.Arity - 1; i >= 0; i--) { exprs.Push(naryExpr[i]); } } return(true); } if (OptimizationRequests != null && (node.Op.Equals(VCExpressionGenerator.MinimizeOp) || node.Op.Equals(VCExpressionGenerator.MaximizeOp))) { string optOp = node.Op.Equals(VCExpressionGenerator.MinimizeOp) ? "minimize" : "maximize"; OptimizationRequests.Add(string.Format("({0} {1})", optOp, ToString(node[0], Namer, ProverOptions, NamedAssumes))); Linearise(node[1], options); return(true); } if (node.Op is VCExprSoftOp) { Linearise(node[1], options); return(true); } if (node.Op.Equals(VCExpressionGenerator.NamedAssumeOp)) { var exprVar = node[0] as VCExprVar; NamedAssumes.Add(exprVar); Linearise(node[1], options); return(true); } return(node.Accept <bool, LineariserOptions /*!*/>(OpLineariser, options)); }