コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }