public bool CheckOutcome(WarningKind kind, IOutput output, Method method, ProofOutcome outcome, string message, int primaryILOffset, int methodILOffset,
                                     IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder,
                                     CacheManager <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, ExternalExpression <APC, SymbolicValue>, SymbolicValue> cacheManager)
            {
                string canonicalMethodName = XmlBaseLine <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> .CanonicalMethodName(method, mdDecoder);

                string canonical = CanonicalFormat(canonicalMethodName, kind, outcome, message, primaryILOffset, methodILOffset, baselineStrategy);

                this.actualOutcomes.Add(canonical);

                // HACK to avoid modifying tons of Clousot code
                if (cacheManager != null && !checkedHashMatch)
                {
                    if (this.methodHash != cacheManager.MethodHashAsString())
                    {
                        // the method names match, but their hashes do not. this means the programmer has changed the method *without* renaming it
                        //TextWriter errorWriter = Console.Error;
                        //errorWriter.WriteLine(string.Format("<Hash/Name Discrepancy>{0}</HashName Discrepancy>", method));
                        //Console.WriteLine(string.Format("<Hash/Name Discrepancy>{0}</HashName Discrepancy>", method));
                    }
                    checkedHashMatch = true;
                }
                if (!this.expectedOutcomes.Contains(canonical))
                {
                    if (kind != WarningKind.Informational)
                    {
                        errorCount++;
                    }
                    return(false);
                }
                return(true);
            }
            static string CanonicalFormat(string methodName, WarningKind kind, ProofOutcome outcome, string message, int primaryILOffset, int methodILOffset, BaseLiningOptions baselineStrategy)
            {
                switch (baselineStrategy)
                {
                case BaseLiningOptions.ilBased:
                    return(String.Format("{0}:{1} PrimaryIL={2} MethodIL={3}", methodName, message, primaryILOffset, methodILOffset));

                case BaseLiningOptions.typeBased:
                    return(String.Format("{0}:{1}", methodName, kind.ToString()));

                case BaseLiningOptions.mixed:
                default:
                    switch (kind)
                    {
                    case WarningKind.Invariant:
                    case WarningKind.Assert:
                    case WarningKind.Requires:
                    case WarningKind.Ensures:
                        return(String.Format("{0} PrimaryIL={1}", message, primaryILOffset));

                    default:
                        return(message);
                    }
                }
            }
        private void EmitOutcomeToBaseLine(WarningKind kind, ProofOutcome outcome, APC pc, string message)
        {
            int primaryILOffset, methodILOffset;

            GetILOffsets(pc, this.currentMethod, out primaryILOffset, out methodILOffset);
            xmlWriter.WriteStartElement("Outcome");
            xmlWriter.WriteAttributeString("Kind", kind.ToString());
            xmlWriter.WriteAttributeString("Outcome", outcome.ToString());
            xmlWriter.WriteAttributeString("Message", message);
            xmlWriter.WriteAttributeString("PrimaryILOffset", primaryILOffset.ToString("x"));
            xmlWriter.WriteAttributeString("MethodILOffset", methodILOffset.ToString("x"));
            xmlWriter.WriteEndElement();
        }
            static string Canonicalize(String methodName, XElement outcomeElement, BaseLiningOptions baselineStrategy)
            {
                var outcomeKind = (string)outcomeElement.Attribute("Outcome");

                if (outcomeKind != null)
                {
                    ProofOutcome outcome         = (ProofOutcome)Enum.Parse(typeof(ProofOutcome), (string)outcomeElement.Attribute("Outcome"), true);
                    WarningKind  kind            = (WarningKind)Enum.Parse(typeof(WarningKind), (string)outcomeElement.Attribute("Kind"), true);
                    string       message         = (string)outcomeElement.Attribute("Message");
                    int          primaryILOffset = Int32.Parse((string)outcomeElement.Attribute("PrimaryILOffset"), System.Globalization.NumberStyles.HexNumber);
                    int          methodILOffset  = Int32.Parse((string)outcomeElement.Attribute("MethodILOffset"), System.Globalization.NumberStyles.HexNumber);
                    return(CanonicalFormat(methodName, kind, outcome, message, primaryILOffset, methodILOffset, baselineStrategy));
                }
                else
                {
                    return((string)outcomeElement.Attribute("Message"));
                }
            }
        private void EmitOutcomeToBaseLine(WarningKind kind, ProofOutcome outcome, APC pc, string format, object[] args)
        {
            var message = String.Format(format, args);

            EmitOutcomeToBaseLine(kind, outcome, pc, message);
        }
Esempio n. 6
0
 public GMWarning(string message, WarningLevel level = WarningLevel.Bad, WarningKind kind = WarningKind.Unknown)
 {
     Message = message;
     Level   = level;
     Kind    = kind;
 }