Exemple #1
0
        /// <summary>
        /// A rewriter for CodeModel method bodies, which changes any foreach loops found in the body into lower level structures.
        /// </summary>
        /// <param name="host">An object representing the application that is hosting the converter. It is used to obtain access to some global
        /// objects and services such as the shared name table and the table for interning references.</param>
        /// <param name="sourceLocationProvider">An object that can map the ILocation objects found in a block of statements to IPrimarySourceLocation objects. May be null.</param>
        public ForEachRemover(IMetadataHost host, ISourceLocationProvider/*?*/ sourceLocationProvider)
            : base(host)
        {
            this.sourceLocationProvider = sourceLocationProvider;


            this.moveNext = new MethodReference()
            {
                CallingConvention = CallingConvention.HasThis,
                ContainingType = host.PlatformType.SystemCollectionsIEnumerator,
                InternFactory = host.InternFactory,
                Name = host.NameTable.GetNameFor("MoveNext"),
                Parameters = new List<IParameterTypeInformation>(),
                Type = host.PlatformType.SystemBoolean,
            };

            var assemblyReference = new Immutable.AssemblyReference(this.host, this.host.CoreAssemblySymbolicIdentity);
            IUnitNamespaceReference ns = new Immutable.RootUnitNamespaceReference(assemblyReference);
            ns = new Immutable.NestedUnitNamespaceReference(ns, this.host.NameTable.GetNameFor("System"));
            var iDisposable = new Immutable.NamespaceTypeReference(this.host, ns, this.host.NameTable.GetNameFor("IDisposable"), 0, false, false, true, PrimitiveTypeCode.Reference);
            this.disposeMethod = new MethodReference()
            {
                CallingConvention = CallingConvention.HasThis,
                ContainingType = iDisposable,
                InternFactory = host.InternFactory,
                Name = this.host.NameTable.GetNameFor("Dispose"),
                Parameters = new List<IParameterTypeInformation>(),
                Type = this.host.PlatformType.SystemVoid,
            };
        }
Exemple #2
0
        /// <summary>
        /// A rewriter for CodeModel method bodies, which changes any foreach loops found in the body into lower level structures.
        /// </summary>
        /// <param name="host">An object representing the application that is hosting the converter. It is used to obtain access to some global
        /// objects and services such as the shared name table and the table for interning references.</param>
        /// <param name="sourceLocationProvider">An object that can map the ILocation objects found in a block of statements to IPrimarySourceLocation objects. May be null.</param>
        public ForEachRemover(IMetadataHost host, ISourceLocationProvider /*?*/ sourceLocationProvider)
            : base(host)
        {
            this.sourceLocationProvider = sourceLocationProvider;


            this.moveNext = new MethodReference()
            {
                CallingConvention = CallingConvention.HasThis,
                ContainingType    = host.PlatformType.SystemCollectionsIEnumerator,
                InternFactory     = host.InternFactory,
                Name       = host.NameTable.GetNameFor("MoveNext"),
                Parameters = new List <IParameterTypeInformation>(),
                Type       = host.PlatformType.SystemBoolean,
            };

            var assemblyReference      = new Immutable.AssemblyReference(this.host, this.host.CoreAssemblySymbolicIdentity);
            IUnitNamespaceReference ns = new Immutable.RootUnitNamespaceReference(assemblyReference);

            ns = new Immutable.NestedUnitNamespaceReference(ns, this.host.NameTable.GetNameFor("System"));
            var iDisposable = new Immutable.NamespaceTypeReference(this.host, ns, this.host.NameTable.GetNameFor("IDisposable"), 0, false, false, true, PrimitiveTypeCode.Reference);

            this.disposeMethod = new MethodReference()
            {
                CallingConvention = CallingConvention.HasThis,
                ContainingType    = iDisposable,
                InternFactory     = host.InternFactory,
                Name       = this.host.NameTable.GetNameFor("Dispose"),
                Parameters = new List <IParameterTypeInformation>(),
                Type       = this.host.PlatformType.SystemVoid,
            };
        }
Exemple #3
0
 /// <summary>
 /// Returns true iff the method reference or its definition have the [System.Diagnostics.Contracts.Pure] attribute.
 /// </summary>
 /// <param name="host">Used to get a reference to the contract assembly in which the attribute is defined.</param>
 /// <param name="methodReference">The method reference to be checked for the presence of the pure attribute.</param>
 /// <returns></returns>
 public static bool IsPure(IMetadataHost host, IMethodReference methodReference) {
   var contractAssemblyReference = new Immutable.AssemblyReference(host, host.ContractAssemblySymbolicIdentity);
   var pureAttribute = ContractHelper.CreateTypeReference(host, contractAssemblyReference, "System.Diagnostics.Contracts.PureAttribute");
   if (AttributeHelper.Contains(methodReference.Attributes, pureAttribute)) return true;
   var methodDefinition = methodReference.ResolvedMethod;
   return methodDefinition != methodReference && AttributeHelper.Contains(methodDefinition.Attributes, pureAttribute);
 }