Esempio n. 1
0
 private bool TryParseInclude(Include include, ModuleDecl module, BuiltIns builtIns, ErrorReporter errorReporter, Errors errors)
 {
     try {
         var dafnyFile  = new DafnyFile(include.includedFilename);
         int errorCount = Parser.Parse(
             useStdin: false,
             dafnyFile.SourceFileName,
             include,
             module,
             builtIns,
             errors,
             verifyThisFile: false,
             compileThisFile: false
             );
         if (errorCount != 0)
         {
             errorReporter.Error(MessageSource.Parser, include.tok, $"{errorCount} parse error(s) detected in {include.includedFilename}");
             return(false);
         }
     } catch (IllegalDafnyFile e) {
         errorReporter.Error(MessageSource.Parser, include.tok, $"Include of file {include.includedFilename} failed.");
         _logger.LogDebug(e, "encountered include of illegal dafny file {}", include.includedFilename);
         return(false);
     } catch (IOException e) {
         errorReporter.Error(MessageSource.Parser, include.tok, $"Unable to open the include {include.includedFilename}.");
         _logger.LogDebug(e, "could not open file {}", include.includedFilename);
         return(false);
     }
     return(true);
 }
        public Boolean parse_file(string filename, string methodname)
        {
            // init parser arguments
            DafnyFile usedFile = new DafnyFile(filename);
            var       files    = new List <DafnyFile>();

            files.Add(usedFile);
            ErrorReporter r = new ConsoleErrorReporter();

            Microsoft.Dafny.Program ret;
            DafnyOptions.Install(new DafnyOptions(r));

            // run parser
            string err = Main.ParseCheck(files, filename, r, out ret);

            //if (err != null)
            //{
            //    return false;
            //}

            // program parsed well
            dafny_program = ret;

            // list of all methods
            var decls             = ret.Modules();
            List <TopLevelDecl> a = new List <TopLevelDecl>();

            foreach (Microsoft.Dafny.ModuleDefinition dec in decls)
            {
                a.AddRange(dec.TopLevelDecls);
            }

            // look for methodname
            var callables = ModuleDefinition.AllCallables(a);

            foreach (Microsoft.Dafny.ICallable method in callables)
            {
                if (method is Microsoft.Dafny.Method)
                {
                    Microsoft.Dafny.Method m = (Microsoft.Dafny.Method)method;
                    if (m.Name == methodname)
                    {
                        currentMethod = m;
                        return(true);
                    }
                }
            }

            return(false);
        }