public ProofState(Program program) { Contract.Requires(program != null); // get a new program instance Datatypes = new Dictionary <string, DatatypeDecl>(); _topLevelClasses = new List <TopLevelClassDeclaration>(); var files = new List <DafnyFile> { new DafnyFile(program.FullName) }; if (program.Raw == null) { Main.Parse(files, program.Name, new ConsoleErrorReporter(), out _original); } else { /* * System.IO.StreamReader reader = new System.IO.StreamReader(program.FullName); * var s = Microsoft.Boogie.ParserHelper.Fill(reader, new List<string>()); * program.Raw = s; */ var reporter = new ConsoleErrorReporter(); ModuleDecl module = new LiteralModuleDecl(new DefaultModuleDecl(), null); BuiltIns builtIns = new BuiltIns(); Parser.Parse(program.Raw, program.FullName, program.FullName, module, builtIns, reporter); _original = new Program(program.FullName, module, builtIns, reporter); } // fill state FillStaticState(program); }
public void Test() { ErrorReporter reporter = new ConsoleErrorReporter(); var options = new DafnyOptions(reporter); options.DafnyPrelude = "../../../../../Binaries/DafnyPrelude.bpl"; DafnyOptions.Install(options); var programString = @"trait Trait<A, B> { }"; ModuleDecl module = new LiteralModuleDecl(new DefaultModuleDecl(), null); Microsoft.Dafny.Type.ResetScopes(); BuiltIns builtIns = new BuiltIns(); Parser.Parse(programString, "virtual", "virtual", module, builtIns, reporter); var dafnyProgram = new Program("programName", module, builtIns, reporter); Main.Resolve(dafnyProgram, reporter); foreach (var prog in Translator.Translate(dafnyProgram, dafnyProgram.reporter)) { var writer = new StringWriter(); var tokenWriter = new Bpl.TokenTextWriter("virtual", writer, true); prog.Item2.Emit(tokenWriter); var parseErrorCount = Bpl.Parser.Parse(writer.ToString(), "virtualBoogie", out var boogieProgram); Assert.Equal(0, parseErrorCount); } }
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); }
//laddon public static Microsoft.Dafny.Program GetProgram(string filename) { List <DafnyFile> dafnyFiles = new List <DafnyFile>(); dafnyFiles.Add(new DafnyFile(filename)); ErrorReporter reporter = new ConsoleErrorReporter(); Microsoft.Dafny.Program ret; Main.ParseCheck(dafnyFiles, filename, reporter, out ret); return(ret); }
public Program getProgram(string filename) { Program dafnyProgram = null; List <DafnyFile> dafnyFiles; List <string> otherFiles; string[] args = new string[] { filename }; DafnyDriver.ProcessCommandLineArguments(args, out dafnyFiles, out otherFiles); ErrorReporter reporter = new ConsoleErrorReporter(); string s = Microsoft.Dafny.Main.ParseCheck(dafnyFiles, "", reporter, out dafnyProgram); return(dafnyProgram); }
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); }
/// <summary> /// Parse a string read (from a certain file) to a Dafny Program /// </summary> public static Program?Parse(string source, string fileName = "") { ModuleDecl module = new LiteralModuleDecl(new DefaultModuleDecl(), null); var builtIns = new BuiltIns(); var reporter = new ConsoleErrorReporter(); var success = Parser.Parse(source, fileName, fileName, null, module, builtIns, new Errors(reporter)) == 0 && Microsoft.Dafny.Main.ParseIncludes(module, builtIns, new List <string>(), new Errors(reporter)) == null; Program?program = null; if (success) { program = new Program(fileName, module, builtIns, reporter); } new Resolver(program).ResolveProgram(program); return(program); }
IEnumerable <BoogieProgram> GetBoogie(string dafnyProgramText) { var module = new LiteralModuleDecl(new DefaultModuleDecl(), null); var fullFilePath = "foo"; Microsoft.Dafny.Type.ResetScopes(); var builtIns = new BuiltIns(); var errorReporter = new ConsoleErrorReporter(); var parseResult = Parser.Parse(dafnyProgramText, fullFilePath, "foo", module, builtIns, errorReporter); Assert.Equal(0, parseResult); var dafnyProgram = new Microsoft.Dafny.Program(fullFilePath, module, builtIns, errorReporter); Main.Resolve(dafnyProgram, errorReporter); var boogiePrograms = Translator.Translate(dafnyProgram, errorReporter).Select(t => t.Item2); return(boogiePrograms); }