예제 #1
0
파일: TacnyDriver.cs 프로젝트: ggrov/tacny
        public Program ParseAndTypeCheck(bool runResolver)
        {
            var errorReporter = new ConsoleErrorReporter();
            var module        = new LiteralModuleDecl(new DefaultModuleDecl(), null);
            var builtIns      = new BuiltIns();
            var parseErrors   = new Errors(errorReporter);
            var errorCount    = Parser.Parse(_snapshot.GetText(), _filename, _filename, module, builtIns, parseErrors);
            var errString     = Main.ParseIncludes(module, builtIns, new List <string>(), parseErrors);

            if (errorCount != 0 || errString != null)
            {
                return(null);
            }

            var program = new Program(_filename, module, builtIns, errorReporter);

            if (!runResolver)
            {
                return(program);
            }

            var r = new Resolver(program);

            r.ResolveProgram(program);
            return(errorReporter.Count(ErrorLevel.Error) == 0 ? program : null);
        }
예제 #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
        }
예제 #3
0
파일: TacnyDriver.cs 프로젝트: ggrov/tacny
    public Program ParseAndTypeCheck(bool runResolver)
    {
      var errorReporter = new ConsoleErrorReporter();
      var module = new LiteralModuleDecl(new DefaultModuleDecl(), null);
      var builtIns = new BuiltIns();
      var parseErrors = new Errors(errorReporter);
      var errorCount = Parser.Parse(_snapshot.GetText(), _filename, _filename, module, builtIns, parseErrors);
      var errString = Main.ParseIncludes(module, builtIns, new List<string>(), parseErrors);
      if (errorCount != 0 || errString != null) return null;

      var program = new Program(_filename, module, builtIns, errorReporter);
      if (!runResolver) return program;

      var r = new Resolver(program);
      r.ResolveProgram(program);
      return errorReporter.Count(ErrorLevel.Error) == 0 ? program : null;
    }
예제 #4
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);
        }
예제 #5
0
        private static string ParseFile(string dafnyFileName, IToken tok, ModuleDecl module, BuiltIns builtIns, Errors errs, bool verifyThisFile = true)
        {
            string fn = CommandLineOptions.Clo.UseBaseNameForFileName ? Path.GetFileName(dafnyFileName) : dafnyFileName;

            try {
                int errorCount = Microsoft.Dafny.Parser.Parse(dafnyFileName, module, builtIns, errs, verifyThisFile);
                if (errorCount != 0)
                {
                    return($"{errorCount} parse errors detected in {fn}");
                }
            } catch (IOException e) {
                errs.SemErr(tok, "Unable to open included file");
                return($"Error opening file \"{fn}\": {e.Message}");
            }
            return(null); // Success
        }
예제 #6
0
        public static string ParseIncludes(ModuleDecl module, BuiltIns builtIns, IList <string> excludeFiles, Errors errs)
        {
            SortedSet <Include> includes = new SortedSet <Include>(new IncludeComparer());

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

            do
            {
                newlyIncluded = false;

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

                foreach (var include in newFilesToInclude)
                {
                    string ret = ParseFile(include.filename, include.tok, module, builtIns, errs, false);
                    if (ret != null)
                    {
                        return(ret);
                    }
                }
            } while (newlyIncluded);

            return(null); // Success
        }
예제 #7
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
        }
예제 #8
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
        }