Ejemplo n.º 1
0
        /////////////////////////////////////////////////////////////////////////////////////

        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }