Ejemplo n.º 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,
            };
        }
Ejemplo n.º 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,
            };
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a type reference anchored in the given assembly reference and whose names are relative to the given host.
 /// When the type name has periods in it, a structured reference with nested namespaces is created.
 /// </summary>
 private static INamespaceTypeReference CreateTypeReference(IMetadataHost host, IAssemblyReference assemblyReference, string typeName)
 {
     IUnitNamespaceReference ns = new Immutable.RootUnitNamespaceReference(assemblyReference);
     string[] names = typeName.Split('.');
     for (int i = 0, n = names.Length - 1; i < n; i++)
         ns = new Immutable.NestedUnitNamespaceReference(ns, host.NameTable.GetNameFor(names[i]));
     return new Immutable.NamespaceTypeReference(host, ns, host.NameTable.GetNameFor(names[names.Length - 1]), 0, false, false, true, PrimitiveTypeCode.NotPrimitive);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a type reference anchored in the given assembly reference and whose names are relative to the given host.
        /// When the type name has periods in it, a structured reference with nested namespaces is created.
        /// </summary>
        private static INamespaceTypeReference CreateTypeReference(IMetadataHost host, IAssemblyReference assemblyReference, string typeName)
        {
            IUnitNamespaceReference ns = new Immutable.RootUnitNamespaceReference(assemblyReference);

            string[] names = typeName.Split('.');
            for (int i = 0, n = names.Length - 1; i < n; i++)
            {
                ns = new Immutable.NestedUnitNamespaceReference(ns, host.NameTable.GetNameFor(names[i]));
            }
            return(new Immutable.NamespaceTypeReference(host, ns, host.NameTable.GetNameFor(names[names.Length - 1]), 0, false, false, true, PrimitiveTypeCode.NotPrimitive));
        }