Ejemplo n.º 1
0
        public void Compile(IWpfTextView activeTextView)
        {
            ResolverTagger resolver;

            if (activeTextView != null &&
                DafnyLanguage.ResolverTagger.ResolverTaggers.TryGetValue(activeTextView.TextBuffer, out resolver) &&
                resolver.Program != null)
            {
                var outputWriter = new StringWriter();
                DafnyMenuPackage.ExecuteAsCompiling(() => { DafnyDriver.Compile(resolver.Program, outputWriter); }, outputWriter);
            }
        }
Ejemplo n.º 2
0
            public VSResolver(Dafny.Program program, DafnyDriver dd)
                : base(program)
            {
                this.dd = dd;

                AdditionalInformationReporter =
                    (addinfo)
                    =>
                {
                    if (!_additionalInformation.ContainsKey(addinfo.Token))
                    {
                        _additionalInformation.Add(addinfo.Token, new HashSet <AdditionalInformation>());
                    }
                    _additionalInformation[addinfo.Token].Add(addinfo);
                };
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Calls the Dafny parser/resolver/type checker on the contents of the buffer, updates the Error List accordingly.
        /// </summary>
        public void ResolveBuffer(object sender, EventArgs args)
        {
            ITextSnapshot snapshot = _buffer.CurrentSnapshot;

            if (snapshot == Snapshot)
            {
                return; // we've already done this snapshot
            }
            string            filename = _document != null ? _document.FilePath : "<program>";
            var               driver   = new DafnyDriver(_buffer, filename);
            List <DafnyError> newErrors;

            Dafny.Program program;
            try
            {
                program            = driver.ProcessResolution(RunResolver);
                MostRecentResolver = driver.MostRecentResolver;
                newErrors          = driver.Errors;
            }
            catch (Exception e)
            {
                newErrors = new List <DafnyError> {
                    new DafnyError(filename, 0, 0, ErrorCategory.InternalError, "internal Dafny error: " + e.Message, snapshot, false)
                };
                program = null;
            }

            lock (this)
            {
                Snapshot = snapshot;
                Program  = program;
            }

            if (program != null && _document != null)
            {
                ResolverTaggers[_document.TextBuffer] = this;
            }
            else if (_document != null)
            {
                ResolverTaggers.Remove(_document.TextBuffer);
            }

            _resolutionErrors      = newErrors;
            FatalVerificationError = null;

            UpdateErrorList(snapshot);
        }
Ejemplo n.º 4
0
        void RunVerifier(Dafny.Program program, ITextSnapshot snapshot, string requestId, ResolverTagger errorListHolder, bool diagnoseTimeouts)
        {
            Contract.Requires(program != null);
            Contract.Requires(snapshot != null);
            Contract.Requires(requestId != null);
            Contract.Requires(errorListHolder != null);

            if (_logSnapshots)
            {
                var logDirName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(program.FullName), "logs");
                Directory.CreateDirectory(logDirName);
                var logFileName = System.IO.Path.Combine(logDirName, System.IO.Path.GetFileName(System.IO.Path.ChangeExtension(program.FullName, string.Format("{0}.v{1}{2}", _created.Ticks, _version, System.IO.Path.GetExtension(program.FullName)))));
                using (var writer = new StreamWriter(logFileName))
                {
                    snapshot.Write(writer);
                }
                _version++;
            }

            DafnyDriver.SetDiagnoseTimeouts(diagnoseTimeouts);

            try
            {
                string filename = _document != null ? _document.FilePath : "<program>";
                var    driver   = new DafnyDriver(_buffer, filename);
                bool   success  = driver.Verify(program, errorListHolder, GetHashCode().ToString(), requestId, errorInfo =>
                {
                    if (!_disposed)
                    {
                        errorInfo.BoogieErrorCode = null;
                        var isRecycled            = false;
                        ITextSnapshot s           = null;
                        if (errorInfo.OriginalRequestId != null)
                        {
                            isRecycled = errorInfo.OriginalRequestId != requestId;
                            RequestIdToSnapshot.TryGetValue(errorInfo.OriginalRequestId, out s);
                        }
                        if (s == null && errorInfo.RequestId != null)
                        {
                            RequestIdToSnapshot.TryGetValue(errorInfo.RequestId, out s);
                        }
                        if (s != null)
                        {
                            errorListHolder.AddError(new DafnyError(errorInfo.Tok.filename, errorInfo.Tok.line - 1, errorInfo.Tok.col - 1, ErrorCategory.VerificationError, errorInfo.FullMsg, s, isRecycled, errorInfo.Model.ToString(), System.IO.Path.GetFullPath(_document.FilePath) == errorInfo.Tok.filename), errorInfo.ImplementationName, requestId);
                            foreach (var aux in errorInfo.Aux)
                            {
                                errorListHolder.AddError(new DafnyError(aux.Tok.filename, aux.Tok.line - 1, aux.Tok.col - 1, ErrorCategory.AuxInformation, aux.FullMsg, s, isRecycled, null, System.IO.Path.GetFullPath(_document.FilePath) == aux.Tok.filename), errorInfo.ImplementationName, requestId);
                            }
                        }
                    }
                });
                if (!success)
                {
                    foreach (var error in driver.Errors)
                    {
                        errorListHolder.AddError(error, "$$program$$", requestId);
                    }
                }
            }
            catch (Exception e)
            {
                errorListHolder.AddError(new DafnyError("$$program$$", 0, 0, ErrorCategory.InternalError, "Verification process error: " + e.Message, snapshot, false), "$$program$$", requestId);
            }
            finally
            {
                DafnyDriver.SetDiagnoseTimeouts(!diagnoseTimeouts);
            }

            lock (this) {
                bufferChangesPreVerificationStart.Clear();
                verificationInProgress = false;
            }

            errorListHolder.UpdateErrorList(snapshot);

            // Notify to-whom-it-may-concern about the cleared pre-verification changes
            NotifyAboutChangedTags(snapshot);

            // If new changes took place since we started the verification, we may need to kick off another verification
            // immediately.
            UponIdle(null, null);
        }
Ejemplo n.º 5
0
 public ErrorSink(DafnyDriver dd)
 {
     this.dd = dd;
 }
Ejemplo n.º 6
0
 public VSErrorReporter(DafnyDriver dd)
 {
     this.dd = dd;
 }
Ejemplo n.º 7
0
 public bool ToggleAutomaticInduction(IWpfTextView activeTextView)
 {
     return(DafnyDriver.ChangeAutomaticInduction());
 }
Ejemplo n.º 8
0
 public bool MoreAdvancedSnapshotVerificationCommandEnabled(IWpfTextView activeTextView)
 {
     return(activeTextView != null &&
            0 < DafnyDriver.IncrementalVerificationMode());
 }
Ejemplo n.º 9
0
 public int ToggleMoreAdvancedSnapshotVerification(IWpfTextView activeTextView)
 {
     return(DafnyDriver.ChangeIncrementalVerification(2));
 }
Ejemplo n.º 10
0
 public VSErrors(DafnyDriver dd)
 {
     this.dd = dd;
 }
Ejemplo n.º 11
0
        private void RunVerifier(Dafny.Program program, ITextSnapshot snapshot, string requestId, ResolverTagger errorListHolder, bool diagnoseTimeouts)
        {
            Contract.Requires(program != null);
            Contract.Requires(snapshot != null);
            Contract.Requires(requestId != null);
            Contract.Requires(errorListHolder != null);

            if (_logSnapshots)
            {
                var logDirName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(program.FullName), "logs");
                Directory.CreateDirectory(logDirName);
                var logFileName = System.IO.Path.Combine(logDirName, System.IO.Path.GetFileName(System.IO.Path.ChangeExtension(program.FullName, string.Format("{0}.v{1}{2}", _created.Ticks, _version, System.IO.Path.GetExtension(program.FullName)))));
                using (var writer = new StreamWriter(logFileName))
                {
                    snapshot.Write(writer);
                }
                _version++;
            }

            DafnyDriver.SetDiagnoseTimeouts(diagnoseTimeouts);
            errorListHolder.FatalVerificationError = null;
            var tacticsErrorList = new List <Tacny.CompoundErrorInformation>();

            //var unresolvedProgram = new TacnyDriver(snapshot.TextBuffer, _document.FilePath).ReParse(false);
            //Dafny.Program unresolvedProgram = null;
            // if (!TacnyDriver.GetExistingProgramFromBuffer(snapshot.TextBuffer, out unresolvedProgram))
            //  unresolvedProgram = new TacnyDriver(snapshot.TextBuffer, _document.FilePath).ReParse(false);

            var success = true;

#if !DEBUGTHROW
            try
            {
#endif
            success = DafnyDriver.Verify(program, errorListHolder, GetHashCode().ToString(), requestId, errorInfo =>
            {
                if (_disposed)
                {
                    return;
                }

                var tacticErrorInfo = errorInfo as Tacny.CompoundErrorInformation;
                if (tacticErrorInfo != null)
                {
                    tacticsErrorList.Add(tacticErrorInfo);
                    return;
                }

                errorInfo.BoogieErrorCode = null;
                var isRecycled            = false;
                ITextSnapshot s           = null;
                if (errorInfo.OriginalRequestId != null)
                {
                    isRecycled = errorInfo.OriginalRequestId != requestId;
                    RequestIdToSnapshot.TryGetValue(errorInfo.OriginalRequestId, out s);
                }
                if (s == null && errorInfo.RequestId != null)
                {
                    RequestIdToSnapshot.TryGetValue(errorInfo.RequestId, out s);
                }
                if (s == null)
                {
                    return;
                }

                errorListHolder.AddError(
                    new DafnyError(errorInfo.Tok.filename, errorInfo.Tok.line - 1, errorInfo.Tok.col - 1,
                                   ErrorCategory.VerificationError, errorInfo.FullMsg, s, isRecycled, errorInfo.Model.ToString(),
                                   System.IO.Path.GetFullPath(_document.FilePath) == errorInfo.Tok.filename),
                    errorInfo.ImplementationName, requestId);
                foreach (var aux in errorInfo.Aux)
                {
                    errorListHolder.AddError(
                        new DafnyError(aux.Tok.filename, aux.Tok.line - 1, aux.Tok.col - 1,
                                       ErrorCategory.AuxInformation, aux.FullMsg, s, isRecycled, null,
                                       System.IO.Path.GetFullPath(_document.FilePath) == aux.Tok.filename),
                        errorInfo.ImplementationName, requestId);
                }
            });
            if (!success)
            {
                errorListHolder.AddError(
                    new DafnyError("$$program$$", 0, 0, ErrorCategory.InternalError, "Verification process error", snapshot, false),
                    "$$program$$", requestId);
            }
#if !DEBUGTHROW
        }

        catch (Exception e)
        {
            errorListHolder.FatalVerificationError = new DafnyError("$$program$$", 0, 0,
                                                                    ErrorCategory.InternalError, "Fatal verification error: " + e.Message + "\n" + e.StackTrace, snapshot, false);
        }
        finally
        {
#endif
            ITextSnapshot snap;
            RequestIdToSnapshot.TryGetValue(requestId, out snap);
            var addedErrors = new List <DafnyError>();
            if (tacticsErrorList.Count > 0)
            {
                success = false;
                try {
                    tacticsErrorList.ForEach(errorInfo => new TacticErrorReportingResolver(errorInfo)
                                             .AddTacticErrors(addedErrors, snap, _document.FilePath));
                    addedErrors.ForEach(error => errorListHolder.AddError(error, "$$program_tactics$$", requestId));
                } catch (TacticErrorResolutionException e) {
                    errorListHolder.AddError(
                        new DafnyError("$$program_tactics$$", 0, 0, ErrorCategory.InternalError,
                                       "Error resolving tactics error " + e.Message + "\n" + e.StackTrace, snapshot, false),
                        "$$program_tactics$$", requestId);
                }
            }
            DafnyDriver.SetDiagnoseTimeouts(!diagnoseTimeouts);
#if !DEBUGTHROW
        }
#endif
            lock (this) {
                bufferChangesPreVerificationStart.Clear();
                verificationInProgress = false;
            }

            if (success)
            {
                DafnyClassifier.DafnyMenuPackage.TacnyMenuProxy.UpdateRot(_document.FilePath, snapshot);
            }

            errorListHolder.UpdateErrorList(snapshot);

            // Notify to-whom-it-may-concern about the cleared pre-verification changes
            NotifyAboutChangedTags(snapshot);

            // If new changes took place since we started the verification, we may need to kick off another verification
            // immediately.
            UponIdle(null, null);
        }