Exemplo 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));
            }
            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 (DafnyOptions.O.PrintIncludesMode != DafnyOptions.IncludesModes.None)
            {
                dmap.PrintMap();
            }

            return(null); // Success
        }
Exemplo 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 (!(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
        }