示例#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,
            };
        }
示例#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,
            };
        }
示例#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);
 }
示例#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));
        }
示例#5
0
    internal LockReplacer(SourceMethodBody sourceMethodBody) {
      Contract.Requires(sourceMethodBody != null);
      this.host = sourceMethodBody.host; Contract.Assume(sourceMethodBody.host != null);
      this.sourceLocationProvider = sourceMethodBody.sourceLocationProvider;
      this.numberOfReferencesToLocal = sourceMethodBody.numberOfReferencesToLocal; Contract.Assume(sourceMethodBody.numberOfReferencesToLocal != null);
      this.numberOfAssignmentsToLocal = sourceMethodBody.numberOfAssignmentsToLocal; Contract.Assume(sourceMethodBody.numberOfAssignmentsToLocal != null);
      this.bindingsThatMakeALastUseOfALocalVersion = sourceMethodBody.bindingsThatMakeALastUseOfALocalVersion; Contract.Assume(sourceMethodBody.bindingsThatMakeALastUseOfALocalVersion != null);
      var systemThreading = new Immutable.NestedUnitNamespaceReference(this.host.PlatformType.SystemObject.ContainingUnitNamespace,
        this.host.NameTable.GetNameFor("Threading"));
      var systemThreadingMonitor = new Immutable.NamespaceTypeReference(this.host, systemThreading, this.host.NameTable.GetNameFor("Monitor"), 0,
        isEnum: false, isValueType: false, typeCode: PrimitiveTypeCode.NotPrimitive);
      var parameters = new IParameterTypeInformation[2];
      this.monitorEnter = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
        this.host.NameTable.GetNameFor("Enter"), 0, parameters);
      parameters[0] = new SimpleParameterTypeInformation(monitorEnter, 0, this.host.PlatformType.SystemObject);
      parameters[1] = new SimpleParameterTypeInformation(monitorEnter, 1, this.host.PlatformType.SystemBoolean, isByReference: true);
      this.monitorExit = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
        this.host.NameTable.GetNameFor("Exit"), 0, this.host.PlatformType.SystemObject);

    }
示例#6
0
        internal LockReplacer(SourceMethodBody sourceMethodBody)
        {
            Contract.Requires(sourceMethodBody != null);
            this.host = sourceMethodBody.host; Contract.Assume(sourceMethodBody.host != null);
            this.sourceLocationProvider     = sourceMethodBody.sourceLocationProvider;
            this.numberOfReferencesToLocal  = sourceMethodBody.numberOfReferencesToLocal; Contract.Assume(sourceMethodBody.numberOfReferencesToLocal != null);
            this.numberOfAssignmentsToLocal = sourceMethodBody.numberOfAssignmentsToLocal; Contract.Assume(sourceMethodBody.numberOfAssignmentsToLocal != null);
            this.bindingsThatMakeALastUseOfALocalVersion = sourceMethodBody.bindingsThatMakeALastUseOfALocalVersion; Contract.Assume(sourceMethodBody.bindingsThatMakeALastUseOfALocalVersion != null);
            var systemThreading = new Immutable.NestedUnitNamespaceReference(this.host.PlatformType.SystemObject.ContainingUnitNamespace,
                                                                             this.host.NameTable.GetNameFor("Threading"));
            var systemThreadingMonitor = new Immutable.NamespaceTypeReference(this.host, systemThreading, this.host.NameTable.GetNameFor("Monitor"), 0,
                                                                              isEnum: false, isValueType: false, typeCode: PrimitiveTypeCode.NotPrimitive);
            var parameters = new IParameterTypeInformation[2];

            this.monitorEnter = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
                                                    this.host.NameTable.GetNameFor("Enter"), 0, parameters);
            parameters[0]    = new SimpleParameterTypeInformation(monitorEnter, 0, this.host.PlatformType.SystemObject);
            parameters[1]    = new SimpleParameterTypeInformation(monitorEnter, 1, this.host.PlatformType.SystemBoolean, isByReference: true);
            this.monitorExit = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
                                                   this.host.NameTable.GetNameFor("Exit"), 0, this.host.PlatformType.SystemObject);
        }