示例#1
0
        public static Program GenerateResolvedProg(ProofState state)
        {
            var prog = state.GetDafnyProgram();
            var r    = new Resolver(prog);

            r.ResolveProgram(prog);
            //get the generated code
            var results = new Dictionary <UpdateStmt, List <Statement> >();

            results.Add(state.TacticApplication, state.GetGeneratedCode().Copy());
            var body = Util.InsertCode(state, results);
            // find the membcl in the resoved prog
            Method dest_md = null;

            foreach (var m in prog.DefaultModuleDef.TopLevelDecls)
            {
                if (m.WhatKind == "class")
                {
                    foreach (var method in (m as DefaultClassDecl).Members)
                    {
                        if (method.FullName == state.TargetMethod.FullName)
                        {
                            dest_md = (method as Method);
                            dest_md.Body.Body.Clear();
                            dest_md.Body.Body.AddRange(body.Body);
                        }// if some other method has tactic call, then empty the body
                        else if (method.CallsTactic)
                        {
                            method.CallsTactic = false;
                            (method as Method).Body.Body.Clear();
                            SetVerifyFalseAttr(method);
                        }
                        else
                        {
                            //set other memberdecl as verify false
                            SetVerifyFalseAttr(method);
                        }
                    }
                }
            }

#if _TACTIC_DEBUG
            Console.WriteLine("*********************Verifying Tacny Generated Prog*****************");
            var printer = new Printer(Console.Out);
            //printer.PrintProgram(prog, false);
            foreach (var stmt in state.GetGeneratedCode())
            {
                printer.PrintStatement(stmt, 0);
            }
            Console.WriteLine("\n*********************Prog END*****************");
#endif

            dest_md.CallsTactic = false;
            r.SetCurClass(dest_md.EnclosingClass as ClassDecl);
            r.ResolveMethodBody(dest_md);

            if (prog.reporter.Count(ErrorLevel.Error) != 0)
            {
#if _TACTIC_DEBUG
                Console.Write("Fail to resolve prog, skip verifier ! \n");
#endif
                return(null);
            }
            else
            {
                return(prog);
            }
        }