示例#1
0
        /// <summary>
        /// Adds the methods of the given type to the method order as well
        /// as recursively calling AddType on nested types within the given type.
        /// Call this with every top-level type to be analyzed.
        /// Internally called with nested types as well.
        /// </summary>
        public void AddType(Type type)
        {
            //TODO:0 HACK HACK HACK for the TechFest demo
            // If it is a compiler generated class, we skip it
            foreach (Attribute a in this.md.GetAttributes(type))
            {
                string fullname = md.FullName(md.AttributeType(a));
                if (fullname == "System.CodeDom.Compiler.GeneratedCodeAttribute")
                {
                    return;
                }
                if (fullname == "System.Diagnostics.Contracts.ContractClassForAttribute")
                {
                    return;
                }
            }


            foreach (Method method in md.Methods(type))
            {
                if (md.Name(method) == "ObjectInvariant")
                {
                    // ignore contract helper method
                    continue;
                }
                this.AddMethod(method);
            }

            foreach (Type nested in md.NestedTypes(type))
            {
                this.AddType(nested);
            }
        }
        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);
        }
        public static bool IsMethodHashAttributeConstructor <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);

            return(metaDataDecoder.FullName(method) == NameFor.MethodHashAttributeConstructor);
        }
示例#4
0
        public override void EndMethod(APC methodEntry, bool ignoreMethodEntryAPC)
        {
            // this is the case when EndMethod was already called
            if (expectedOutcomes == null)
            {
                return;
            }

            if (!this.skipCurrentMethod && !expectedOutcomes.Passed(false))
            {
                this.errorCount += expectedOutcomes.Errors;
                base.WriteLine("Method {0}", mdDecoder.FullName(this.currentMethod));
                expectedOutcomes.ReportRegressions(this.UnderlyingOutput);
            }
            base.EndMethod(methodEntry, ignoreMethodEntryAPC);
            expectedOutcomes = null;
        }
示例#5
0
        public override Domain Newobj <ArgList>(APC pc, Method ctor, Variable dest, ArgList args, Domain data)
        {
            IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> decoder = this.methodDriver.MetaDataDecoder;
            string fullName       = decoder.FullName(ctor);
            Type   enumerableType = decoder.DeclaringType(ctor);

            Debug.Assert(enumerableType != null);
            foreach (Method m in decoder.Methods(enumerableType))
            {
                if (decoder.Name(m) == "MoveNext")
                {
                    this.moveNext   = m;
                    this.fieldsHold = FunctionalMap <string, int> .Empty;
                    // DebugHelper.WriteLine("Find the desired MoveNext Method:{0}", m);
                    break;
                }
            }
            return(base.Newobj <ArgList>(pc, ctor, dest, args, data));
        }
示例#6
0
        /// <summary>
        /// Adds the methods of the given type to the method order as well
        /// as recursively calling AddType on nested types within the given type (if necessary).
        /// Call this with every top-level type to be analyzed.
        /// Internally called with nested types as well.
        /// </summary>
        public virtual void AddType(Type type)
        {
            foreach (var a in this.md.GetAttributes(type))
            {
                var fullname = this.md.FullName(md.AttributeType(a));

                if (fullname == "System.Diagnostics.Contracts.ContractClassForAttribute")
                {
                    return;
                }
            }

            foreach (var method in this.md.Methods(type).OrderBy(m => md.FullName(m)))
            {
                if (this.IsObjectInvariantMethod(method))
                {
                    continue; // ignore contract helper method
                }
                if (this.md.IsConstructor(method))
                {
                    continue; // added separately
                }
                this.AddMethod(method);
            }

            // add constructors so they have a chance to be analyzed first
            foreach (var method in this.md.Methods(type))
            {
                if (this.md.IsConstructor(method) && !this.md.IsMethodHashAttributeConstructor(method))
                {
                    this.AddMethod(method);
                }
            }

            foreach (var nested in this.md.NestedTypes(type))
            {
                this.AddType(nested);
            }
        }
示例#7
0
 public Unit Call <TypeList, ArgList>(Label pc, Method method, bool tail, bool virt, TypeList extraVarargs, Dest dest, ArgList args, TextWriter data)
     where TypeList : IIndexable <Type>
     where ArgList : IIndexable <Source>
 {
     data.Write("{0}{4} = {1}call{3} {2}(", prefix, tail ? "tail." : null, mdDecoder.FullName(method), virt ? "virt" : null, DestName(dest));
     if (args != null)
     {
         for (int i = 0; i < args.Count; i++)
         {
             var tmp = string.Format("{0} ", SourceName(args[i]));
             data.Write(tmp);
         }
     }
     data.WriteLine(")");
     return(Unit.Value);
 }
示例#8
0
 public Unit Isinst(ExternalExpression <Label, SymbolicValue> pc, Type type, SymbolicValue dest, ExternalExpression <Label, SymbolicValue> obj, StringBuilder data)
 {
     data.AppendFormat("IsInst({0}) ", mdDecoder.FullName(type));
     Recurse(data, obj);
     return(Unit.Value);
 }