Beispiel #1
0
        public static HashSet <string /*!*/> /*!*/ FindLabels(VCExpr /*!*/ expr)
        {
            Contract.Requires(expr != null);
            Contract.Ensures(cce.NonNull(Contract.Result <HashSet <string /*!*/> /*!*/>()));

            FindLabelsVisitor visitor = new FindLabelsVisitor();

            visitor.Traverse(expr, true);
            return(visitor.Labels);
        }
Beispiel #2
0
        public void NewProblem(string descriptiveName, VCExpr vc, ProverInterface.ErrorHandler handler)
        {
            Contract.Requires(descriptiveName != null);
            Contract.Requires(vc != null);
            Contract.Requires(handler != null);
            HashSet <string /*!*/> /*!*/ labels = FindLabelsVisitor.FindLabels(vc);

            Contract.Assert(labels != null);
            toInspector.WriteLine("PROBLEM " + descriptiveName);
            toInspector.WriteLine("TOKEN BEGIN");
            foreach (string lab in labels)
            {
                Contract.Assert(lab != null);
                string no   = lab.Substring(1);
                Absy   absy = handler.Label2Absy(no);

                IToken    tok   = absy.tok;
                AssertCmd assrt = absy as AssertCmd;
                Block     blk   = absy as Block;
                string    val   = tok.val; // might require computation, so cache it
                if (val == "foo" || tok.filename == null)
                {
                    continue;                               // no token
                }
                toInspector.Write("TOKEN ");
                toInspector.Write(lab);
                toInspector.Write(" ");

                if (assrt != null)
                {
                    toInspector.Write("ASSERT");
                    string errData = assrt.ErrorData as string;
                    if (errData != null)
                    {
                        val = errData;
                    }
                    else if (assrt.ErrorMessage != null)
                    {
                        val = assrt.ErrorMessage;
                    }
                }
                else if (blk != null)
                {
                    toInspector.Write("BLOCK ");
                    toInspector.Write(blk.Label);
                }
                else
                {
                    Contract.Assume(false);
                }
                if (val == null || val == "assert" || val == "ensures")
                {
                    val = "";
                }

                if (absy is LoopInitAssertCmd)
                {
                    val += " (loop entry)";
                }
                else if (absy is LoopInvMaintainedAssertCmd)
                {
                    val += " (loop body)";
                }
                else if (val.IndexOf("#VCCERR") >= 0)
                {
                    // skip further transformations
                }
                else if (absy is AssertRequiresCmd)
                {
                    AssertRequiresCmd req  = (AssertRequiresCmd)absy;
                    IToken            t2   = req.Requires.tok;
                    string            tval = t2.val;
                    if (tval == "requires")
                    {
                        tval = string.Format("{0}({1},{2}))", t2.filename, t2.line, t2.col);
                    }
                    string call = "";
                    if (val != "call")
                    {
                        call = " in call to " + val;
                    }
                    val = string.Format("precondition {0}{1}", tval, call);
                }

                val = val.Replace("\r", "").Replace("\n", " ");

                toInspector.WriteLine(string.Format(" {0} {1} :@:{2}:@:{3}", tok.line, tok.col, tok.filename, val));
            }
            toInspector.WriteLine("TOKEN END");
        }