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); }
private Interpreter(Program program, Program unresolvedProgram = null) { Contract.Requires(tcce.NonNull(program)); // initialize state _errorReporter = new ConsoleErrorReporter(); _state = new ProofState(program, _errorReporter, unresolvedProgram); _frame = new Stack<Dictionary<IVariable, Type>>(); _resultList = new Dictionary<UpdateStmt, List<Statement>>(); }
internal static void ApplyArgs(string[] args, ErrorReporter reporter) { Dafny.DafnyOptions.Install(new Dafny.DafnyOptions(reporter)); Dafny.DafnyOptions.O.ProverKillTime = 10; //This is just a default; it can be overriden if (CommandLineOptions.Clo.Parse(args)) { DafnyOptions.O.VerifySnapshots = 2; // Use caching DafnyOptions.O.VcsCores = Math.Max(1, System.Environment.ProcessorCount / 2); // Don't use too many cores DafnyOptions.O.PrintTooltips = true; // Dump tooptips (ErrorLevel.Info) to stdout //DafnyOptions.O.UnicodeOutput = true; // Use pretty warning signs DafnyOptions.O.TraceProofObligations = true; // Show which method is being verified, but don't show duration of verification } else { throw new ServerException("Invalid command line options"); } }
public ProofState(Program program, ErrorReporter reporter) { Contract.Requires(program != null); // get a new program instance Datatypes = new Dictionary<string, DatatypeDecl>(); _topLevelClasses = new List<TopLevelClassDeclaration>(); Reporter = reporter; //note the differences between this ParseCheck and the one at the top level. This function only parses but the other one resolves. var err = Parser.ParseOnly(new List<string>() { program.FullName }, program.Name, out _original); if (err != null) reporter.Error(MessageSource.Tacny, program.DefaultModuleDef.tok, $"Error parsing a fresh Tacny program: {err}"); // fill state FillStaticState(program); }
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); }
public ProofState(Program program, ErrorReporter reporter, Program unresolvedProgram = null) { Contract.Requires(program != null); // get a new program instance Datatypes = new Dictionary<string, DatatypeDecl>(); _topLevelClasses = new List<TopLevelClassDeclaration>(); Reporter = reporter; //get some token such that _filename != null var tld = (ClassDecl) program.DefaultModuleDef.TopLevelDecls.FirstOrDefault(x => x is ClassDecl); var member = tld?.Members.FirstOrDefault(); var tok = member?.tok; if (unresolvedProgram == null) { var err = Parser.ParseCheck(new List<string>() {tok?.filename ?? program.FullName}, program.Name, out _original); if (err != null) reporter.Error(MessageSource.Tacny, program.DefaultModuleDef.tok, $"Error parsing a fresh Tacny program: {err}"); } else { _original = unresolvedProgram ; } ResultCache = new List<TacticCache>(); // fill state FillStaticState(program); }
public FixpointLemmaSpecificationSubstituter(ISet<Expression> friendlyCalls, Expression k, ErrorReporter reporter, bool isCoContext) : base(k, reporter) { Contract.Requires(friendlyCalls != null); Contract.Requires(k != null); Contract.Requires(reporter != null); this.isCoContext = isCoContext; this.friendlyCalls = friendlyCalls; }
protected FixpointCloner(Expression k, ErrorReporter reporter) { Contract.Requires(k != null); Contract.Requires(reporter != null); this.k = k; this.reporter = reporter; this.suffix = string.Format("#[{0}]", Printer.ExprToString(k)); }
public DafnyOptions(ErrorReporter errorReporter = null) : base("Dafny", "Dafny program verifier") { this.errorReporter = errorReporter; }
///<summary> /// Parses top-level things (modules, classes, datatypes, class members) /// and appends them in appropriate form to "module". /// Returns the number of parsing errors encountered. /// Note: first initialize the Scanner. ///</summary> public static int Parse(string/*!*/ s, string/*!*/ fullFilename, string/*!*/ filename, ModuleDecl module, BuiltIns builtIns, ErrorReporter reporter, bool verifyThisFile=true) { Contract.Requires(s != null); Contract.Requires(filename != null); Contract.Requires(module != null); Errors errors = new Errors(reporter); return Parse(s, fullFilename, filename, module, builtIns, errors, verifyThisFile); }
RefinementCloner refinementCloner; // This cloner wraps things in a RefinementToken #endregion Fields #region Constructors public RefinementTransformer(ErrorReporter reporter) : base(reporter) { rawCloner = new Cloner(); }
static ExitValue ProcessFiles(IList<DafnyFile/*!*/>/*!*/ dafnyFiles, ReadOnlyCollection<string> otherFileNames, ErrorReporter reporter, bool lookForSnapshots = true, string programId = null) { Contract.Requires(cce.NonNullElements(dafnyFiles)); var dafnyFileNames = DafnyFile.fileNames(dafnyFiles); ExitValue exitValue = ExitValue.VERIFIED; if (CommandLineOptions.Clo.VerifySeparately && 1 < dafnyFiles.Count) { foreach (var f in dafnyFiles) { Console.WriteLine(); Console.WriteLine("-------------------- {0} --------------------", f); var ev = ProcessFiles(new List<DafnyFile> { f }, new List<string>().AsReadOnly(), reporter, lookForSnapshots, f.FilePath); if (exitValue != ev && ev != ExitValue.VERIFIED) { exitValue = ev; } } return exitValue; } if (0 <= CommandLineOptions.Clo.VerifySnapshots && lookForSnapshots) { var snapshotsByVersion = ExecutionEngine.LookForSnapshots(dafnyFileNames); foreach (var s in snapshotsByVersion) { var snapshots = new List<DafnyFile>(); foreach (var f in s) { snapshots.Add(new DafnyFile(f)); } var ev = ProcessFiles(snapshots, new List<string>().AsReadOnly(), reporter, false, programId); if (exitValue != ev && ev != ExitValue.VERIFIED) { exitValue = ev; } } return exitValue; } Dafny.Program dafnyProgram; string programName = dafnyFileNames.Count == 1 ? dafnyFileNames[0] : "the program"; string err = Dafny.Main.ParseCheck(dafnyFiles, programName, reporter, out dafnyProgram); if (err != null) { exitValue = ExitValue.DAFNY_ERROR; ExecutionEngine.printer.ErrorWriteLine(Console.Out, err); } else if (dafnyProgram != null && !CommandLineOptions.Clo.NoResolve && !CommandLineOptions.Clo.NoTypecheck && DafnyOptions.O.DafnyVerify) { var boogiePrograms = Translate(dafnyProgram); Dictionary<string, PipelineStatistics> statss; PipelineOutcome oc; string baseName = cce.NonNull(Path.GetFileName(dafnyFileNames[dafnyFileNames.Count - 1])); var verified = Boogie(baseName, boogiePrograms, programId, out statss, out oc); var compiled = Compile(dafnyFileNames[0], otherFileNames, dafnyProgram, oc, statss, verified); exitValue = verified && compiled ? ExitValue.VERIFIED : !verified ? ExitValue.NOT_VERIFIED : ExitValue.COMPILE_ERROR; } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintStats) { Util.PrintStats(dafnyProgram); } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintFunctionCallGraph) { Util.PrintFunctionCallGraph(dafnyProgram); } return exitValue; }
public ErrorReporterWrapper(ErrorReporter reporter, string msgPrefix) { this.msgPrefix = msgPrefix; this.WrappedReporter = reporter; }
public DafnyOptions(ErrorReporter errorReporter = null) : base("Dafny", "Dafny program verifier") { this.errorReporter = errorReporter; SetZ3ExecutableName(); }
public JavaScriptCompiler(ErrorReporter reporter) : base(reporter) { }
static ExitValue ProcessFiles(IList <DafnyFile /*!*/> /*!*/ dafnyFiles, ReadOnlyCollection <string> otherFileNames, ErrorReporter reporter, bool lookForSnapshots = true, string programId = null) { Contract.Requires(cce.NonNullElements(dafnyFiles)); var dafnyFileNames = DafnyFile.fileNames(dafnyFiles); ExitValue exitValue = ExitValue.SUCCESS; if (CommandLineOptions.Clo.VerifySeparately && 1 < dafnyFiles.Count) { foreach (var f in dafnyFiles) { Console.WriteLine(); Console.WriteLine("-------------------- {0} --------------------", f); var ev = ProcessFiles(new List <DafnyFile> { f }, new List <string>().AsReadOnly(), reporter, lookForSnapshots, f.FilePath); if (exitValue != ev && ev != ExitValue.SUCCESS) { exitValue = ev; } } return(exitValue); } if (0 <= CommandLineOptions.Clo.VerifySnapshots && lookForSnapshots) { var snapshotsByVersion = ExecutionEngine.LookForSnapshots(dafnyFileNames); foreach (var s in snapshotsByVersion) { var snapshots = new List <DafnyFile>(); foreach (var f in s) { snapshots.Add(new DafnyFile(f)); } var ev = ProcessFiles(snapshots, new List <string>().AsReadOnly(), reporter, false, programId); if (exitValue != ev && ev != ExitValue.SUCCESS) { exitValue = ev; } } return(exitValue); } Dafny.Program dafnyProgram; string programName = dafnyFileNames.Count == 1 ? dafnyFileNames[0] : "the program"; string err = Dafny.Main.ParseCheck(dafnyFiles, programName, reporter, out dafnyProgram); if (err != null) { exitValue = ExitValue.DAFNY_ERROR; ExecutionEngine.printer.ErrorWriteLine(Console.Out, err); } else if (dafnyProgram != null && !CommandLineOptions.Clo.NoResolve && !CommandLineOptions.Clo.NoTypecheck && DafnyOptions.O.DafnyVerify) { var boogiePrograms = Translate(dafnyProgram); Dictionary <string, PipelineStatistics> statss; PipelineOutcome oc; string baseName = cce.NonNull(Path.GetFileName(dafnyFileNames[dafnyFileNames.Count - 1])); var verified = Boogie(baseName, boogiePrograms, programId, out statss, out oc); var compiled = Compile(dafnyFileNames[0], otherFileNames, dafnyProgram, oc, statss, verified); exitValue = verified && compiled ? ExitValue.SUCCESS : !verified ? ExitValue.VERIFICATION_ERROR : ExitValue.COMPILE_ERROR; } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintStats) { Util.PrintStats(dafnyProgram); } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintFunctionCallGraph) { Util.PrintFunctionCallGraph(dafnyProgram); } return(exitValue); }
public FixpointLemmaBodyCloner(FixpointLemma context, Expression k, ISet<FixpointPredicate> focalPredicates, ErrorReporter reporter) : base(k, reporter) { Contract.Requires(context != null); Contract.Requires(k != null); Contract.Requires(reporter != null); this.context = context; this.focalPredicates = focalPredicates; }
static ExitValue ProcessFiles(IList<string/*!*/>/*!*/ dafnyFileNames, ReadOnlyCollection<string> otherFileNames, ErrorReporter reporter, bool lookForSnapshots = true, string programId = null) { Contract.Requires(cce.NonNullElements(dafnyFileNames)); if (programId == null) { programId = "main_program_id"; } ExitValue exitValue = ExitValue.VERIFIED; if (CommandLineOptions.Clo.VerifySeparately && 1 < dafnyFileNames.Count) { foreach (var f in dafnyFileNames) { string extension = Path.GetExtension(f); if (extension != null) { extension = extension.ToLower(); } if (extension != ".dfy"){ continue; } Console.WriteLine(); Console.WriteLine("-------------------- {0} --------------------", f); var ev = ProcessFiles(new List<string> { f }, new List<string>().AsReadOnly(), reporter, lookForSnapshots, f); if (exitValue != ev && ev != ExitValue.VERIFIED) { exitValue = ev; } } return exitValue; } if (0 <= CommandLineOptions.Clo.VerifySnapshots && lookForSnapshots) { var snapshotsByVersion = ExecutionEngine.LookForSnapshots(dafnyFileNames); foreach (var s in snapshotsByVersion) { var ev = ProcessFiles(new List<string>(s), new List<string>().AsReadOnly(), reporter, false, programId); if (exitValue != ev && ev != ExitValue.VERIFIED) { exitValue = ev; } } return exitValue; } using (XmlFileScope xf = new XmlFileScope(CommandLineOptions.Clo.XmlSink, dafnyFileNames[dafnyFileNames.Count-1])) { Dafny.Program dafnyProgram; string programName = dafnyFileNames.Count == 1 ? dafnyFileNames[0] : "the program"; string err = Dafny.Main.ParseCheck(dafnyFileNames, programName, reporter, out dafnyProgram); if (err != null) { exitValue = ExitValue.DAFNY_ERROR; ExecutionEngine.printer.ErrorWriteLine(Console.Out, err); } else if (dafnyProgram != null && !CommandLineOptions.Clo.NoResolve && !CommandLineOptions.Clo.NoTypecheck && DafnyOptions.O.DafnyVerify) { Dafny.Translator translator = new Dafny.Translator(dafnyProgram.reporter); Bpl.Program boogieProgram = translator.Translate(dafnyProgram); if (CommandLineOptions.Clo.PrintFile != null) { ExecutionEngine.PrintBplFile(CommandLineOptions.Clo.PrintFile, boogieProgram, false, false, CommandLineOptions.Clo.PrettyPrint); } string bplFilename; if (CommandLineOptions.Clo.PrintFile != null) { bplFilename = CommandLineOptions.Clo.PrintFile; } else { string baseName = cce.NonNull(Path.GetFileName(dafnyFileNames[dafnyFileNames.Count-1])); baseName = cce.NonNull(Path.ChangeExtension(baseName, "bpl")); bplFilename = Path.Combine(Path.GetTempPath(), baseName); } PipelineStatistics stats = null; PipelineOutcome oc = BoogiePipelineWithRerun(boogieProgram, bplFilename, out stats, 1 < Dafny.DafnyOptions.Clo.VerifySnapshots ? programId : null); var allOk = stats.ErrorCount == 0 && stats.InconclusiveCount == 0 && stats.TimeoutCount == 0 && stats.OutOfMemoryCount == 0; var resultFileName = DafnyOptions.O.DafnyPrintCompiledFile ?? dafnyFileNames[0]; switch (oc) { case PipelineOutcome.VerificationCompleted: ExecutionEngine.printer.WriteTrailer(stats); if ((DafnyOptions.O.Compile && allOk && CommandLineOptions.Clo.ProcsToCheck == null) || DafnyOptions.O.ForceCompile) CompileDafnyProgram(dafnyProgram, resultFileName, otherFileNames); break; case PipelineOutcome.Done: ExecutionEngine.printer.WriteTrailer(stats); if (DafnyOptions.O.ForceCompile) CompileDafnyProgram(dafnyProgram, resultFileName, otherFileNames); break; default: // error has already been reported to user break; } exitValue = allOk ? ExitValue.VERIFIED : ExitValue.NOT_VERIFIED; } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintStats) { Util.PrintStats(dafnyProgram); } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintFunctionCallGraph) { Util.PrintFunctionCallGraph(dafnyProgram); } } return exitValue; }
public Errors(ErrorReporter Reporting) { Contract.Requires(Reporting != null); this.Reporting = Reporting; }
/// <summary> /// Initialize the top level frame /// </summary> /// <param name="tactic"></param> /// <param name="reporter"></param> public Frame(ITactic tactic, ErrorReporter reporter) { Contract.Requires<ArgumentNullException>(tactic != null, "tactic"); Parent = null; var o = tactic as Tactic; if (o != null) Body = o.Body.Body; else { throw new NotSupportedException("tactic functions are not yet supported"); } ActiveTactic = tactic; ParseTacticAttributes(((MemberDecl)ActiveTactic).Attributes); _reporter = reporter; _declaredVariables = new Dictionary<string, object>(); _generatedCode = new List<Statement>(); }
/// <summary> /// Returns null on success, or an error string otherwise. /// </summary> public static string ParseCheck(IList <DafnyFile /*!*/> /*!*/ files, string /*!*/ programName, ErrorReporter reporter, out Program program) //modifies Bpl.CommandLineOptions.Clo.XmlSink.*; { string err = Parse(files, programName, reporter, out program); if (err != null) { return(err); } return(Resolve(program, reporter)); }
public Frame(Frame parent, List<Statement> body, bool partial, string kind) { Contract.Requires<ArgumentNullException>(parent != null); Contract.Requires<ArgumentNullException>(tcce.NonNullElements(body), "body"); // carry over the tactic info Body = body; _declaredVariables = new Dictionary<string, object>(); _DafnyVariables = new Dictionary<string, VariableData>(); Parent = parent; ActiveTactic = parent.ActiveTactic; _reporter = parent._reporter; _generatedCode = null; _rawCodeList = new List<List<Statement>>(); WhatKind = kind; FrameCtrlInfo = parent.FrameCtrlInfo; FrameCtrlInfo.IsPartial = FrameCtrlInfo.IsPartial || partial; }
public Frame(Frame parent, List<Statement> body) { Contract.Requires<ArgumentNullException>(parent != null); Contract.Requires<ArgumentNullException>(tcce.NonNullElements(body), "body"); // carry over the tactic info TacticInfo = parent.TacticInfo; Body = body; _declaredVariables = new Dictionary<string, object>(); Parent = parent; ActiveTactic = parent.ActiveTactic; _reporter = parent._reporter; }
static ExitValue ProcessFiles(IList<string/*!*/>/*!*/ dafnyFileNames, ReadOnlyCollection<string> otherFileNames, ErrorReporter reporter, bool lookForSnapshots = true, string programId = null) { Contract.Requires(cce.NonNullElements(dafnyFileNames)); ExitValue exitValue = ExitValue.VERIFIED; if (CommandLineOptions.Clo.VerifySeparately && 1 < dafnyFileNames.Count) { foreach (var f in dafnyFileNames) { string extension = Path.GetExtension(f); if (extension != null) { extension = extension.ToLower(); } if (extension != ".dfy"){ continue; } Console.WriteLine(); Console.WriteLine("-------------------- {0} --------------------", f); var ev = ProcessFiles(new List<string> { f }, new List<string>().AsReadOnly(), reporter, lookForSnapshots, f); if (exitValue != ev && ev != ExitValue.VERIFIED) { exitValue = ev; } } return exitValue; } if (0 <= CommandLineOptions.Clo.VerifySnapshots && lookForSnapshots) { var snapshotsByVersion = ExecutionEngine.LookForSnapshots(dafnyFileNames); foreach (var s in snapshotsByVersion) { var ev = ProcessFiles(new List<string>(s), new List<string>().AsReadOnly(), reporter, false, programId); if (exitValue != ev && ev != ExitValue.VERIFIED) { exitValue = ev; } } return exitValue; } Dafny.Program dafnyProgram; Resolver r = null; string programName = dafnyFileNames.Count == 1 ? dafnyFileNames[0] : "the program"; //Same as ParseCheck, except for the instance of out Resolver string err = Dafny.Main.Parse(dafnyFileNames, programName, reporter, out dafnyProgram); if (err == null){ err = Dafny.Main.Resolve(dafnyProgram, reporter, out r); } if(err != null) { exitValue = ExitValue.DAFNY_ERROR; ExecutionEngine.printer.ErrorWriteLine(Console.Out, err); } else if (dafnyProgram != null && !CommandLineOptions.Clo.NoResolve && !CommandLineOptions.Clo.NoTypecheck && DafnyOptions.O.DafnyVerify) { Bpl.Program boogieProgram = Translate(dafnyProgram, r); PipelineStatistics stats; PipelineOutcome oc; var verified = Boogie(dafnyFileNames, boogieProgram, programId, out stats, out oc); Compile(dafnyFileNames[0], otherFileNames, dafnyProgram, oc, stats, verified); exitValue = verified ? ExitValue.VERIFIED : ExitValue.NOT_VERIFIED; } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintStats) { Util.PrintStats(dafnyProgram); } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintFunctionCallGraph) { Util.PrintFunctionCallGraph(dafnyProgram); } return exitValue; }