Пример #1
0
        public static List <CompoundErrorInformation> GenerateErrorInfoList(ProofState state, string msg = "")
        {
            List <CompoundErrorInformation> errs = new List <CompoundErrorInformation>();
            //resolving errors: moving those errors to error info
            var report = state.GetErrHandler().Reporter;

            if (report.Count(ErrorLevel.Error) != 0)
            {
                foreach (var errMsg in report.AllMessages[ErrorLevel.Error])
                {
                    AddErrorInfo(state, errMsg.message);
                }
            }
            // verification error + resolving errors
            var l = state.GetErrHandler().ErrorList;

            Console.WriteLine("\n================ Tactic exception: ================");

            if (l != null && l.Count > 0)
            {
                foreach (var err in l)
                {
                    errs.Add(new CompoundErrorInformation(msg, err, state));
                    Console.WriteLine(err.FullMsg);
                }
            }
            var errInfo = new CompoundErrorInformation(msg, state);

            Console.WriteLine(errInfo.FullMsg);
            Console.WriteLine("================ End of tactic exception ================");
            errs.Add(errInfo);

            return(errs);
        }
Пример #2
0
        internal static void AddErrorInfo(ProofState state, string msg)
        {
            var errInfo = new CompoundErrorInformation(msg, state);

            if (state.GetErrHandler().ErrorList == null)
            {
                state.GetErrHandler().ErrorList = new List <ErrorInformation>();
            }
            state.GetErrHandler().ErrorList.Add(errInfo);
        }
Пример #3
0
        public static Program GenerateResolvedProg0(ProofState state)
        {
            var prog = state.GetDafnyProgram();
            var r    = new Resolver(prog);

            r.ResolveProgram(prog);
            //get the generated code
            var results = new Dictionary <Statement, List <Statement> >
            {
                { state.TopLevelTacApp, state.GetGeneratedCode().Copy() }
            };
            var body = InsertCode(state, results);
            // find the membcl in the resoved prog
            Method destMd = null;

            foreach (var m in prog.DefaultModuleDef.TopLevelDecls)
            {
                if (m.WhatKind == "class")
                {
                    var defaultClassDecl = m as DefaultClassDecl;
                    if (defaultClassDecl != null)
                    {
                        foreach (var method in defaultClassDecl.Members)
                        {
                            if (method.FullName == state.TargetMethod.FullName)
                            {
                                destMd = (method as Method);
                                if (destMd != null)
                                {
                                    destMd.CallsTactic = 0;
                                    destMd.Body.Body.Clear();
                                    destMd.Body.Body.AddRange(body.Body);
                                }
                            }// if some other method has tactic call, then empty the body
                            else if (method.CallsTactic != 0)
                            {
                                method.CallsTactic = 0;
                                var o = method as Method;
                                o?.Body.Body.Clear();
                                SetVerifyFalseAttr(method);
                            }
                            else
                            {
                                //set other memberdecl as verify false
                                SetVerifyFalseAttr(method);
                            }
                        }
                    }
                }
            }
            //
#if _TACTIC_DEBUG_L1
            Console.WriteLine("********************* Tactic in : " + destMd + " *****************");
            var printer = new Printer(Console.Out);
            //printer.PrintProgram(prog, false);
            foreach (var stmt in state.GetGeneratedCode())
            {
                printer.PrintStatement(stmt, 0);
                Console.WriteLine("");
            }
            Console.WriteLine("********************* Stmts END *****************");
#endif
            //

            if (destMd != null)
            {
                destMd.CallsTactic = 0;
                r.SetCurClass(destMd.EnclosingClass as ClassDecl);
                r.ResolveMethodBody(destMd, state.GetDafnyProgram().DefaultModuleDef.Name);
            }


            if (prog.reporter.Count(ErrorLevel.Error) != 0)
            {
                state.GetErrHandler().Reporter = prog.reporter;
#if _TACTIC_DEBUG_L1
                Console.Write("Fail to resolve prog, skip verifier ! \n");
#endif
                return(null);
            }
            else
            {
                return(prog);
            }
        }
Пример #4
0
        public static Program GenerateResolvedProg(ProofState state)
        {
            var prog = state.GetDafnyProgram();

            var result = TacnyDriver.GetResultList().Where(
                kvp => kvp.Key.Tok.pos != state.TopLevelTacApp.Tok.pos).ToDictionary(c => c.Key, c => c.Value);

            result.Add(state.TopLevelTacApp, state.GetGeneratedCode().Copy());

            var body = InsertCode(state, result);

            Method           destMd           = null;
            DefaultClassDecl defaultClassDecl = null;

            foreach (var m in prog.DefaultModuleDef.TopLevelDecls)
            {
                if (m.WhatKind == "class")
                {
                    var classDecl = m as DefaultClassDecl;
                    if (classDecl != null)
                    {
                        foreach (var method in classDecl.Members)
                        {
                            if (method.Name == state.TargetMethod.Name)
                            {
                                destMd           = (method as Method);
                                defaultClassDecl = classDecl;
                            }
                            else if (!(method is Tactic))
                            {
                                method.CallsTactic = 0;
                                var o = method as Method;
                                if (o != null && o.Body != null)
                                {
                                    o?.Body.Body.Clear();
                                }
                                SetVerifyFalseAttr(method);
                            }
                        }
                    }
                }
            }


            destMd.CallsTactic = 0;
            destMd.Body.Body.Clear();
            destMd.Body.Body.AddRange(body.Body);

            var r = new Resolver(prog);

            r.ResolveProgram(prog);

            if (prog.reporter.Count(ErrorLevel.Error) != 0)
            {
                state.GetErrHandler().Reporter = prog.reporter;
#if _TACTIC_DEBUG_L1
                Console.Write("Fail to resolve prog, skip verifier ! \n");
#endif
                return(null);
            }
            else
            {
                return(prog);
            }
        }
Пример #5
0
        public static IEnumerable <ProofState> EvalTopLevelTactic(ProofState state, Dictionary <IVariable, Type> variables,
                                                                  Statement tacticApplication, ApplySuffix aps, ErrorReporterDelegate errorDelegate, bool ifPartial)
        {
            Contract.Requires <ArgumentNullException>(Tcce.NonNull(variables));
            Contract.Requires <ArgumentNullException>(Tcce.NonNull(tacticApplication));
            Contract.Requires <ArgumentNullException>(state != null, "state");
            Contract.Requires(tacticApplication == null ||
                              tacticApplication is UpdateStmt || tacticApplication is InlineTacticBlockStmt);

            IEnumerable <ProofState> branches;

            if (state.InitState(tacticApplication, aps, variables, ifPartial) == false)
            {
                return(null);
            }

#if !TACNY_DEBUG
            try {
#endif
            if (state.GetErrHandler().Reporter.Count(ErrorLevel.Error) != 0)
            {
                var errs = CompoundErrorInformation.GenerateErrorInfoList(state);
                if (errorDelegate != null)
                {
                    foreach (var err in errs)
                    {
                        errorDelegate(err);
                    }
                }

                return(null);
            }
            branches = GenerateSolution(state, errorDelegate);

      #if !TACNY_DEBUG
        }

        catch (Exception e) {
            String msg;
            List <CompoundErrorInformation> errs;
            try {
                msg  = "Tactic unknown exception: " + e.Message;
                errs = CompoundErrorInformation.GenerateErrorInfoList(state, msg);
            } catch (Exception) {
                msg  = "Tactic exception";
                errs = new List <CompoundErrorInformation>();
            }

            if (errorDelegate != null)
            {
                foreach (var err in errs)
                {
                    errorDelegate(err);
                }
            }
            return(null);
        }
#endif

            return(branches);
        }