public override bool IsMasked(Witness witness)
        {
            if (this.options.MaskedWarnings && this.methodmask != null)
            {
                var encode = this.suppressWarningsManager.ComputeWarningMask(witness);

                // Is it masked?
                if (this.methodmask.IsMasked(encode))
                {
                    return(true);
                }

                // Is it a masked precondition ?
                Method m; Type t;
                if (witness.PC.InsideRequiresAtCall &&
                    witness.PC.TryGetContainingMethod(out m))
                {
                    var encodeRequiresAtCall         = this.suppressWarningsManager.ComputeWarningMaskAtCallee(witness);
                    var methodNameContainingRequires = this.mdDecoder.FullName(m);
                    if (MaskedWarnings.IsMaskedInTheOriginalMethod(m, this.mdDecoder, encodeRequiresAtCall))
                    {
                        return(true);
                    }
                }
                // Is it a masked postcondition ?
                else if (witness.PC.InsideEnsuresInMethod)
                {
                    var encodeEnsures = this.suppressWarningsManager.ComputeWarningMaskForEnsures(witness);

                    if (encodeEnsures != null)
                    {
                        if (this.methodmask.IsMasked(encodeEnsures))
                        {
                            return(true);
                        }
                    }

                    if (witness.PC.TryGetContainingMethod(out m))
                    {
                        var encodeEnsuresAtCall         = this.suppressWarningsManager.ComputeWarningMaskAtBaseMethod(witness);
                        var methodNameContainingEnsures = this.mdDecoder.FullName(m);
                        if (MaskedWarnings.IsMaskedInTheOriginalMethod(m, this.mdDecoder, encodeEnsuresAtCall))
                        {
                            return(true);
                        }
                    }
                }
                // Is it a masked invariant?
                else if (witness.PC.InsideInvariantInMethod &&
                         witness.PC.TryGetContainingType(out t))
                {
                    var encodeInvariant             = this.suppressWarningsManager.ComputeWarningMaskForInvariant(witness);
                    var typeNameContainingInvariant = this.mdDecoder.FullName(t);
                    if (MaskedWarnings.IsMaskedInType(t, this.mdDecoder, encodeInvariant))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        private bool EmitOutcome_Internal(bool emitRelatedToo, Witness witness, string format, params object[] args)
        {
            Contract.Requires(witness != null);
            Contract.Requires(format != null);

            string encode = null;
            string encodeRequiresAtCall         = null;
            string methodNameContainingRequires = null;

            string encodeEnsures               = null;
            string encodeEnsuresAtCall         = null;
            string methodNameContainingEnsures = null;

            string encodeInvariant             = null;
            string typeNameContainingInvariant = null;

            if (witness.Outcome != ProofOutcome.True && this.options.MaskedWarnings &&
                this.methodmask != null // We add this check as we are not enforcing the typestate
                )
            {
                encode = this.suppressWarningsManager.ComputeWarningMask(witness);

                // Is it masked?
                if (this.methodmask.IsMasked(encode))
                {
                    this.methodmask.SignalMasked(encode);
                    this.swallowedCount.UpdateCounter(witness.Outcome);

                    return(false);
                }

                // Is it a masked precondition ?
                Method m; Type t;
                if (witness.PC.InsideRequiresAtCall && witness.PC.TryGetContainingMethod(out m))
                {
                    encodeRequiresAtCall         = this.suppressWarningsManager.ComputeWarningMaskAtCallee(witness);
                    methodNameContainingRequires = this.mdDecoder.FullName(m);
                    if (MaskedWarnings.IsMaskedInTheOriginalMethod(m, this.mdDecoder, encodeRequiresAtCall))
                    {
                        this.methodmask.SignalMasked(encodeRequiresAtCall);
                        this.swallowedCount.UpdateCounter(witness.Outcome);

                        return(false);
                    }
                }
                // Is it a masked postcondition ?
                else if (witness.PC.InsideEnsuresInMethod)
                {
                    encodeEnsures = this.suppressWarningsManager.ComputeWarningMaskForEnsures(witness);

                    if (encodeEnsures != null)
                    {
                        if (this.methodmask.IsMasked(encodeEnsures))
                        {
                            this.methodmask.SignalMasked(encodeEnsures);
                            this.swallowedCount.UpdateCounter(witness.Outcome);

                            return(false);
                        }
                    }

                    if (witness.PC.TryGetContainingMethod(out m))
                    {
                        encodeEnsuresAtCall         = this.suppressWarningsManager.ComputeWarningMaskAtBaseMethod(witness);
                        methodNameContainingEnsures = this.mdDecoder.FullName(m);
                        if (MaskedWarnings.IsMaskedInTheOriginalMethod(m, this.mdDecoder, encodeEnsuresAtCall))
                        {
                            this.methodmask.SignalMasked(encodeEnsuresAtCall);
                            this.swallowedCount.UpdateCounter(witness.Outcome);

                            return(false);
                        }
                    }
                }
                // Is it a masked invariant?
                else if (witness.PC.InsideInvariantInMethod &&
                         witness.PC.TryGetContainingType(out t))
                {
                    encodeInvariant             = this.suppressWarningsManager.ComputeWarningMaskForInvariant(witness);
                    typeNameContainingInvariant = this.mdDecoder.FullName(t);
                    if (MaskedWarnings.IsMaskedInType(t, this.mdDecoder, encodeInvariant))
                    {
                        this.swallowedCount.UpdateCounter(witness.Outcome);

                        return(false);
                    }
                }
            }

            bool result;

            if (emitRelatedToo)
            {
                result = base.EmitOutcomeAndRelated(witness, format, args);
            }
            else
            {
                result = base.EmitOutcome(witness, format, args);
            }

            if (witness.Outcome != ProofOutcome.True && this.options.OutputWarningMasks)
            {
                this.WriteLine("Method {0}: To mask the warning {1}{2}       add the attribute: {3}",
                               this.currMethod.ToString(),
                               witness.PC.HasRealSourceContext?
                               "at " + witness.PC.PrimaryMethodLocation().PrimarySourceContext():
                               "",
                               "\n", // f: using "\n" instead of Environment.NewLine, because the last one caused '\n' to be printed in the output window of VS

                               encodeEnsures != null?
                               this.suppressWarningsManager.ComputeSuppressMessage(encodeEnsures) :
                               this.suppressWarningsManager.ComputeSuppressMessage(encode));

                if (encodeRequiresAtCall != null && methodNameContainingRequires != null)
                {
                    this.WriteLine("Method {0}: To mask *all* warnings issued like the precondition {1}{2}        add the attribute: {3} to the method {4}",
                                   this.currMethod.ToString(),
                                   witness.PC.HasRealSourceContext ?
                                   "at " + witness.PC.PrimaryMethodLocation().PrimarySourceContext() :
                                   "",
                                   "\n",// f: using "\n" instead of Environment.NewLine, because the last one caused '\n' to be printed in the output window of VS
                                   this.suppressWarningsManager.ComputeSuppressMessage(encodeRequiresAtCall),
                                   methodNameContainingRequires);
                }

                if (encodeEnsuresAtCall != null && methodNameContainingEnsures != null)
                {
                    this.WriteLine("Method {0}: To mask *all* warnings issued like the postcondition {1}{2}        add the attribute: {3} to the method {4}",
                                   this.currMethod.ToString(),
                                   witness.PC.HasRealSourceContext ?
                                   "at " + witness.PC.PrimaryMethodLocation().PrimarySourceContext() :
                                   "",
                                   "\n", // f: using "\n" instead of Environment.NewLine, because the last one caused '\n' to be printed in the output window of VS
                                   this.suppressWarningsManager.ComputeSuppressMessage(encodeEnsuresAtCall),
                                   methodNameContainingEnsures);
                }

                if (encodeInvariant != null && typeNameContainingInvariant != null)
                {
                    this.WriteLine("Method {0}: To mask *all* warnings issued like the invariant {1}{2}        add the attribute: {3} to the type {4}",
                                   this.currMethod.ToString(),
                                   witness.PC.HasRealSourceContext ?
                                   "at " + witness.PC.PrimaryMethodLocation().PrimarySourceContext() :
                                   "",
                                   "\n",// f: using "\n" instead of Environment.NewLine, because the last one caused '\n' to be printed in the output window of VS
                                   this.suppressWarningsManager.ComputeSuppressMessage(encodeInvariant),
                                   typeNameContainingInvariant);
                }
            }

            return(result);
        }
 public override bool EmitOutcomeAndRelated(Witness witness, string format, params object[] args)
 {
     return(EmitOutcome_Internal(true, witness, format, args));
 }
 public override bool EmitOutcome(Witness witness, string format, params object[] args)
 {
     return(EmitOutcome_Internal(false, witness, format, args));
 }
 public bool IsMasked(Witness witness)
 {
     return(this.output.IsMasked(witness));
 }
Example #6
0
 public override bool EmitOutcome(Witness witness, string format, params object[] args)
 {
     return(EmitOutcomeInternal(Bucket.Kind.EmitOutcome, witness, format, args));
 }