Пример #1
0
        public static bool TryGetMethodHashAttribute <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(
            this IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> metaDataDecoder,
            Method method,
            out MethodHashAttribute mhAttr)
        {
            Contract.Requires(metaDataDecoder != null);
            Contract.Ensures(!Contract.Result <bool>() || Contract.ValueAtReturn(out mhAttr) != null);

#if false                                          // dead code???
            if (false && method.Equals(cache.One)) // problem: successive analyses are run in the same worker
            {
                mhAttr = cache.Two;
                return(mhAttr != null);
            }
#endif
            mhAttr = null;
            foreach (var attr in metaDataDecoder.GetAttributes(method))
            {
                var attrType = metaDataDecoder.AttributeType(attr);
                if (metaDataDecoder.FullName(attrType) == NameFor.MethodHashAttribute)
                {
                    mhAttr = MethodHashAttribute.FromDecoder(metaDataDecoder.PositionalArguments(attr));
                    if (mhAttr != null)
                    {
                        break;
                    }
                }
            }

            cache = Pair.For <object, MethodHashAttribute>(method, mhAttr);

            return(mhAttr != null);
        }
Пример #2
0
        public static MethodRegressionOutcomes GetOutcomes <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(Method method, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder)
        {
            if (mdDecoder.GetMethodHashAttributeFlags(method).HasFlag(MethodHashAttributeFlags.IgnoreRegression))
            {
                return(new IgnoreRegressionOutcomes());
            }

            var outcomes = new Set <string>();

            foreach (Attribute attr in mdDecoder.GetAttributes(method))
            {
                var attrType = mdDecoder.AttributeType(attr);
                if (mdDecoder.Name(attrType) != "RegressionOutcomeAttribute")
                {
                    continue;
                }
                var posArgs = mdDecoder.PositionalArguments(attr);
                if (posArgs.Count == 0)
                {
                    var outcome = (ProofOutcome)(byte)GetNamedArgOrDefault <int, Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(mdDecoder, "Outcome", attr);

                    // at some places we have "this.x" instead of "x", both should be treated equal.
                    string msg           = ((string)mdDecoder.NamedArgument("Message", attr)).Replace("this.", string.Empty);
                    int    primaryOffset = GetNamedArgOrDefault <int, Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(mdDecoder, "PrimaryILOffset", attr);
                    int    methodOffset  = GetNamedArgOrDefault <int, Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(mdDecoder, "MethodILOffset", attr);

                    outcomes.Add(CanonicalFormat(outcome, msg, primaryOffset, methodOffset));
                }
                else
                {
                    outcomes.Add((string)posArgs[0]);
                }
            }
            return(new MethodRegressionOutcomes(outcomes));
        }
Пример #3
0
        public static bool IsObjectInvariantMethod <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(
            this IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> metaDataDecoder,
            Method method)
        {
            Contract.Requires(metaDataDecoder != null);

            if (metaDataDecoder.Name(method) == NameFor.ObjectInvariantMethodName)
            {
                return(true);
            }

            return(metaDataDecoder.GetAttributes(method).Any(attr => metaDataDecoder.Name(metaDataDecoder.AttributeType(attr)) == NameFor.ObjectInvariantMethodAttribute));
        }
Пример #4
0
            internal static MaskedWarnings GetMaskedWarningsFor(Set <string> mask, Method method,
                                                                IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder)
            {
                Contract.Requires(mask != null);
                Contract.Requires(mdDecoder != null);

                Contract.Ensures(Contract.Result <MaskedWarnings>() != null);

                // Add Type attributes
                var typeAttrib = mdDecoder.GetAttributes(mdDecoder.DeclaringType(method));

                Contract.Assume(typeAttrib != null);
                foreach (var attrib in typeAttrib)
                {
                    string dummy;

                    TryAddAttribute(mask, attrib, mdDecoder, out dummy);
                }

                // Save the mask for the warnings as we use it later
                var methodMask = new Set <string>();

                // Add Method attributes
                var methodAttrib = mdDecoder.GetAttributes(method);

                Contract.Assume(methodAttrib != null);
                foreach (var attrib in methodAttrib)
                {
                    string attribName;
                    if (TryAddAttribute(mask, attrib, mdDecoder, out attribName))
                    {
                        methodMask.Add(attribName);
                    }
                }

                Contract.Assume(methodMask.Count <= mask.Count);
                return(new MaskedWarnings(mask, methodMask));
            }
Пример #5
0
        public static AssemblyRegressionOutcomes GetOutcomes <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(Assembly assembly, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder)
        {
            Set <string> outcomes = new Set <string>();

            foreach (Attribute attr in mdDecoder.GetAttributes(assembly))
            {
                Type attrType = mdDecoder.AttributeType(attr);
                if (mdDecoder.Name(attrType) != "RegressionOutcomeAttribute")
                {
                    continue;
                }
                string expectedString = (string)mdDecoder.PositionalArguments(attr)[0];
                outcomes.Add(expectedString);
            }
            return(new AssemblyRegressionOutcomes(outcomes));
        }
Пример #6
0
            internal static Set <string> GetMaskedWarningsFor(Assembly assembly,
                                                              IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder)
            {
                Contract.Requires(mdDecoder != null);
                Contract.Ensures(Contract.Result <Set <string> >() != null);

                var mask       = new Set <String>();
                var attribMask = mdDecoder.GetAttributes(assembly);

                Contract.Assume(attribMask != null);
                foreach (var attrib in attribMask)
                {
                    string dummy;
                    TryAddAttribute(mask, attrib, mdDecoder, out dummy);
                }

                return(mask);
            }
Пример #7
0
        public static int GetReanalyisCountIfAny <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(Method method, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder)
        {
            if (mdDecoder.GetMethodHashAttributeFlags(method).HasFlag(MethodHashAttributeFlags.IgnoreRegression))
            {
                return(0);
            }

            foreach (Attribute attr in mdDecoder.GetAttributes(method))
            {
                Type attrType = mdDecoder.AttributeType(attr);
                if (mdDecoder.Name(attrType) != "RegressionReanalysisCountAttribute")
                {
                    continue;
                }
                var posArgs = mdDecoder.PositionalArguments(attr);
                if (posArgs.Count != 0)
                {
                    return((int)posArgs[0]);
                }
            }

            return(0);
        }
Пример #8
0
            internal static bool IsMaskedInType(Type t,
                                                IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder,
                                                string maskingString)
            {
                Contract.Requires(mdDecoder != null);
                Contract.Ensures(!Contract.Result <bool>() || maskingString != null);

                if (maskingString == null)
                {
                    return(false);
                }

                foreach (var attrib in mdDecoder.GetAttributes(t))
                {
                    var attribType = mdDecoder.AttributeType(attrib);
                    if (mdDecoder.Name(attribType) == "SuppressMessageAttribute")
                    {
                        var args = mdDecoder.PositionalArguments(attrib);

                        Contract.Assume(args != null);

                        if (args.Count < 2)
                        {
                            return(false);
                        }

                        var name = (string)args[0];

                        if (name == "Microsoft.Contracts" && ((args[1] as string) == maskingString))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }