Ejemplo n.º 1
0
        public static string Parse(IList <DafnyFile> files, string programName, ErrorReporter reporter, out Program program)
        {
            Contract.Requires(programName != null);
            Contract.Requires(files != null);
            program = null;

            ModuleDecl module = new LiteralModuleDecl(new DefaultModuleDecl(), null);

            BuiltIns builtIns = new BuiltIns();

            foreach (DafnyFile dafnyFile in files)
            {
                Contract.Assert(dafnyFile != null);
                if (Bpl.CommandLineOptions.Clo.XmlSink != null && Bpl.CommandLineOptions.Clo.XmlSink.IsOpen)
                {
                    Bpl.CommandLineOptions.Clo.XmlSink.WriteFileFragment(dafnyFile.FilePath);
                }
                if (Bpl.CommandLineOptions.Clo.Trace)
                {
                    Console.WriteLine("Parsing " + dafnyFile.FilePath);
                }

                string err = ParseFile(dafnyFile, null, module, builtIns, new Errors(reporter));
                if (err != null)
                {
                    return(err);
                }
            }

            if (!(DafnyOptions.O.DisallowIncludes || DafnyOptions.O.PrintIncludesMode == DafnyOptions.IncludesModes.Immediate))
            {
                string errString = ParseIncludes(module, builtIns, DafnyFile.fileNames(files), new Errors(reporter));
                if (errString != null)
                {
                    return(errString);
                }
            }

            if (DafnyOptions.O.PrintIncludesMode == DafnyOptions.IncludesModes.Immediate)
            {
                DependencyMap dmap = new DependencyMap();
                dmap.AddIncludes(((LiteralModuleDecl)module).ModuleDef.Includes);
                dmap.PrintMap();
            }

            program = new Program(programName, module, builtIns, reporter);

            MaybePrintProgram(program, DafnyOptions.O.DafnyPrintFile, false);

            return(null); // success
        }
Ejemplo n.º 2
0
        static ExitValue ProcessFiles(IList <DafnyFile /*!*/> /*!*/ dafnyFiles, ReadOnlyCollection <string> otherFileNames,
                                      ErrorReporter reporter, bool lookForSnapshots = true, string programId = null)
        {
            Contract.Requires(cce.NonNullElements(dafnyFiles));
            var dafnyFileNames = DafnyFile.fileNames(dafnyFiles);

            ExitValue exitValue = ExitValue.VERIFIED;

            if (CommandLineOptions.Clo.VerifySeparately && 1 < dafnyFiles.Count)
            {
                foreach (var f in dafnyFiles)
                {
                    Console.WriteLine();
                    Console.WriteLine("-------------------- {0} --------------------", f);
                    var ev = ProcessFiles(new List <DafnyFile> {
                        f
                    }, new List <string>().AsReadOnly(), reporter, lookForSnapshots, f.FilePath);
                    if (exitValue != ev && ev != ExitValue.VERIFIED)
                    {
                        exitValue = ev;
                    }
                }
                return(exitValue);
            }

            if (0 <= CommandLineOptions.Clo.VerifySnapshots && lookForSnapshots)
            {
                var snapshotsByVersion = ExecutionEngine.LookForSnapshots(dafnyFileNames);
                foreach (var s in snapshotsByVersion)
                {
                    var snapshots = new List <DafnyFile>();
                    foreach (var f in s)
                    {
                        snapshots.Add(new DafnyFile(f));
                    }
                    var ev = ProcessFiles(snapshots, new List <string>().AsReadOnly(), reporter, false, programId);
                    if (exitValue != ev && ev != ExitValue.VERIFIED)
                    {
                        exitValue = ev;
                    }
                }
                return(exitValue);
            }

            Dafny.Program dafnyProgram;
            string        programName = dafnyFileNames.Count == 1 ? dafnyFileNames[0] : "the program";
            string        err         = Dafny.Main.ParseCheck(dafnyFiles, programName, reporter, out dafnyProgram);

            if (err != null)
            {
                exitValue = ExitValue.DAFNY_ERROR;
                ExecutionEngine.printer.ErrorWriteLine(Console.Out, err);
            }
            else if (dafnyProgram != null && !CommandLineOptions.Clo.NoResolve && !CommandLineOptions.Clo.NoTypecheck &&
                     DafnyOptions.O.DafnyVerify)
            {
                var boogiePrograms = Translate(dafnyProgram);

                Dictionary <string, PipelineStatistics> statss;
                PipelineOutcome oc;
                string          baseName = cce.NonNull(Path.GetFileName(dafnyFileNames[dafnyFileNames.Count - 1]));
                var             verified = Boogie(baseName, boogiePrograms, programId, out statss, out oc);
                var             compiled = Compile(dafnyFileNames[0], otherFileNames, dafnyProgram, oc, statss, verified);
                exitValue = verified && compiled ? ExitValue.VERIFIED : !verified ? ExitValue.NOT_VERIFIED : ExitValue.COMPILE_ERROR;
            }

            if (err == null && dafnyProgram != null && DafnyOptions.O.PrintStats)
            {
                Util.PrintStats(dafnyProgram);
            }
            if (err == null && dafnyProgram != null && DafnyOptions.O.PrintFunctionCallGraph)
            {
                Util.PrintFunctionCallGraph(dafnyProgram);
            }
            return(exitValue);
        }