Example #1
0
        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);
            }
        }
Example #2
0
        /// <summary>
        /// Return the counterexample log produced by trying to verify this modified
        /// version of the original boogie program. Return null if this
        /// counterexample does not cover any new SourceModifications.
        /// </summary>
        public virtual string?GetCounterExampleLog()
        {
            var oldOptions = DafnyOptions.O;
            var options    = SetupOptions(procedure);

            DafnyOptions.Install(options);
            var uniqueId = Guid.NewGuid().ToString();

            program.Resolve();
            program.Typecheck();
            ExecutionEngine.EliminateDeadVariables(program);
            ExecutionEngine.CollectModSets(program);
            ExecutionEngine.CoalesceBlocks(program);
            ExecutionEngine.Inline(program);
            var log = Utils.CaptureConsoleOutput(
                () => ExecutionEngine.InferAndVerify(program,
                                                     new PipelineStatistics(), uniqueId,
                                                     _ => { }, uniqueId));

            DafnyOptions.Install(oldOptions);
            // make sure that there is a counterexample (i.e. no parse errors, etc):
            string?line;
            var    stringReader = new StringReader(log);

            while ((line = stringReader.ReadLine()) != null)
            {
                if (line.StartsWith("Block |"))
                {
                    return(log);
                }
            }
            return(null);
        }
Example #3
0
 public static void Main(string[] args)
 {
     try
     {
         Util.DebugWriteLine("hello");
         DafnySpec_Options options = new DafnySpec_Options();
         DafnyOptions.Install(options);
         Bpl.CommandLineOptions.Clo.RunningBoogieFromCommandLine = true;
         if (!Bpl.CommandLineOptions.Clo.Parse(args))
         {
             throw new Exception("argument parse error");
         }
         IList <string> files = Bpl.CommandLineOptions.Clo.Files;
         if (files.Count == 0)
         {
             throw new Exception("*** Error: No input files were specified.");
         }
         new DafnySpec().CompileSpec(options, files);
     }
     catch (Exception e)
     {
         Console.OpenStandardOutput().Flush();
         Console.WriteLine(e);
         Console.Error.WriteLine(e);
         Environment.Exit(-1);
     }
 }
Example #4
0
 private static void SetupEnvironment()
 {
     DafnyOptions.Install(new DafnyOptions());
     Bpl.CommandLineOptions.Clo.ApplyDefaultOptions();
     DafnyOptions.O.Z3ExecutablePath = _z3Loc;
     DafnyOptions.O.ApplyDefaultOptions();
     DafnyOptions.O.RunningBoogieFromCommandLine = true;
     DafnyOptions.O.VerifySnapshots = 1;
     DafnyOptions.O.ErrorTrace      = 0;
     DafnyOptions.O.ProverKillTime  = 15;
     Bpl.ExecutionEngine.printer    = new InvisibleConsolePrinter();
     Contract.ContractFailed       += ContractFailureHandler;
 }
Example #5
0
        private void Initialise()
        {
            DafnyOptions.Install(new DafnyOptions());
            Bpl.CommandLineOptions.Clo.Z3ExecutablePath = "H:\\dafny\\repos\\tacny\\tacny\\Binaries\\z3.exe";
//            Bpl.CommandLineOptions.Clo.Z3ExecutablePath = "C:\\users\\Duncan\\Documents\\tacny\\tacny\\Binaries\\z3.exe";
            Bpl.CommandLineOptions.Clo.ApplyDefaultOptions();
            Bpl.CommandLineOptions.Clo.VerifySnapshots = 1;
            DafnyOptions.O.ProverKillTime         = 10;
            Bpl.CommandLineOptions.Clo.ErrorTrace = 0;
            Bpl.OutputPrinter printer = new InvisibleConsolePrinter();
            Bpl.ExecutionEngine.printer = printer;
            Contract.ContractFailed    += ContractFailureHandler;
        }
        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);
        }
Example #7
0
 /// <summary>
 /// Factory method to safely create a new instance of the parser. It ensures that global/static
 /// settings are set exactly ones.
 /// </summary>
 /// <param name="logger">A logger instance that may be used by this parser instance.</param>
 /// <returns>A safely created dafny parser instance.</returns>
 public static DafnyLangParser Create(ILogger <DafnyLangParser> logger)
 {
     lock (_initializationSyncObject) {
         if (!_initialized)
         {
             // TODO no error reporter is supplied at this time since it appears that there is not any usage inside dafny.
             DafnyOptions.Install(new DafnyOptions());
             DafnyOptions.Clo.ApplyDefaultOptions();
             DafnyOptions.O.PrintIncludesMode = DafnyOptions.IncludesModes.None;
             _initialized = true;
         }
         logger.LogTrace("initialized the dafny pipeline...");
         return(new DafnyLangParser(logger));
     }
 }
Example #8
0
        public static void SetupDafnyOptions(string[] extraArgs = null)
        {
            var options = new DafnyOptions();

            options.Parse(extraArgs ?? System.Array.Empty <string>());
            options.DefiniteAssignmentLevel        = 3;
            options.WarnShadowing                  = true;
            options.VerifyAllModules               = true;
            options.LoopUnrollCount                = 5;
            options.TestGenOptions.SeqLengthLimit  = 3;
            options.TestGenOptions.Mode            = TestGenerationOptions.Modes.Block;
            options.TestGenOptions.WarnDeadCode    = false;
            options.TestGenOptions.TestInlineDepth = 0;
            DafnyOptions.Install(options);
        }
Example #9
0
        /// <summary>
        /// Setup CommandLineArguments to prepare verification. This is necessary
        /// because the procsToCheck field in CommandLineOptions (part of Boogie)
        /// is private meaning that the only way of setting this field is by calling
        /// options.Parse() on a new DafnyObject.
        /// </summary>
        private static DafnyOptions SetupOptions(string procedure)
        {
            var options = new DafnyOptions();

            options.Parse(new[] { "/proc:" + procedure });
            options.EnhancedErrorMessages = 1;
            options.ModelViewFile         = "-";
            options.ProverOptions         = new List <string>()
            {
                "O:model_compress=false",
                "O:model_evaluator.completion=true",
                "O:model.completion=true"
            };
            options.ProverOptions.AddRange(DafnyOptions.O.ProverOptions);
            options.LoopUnrollCount         = DafnyOptions.O.LoopUnrollCount;
            options.DefiniteAssignmentLevel = DafnyOptions.O.DefiniteAssignmentLevel;
            options.WarnShadowing           = DafnyOptions.O.WarnShadowing;
            options.VerifyAllModules        = DafnyOptions.O.VerifyAllModules;
            options.TimeLimit = DafnyOptions.O.TimeLimit;
            return(options);
        }
Example #10
0
        public void NoUniqueLinesWhenConcatenatingUnrelatedPrograms()
        {
            var program = $@"
datatype Friends = Agnes | Agatha | Jermaine

function SomeFunc(funcFormal: int): nat {{ 3 }}

method SomeMethod(methodFormal: int) returns (result: bool)
  ensures result == true 
{{
  result := methodFormal == 3;
}}
";

            var renamedProgram = $@"
datatype Friends2 = Agnes2 | Agatha2 | Jermaine2

function SomeFunc2(funcFormal: int): nat {{ 3 }}

method SomeMethod2(methodFormal: int) returns (result: bool) 
  ensures result == true
{{
  result := methodFormal == 3;
}}
";

            DafnyOptions.Install(new DafnyOptions());

            var regularBoogie  = GetBoogieText(program);
            var renamedBoogie  = GetBoogieText(renamedProgram);
            var separate       = UniqueNonCommentLines(regularBoogie + renamedBoogie);
            var combinedBoogie = GetBoogieText(program + renamedProgram);
            var together       = UniqueNonCommentLines(combinedBoogie);

            var uniqueLines = separate.Union(together).Except(separate.Intersect(together)).ToList();

            Assert.Equal(Enumerable.Empty <string>(), uniqueLines);
        }
 /// <summary>
 /// Sets Up Default Dafny Options except for the ModelViewFile Option, which is custom.
 /// </summary>
 private void SetUpDafnyOptions()
 {
     DafnyOptions.Install(new DafnyOptions(_reporter));
     DafnyOptions.Clo.ApplyDefaultOptions();
     DafnyOptions.O.ModelViewFile = FileAndFolderLocations.modelBVD;
 }
Example #12
0
 public static void Install(TacnyOptions options)
 {
     Contract.Requires(options != null);
     clo = options;
     DafnyOptions.Install(options);
 }