コード例 #1
0
        private string ScanMemberBody(MemberDecl md)
        {
            Contract.Requires(md != null);
            solution_list.plist.Clear();
            Method m = md as Method;

            if (m == null)
            {
                return(null);
            }
            if (m.Body == null)
            {
                return(null);
            }

            List <IVariable> variables = new List <IVariable>();

            variables.AddRange(m.Ins);
            variables.AddRange(m.Outs);
            SolutionList sol_list = new SolutionList();

            sol_list.AddRange(solution_list.plist);
            if (TacnyOptions.O.ParallelExecution)
            {
                Parallel.ForEach(m.Body.Body, st =>
                {
                    // register local variables
                    VarDeclStmt vds = st as VarDeclStmt;
                    if (vds != null)
                    {
                        variables.AddRange(vds.Locals);
                    }

                    UpdateStmt us = st as UpdateStmt;
                    if (us != null)
                    {
                        if (tacnyProgram.IsTacticCall(us))
                        {
                            try
                            {
                                tacnyProgram.SetCurrent(tacnyProgram.GetTactic(us), md);
                                // get the resolved variables
                                List <IVariable> resolved = tacnyProgram.GetResolvedVariables(md);
                                resolved.AddRange(m.Ins);     // add input arguments as resolved variables
                                Atomic.ResolveTactic(tacnyProgram.GetTactic(us), us, md, tacnyProgram, variables, resolved, ref sol_list);
                                tacnyProgram.CurrentDebug.Fin();
                            }
                            catch (AggregateException e)
                            {
                                foreach (var err in e.Data)
                                {
                                    Printer.Error(err.ToString());
                                }
                            }
                        }
                    }
                });
            }
            else
            {
                foreach (var st in m.Body.Body)
                {
                    // register local variables
                    VarDeclStmt vds = st as VarDeclStmt;
                    if (vds != null)
                    {
                        variables.AddRange(vds.Locals);
                    }

                    UpdateStmt us = st as UpdateStmt;
                    if (us != null)
                    {
                        if (tacnyProgram.IsTacticCall(us))
                        {
                            try
                            {
                                tacnyProgram.SetCurrent(tacnyProgram.GetTactic(us), md);
                                // get the resolved variables
                                List <IVariable> resolved = tacnyProgram.GetResolvedVariables(md);
                                resolved.AddRange(m.Ins); // add input arguments as resolved variables
                                Atomic.ResolveTactic(tacnyProgram.GetTactic(us), us, md, tacnyProgram, variables, resolved, ref sol_list);
                                tacnyProgram.CurrentDebug.Fin();
                            }
                            catch (Exception e)
                            {
                                return(e.Message);
                            }
                        }
                    }
                }
            }
            solution_list.AddRange(sol_list.plist);
            return(null);
        }
コード例 #2
0
ファイル: TacnyDriver.cs プロジェクト: ggrov/tacny
        /// <summary>
        /// Processes the file
        /// </summary>
        /// <param name="fileNames"></param>
        /// <param name="programId"></param>
        /// <returns></returns>
        static ExitValue ProcessFiles(IList <string /*!*/> /*!*/ fileNames, string programId = null)
        {
            //Contract.Requires(Tacny.tcce.NonNullElements(fileNames));

            if (programId == null)
            {
                programId = fileNames[0];
            }

            var exitValue = ExitValue.Verified;

            if (CommandLineOptions.Clo.VerifySeparately && 1 < fileNames.Count)
            {
                foreach (string f in fileNames)
                {
                    Console.WriteLine();
                    Console.WriteLine($"-------------------- {f} --------------------");
                    var ev = ProcessFiles(new List <string> {
                        f
                    }, f);
                    if (exitValue != ev && ev != ExitValue.Verified)
                    {
                        exitValue = ev;
                    }
                }
                return(exitValue);
            }

            using (new XmlFileScope(CommandLineOptions.Clo.XmlSink, fileNames[fileNames.Count - 1])) {
                Program tacnyProgram;
                string  programName = fileNames.Count == 1 ? fileNames[0] : "the program";
                // install Util.Printer
                try {
                    Debug.WriteLine("Initializing Tacny Program");
                    tacnyProgram = new Program(fileNames, programId);
                    // Initialize the printer
                    Printer.Install(fileNames[0]);
                    tacnyProgram.MaybePrintProgram(tacnyProgram.DafnyProgram, programName + "_src");
                } catch (ArgumentException ex) {
                    exitValue = ExitValue.DafnyError;
                    _printer.ErrorWriteLine(Console.Out, ex.Message);
                    return(exitValue);
                }


                var program = tacnyProgram.ParseProgram();
                int qq      = tacnyProgram.ResolveProgram(program);
                var md      = Interpreter.FindAndApplyTactic(tacnyProgram.ParseProgram(), ((ClassDecl)program.DefaultModuleDef.TopLevelDecls[0]).Members[0], null);
                Printer.P.GetConsolePrinter().PrintMethod(md as Method, 0, false);


                if (!CommandLineOptions.Clo.NoResolve && !CommandLineOptions.Clo.NoTypecheck && DafnyOptions.O.DafnyVerify)
                {
                    Debug.WriteLine("Starting lazy tactic evaluation");
                    LazyTacny.Interpreter r = new LazyTacny.Interpreter(tacnyProgram);
                    var prog = r.ResolveProgram();
                    tacnyProgram.PrintProgram(prog);
                    Debug.WriteLine("Fnished lazy tactic evaluation");
                }
                tacnyProgram.PrintAllDebugData(TacnyOptions.O.PrintCsv);
            }
            return(exitValue);
        }