Esempio n. 1
0
        public static string ParseIncludes(ModuleDecl module, BuiltIns builtIns, IList <string> excludeFiles, Errors errs)
        {
            SortedSet <Include> includes = new SortedSet <Include>(new IncludeComparer());
            DependencyMap       dmap     = new DependencyMap();

            foreach (string fileName in excludeFiles)
            {
                includes.Add(new Include(null, null, fileName, Path.GetFullPath(fileName), null));
            }
            dmap.AddIncludes(includes);
            bool newlyIncluded;

            do
            {
                newlyIncluded = false;

                List <Include> newFilesToInclude = new List <Include>();
                dmap.AddIncludes(((LiteralModuleDecl)module).ModuleDef.Includes);
                foreach (Include include in ((LiteralModuleDecl)module).ModuleDef.Includes)
                {
                    bool isNew = includes.Add(include);
                    if (isNew)
                    {
                        newlyIncluded = true;
                        newFilesToInclude.Add(include);
                    }
                }

                foreach (Include include in newFilesToInclude)
                {
                    DafnyFile file;
                    try { file = new DafnyFile(include.includedFilename); }
                    catch (IllegalDafnyFile) {
                        return(String.Format("Include of file \"{0}\" failed.", include.includedFilename));
                    }
                    string ret = ParseFile(file, include, module, builtIns, errs, false);
                    if (ret != null)
                    {
                        return(ret);
                    }
                }
            } while (newlyIncluded);


            if (ArmadaOptions.O.PrintIncludesMode != ArmadaOptions.IncludesModes.None)
            {
                dmap.PrintMap();
            }

            return(null); // Success
        }
Esempio n. 2
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 (!(ArmadaOptions.O.DisallowIncludes || ArmadaOptions.O.PrintIncludesMode == ArmadaOptions.IncludesModes.Immediate))
            {
                string errString = ParseIncludes(module, builtIns, DafnyFile.fileNames(files), new Errors(reporter));
                if (errString != null)
                {
                    return(errString);
                }
            }

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

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

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

            return(null); // success
        }
Esempio n. 3
0
        private static string ParseFile(DafnyFile dafnyFile, Include include, ModuleDecl module, BuiltIns builtIns, Errors errs, bool verifyThisFile = true)
        {
            var fn = ArmadaOptions.Clo.UseBaseNameForFileName ? Path.GetFileName(dafnyFile.FilePath) : dafnyFile.FilePath;

            try {
                int errorCount = Microsoft.Armada.Parser.Parse(dafnyFile.SourceFileName, include, module, builtIns, errs, verifyThisFile);
                if (errorCount != 0)
                {
                    return(string.Format("{0} parse errors detected in {1}", errorCount, fn));
                }
            } catch (IOException e) {
                Bpl.IToken tok = include == null ? Bpl.Token.NoToken : include.tok;
                errs.SemErr(tok, "Unable to open included file");
                return(string.Format("Error opening file \"{0}\": {1}", fn, e.Message));
            }
            return(null); // Success
        }
Esempio n. 4
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);
            }

            Microsoft.Armada.Program dafnyProgram;
            string programName = dafnyFileNames.Count == 1 ? dafnyFileNames[0] : "the program";
            string err         = Microsoft.Armada.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 &&
                     ArmadaOptions.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;
            }
            else
            {
                // Console.WriteLine("Force compiling!");
                Dictionary <string, PipelineStatistics> statss;
                PipelineOutcome oc;
                oc     = PipelineOutcome.VerificationCompleted;
                statss = new Dictionary <string, PipelineStatistics>();

                var compiled = Compile(dafnyFileNames[0], otherFileNames, dafnyProgram, oc, statss, false);
            }

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