public override void EndMethod(APC methodEntry, bool ignoreMethodEntryAPC)
        {
            // Collect the obsolete suppressions for warning messages
            List <string> unusedMethodMaskedWarnings;

            if (this.methodmask != null && this.methodmask.TryGetUnusedMethodMaskedWarnings(out unusedMethodMaskedWarnings))
            {
                Contract.Assert(unusedMethodMaskedWarnings != null);
                foreach (var s in unusedMethodMaskedWarnings)
                {
                    Contract.Assume(s != null);

                    var methodName = this.mdDecoder.Name(this.currMethod);
                    var dt         = this.mdDecoder.DeclaringType(this.currMethod);
                    var dtName     = this.mdDecoder.Name(dt);
                    var nsName     = this.mdDecoder.Namespace(dt);
                    methodName = String.Format("{0}.{1}.{2}", nsName, dtName, methodName);

#if false
                    this.WriteLine("{0}Unused suppression of a warning message: {1}",
                                   methodName != null? ("Method " + methodName + ": ") : "",
                                   ComputeSuppressMessage(s));
#endif
                    var suggestion = string.Format("{0}Unused suppression of a warning message: {1}",
                                                   "Method " + methodName + ": ",
                                                   this.suppressWarningsManager.ComputeSuppressMessage(s));
                    this.Suggestion(ClousotSuggestion.Kind.UnusedSuppressWarning, ClousotSuggestion.Kind.UnusedSuppressWarning.Message(),
                                    methodEntry, suggestion, null, ClousotSuggestion.ExtraSuggestionInfo.None);
                }
            }

            this.methodmask = null;
            this.currMethod = default(Method);
            base.EndMethod(methodEntry, ignoreMethodEntryAPC);
        }
 public override void StartMethod(Method method)
 {
     this.currMethod = method;
     this.methodmask = MaskedWarnings.GetMaskedWarningsFor(
         this.assemblymask != null? new Set <string>(this.assemblymask) : new Set <string>(),
         method, this.mdDecoder);
     base.StartMethod(method);
 }
        public MaskingOutput(IOutputFullResults <Method, Assembly> output, GeneralOptions options,
                             IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder)
            : base(output)
        {
            Contract.Requires(output != null);
            Contract.Requires(options != null);
            Contract.Requires(mdDecoder != null);

            this.options                 = options;
            this.mdDecoder               = mdDecoder;
            this.currMethod              = default(Method);
            this.methodmask              = null;
            this.assemblymask            = null;
            this.swallowedCount          = new SwallowedBuckets();
            this.suppressWarningsManager = new SuppressWarningsManager <Method>();
            this.errorsWereEmitted       = false;
        }
        public override void StartAssembly(Assembly assembly)
        {
            this.assemblymask = MaskedWarnings.GetMaskedWarningsFor(assembly, mdDecoder);
            base.StartAssembly(assembly);

            if (this.delayedErrors != null)
            {
                foreach (var error in delayedErrors)
                {
                    if (error == null)
                    {
                        continue;
                    }
                    this.EmitError(error);
                }
                this.delayedErrors = null;
            }
        }
        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);
        }