Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="program"></param>
        /// <param name="target"></param>
        /// <param name="erd"></param>
        ///  only used this to report error, local errors which are genereaed during searching should not use this

        /// <param name="r"></param>
        /// <returns></returns>
        public static MemberDecl FindAndApplyTactic(Program program, MemberDecl target, ErrorReporterDelegate erd, Resolver r = null)
        {
            Contract.Requires(program != null);
            Contract.Requires(target != null);
            Stopwatch watch = new Stopwatch();

            watch.Start();
            _i = new Interpreter(program);
            _errorReporterDelegate = erd;

            var result = _i.EvalTacticApplication(target, r);

            var p = new Printer(Console.Out);

            p.PrintMembers(new List <MemberDecl>()
            {
                result
            }, 0, "");

            watch.Stop();
            Console.WriteLine("Time Used: " + watch.Elapsed.TotalSeconds.ToString());

            _errorReporterDelegate = null;
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Generate test methods for a certain Dafny program.
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <TestMethod> GetTestMethodsForProgram(
            Program program, DafnyInfo?dafnyInfo = null)
        {
            dafnyInfo ??= new DafnyInfo(program);
            var modifications = GetModifications(program).ToList();

            // Generate tests based on counterexamples produced from modifications
            var testMethods = new ConcurrentBag <TestMethod>();

            for (var i = modifications.Count - 1; i >= 0; i--)
            {
                var log = modifications[i].GetCounterExampleLog();
                if (log == null)
                {
                    continue;
                }
                var testMethod = new TestMethod(dafnyInfo, log);
                if (testMethods.Contains(testMethod))
                {
                    continue;
                }
                testMethods.Add(testMethod);
                yield return(testMethod);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This method returns each capturedState that is unreachable, one by one,
        /// and then a line with the summary of how many such states there are, etc.
        /// Note that loop unrolling may cause false positives and the absence of
        /// loop unrolling may cause false negatives.
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <string> GetDeadCodeStatistics(Program program)
        {
            var modifications              = GetModifications(program).ToList();
            var blocksReached              = modifications.Count;
            HashSet <string> allStates     = new();
            HashSet <string> allDeadStates = new();

            // Generate tests based on counterexamples produced from modifications
            for (var i = modifications.Count - 1; i >= 0; i--)
            {
                modifications[i].GetCounterExampleLog();
                var deadStates = ((BlockBasedModification)modifications[i]).GetKnownDeadStates();
                if (deadStates.Count != 0)
                {
                    foreach (var capturedState in deadStates)
                    {
                        yield return($"Code at {capturedState} is potentially unreachable.");
                    }
                    blocksReached--;
                    allDeadStates.UnionWith(deadStates);
                }
                allStates.UnionWith(((BlockBasedModification)modifications[i]).GetAllStates());
            }

            yield return($"Out of {modifications.Count} basic blocks " +
                         $"({allStates.Count} capturedStates), {blocksReached} " +
                         $"({allStates.Count - allDeadStates.Count}) are reachable. " +
                         $"There might be false negatives if you are not unrolling " +
                         $"loops. False positives are always possible.");
        }
Esempio n. 4
0
        /// <summary>
        /// Returns null on success, or an error string otherwise.
        /// </summary>
        public static string ParseOnly(IList <string /*!*/> /*!*/ fileNames, string /*!*/ programName, out Program program)
        {
            Contract.Requires(programName != null);
            Contract.Requires(fileNames != null);
            program = null;
            ModuleDecl module   = new LiteralModuleDecl(new DefaultModuleDecl(), null);
            BuiltIns   builtIns = new BuiltIns();

            foreach (string dafnyFileName in fileNames)
            {
                Contract.Assert(dafnyFileName != null);

                string err = ParseFile(dafnyFileName, Token.NoToken, module, builtIns, new Errors(new ConsoleErrorReporter()));
                if (err != null)
                {
                    return(err);
                }
            }

            if (!DafnyOptions.O.DisallowIncludes)
            {
                string errString = ParseIncludes(module, builtIns, fileNames, new Errors(new ConsoleErrorReporter()));
                if (errString != null)
                {
                    return(errString);
                }
            }

            program = new Program(programName, module, builtIns, new ConsoleErrorReporter());
            return(null);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        bool ParseAndTypeCheck()
        {
            Dafny.ModuleDecl module      = new Dafny.LiteralModuleDecl(new Dafny.DefaultModuleDecl(), null);
            Dafny.BuiltIns   builtIns    = new Dafny.BuiltIns();
            Dafny.Errors     parseErrors = new VSErrors(this);
            int    errorCount            = Dafny.Parser.Parse(_snapshot.GetText(), _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);

            var r = new VSResolver(program, this);

            r.ResolveProgram(program);
            if (r.ErrorCount != 0)
            {
                return(false);
            }

            program.AdditionalInformation.AddRange(r.AdditionalInformation);
            _program = program;
            return(true); // success
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        public static bool Verify(Dafny.Program dafnyProgram, ResolverTagger resolver, string uniqueIdPrefix, string requestId, ErrorReporterDelegate er)
        {
            Dafny.Translator translator = new Dafny.Translator(dafnyProgram.reporter, er);
            translator.InsertChecksums = true;
            translator.UniqueIdPrefix  = uniqueIdPrefix;
            Bpl.Program boogieProgram = translator.Translate(dafnyProgram, r: resolver.MostRecentResolver);

            //Interpreter.ResetTacnyResultList();
            resolver.ReInitializeVerificationErrors(requestId, boogieProgram.Implementations);

            // TODO(wuestholz): Maybe we should use a fixed program ID to limit the memory overhead due to the program cache in Boogie.
            PipelineOutcome oc = BoogiePipeline(boogieProgram, 1 < Dafny.DafnyOptions.Clo.VerifySnapshots ? uniqueIdPrefix : null, requestId, er);

            switch (oc)
            {
            case PipelineOutcome.Done:
            case PipelineOutcome.VerificationCompleted:
                // TODO:  This would be the place to proceed to compile the program, if desired
                return(true);

            case PipelineOutcome.FatalError:
            default:
                return(false);
            }
        }
Esempio n. 9
0
 public static void Add(List <IdRegion> regions, Microsoft.Dafny.Program prog, Bpl.IToken tok, string text, List <TypeParameter> typeArgs)
 {
     Contract.Requires(regions != null);
     Contract.Requires(prog != null);
     Contract.Requires(tok != null);
     Contract.Requires(text != null);
     Contract.Requires(typeArgs != null);
     if (InMainFileAndUserDefined(prog, tok))
     {
         if (typeArgs.Count > 0)
         {
             var pre = "<";
             foreach (var tp in typeArgs)
             {
                 text += pre + tp.Name;
                 if (tp.MustSupportEquality)
                 {
                     text += "(==)";
                 }
                 pre = ", ";
             }
             text += ">";
         }
         regions.Add(new IdRegion(tok, OccurrenceKind.AdditionalInformation, text, tok.val.Length));
     }
 }
Esempio n. 10
0
        public int ResolveProgram(Microsoft.Dafny.Program program)
        {
            Debug.WriteLine("Resolving Dafny program");

            IncCallsToDafny(CurrentDebug);
            //disable Dafny output
            var cOut = Console.Out;
            //Console.SetOut(TextWriter.Null);
            Resolver r     = new Resolver(program);
            var      start = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;

            r.ResolveProgram(program);
            var end = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;

            Console.SetOut(cOut);
            IncTimeAtDafny(CurrentDebug, end - start);

            if (program.reporter.Count(ErrorLevel.Error) != 0)
            {
                Debug.WriteLine("Resolution FAILED");
                Debug.WriteLine("{0} resolution/type errors detected in {1}", program.reporter.Count(ErrorLevel.Error), program.Name);
                IncBadBranchCount(CurrentDebug);
            }
            else
            {
                Debug.WriteLine("Resolution SUCCESSFUL");
                IncGoodBranchCount(CurrentDebug);
            }

            return(program.reporter.Count(ErrorLevel.Error));
        }
Esempio n. 11
0
        public void VerifyProgram(Microsoft.Dafny.Program prog)
        {
            Debug.WriteLine("Verifying Dafny program");

            IncCallsToBoogie(CurrentDebug);
            //disable Dafny output
            var cOut = Console.Out;
            //  Console.SetOut(TextWriter.Null);
            double start = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
            var    pl    = new Pipeline();

            Po = pl.VerifyProgram(prog, _fileNames, ProgramId, out Stats, out ErrList, out ErrorInfo);
            double end = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;

            Console.SetOut(cOut);
            IncTimeAtBoogie(CurrentDebug, end - start);
            if (Stats.ErrorCount == 0)
            {
                Debug.WriteLine("Dafny program VERIFIED");
                IncVerificationSuccess(CurrentDebug);
            }
            else
            {
                Debug.WriteLine("Dafny program NOT VERIFIED");
                IncVerificationFailure(CurrentDebug);
            }
        }
Esempio n. 12
0
        private bool TryEnsureProgramVerifies(Program program)
        {
            var copy           = SimpleCloner.CloneProgram(program);
            var dareController = new DareController(copy);

            return(dareController.IsProgramValid());
        }
Esempio n. 13
0
 public static bool GetExistingProgramFromBuffer(ITextBuffer buffer, out Program program) {
   program = null;
   Tuple<ITextSnapshot, Program, List<DafnyError>> parseResult;
   if (!buffer.Properties.TryGetProperty(bufferDafnyKey, out parseResult) || (parseResult.Item1 != buffer.CurrentSnapshot))
     return false;
   program = parseResult.Item2;
   return program!=null;
 }
Esempio n. 14
0
 new public void PrintProgram(Program prog) {
     Contract.Requires(prog != null);
     wr = new StreamWriter(prog.FullName + ".dfy");
     var printer = new Microsoft.Dafny.Printer(wr, DafnyOptions.PrintModes.Everything);
     printer.PrintTopLevelDecls(prog.DefaultModuleDef.TopLevelDecls, 0, prog.FullName);
     //printer.PrintProgram(prog);// PrintTopLevelDecls(prog.DefaultModuleDef.TopLevelDecls, 0, Path.GetFullPath(prog.FullName));
     wr.Flush();
 }
Esempio n. 15
0
 public static void Add(List <IdRegion> regions, Microsoft.Dafny.Program prog, Bpl.IToken tok, IVariable v, bool isDefinition, ICallable callableContext, ModuleDefinition context)
 {
     Contract.Requires(regions != null);
     Contract.Requires(prog != null);
     Contract.Requires(tok != null);
     Contract.Requires(v != null);
     Add(regions, prog, tok, v, isDefinition, null, callableContext, context);
 }
Esempio n. 16
0
 public RunVerifierThreadParams(Dafny.Program i_program, ITextSnapshot i_snapshot, string i_requestId, ResolverTagger i_errorListHolder, bool i_diagnoseTimeouts)
 {
     program          = i_program;
     snapshot         = i_snapshot;
     requestId        = i_requestId;
     errorListHolder  = i_errorListHolder;
     diagnoseTimeouts = i_diagnoseTimeouts;
 }
Esempio n. 17
0
 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>>();
 }
Esempio n. 18
0
 public Program(IList <string> fileNames, string programId, Microsoft.Dafny.Program program)
 {
     _fileNames   = fileNames;
     ProgramId    = programId;
     _original    = program;
     DafnyProgram = program;
     Init();
 }
Esempio n. 19
0
 public static void Add(List <OutliningRegion> regions, Microsoft.Dafny.Program prog, Dafny1.INamedRegion decl, string kind)
 {
     Contract.Requires(regions != null);
     Contract.Requires(prog != null);
     if (InMainFileAndUserDefined(prog, decl.BodyStartTok))
     {
         regions.Add(new OutliningRegion(decl, kind));
     }
 }
Esempio n. 20
0
 private bool EnsureProgramVerifies(Program program)
 {
     try {
         return(TryEnsureProgramVerifies(program));
     }
     catch {
         return(false);
     }
 }
Esempio n. 21
0
 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> >();
 }
Esempio n. 22
0
        public static void Compile(Dafny.Program dafnyProgram, TextWriter outputWriter)
        {
            Microsoft.Dafny.DafnyOptions.O.SpillTargetCode = true;
            // Currently there are no provisions for specifying other files to compile with from the
            // VS interface, so just send an empty list.
            ReadOnlyCollection <string> otherFileNames = new List <string>().AsReadOnly();

            Microsoft.Dafny.DafnyDriver.CompileDafnyProgram(dafnyProgram, dafnyProgram.FullName, otherFileNames, outputWriter);
        }
Esempio n. 23
0
        private long GetAverageVerificationTime(Program program)
        {
            long verificationTime = 0;

            for (var i = 0; i < _numberOfVerifications; i++)
            {
                verificationTime += GetVerificationTime(program);
            }
            return(verificationTime / _numberOfVerifications);
        }
Esempio n. 24
0
        new public void PrintProgram(Program prog)
        {
            Contract.Requires(prog != null);
            wr = new StreamWriter(prog.FullName + ".dfy");
            var printer = new Microsoft.Dafny.Printer(wr, DafnyOptions.PrintModes.Everything);

            printer.PrintTopLevelDecls(prog.DefaultModuleDef.TopLevelDecls, 0, prog.FullName);
            //printer.PrintProgram(prog);// PrintTopLevelDecls(prog.DefaultModuleDef.TopLevelDecls, 0, Path.GetFullPath(prog.FullName));
            wr.Flush();
        }
Esempio n. 25
0
        /// <summary>
        /// Create new instance of the working Dafny.Program
        /// </summary>
        /// <returns>Instance of dafny.Program</returns>
        public Microsoft.Dafny.Program ParseProgram()
        {
            //Dafny.Program prog;
            //ParseCheck(fileNames, programId, out prog);
            Cloner     cl     = new Cloner();
            ModuleDecl module = new LiteralModuleDecl(cl.CloneModuleDefinition(_original.DefaultModuleDef, _original.Name), null);

            DafnyProgram = new Microsoft.Dafny.Program(_original.Name, module, _original.BuiltIns, new ConsoleErrorReporter());
            return(DafnyProgram);
        }
Esempio n. 26
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
        }
Esempio n. 27
0
 public static List<Statement> FindSingleTactic(Program program, MemberDecl target,
   UpdateStmt chosenTacticCall, ErrorReporterDelegate erd, Program unresolvedProgram)
 {
   Contract.Requires(program != null);
   Contract.Requires(target != null);
   var i = new Interpreter(program, unresolvedProgram);
   _errorReporterDelegate = erd;
   var list = i.FindSingleTacticApplication(target, chosenTacticCall);
   _errorReporterDelegate = null;
   return list;
 }
Esempio n. 28
0
 public static void Add(List <IdRegion> regions, Microsoft.Dafny.Program prog, Bpl.IToken tok, string text, int length)
 {
     Contract.Requires(regions != null);
     Contract.Requires(prog != null);
     Contract.Requires(tok != null);
     Contract.Requires(text != null);
     if (InMainFileAndUserDefined(prog, tok))
     {
         regions.Add(new IdRegion(tok, OccurrenceKind.AdditionalInformation, text, length));
     }
 }
Esempio n. 29
0
 public static void Add(List <IdRegion> regions, Microsoft.Dafny.Program prog, Bpl.IToken tok, IVariable v, bool isDefinition, string kind, ICallable callableContext, ModuleDefinition context)
 {
     Contract.Requires(regions != null);
     Contract.Requires(prog != null);
     Contract.Requires(tok != null);
     Contract.Requires(v != null);
     if (InMainFileAndUserDefined(prog, tok))
     {
         regions.Add(new IdRegion(tok, v, isDefinition, kind, callableContext, context));
     }
 }
Esempio n. 30
0
 public static void Add(List <IdRegion> regions, Microsoft.Dafny.Program prog, Bpl.IToken tok, Field decl, Microsoft.Dafny.Type showType, string kind, bool isDefinition, ModuleDefinition context)
 {
     Contract.Requires(regions != null);
     Contract.Requires(prog != null);
     Contract.Requires(tok != null);
     Contract.Requires(decl != null);
     Contract.Requires(kind != null);
     if (InMainFileAndUserDefined(prog, tok))
     {
         regions.Add(new IdRegion(tok, decl, showType, kind, isDefinition, context));
     }
 }
Esempio n. 31
0
 public static bool Verify(Program dafnyProgram, ResolverTagger resolver, string uniqueIdPrefix, string requestId, ErrorReporterDelegate er, Program unresolvedProgram)
 {
   var translator = new Translator(dafnyProgram.reporter, er)
   {
     InsertChecksums = true,
     UniqueIdPrefix = uniqueIdPrefix
   };
   var boogieProgram = translator.Translate(dafnyProgram, unresolvedProgram);
   resolver.ReInitializeVerificationErrors(requestId, boogieProgram.Implementations);
   var outcome = BoogiePipeline(boogieProgram, 1 < CommandLineOptions.Clo.VerifySnapshots ? uniqueIdPrefix : null, requestId, er);
   return outcome == PipelineOutcome.Done || outcome == PipelineOutcome.VerificationCompleted;
 }
Esempio n. 32
0
        public static bool GetExistingProgramFromBuffer(ITextBuffer buffer, out Program program)
        {
            program = null;
            Tuple <ITextSnapshot, Program, List <DafnyError> > parseResult;

            if (!buffer.Properties.TryGetProperty(bufferDafnyKey, out parseResult) || (parseResult.Item1 != buffer.CurrentSnapshot))
            {
                return(false);
            }
            program = parseResult.Item2;
            return(program != null);
        }
Esempio n. 33
0
        /*
         * public static bool ResolveAndVerify(Program program, ErrorReporterDelegate er) {
         * Contract.Requires<ArgumentNullException>(program != null);
         * var r = new Resolver(program);
         * //var start = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
         * r.ResolveProgram(program);
         * //TODO: get program.reporter to check resolving result before verifying
         * //var end = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds
         *
         * // check if resolution fails
         * if (program.reporter.Count(ErrorLevel.Error) != 0){
         *  Console.Write("Fail to resolve prog, skip verifier ! \n");
         *  return false;
         *
         * }
         * var boogieProg = Translate(program, program.Name, er);
         * PipelineStatistics stats;
         * List<ErrorInformation> errorList;
         *
         * //Console.WriteLine("call verifier in Tacny !!!");
         * PipelineOutcome tmp = BoogiePipeline(boogieProg,
         *  new List<string> {program.Name}, program.Name, er,
         *  out stats, out errorList, program);
         *
         * return errorList.Count == 0;
         * }
         */
        public static Bpl.Program Translate(Program dafnyProgram, string uniqueIdPrefix, ErrorReporterDelegate er)
        {
            Contract.Requires <ArgumentNullException>(dafnyProgram != null, "dafnyProgram");
            Contract.Requires <ArgumentNullException>(uniqueIdPrefix != null, "uniqueIdPrefix");
            Contract.Ensures(Contract.Result <Bpl.Program>() != null);
            var translator = new Translator(dafnyProgram.reporter, er)
            {
                InsertChecksums = true,
                UniqueIdPrefix  = uniqueIdPrefix
            };

            return(translator.Translate(dafnyProgram));
        }
Esempio n. 34
0
        public static Microsoft.Dafny.Program RemoveTactics(Microsoft.Dafny.Program program)
        {
            for (var i = 0; i < program.DefaultModuleDef.TopLevelDecls.Count; i++)
            {
                var curDecl = program.DefaultModuleDef.TopLevelDecls[i] as ClassDecl;
                if (curDecl != null)
                {
                    program.DefaultModuleDef.TopLevelDecls[i] = RemoveTactics(curDecl);
                }
            }

            return(program);
        }
Esempio n. 35
0
        public static List <Statement> FindSingleTactic(Program program, MemberDecl target,
                                                        UpdateStmt chosenTacticCall, ErrorReporterDelegate erd, Program unresolvedProgram)
        {
            Contract.Requires(program != null);
            Contract.Requires(target != null);
            var i = new Interpreter(program, unresolvedProgram);

            _errorReporterDelegate = erd;
            var list = i.FindSingleTacticApplication(target, chosenTacticCall);

            _errorReporterDelegate = null;
            return(list);
        }
Esempio n. 36
0
 public static MemberDecl FindAndApplyTactic(Program program, MemberDecl target, ErrorReporterDelegate erd, Program unresolvedProgram = null) {
   Contract.Requires(program != null);
   Contract.Requires(target != null);
   // TODO Re-Enable with more permanent solution
   // Currently, if the interpreter is the same, static across calls, each time the interpreter is
   //   needed, it will just re-use the previous proof states, frames etc. Which will likely cause
   //   problems in the extension, where it is called many times consecutively.
   //if (_i == null) {
     _i = new Interpreter(program, unresolvedProgram);
   //}
   _errorReporterDelegate = erd;
   var result = _i.FindTacticApplication(target);
   _errorReporterDelegate = null;
   return result;
 }
Esempio n. 37
0
    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;
    }
Esempio n. 38
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="program"></param>
    /// <param name="target"></param>
    /// <param name="erd"></param>
    ///  only used this to report error, local errors which are genereaed during searching should not use this

    /// <param name="r"></param>
    /// <returns></returns>
    public static MemberDecl FindAndApplyTactic(Program program, MemberDecl target, ErrorReporterDelegate erd, Resolver r = null) {
      Contract.Requires(program != null);
      Contract.Requires(target != null);
      Stopwatch watch = new Stopwatch();
      watch.Start();
      _i = new Interpreter(program);
      _errorReporterDelegate = erd;

      var result = _i.EvalTacticApplication(target, r);

      var p = new Printer(Console.Out);
      p.PrintMembers(new List<MemberDecl>() { result }, 0, "");

      watch.Stop();
      Console.WriteLine("Time Used: " + watch.Elapsed.TotalSeconds.ToString());

      _errorReporterDelegate = null;
      return result;
    }
Esempio n. 39
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
        }
Esempio n. 40
0
 public TacticReplacerActor(ITextBuffer tb, int position = -1)
 {
   Contract.Requires(tb != null);
   string currentFileName;
   LoadStatus = Util.LoadAndCheckDocument(tb, out currentFileName) ? TacticReplaceStatus.Success : TacticReplaceStatus.NoDocumentPersistence;
   if(LoadStatus!=TacticReplaceStatus.Success) return;
   _program = Util.GetProgram(tb, currentFileName, true);
   _unresolvedProgram = Util.GetProgram(tb, currentFileName, false);
   _tld = (DefaultClassDecl)_program?.DefaultModuleDef.TopLevelDecls.FirstOrDefault();
   _tldMembers = _tld?.Members.GetEnumerator();
   LoadStatus = _tld != null ? TacticReplaceStatus.Success : TacticReplaceStatus.NotResolved;
   if (LoadStatus != TacticReplaceStatus.Success) return;
   if (position == -1) return;
   SetMember(position);
   SetTacticCall(position);
 }
Esempio n. 41
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
        }
Esempio n. 42
0
    bool ParseAndTypeCheck() {
      Dafny.ModuleDecl module = new Dafny.LiteralModuleDecl(new Dafny.DefaultModuleDecl(), null);
      Dafny.BuiltIns builtIns = new Dafny.BuiltIns();
      Dafny.Errors parseErrors = new VSErrors(this);
      int errorCount = Dafny.Parser.Parse(_snapshot.GetText(), _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);

      var r = new VSResolver(program, this);
      r.ResolveProgram(program);
      if (r.ErrorCount != 0)
        return false;

      program.AdditionalInformation.AddRange(r.AdditionalInformation);
      _program = program;
      return true;  // success
    }