Beispiel #1
0
        bool ParseAndTypeCheck()
        {
            Dafny.ModuleDecl module      = new Dafny.LiteralModuleDecl(new Dafny.DefaultModuleDecl(), null);
            Dafny.BuiltIns   builtIns    = new Dafny.BuiltIns();
            Dafny.Errors     parseErrors = new VSErrors(this);
            int    errorCount            = Dafny.Parser.Parse(_snapshot.GetText(), _filename, module, builtIns, parseErrors);
            string errString             = Dafny.Main.ParseIncludes(module, builtIns, new List <string>(), parseErrors);

            if (errorCount != 0 || errString != null)
            {
                return(false);
            }
            Dafny.Program program = new Dafny.Program(_filename, module, builtIns);

            var r = new VSResolver(program, this);

            r.ResolveProgram(program);
            if (r.ErrorCount != 0)
            {
                return(false);
            }

            program.AdditionalInformation.AddRange(r.AdditionalInformation);
            _program = program;
            return(true); // success
        }
Beispiel #2
0
        bool ParseAndTypeCheck(bool runResolver)
        {
            Tuple <ITextSnapshot, Dafny.Program, List <DafnyError> > parseResult;

            Dafny.Program program;
            var           errorReporter = new VSErrorReporter(this);

            if (_buffer.Properties.TryGetProperty(bufferDafnyKey, out parseResult) &&
                (parseResult.Item1 == _snapshot))
            {
                // already parsed;
                program = parseResult.Item2;
                _errors = parseResult.Item3;
                if (program == null)
                {
                    runResolver = false;
                }
            }
            else
            {
                Dafny.ModuleDecl module   = new Dafny.LiteralModuleDecl(new Dafny.DefaultModuleDecl(), null);
                Dafny.BuiltIns   builtIns = new Dafny.BuiltIns();
                var parseErrors           = new Dafny.Errors(errorReporter);
                int errorCount            = Dafny.Parser.Parse(_snapshot.GetText(), _filename, _filename, null, module, builtIns, parseErrors);
                /* (_snapshot.GetText(), _filename, _filename, module, builtIns, parseErrors);*/
                string errString = Dafny.Main.ParseIncludes(module, builtIns, new List <string>(), parseErrors);

                if (errorCount != 0 || errString != null)
                {
                    runResolver = false;
                    program     = null;
                }
                else
                {
                    program = new Dafny.Program(_filename, module, builtIns, errorReporter);
                }
                _buffer.Properties[bufferDafnyKey] = new Tuple <ITextSnapshot, Dafny.Program, List <DafnyError> >(_snapshot, program, _errors);
            }
            if (!runResolver)
            {
                return(false);
            }
            program.Raw = _snapshot.GetText();
            var r = new Resolver(program);

            r.ResolveProgram(program);
            MostRecentResolver = r;
            if (errorReporter.Count(ErrorLevel.Error) != 0)
            {
                return(false);
            }

            _program = program;
            return(true); // success
        }
Beispiel #3
0
        public static int Start_Dafny(string[] args, Dafny.ModuleDecl module, Dafny.BuiltIns builtIns)
        {
            int ret    = 0;
            var thread = new System.Threading.Thread(
                new System.Threading.ThreadStart(() =>
                                                 { ret = ThreadMain(args, module, builtIns); }),
                0x10000000); // 256MB stack size to prevent stack overflow

            thread.Start();
            thread.Join();
            return(ret);
        }
Beispiel #4
0
        public static int ThreadMain(string[] args, Dafny.ModuleDecl module, Dafny.BuiltIns builtIns)
        {
            Contract.Requires(cce.NonNullElements(args));
            Contract.Requires(module != null);
            Contract.Requires(builtIns != null);

            Dafny.ErrorReporter reporter = new Dafny.ConsoleErrorReporter();
            ExecutionEngine.printer = new DafnyConsolePrinter(); // For boogie errors

            Dafny.DafnyOptions.Install(new Dafny.DafnyOptions(reporter));

            // Temporarily change .vad to .dfy
            var valeFileName = args[args.Length - 1];

            args[args.Length - 1] = valeFileName.Replace(".vad", ".dfy");

            List <Microsoft.Dafny.DafnyFile> valeFile;
            List <string> otherFiles;
            ExitValue     exitValue = Dafny.DafnyDriver.ProcessCommandLineArguments(args, out valeFile, out otherFiles);

            // Replace .dfy with .vad
            var fileNames = valeFile.ConvertAll(f => f.FilePath);

            fileNames[0] = valeFileName;

            if (exitValue == ExitValue.VERIFIED)
            {
                exitValue = ProcessFile(fileNames, module, builtIns, reporter);
            }

            if (CommandLineOptions.Clo.XmlSink != null)
            {
                CommandLineOptions.Clo.XmlSink.Close();
            }
            if (CommandLineOptions.Clo.Wait)
            {
                Console.WriteLine("Press Enter to exit.");
                Console.ReadLine();
            }
            if (!Dafny.DafnyOptions.O.CountVerificationErrors && exitValue != ExitValue.PREPROCESSING_ERROR)
            {
                return(0);
            }
            return((int)exitValue);
        }
Beispiel #5
0
        public static int Parse_Verbatim_Block(string verbatim_block, string filename, int line, Dafny.ModuleDecl module,
                                               Dafny.BuiltIns builtIns, bool verifyThisFile = true)
        {
            Contract.Requires(verbatim_block != null);
            Contract.Requires(filename != null);
            Contract.Requires(module != null);

            Dafny.ErrorReporter reporter = new Dafny.ConsoleErrorReporter();
            Dafny.Errors        errors   = new Dafny.Errors(reporter);

            byte[]       buffer       = cce.NonNull(System.Text.UTF8Encoding.Default.GetBytes(verbatim_block));
            MemoryStream ms           = new MemoryStream(buffer, false);
            string       fullFilename = Path.GetFullPath(filename);

            Dafny.Scanner scanner = new Dafny.Scanner(ms, errors, fullFilename, filename, line);
            Dafny.Parser  parser  = new Dafny.Parser(scanner, errors, null, module, builtIns, verifyThisFile);
            parser.Parse();
            return(parser.errors.ErrorCount);
        }
Beispiel #6
0
        static ExitValue ProcessFile(IList <string> valeFileName, Dafny.ModuleDecl module, Dafny.BuiltIns builtIns,
                                     Dafny.ErrorReporter reporter, string programId = null)
        {
            Contract.Requires(valeFileName.Count == 1);
            Contract.Requires(cce.NonNullElements(valeFileName));

            ExitValue exitValue = ExitValue.VERIFIED;

            Dafny.Program dafnyProgram;
            string        programName = valeFileName[0];

            string err = Parse(valeFileName, programName, module, builtIns, reporter, out dafnyProgram);

            if (err == null)
            {
                err = Dafny.Main.Resolve(dafnyProgram, reporter);
            }

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

                Dictionary <string, PipelineStatistics> statss;
                PipelineOutcome oc;
                string          baseName = cce.NonNull(Path.GetFileName(valeFileName[valeFileName.Count - 1]));
                var             verified = Dafny.DafnyDriver.Boogie(baseName, boogiePrograms, programId, out statss, out oc);
                var             compiled = Dafny.DafnyDriver.Compile(valeFileName[0], new List <string>().AsReadOnly(), dafnyProgram, oc, statss, verified);

                exitValue = verified && compiled ? ExitValue.VERIFIED : !verified ? ExitValue.NOT_VERIFIED : ExitValue.COMPILE_ERROR;
            }

            if (err == null && dafnyProgram != null && Dafny.DafnyOptions.O.PrintStats)
            {
                Dafny.Util.PrintStats(dafnyProgram);
            }
            if (err == null && dafnyProgram != null && Dafny.DafnyOptions.O.PrintFunctionCallGraph)
            {
                Dafny.Util.PrintFunctionCallGraph(dafnyProgram);
            }
            return(exitValue);
        }
Beispiel #7
0
        public static string Parse(IList <string> fileName, string programName, Dafny.ModuleDecl module, Dafny.BuiltIns builtIns,
                                   Dafny.ErrorReporter reporter, out Dafny.Program program)
        {
            Contract.Requires(fileName != null);
            Contract.Requires(programName != null);
            Contract.Requires(fileName.Count == 1);
            program = null;

            if (Bpl.CommandLineOptions.Clo.Trace)
            {
                Console.WriteLine("Finished parsing " + fileName);
            }

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

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

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

            return(null);
        }
Beispiel #8
0
        bool ParseAndTypeCheck(bool runResolver)
        {
            Tuple<ITextSnapshot, Dafny.Program, List<DafnyError>> parseResult;
              Dafny.Program program;
              var errorReporter = new VSErrorReporter(this);
              if (_buffer.Properties.TryGetProperty(bufferDafnyKey, out parseResult) &&
             (parseResult.Item1 == _snapshot)) {
            // already parsed;
            program = parseResult.Item2;
            _errors = parseResult.Item3;
            if (program == null)
              runResolver = false;
              } else {
            Dafny.ModuleDecl module = new Dafny.LiteralModuleDecl(new Dafny.DefaultModuleDecl(), null);
            Dafny.BuiltIns builtIns = new Dafny.BuiltIns();
            var parseErrors = new Dafny.Errors(errorReporter);
            int errorCount = Dafny.Parser.Parse(_snapshot.GetText(), _filename, _filename, module, builtIns, parseErrors);
            string errString = Dafny.Main.ParseIncludes(module, builtIns, new List<string>(), parseErrors);

            if (errorCount != 0 || errString != null) {
              runResolver = false;
              program = null;
            } else {
              program = new Dafny.Program(_filename, module, builtIns, errorReporter);
            }
            _buffer.Properties[bufferDafnyKey] = new Tuple<ITextSnapshot, Dafny.Program, List<DafnyError>>(_snapshot, program, _errors);
              }
              if (!runResolver) {
            return false;
              }

              var r = new Resolver(program);
              r.ResolveProgram(program);
              if (errorReporter.Count(ErrorLevel.Error) != 0)
            return false;

              _program = program;
              return true;  // success
        }
Beispiel #9
0
    bool ParseAndTypeCheck() {
      Dafny.ModuleDecl module = new Dafny.LiteralModuleDecl(new Dafny.DefaultModuleDecl(), null);
      Dafny.BuiltIns builtIns = new Dafny.BuiltIns();
      Dafny.Errors parseErrors = new VSErrors(this);
      int errorCount = Dafny.Parser.Parse(_snapshot.GetText(), _filename, module, builtIns, parseErrors);
      string errString = Dafny.Main.ParseIncludes(module, builtIns, new List<string>(), parseErrors);
      if (errorCount != 0 || errString != null)
        return false;
      Dafny.Program program = new Dafny.Program(_filename, module, builtIns);

      var r = new VSResolver(program, this);
      r.ResolveProgram(program);
      if (r.ErrorCount != 0)
        return false;

      program.AdditionalInformation.AddRange(r.AdditionalInformation);
      _program = program;
      return true;  // success
    }
Beispiel #10
0
        bool ParseAndTypeCheck()
        {
            Dafny.ModuleDecl module = new Dafny.LiteralModuleDecl(new Dafny.DefaultModuleDecl(), null);
              Dafny.BuiltIns builtIns = new Dafny.BuiltIns();

              var errorReporter = new VSErrorReporter(this);
              var parseErrors = new Dafny.Errors(errorReporter);

              int errorCount = Dafny.Parser.Parse(_snapshot.GetText(), _filename, _filename, module, builtIns, parseErrors);
              string errString = Dafny.Main.ParseIncludes(module, builtIns, new List<string>(), parseErrors);
              if (errorCount != 0 || errString != null)
            return false;
              Dafny.Program program = new Dafny.Program(_filename, module, builtIns, errorReporter);

              var r = new Resolver(program);
              r.ResolveProgram(program);
              if (errorReporter.Count(ErrorLevel.Error) != 0)
            return false;

              _program = program;
              return true;  // success
        }