예제 #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 (!(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
        }