예제 #1
0
        /// <summary>
        /// Returns null on success, or an error string otherwise.
        /// </summary>
        public static string ParseCheck(IList <string /*!*/> /*!*/ fileNames, string /*!*/ programName, ErrorReporter reporter, out Program program)
        //modifies Bpl.CommandLineOptions.Clo.XmlSink.*;
        {
            Contract.Requires(programName != null);
            Contract.Requires(fileNames != null);
            program = null;
            ModuleDecl module   = new LiteralModuleDecl(new DefaultModuleDecl(), null);
            BuiltIns   builtIns = new BuiltIns();

            foreach (string dafnyFileName in fileNames)
            {
                Contract.Assert(dafnyFileName != null);
                if (Bpl.CommandLineOptions.Clo.XmlSink != null && Bpl.CommandLineOptions.Clo.XmlSink.IsOpen)
                {
                    Bpl.CommandLineOptions.Clo.XmlSink.WriteFileFragment(dafnyFileName);
                }
                if (Bpl.CommandLineOptions.Clo.Trace)
                {
                    Console.WriteLine("Parsing " + dafnyFileName);
                }

                string err = ParseFile(dafnyFileName, Bpl.Token.NoToken, module, builtIns, new Errors(reporter));
                if (err != null)
                {
                    return(err);
                }
            }

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

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

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

            if (Bpl.CommandLineOptions.Clo.NoResolve || Bpl.CommandLineOptions.Clo.NoTypecheck)
            {
                return(null);
            }

            Dafny.Resolver r = new Dafny.Resolver(program);
            r.ResolveProgram(program);
            MaybePrintProgram(program, DafnyOptions.O.DafnyPrintResolvedFile, true);

            if (reporter.Count(ErrorLevel.Error) != 0)
            {
                return(string.Format("{0} resolution/type errors detected in {1}", reporter.Count(ErrorLevel.Error), program.Name));
            }

            return(null); // success
        }
예제 #2
0
        public static string Resolve(Program program, ErrorReporter reporter)
        {
            if (Bpl.CommandLineOptions.Clo.NoResolve || Bpl.CommandLineOptions.Clo.NoTypecheck)
            {
                return(null);
            }

            Dafny.Resolver r = new Dafny.Resolver(program);
            r.ResolveProgram(program);
            MaybePrintProgram(program, DafnyOptions.O.DafnyPrintResolvedFile, true);
            if (reporter.Count(ErrorLevel.Error) != 0)
            {
                return(string.Format("{0} resolution/type errors detected in {1}", reporter.Count(ErrorLevel.Error), program.Name));
            }

            return(null); // success
        }