summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen')
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventItfInfo.cs53
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventProviderWriter.cs774
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventSinkHelperWriter.cs298
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/NameSpaceExtractor.cs21
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/TCEAdapterGenerator.cs141
5 files changed, 0 insertions, 1287 deletions
diff --git a/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventItfInfo.cs b/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventItfInfo.cs
deleted file mode 100644
index 29b094c9e8..0000000000
--- a/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventItfInfo.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace System.Runtime.InteropServices.TCEAdapterGen {
-
- using System;
- using System.Reflection;
- using System.Collections;
-
- internal class EventItfInfo
- {
- public EventItfInfo(String strEventItfName,
- String strSrcItfName,
- String strEventProviderName,
- RuntimeAssembly asmImport,
- RuntimeAssembly asmSrcItf)
- {
- m_strEventItfName = strEventItfName;
- m_strSrcItfName = strSrcItfName;
- m_strEventProviderName = strEventProviderName;
- m_asmImport = asmImport;
- m_asmSrcItf = asmSrcItf;
- }
-
- public Type GetEventItfType()
- {
- Type t = m_asmImport.GetType(m_strEventItfName, true, false);
- if (t != null && !t.IsVisible)
- t = null;
- return t;
- }
-
- public Type GetSrcItfType()
- {
- Type t = m_asmSrcItf.GetType(m_strSrcItfName, true, false);
- if (t != null && !t.IsVisible)
- t = null;
- return t;
- }
-
- public String GetEventProviderName()
- {
- return m_strEventProviderName;
- }
-
- private String m_strEventItfName;
- private String m_strSrcItfName;
- private String m_strEventProviderName;
- private RuntimeAssembly m_asmImport;
- private RuntimeAssembly m_asmSrcItf;
- }
-}
diff --git a/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventProviderWriter.cs b/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventProviderWriter.cs
deleted file mode 100644
index 160a0ab491..0000000000
--- a/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventProviderWriter.cs
+++ /dev/null
@@ -1,774 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace System.Runtime.InteropServices.TCEAdapterGen {
- using System.Runtime.InteropServices.ComTypes;
- using ubyte = System.Byte;
- using System;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.Collections;
- using System.Threading;
- using System.Diagnostics;
- using System.Diagnostics.Contracts;
-
- internal class EventProviderWriter
- {
- private const BindingFlags DefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
-
- private readonly Type[] MonitorEnterParamTypes = new Type[] { typeof(Object), Type.GetType("System.Boolean&") };
-
- public EventProviderWriter( ModuleBuilder OutputModule, String strDestTypeName, Type EventItfType, Type SrcItfType, Type SinkHelperType )
- {
- m_OutputModule = OutputModule;
- m_strDestTypeName = strDestTypeName;
- m_EventItfType = EventItfType;
- m_SrcItfType = SrcItfType;
- m_SinkHelperType = SinkHelperType;
- }
-
- public Type Perform()
- {
- // Create the event provider class.
- TypeBuilder OutputTypeBuilder = m_OutputModule.DefineType(
- m_strDestTypeName,
- TypeAttributes.Sealed | TypeAttributes.NotPublic,
- typeof(Object),
- new Type[]{m_EventItfType, typeof(IDisposable)}
- );
-
- // Create the event source field.
- FieldBuilder fbCPC = OutputTypeBuilder.DefineField(
- "m_ConnectionPointContainer",
- typeof(IConnectionPointContainer),
- FieldAttributes.Private
- );
-
- // Create array of event sink helpers.
- FieldBuilder fbSinkHelper = OutputTypeBuilder.DefineField(
- "m_aEventSinkHelpers",
- typeof(ArrayList),
- FieldAttributes.Private
- );
-
- // Define the connection point field.
- FieldBuilder fbEventCP = OutputTypeBuilder.DefineField(
- "m_ConnectionPoint",
- typeof(IConnectionPoint),
- FieldAttributes.Private
- );
-
- // Define the InitXXX method.
- MethodBuilder InitSrcItfMethodBuilder =
- DefineInitSrcItfMethod( OutputTypeBuilder, m_SrcItfType, fbSinkHelper, fbEventCP, fbCPC );
-
- // Process all the methods in the event interface.
- MethodInfo[] aMethods = TCEAdapterGenerator.GetNonPropertyMethods(m_SrcItfType);
- for ( int cMethods = 0; cMethods < aMethods.Length; cMethods++ )
- {
- if ( m_SrcItfType == aMethods[cMethods].DeclaringType )
- {
- // Define the add_XXX method.
- MethodBuilder AddEventMethodBuilder = DefineAddEventMethod(
- OutputTypeBuilder, aMethods[cMethods], m_SinkHelperType, fbSinkHelper, fbEventCP, InitSrcItfMethodBuilder );
-
- // Define the remove_XXX method.
- MethodBuilder RemoveEventMethodBuilder = DefineRemoveEventMethod(
- OutputTypeBuilder, aMethods[cMethods], m_SinkHelperType, fbSinkHelper, fbEventCP );
- }
- }
-
- // Define the constructor.
- DefineConstructor( OutputTypeBuilder, fbCPC );
-
- // Define the finalize method.
- MethodBuilder FinalizeMethod = DefineFinalizeMethod( OutputTypeBuilder, m_SinkHelperType, fbSinkHelper, fbEventCP );
-
- // Define the Dispose method.
- DefineDisposeMethod( OutputTypeBuilder, FinalizeMethod);
-
- return OutputTypeBuilder.CreateType();
- }
-
- private MethodBuilder DefineAddEventMethod( TypeBuilder OutputTypeBuilder, MethodInfo SrcItfMethod, Type SinkHelperClass, FieldBuilder fbSinkHelperArray, FieldBuilder fbEventCP, MethodBuilder mbInitSrcItf )
- {
- Type[] aParamTypes;
-
- // Find the delegate on the event sink helper.
- FieldInfo DelegateField = SinkHelperClass.GetField( "m_" + SrcItfMethod.Name + "Delegate" );
- Debug.Assert(DelegateField != null, "Unable to find the field m_" + SrcItfMethod.Name + "Delegate on the sink helper");
-
- // Find the cookie on the event sink helper.
- FieldInfo CookieField = SinkHelperClass.GetField( "m_dwCookie" );
- Debug.Assert(CookieField != null, "Unable to find the field m_dwCookie on the sink helper");
-
- // Retrieve the sink helper's constructor.
- ConstructorInfo SinkHelperCons = SinkHelperClass.GetConstructor(EventProviderWriter.DefaultLookup | BindingFlags.NonPublic, null, Array.Empty<Type>(), null );
- Debug.Assert(SinkHelperCons != null, "Unable to find the constructor for the sink helper");
-
- // Retrieve the IConnectionPoint.Advise method.
- MethodInfo CPAdviseMethod = typeof(IConnectionPoint).GetMethod( "Advise" );
- Debug.Assert(CPAdviseMethod != null, "Unable to find the method ConnectionPoint.Advise");
-
- // Retrieve the ArrayList.Add method.
- aParamTypes = new Type[1];
- aParamTypes[0] = typeof(Object);
- MethodInfo ArrayListAddMethod = typeof(ArrayList).GetMethod( "Add", aParamTypes, null );
- Debug.Assert(ArrayListAddMethod != null, "Unable to find the method ArrayList.Add");
-
- // Retrieve the Monitor.Enter() method.
- MethodInfo MonitorEnterMethod = typeof(Monitor).GetMethod( "Enter", MonitorEnterParamTypes, null );
- Debug.Assert(MonitorEnterMethod != null, "Unable to find the method Monitor.Enter()");
-
- // Retrieve the Monitor.Exit() method.
- aParamTypes[0] = typeof(Object);
- MethodInfo MonitorExitMethod = typeof(Monitor).GetMethod( "Exit", aParamTypes, null );
- Debug.Assert(MonitorExitMethod != null, "Unable to find the method Monitor.Exit()");
-
- // Define the add_XXX method.
- Type[] parameterTypes;
- parameterTypes = new Type[1];
- parameterTypes[0] = DelegateField.FieldType;
- MethodBuilder Meth = OutputTypeBuilder.DefineMethod(
- "add_" + SrcItfMethod.Name,
- MethodAttributes.Public | MethodAttributes.Virtual,
- null,
- parameterTypes );
-
- ILGenerator il = Meth.GetILGenerator();
-
- // Define a label for the m_IFooEventsCP comparision.
- Label EventCPNonNullLabel = il.DefineLabel();
-
- // Declare the local variables.
- LocalBuilder ltSinkHelper = il.DeclareLocal( SinkHelperClass );
- LocalBuilder ltCookie = il.DeclareLocal( typeof(Int32) );
- LocalBuilder ltLockTaken = il.DeclareLocal( typeof(bool) );
-
- // Generate the following code:
- // try {
- il.BeginExceptionBlock();
-
- // Generate the following code:
- // Monitor.Enter(this, ref lockTaken);
- il.Emit(OpCodes.Ldarg, (short)0);
- il.Emit(OpCodes.Ldloca_S, ltLockTaken);
- il.Emit(OpCodes.Call, MonitorEnterMethod);
-
- // Generate the following code:
- // if ( m_IFooEventsCP != null ) goto EventCPNonNullLabel;
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbEventCP );
- il.Emit( OpCodes.Brtrue, EventCPNonNullLabel );
-
- // Generate the following code:
- // InitIFooEvents();
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Call, mbInitSrcItf );
-
- // Mark this as label to jump to if the CP is not null.
- il.MarkLabel( EventCPNonNullLabel );
-
- // Generate the following code:
- // IFooEvents_SinkHelper SinkHelper = new IFooEvents_SinkHelper;
- il.Emit( OpCodes.Newobj, SinkHelperCons );
- il.Emit( OpCodes.Stloc, ltSinkHelper );
-
- // Generate the following code:
- // dwCookie = 0;
- il.Emit( OpCodes.Ldc_I4_0 );
- il.Emit( OpCodes.Stloc, ltCookie );
-
- // Generate the following code:
- // m_IFooEventsCP.Advise( SinkHelper, dwCookie );
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbEventCP );
- il.Emit( OpCodes.Ldloc, ltSinkHelper );
- il.Emit( OpCodes.Castclass, typeof(Object) );
- il.Emit( OpCodes.Ldloca, ltCookie );
- il.Emit( OpCodes.Callvirt, CPAdviseMethod );
-
- // Generate the following code:
- // SinkHelper.m_dwCookie = dwCookie;
- il.Emit( OpCodes.Ldloc, ltSinkHelper );
- il.Emit( OpCodes.Ldloc, ltCookie );
- il.Emit( OpCodes.Stfld, CookieField );
-
- // Generate the following code:
- // SinkHelper.m_FooDelegate = d;
- il.Emit( OpCodes.Ldloc, ltSinkHelper );
- il.Emit( OpCodes.Ldarg, (short)1 );
- il.Emit( OpCodes.Stfld, DelegateField );
-
- // Generate the following code:
- // m_aIFooEventsHelpers.Add( SinkHelper );
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbSinkHelperArray );
- il.Emit( OpCodes.Ldloc, ltSinkHelper );
- il.Emit( OpCodes.Castclass, typeof(Object) );
- il.Emit( OpCodes.Callvirt, ArrayListAddMethod );
- il.Emit( OpCodes.Pop );
-
- // Generate the following code:
- // } finally {
- il.BeginFinallyBlock();
-
- // Generate the following code:
- // if (lockTaken)
- // Monitor.Exit(this);
- Label skipExit = il.DefineLabel();
- il.Emit( OpCodes.Ldloc, ltLockTaken );
- il.Emit( OpCodes.Brfalse_S, skipExit );
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Call, MonitorExitMethod );
- il.MarkLabel(skipExit);
-
- // Generate the following code:
- // }
- il.EndExceptionBlock();
-
- // Generate the return opcode.
- il.Emit( OpCodes.Ret );
-
- return Meth;
- }
-
- private MethodBuilder DefineRemoveEventMethod( TypeBuilder OutputTypeBuilder, MethodInfo SrcItfMethod, Type SinkHelperClass, FieldBuilder fbSinkHelperArray, FieldBuilder fbEventCP )
- {
- Type[] aParamTypes;
-
- // Find the delegate on the event sink helper.
- FieldInfo DelegateField = SinkHelperClass.GetField( "m_" + SrcItfMethod.Name + "Delegate" );
- Debug.Assert(DelegateField != null, "Unable to find the field m_" + SrcItfMethod.Name + "Delegate on the sink helper");
-
- // Find the cookie on the event sink helper.
- FieldInfo CookieField = SinkHelperClass.GetField( "m_dwCookie" );
- Debug.Assert(CookieField != null, "Unable to find the field m_dwCookie on the sink helper");
-
- // Retrieve the ArrayList.RemoveAt method.
- aParamTypes = new Type[1];
- aParamTypes[0] = typeof(Int32);
- MethodInfo ArrayListRemoveMethod = typeof(ArrayList).GetMethod( "RemoveAt", aParamTypes, null );
- Debug.Assert(ArrayListRemoveMethod != null, "Unable to find the method ArrayList.RemoveAt()");
-
- // Retrieve the ArrayList.Item property get method.
- PropertyInfo ArrayListItemProperty = typeof(ArrayList).GetProperty( "Item" );
- Debug.Assert(ArrayListItemProperty != null, "Unable to find the property ArrayList.Item");
- MethodInfo ArrayListItemGetMethod = ArrayListItemProperty.GetGetMethod();
- Debug.Assert(ArrayListItemGetMethod != null, "Unable to find the get method for property ArrayList.Item");
-
- // Retrieve the ArrayList.Count property get method.
- PropertyInfo ArrayListSizeProperty = typeof(ArrayList).GetProperty( "Count" );
- Debug.Assert(ArrayListSizeProperty != null, "Unable to find the property ArrayList.Count");
- MethodInfo ArrayListSizeGetMethod = ArrayListSizeProperty.GetGetMethod();
- Debug.Assert(ArrayListSizeGetMethod != null, "Unable to find the get method for property ArrayList.Count");
-
- // Retrieve the Delegate.Equals() method.
- aParamTypes[0] = typeof(Delegate);
- MethodInfo DelegateEqualsMethod = typeof(Delegate).GetMethod( "Equals", aParamTypes, null );
- Debug.Assert(DelegateEqualsMethod != null, "Unable to find the method Delegate.Equlals()");
-
- // Retrieve the Monitor.Enter() method.
- MethodInfo MonitorEnterMethod = typeof(Monitor).GetMethod("Enter", MonitorEnterParamTypes, null);
- Debug.Assert(MonitorEnterMethod != null, "Unable to find the method Monitor.Enter()");
-
- // Retrieve the Monitor.Exit() method.
- aParamTypes[0] = typeof(Object);
- MethodInfo MonitorExitMethod = typeof(Monitor).GetMethod( "Exit", aParamTypes, null );
- Debug.Assert(MonitorExitMethod != null, "Unable to find the method Monitor.Exit()");
-
- // Retrieve the ConnectionPoint.Unadvise() method.
- MethodInfo CPUnadviseMethod = typeof(IConnectionPoint).GetMethod( "Unadvise" );
- Debug.Assert(CPUnadviseMethod != null, "Unable to find the method ConnectionPoint.Unadvise()");
-
- // Retrieve the Marshal.ReleaseComObject() method.
- MethodInfo ReleaseComObjectMethod = typeof(Marshal).GetMethod( "ReleaseComObject" );
- Debug.Assert(ReleaseComObjectMethod != null, "Unable to find the method Marshal.ReleaseComObject()");
-
- // Define the remove_XXX method.
- Type[] parameterTypes;
- parameterTypes = new Type[1];
- parameterTypes[0] = DelegateField.FieldType;
- MethodBuilder Meth = OutputTypeBuilder.DefineMethod(
- "remove_" + SrcItfMethod.Name,
- MethodAttributes.Public | MethodAttributes.Virtual,
- null,
- parameterTypes );
-
- ILGenerator il = Meth.GetILGenerator();
-
- // Declare the local variables.
- LocalBuilder ltNumSinkHelpers = il.DeclareLocal( typeof(Int32) );
- LocalBuilder ltSinkHelperCounter = il.DeclareLocal( typeof(Int32) );
- LocalBuilder ltCurrSinkHelper = il.DeclareLocal( SinkHelperClass );
- LocalBuilder ltLockTaken = il.DeclareLocal(typeof(bool));
-
- // Generate the labels for the for loop.
- Label ForBeginLabel = il.DefineLabel();
- Label ForEndLabel = il.DefineLabel();
- Label FalseIfLabel = il.DefineLabel();
- Label MonitorExitLabel = il.DefineLabel();
-
- // Generate the following code:
- // try {
- il.BeginExceptionBlock();
-
- // Generate the following code:
- // Monitor.Enter(this, ref lockTaken);
- il.Emit(OpCodes.Ldarg, (short)0);
- il.Emit(OpCodes.Ldloca_S, ltLockTaken);
- il.Emit(OpCodes.Call, MonitorEnterMethod);
-
- // Generate the following code:
- // if ( m_aIFooEventsHelpers == null ) goto ForEndLabel;
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbSinkHelperArray );
- il.Emit( OpCodes.Brfalse, ForEndLabel );
-
- // Generate the following code:
- // int NumEventHelpers = m_aIFooEventsHelpers.Count;
- // int cEventHelpers = 0;
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbSinkHelperArray );
- il.Emit( OpCodes.Callvirt, ArrayListSizeGetMethod );
- il.Emit( OpCodes.Stloc, ltNumSinkHelpers );
- il.Emit( OpCodes.Ldc_I4, 0 );
- il.Emit( OpCodes.Stloc, ltSinkHelperCounter );
-
- // Generate the following code:
- // if ( 0 >= NumEventHelpers ) goto ForEndLabel;
- il.Emit( OpCodes.Ldc_I4, 0 );
- il.Emit( OpCodes.Ldloc, ltNumSinkHelpers );
- il.Emit( OpCodes.Bge, ForEndLabel );
-
- // Mark this as the beginning of the for loop's body.
- il.MarkLabel( ForBeginLabel );
-
- // Generate the following code:
- // CurrentHelper = (IFooEvents_SinkHelper)m_aIFooEventsHelpers.Get( cEventHelpers );
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbSinkHelperArray );
- il.Emit( OpCodes.Ldloc, ltSinkHelperCounter );
- il.Emit( OpCodes.Callvirt, ArrayListItemGetMethod );
- il.Emit( OpCodes.Castclass, SinkHelperClass );
- il.Emit( OpCodes.Stloc, ltCurrSinkHelper );
-
- // Generate the following code:
- // if ( CurrentHelper.m_FooDelegate )
- il.Emit( OpCodes.Ldloc, ltCurrSinkHelper );
- il.Emit( OpCodes.Ldfld, DelegateField );
- il.Emit( OpCodes.Ldnull );
- il.Emit( OpCodes.Beq, FalseIfLabel );
-
- // Generate the following code:
- // if ( CurrentHelper.m_FooDelegate.Equals( d ) )
- il.Emit( OpCodes.Ldloc, ltCurrSinkHelper );
- il.Emit( OpCodes.Ldfld, DelegateField );
- il.Emit( OpCodes.Ldarg, (short)1 );
- il.Emit( OpCodes.Castclass, typeof(Object) );
- il.Emit( OpCodes.Callvirt, DelegateEqualsMethod );
- il.Emit( OpCodes.Ldc_I4, 0xff );
- il.Emit( OpCodes.And );
- il.Emit( OpCodes.Ldc_I4, 0 );
- il.Emit( OpCodes.Beq, FalseIfLabel );
-
- // Generate the following code:
- // m_aIFooEventsHelpers.RemoveAt( cEventHelpers );
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbSinkHelperArray );
- il.Emit( OpCodes.Ldloc, ltSinkHelperCounter );
- il.Emit( OpCodes.Callvirt, ArrayListRemoveMethod );
-
- // Generate the following code:
- // m_IFooEventsCP.Unadvise( CurrentHelper.m_dwCookie );
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbEventCP );
- il.Emit( OpCodes.Ldloc, ltCurrSinkHelper );
- il.Emit( OpCodes.Ldfld, CookieField );
- il.Emit( OpCodes.Callvirt, CPUnadviseMethod );
-
- // Generate the following code:
- // if ( NumEventHelpers > 1) break;
- il.Emit( OpCodes.Ldloc, ltNumSinkHelpers );
- il.Emit( OpCodes.Ldc_I4, 1 );
- il.Emit( OpCodes.Bgt, ForEndLabel );
-
- // Generate the following code:
- // Marshal.ReleaseComObject(m_IFooEventsCP);
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbEventCP );
- il.Emit( OpCodes.Call, ReleaseComObjectMethod );
- il.Emit( OpCodes.Pop );
-
- // Generate the following code:
- // m_IFooEventsCP = null;
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldnull );
- il.Emit( OpCodes.Stfld, fbEventCP );
-
- // Generate the following code:
- // m_aIFooEventsHelpers = null;
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldnull );
- il.Emit( OpCodes.Stfld, fbSinkHelperArray );
-
- // Generate the following code:
- // break;
- il.Emit( OpCodes.Br, ForEndLabel );
-
- // Mark this as the label to jump to when the if statement is false.
- il.MarkLabel( FalseIfLabel );
-
- // Generate the following code:
- // cEventHelpers++;
- il.Emit( OpCodes.Ldloc, ltSinkHelperCounter );
- il.Emit( OpCodes.Ldc_I4, 1 );
- il.Emit( OpCodes.Add );
- il.Emit( OpCodes.Stloc, ltSinkHelperCounter );
-
- // Generate the following code:
- // if ( cEventHelpers < NumEventHelpers ) goto ForBeginLabel;
- il.Emit( OpCodes.Ldloc, ltSinkHelperCounter );
- il.Emit( OpCodes.Ldloc, ltNumSinkHelpers );
- il.Emit( OpCodes.Blt, ForBeginLabel );
-
- // Mark this as the end of the for loop's body.
- il.MarkLabel( ForEndLabel );
-
- // Generate the following code:
- // } finally {
- il.BeginFinallyBlock();
-
- // Generate the following code:
- // if (lockTaken)
- // Monitor.Exit(this);
- Label skipExit = il.DefineLabel();
- il.Emit(OpCodes.Ldloc, ltLockTaken);
- il.Emit(OpCodes.Brfalse_S, skipExit);
- il.Emit(OpCodes.Ldarg, (short)0);
- il.Emit(OpCodes.Call, MonitorExitMethod);
- il.MarkLabel(skipExit);
-
- // Generate the following code:
- // }
- il.EndExceptionBlock();
-
- // Generate the return opcode.
- il.Emit( OpCodes.Ret );
-
- return Meth;
- }
-
- private MethodBuilder DefineInitSrcItfMethod( TypeBuilder OutputTypeBuilder, Type SourceInterface, FieldBuilder fbSinkHelperArray, FieldBuilder fbEventCP, FieldBuilder fbCPC )
- {
- // Retrieve the constructor info for the array list's default constructor.
- ConstructorInfo DefaultArrayListCons = typeof(ArrayList).GetConstructor(EventProviderWriter.DefaultLookup, null, Array.Empty<Type>(), null );
- Debug.Assert(DefaultArrayListCons != null, "Unable to find the constructor for class ArrayList");
-
- // Temp byte array for Guid
- ubyte[] rgByteGuid = new ubyte[16];
-
- // Retrieve the constructor info for the Guid constructor.
- Type[] aParamTypes = new Type[1];
- aParamTypes[0] = typeof(Byte[]);
- ConstructorInfo ByteArrayGUIDCons = typeof(Guid).GetConstructor(EventProviderWriter.DefaultLookup, null, aParamTypes, null );
- Debug.Assert(ByteArrayGUIDCons != null, "Unable to find the constructor for GUID that accepts a string as argument");
-
- // Retrieve the IConnectionPointContainer.FindConnectionPoint() method.
- MethodInfo CPCFindCPMethod = typeof(IConnectionPointContainer).GetMethod( "FindConnectionPoint" );
- Debug.Assert(CPCFindCPMethod != null, "Unable to find the method ConnectionPointContainer.FindConnectionPoint()");
-
- // Define the Init method itself.
- MethodBuilder Meth = OutputTypeBuilder.DefineMethod(
- "Init",
- MethodAttributes.Private,
- null,
- null );
-
- ILGenerator il = Meth.GetILGenerator();
-
- // Declare the local variables.
- LocalBuilder ltCP = il.DeclareLocal( typeof(IConnectionPoint) );
- LocalBuilder ltEvGuid = il.DeclareLocal( typeof(Guid) );
- LocalBuilder ltByteArrayGuid = il.DeclareLocal( typeof(Byte[]) );
-
- // Generate the following code:
- // IConnectionPoint CP = NULL;
- il.Emit( OpCodes.Ldnull );
- il.Emit( OpCodes.Stloc, ltCP );
-
- // Get unsigned byte array for the GUID of the event interface.
- rgByteGuid = SourceInterface.GUID.ToByteArray();
-
- // Generate the following code:
- // ubyte rgByteArray[] = new ubyte [16];
- il.Emit( OpCodes.Ldc_I4, 0x10 );
- il.Emit( OpCodes.Newarr, typeof(Byte) );
- il.Emit( OpCodes.Stloc, ltByteArrayGuid );
-
- // Generate the following code:
- // rgByteArray[i] = rgByteGuid[i];
- for (int i = 0; i < 16; i++ )
- {
- il.Emit( OpCodes.Ldloc, ltByteArrayGuid );
- il.Emit( OpCodes.Ldc_I4, i );
- il.Emit( OpCodes.Ldc_I4, (int) (rgByteGuid[i]) );
- il.Emit( OpCodes.Stelem_I1);
- }
-
- // Generate the following code:
- // EventItfGuid = Guid( ubyte b[] );
- il.Emit( OpCodes.Ldloca, ltEvGuid );
- il.Emit( OpCodes.Ldloc, ltByteArrayGuid );
- il.Emit( OpCodes.Call, ByteArrayGUIDCons );
-
- // Generate the following code:
- // m_ConnectionPointContainer.FindConnectionPoint( EventItfGuid, CP );
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbCPC );
- il.Emit( OpCodes.Ldloca, ltEvGuid );
- il.Emit( OpCodes.Ldloca, ltCP );
- il.Emit( OpCodes.Callvirt, CPCFindCPMethod );
-
- // Generate the following code:
- // m_ConnectionPoint = (IConnectionPoint)CP;
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldloc, ltCP );
- il.Emit( OpCodes.Castclass, typeof(IConnectionPoint) );
- il.Emit( OpCodes.Stfld, fbEventCP );
-
- // Generate the following code:
- // m_aEventSinkHelpers = new ArrayList;
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Newobj, DefaultArrayListCons );
- il.Emit( OpCodes.Stfld, fbSinkHelperArray );
-
- // Generate the return opcode.
- il.Emit( OpCodes.Ret );
-
- return Meth;
- }
-
- private void DefineConstructor( TypeBuilder OutputTypeBuilder, FieldBuilder fbCPC )
- {
- // Retrieve the constructor info for the base class's constructor.
- ConstructorInfo DefaultBaseClsCons = typeof(Object).GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, Array.Empty<Type>(), null );
- Debug.Assert(DefaultBaseClsCons != null, "Unable to find the object's public default constructor");
-
- // Define the default constructor.
- MethodAttributes ctorAttributes = MethodAttributes.SpecialName | (DefaultBaseClsCons.Attributes & MethodAttributes.MemberAccessMask);
- MethodBuilder Cons = OutputTypeBuilder.DefineMethod(
- ".ctor",
- ctorAttributes,
- null,
- new Type[]{typeof(Object)} );
-
- ILGenerator il = Cons.GetILGenerator();
-
- // Generate the call to the base class constructor.
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Call, DefaultBaseClsCons );
-
- // Generate the following code:
- // m_ConnectionPointContainer = (IConnectionPointContainer)EventSource;
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldarg, (short)1 );
- il.Emit( OpCodes.Castclass, typeof(IConnectionPointContainer) );
- il.Emit( OpCodes.Stfld, fbCPC );
-
- // Generate the return opcode.
- il.Emit( OpCodes.Ret );
- }
-
- private MethodBuilder DefineFinalizeMethod( TypeBuilder OutputTypeBuilder, Type SinkHelperClass, FieldBuilder fbSinkHelper, FieldBuilder fbEventCP )
- {
- // Find the cookie on the event sink helper.
- FieldInfo CookieField = SinkHelperClass.GetField( "m_dwCookie" );
- Debug.Assert(CookieField != null, "Unable to find the field m_dwCookie on the sink helper");
-
- // Retrieve the ArrayList.Item property get method.
- PropertyInfo ArrayListItemProperty = typeof(ArrayList).GetProperty( "Item" );
- Debug.Assert(ArrayListItemProperty != null, "Unable to find the property ArrayList.Item");
- MethodInfo ArrayListItemGetMethod = ArrayListItemProperty.GetGetMethod();
- Debug.Assert(ArrayListItemGetMethod != null, "Unable to find the get method for property ArrayList.Item");
-
- // Retrieve the ArrayList.Count property get method.
- PropertyInfo ArrayListSizeProperty = typeof(ArrayList).GetProperty( "Count" );
- Debug.Assert(ArrayListSizeProperty != null, "Unable to find the property ArrayList.Count");
- MethodInfo ArrayListSizeGetMethod = ArrayListSizeProperty.GetGetMethod();
- Debug.Assert(ArrayListSizeGetMethod != null, "Unable to find the get method for property ArrayList.Count");
-
- // Retrieve the ConnectionPoint.Unadvise() method.
- MethodInfo CPUnadviseMethod = typeof(IConnectionPoint).GetMethod( "Unadvise" );
- Debug.Assert(CPUnadviseMethod != null, "Unable to find the method ConnectionPoint.Unadvise()");
-
- // Retrieve the Marshal.ReleaseComObject() method.
- MethodInfo ReleaseComObjectMethod = typeof(Marshal).GetMethod( "ReleaseComObject" );
- Debug.Assert(ReleaseComObjectMethod != null, "Unable to find the method Marshal.ReleaseComObject()");
-
- // Retrieve the Monitor.Enter() method.
- MethodInfo MonitorEnterMethod = typeof(Monitor).GetMethod("Enter", MonitorEnterParamTypes, null);
- Debug.Assert(MonitorEnterMethod != null, "Unable to find the method Monitor.Enter()");
-
- // Retrieve the Monitor.Exit() method.
- Type[] aParamTypes = new Type[1];
- aParamTypes[0] = typeof(Object);
- MethodInfo MonitorExitMethod = typeof(Monitor).GetMethod( "Exit", aParamTypes, null );
- Debug.Assert(MonitorExitMethod != null, "Unable to find the method Monitor.Exit()");
-
- // Define the Finalize method itself.
- MethodBuilder Meth = OutputTypeBuilder.DefineMethod( "Finalize", MethodAttributes.Public | MethodAttributes.Virtual, null, null );
-
- ILGenerator il = Meth.GetILGenerator();
-
- // Declare the local variables.
- LocalBuilder ltNumSinkHelpers = il.DeclareLocal( typeof(Int32) );
- LocalBuilder ltSinkHelperCounter = il.DeclareLocal( typeof(Int32) );
- LocalBuilder ltCurrSinkHelper = il.DeclareLocal( SinkHelperClass );
- LocalBuilder ltLockTaken = il.DeclareLocal(typeof(bool));
-
- // Generate the following code:
- // try {
- il.BeginExceptionBlock();
-
- // Generate the following code:
- // Monitor.Enter(this, ref lockTaken);
- il.Emit(OpCodes.Ldarg, (short)0);
- il.Emit(OpCodes.Ldloca_S, ltLockTaken);
- il.Emit(OpCodes.Call, MonitorEnterMethod);
-
- // Generate the labels.
- Label ForBeginLabel = il.DefineLabel();
- Label ReleaseComObjectLabel = il.DefineLabel();
- Label AfterReleaseComObjectLabel = il.DefineLabel();
-
- // Generate the following code:
- // if ( m_IFooEventsCP == null ) goto AfterReleaseComObjectLabel;
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbEventCP );
- il.Emit( OpCodes.Brfalse, AfterReleaseComObjectLabel );
-
- // Generate the following code:
- // int NumEventHelpers = m_aIFooEventsHelpers.Count;
- // int cEventHelpers = 0;
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbSinkHelper );
- il.Emit( OpCodes.Callvirt, ArrayListSizeGetMethod );
- il.Emit( OpCodes.Stloc, ltNumSinkHelpers );
- il.Emit( OpCodes.Ldc_I4, 0 );
- il.Emit( OpCodes.Stloc, ltSinkHelperCounter );
-
- // Generate the following code:
- // if ( 0 >= NumEventHelpers ) goto ReleaseComObjectLabel;
- il.Emit( OpCodes.Ldc_I4, 0 );
- il.Emit( OpCodes.Ldloc, ltNumSinkHelpers );
- il.Emit( OpCodes.Bge, ReleaseComObjectLabel );
-
- // Mark this as the beginning of the for loop's body.
- il.MarkLabel( ForBeginLabel );
-
- // Generate the following code:
- // CurrentHelper = (IFooEvents_SinkHelper)m_aIFooEventsHelpers.Get( cEventHelpers );
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbSinkHelper );
- il.Emit( OpCodes.Ldloc, ltSinkHelperCounter );
- il.Emit( OpCodes.Callvirt, ArrayListItemGetMethod );
- il.Emit( OpCodes.Castclass, SinkHelperClass );
- il.Emit( OpCodes.Stloc, ltCurrSinkHelper );
-
- // Generate the following code:
- // m_IFooEventsCP.Unadvise( CurrentHelper.m_dwCookie );
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbEventCP );
- il.Emit( OpCodes.Ldloc, ltCurrSinkHelper );
- il.Emit( OpCodes.Ldfld, CookieField );
- il.Emit( OpCodes.Callvirt, CPUnadviseMethod );
-
- // Generate the following code:
- // cEventHelpers++;
- il.Emit( OpCodes.Ldloc, ltSinkHelperCounter );
- il.Emit( OpCodes.Ldc_I4, 1 );
- il.Emit( OpCodes.Add );
- il.Emit( OpCodes.Stloc, ltSinkHelperCounter );
-
- // Generate the following code:
- // if ( cEventHelpers < NumEventHelpers ) goto ForBeginLabel;
- il.Emit( OpCodes.Ldloc, ltSinkHelperCounter );
- il.Emit( OpCodes.Ldloc, ltNumSinkHelpers );
- il.Emit( OpCodes.Blt, ForBeginLabel );
-
- // Mark this as the end of the for loop's body.
- il.MarkLabel( ReleaseComObjectLabel );
-
- // Generate the following code:
- // Marshal.ReleaseComObject(m_IFooEventsCP);
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbEventCP );
- il.Emit( OpCodes.Call, ReleaseComObjectMethod );
- il.Emit( OpCodes.Pop );
-
- // Mark this as the end of the for loop's body.
- il.MarkLabel( AfterReleaseComObjectLabel );
-
- // Generate the following code:
- // } catch {
- il.BeginCatchBlock(typeof(System.Exception));
- il.Emit( OpCodes.Pop );
-
- // Generate the following code:
- // } finally {
- il.BeginFinallyBlock();
-
- // Generate the following code:
- // if (lockTaken)
- // Monitor.Exit(this);
- Label skipExit = il.DefineLabel();
- il.Emit(OpCodes.Ldloc, ltLockTaken);
- il.Emit(OpCodes.Brfalse_S, skipExit);
- il.Emit(OpCodes.Ldarg, (short)0);
- il.Emit(OpCodes.Call, MonitorExitMethod);
- il.MarkLabel(skipExit);
-
- // Generate the following code:
- // }
- il.EndExceptionBlock();
-
- // Generate the return opcode.
- il.Emit( OpCodes.Ret );
-
- return Meth;
- }
-
- private void DefineDisposeMethod( TypeBuilder OutputTypeBuilder, MethodBuilder FinalizeMethod )
- {
- // Retrieve the method info for GC.SuppressFinalize().
- MethodInfo SuppressFinalizeMethod = typeof(GC).GetMethod("SuppressFinalize");
- Debug.Assert(SuppressFinalizeMethod != null, "Unable to find the GC.SuppressFinalize");
-
- // Define the Finalize method itself.
- MethodBuilder Meth = OutputTypeBuilder.DefineMethod( "Dispose", MethodAttributes.Public | MethodAttributes.Virtual, null, null );
-
- ILGenerator il = Meth.GetILGenerator();
-
- // Generate the following code:
- // Finalize()
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Callvirt, FinalizeMethod );
-
- // Generate the following code:
- // GC.SuppressFinalize()
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Call, SuppressFinalizeMethod );
-
- // Generate the return opcode.
- il.Emit( OpCodes.Ret );
- }
-
- private ModuleBuilder m_OutputModule;
- private String m_strDestTypeName;
- private Type m_EventItfType;
- private Type m_SrcItfType;
- private Type m_SinkHelperType;
- }
-}
diff --git a/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventSinkHelperWriter.cs b/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventSinkHelperWriter.cs
deleted file mode 100644
index 862419cc98..0000000000
--- a/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventSinkHelperWriter.cs
+++ /dev/null
@@ -1,298 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace System.Runtime.InteropServices.TCEAdapterGen {
- using System.Runtime.InteropServices;
- using System;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.Collections;
- using System.Diagnostics;
- using System.Diagnostics.Contracts;
- internal class EventSinkHelperWriter
- {
- public static readonly String GeneratedTypeNamePostfix = "_SinkHelper";
-
- public EventSinkHelperWriter( ModuleBuilder OutputModule, Type InputType, Type EventItfType )
- {
- m_InputType = InputType;
- m_OutputModule = OutputModule;
- m_EventItfType = EventItfType;
- }
-
- public Type Perform()
- {
- // Create the output Type.
- Type[] aInterfaces = new Type[1];
- aInterfaces[0] = m_InputType;
- String strFullName = null;
- String strNameSpace = NameSpaceExtractor.ExtractNameSpace( m_EventItfType.FullName );
-
- if (strNameSpace != "")
- strFullName = strNameSpace + ".";
-
- strFullName += m_InputType.Name + GeneratedTypeNamePostfix;
- TypeBuilder OutputTypeBuilder = TCEAdapterGenerator.DefineUniqueType(
- strFullName,
- TypeAttributes.Sealed | TypeAttributes.Public,
- null,
- aInterfaces,
- m_OutputModule
- );
- // Hide the _SinkProvider interface
- TCEAdapterGenerator.SetHiddenAttribute(OutputTypeBuilder);
-
- // Set the class interface to none.
- TCEAdapterGenerator.SetClassInterfaceTypeToNone(OutputTypeBuilder);
-
- // Retrieve the property methods on the input interface and give them a dummy implementation.
- MethodInfo[] pMethods = TCEAdapterGenerator.GetPropertyMethods(m_InputType);
- foreach (MethodInfo method in pMethods)
- {
- DefineBlankMethod(OutputTypeBuilder, method);
- }
-
- // Retrieve the non-property methods on the input interface.
- MethodInfo[] aMethods = TCEAdapterGenerator.GetNonPropertyMethods(m_InputType);
-
- // Allocate an array to contain the delegate fields.
- FieldBuilder[] afbDelegates = new FieldBuilder[aMethods.Length];
- // Process all the methods on the input interface.
- for ( int cMethods = 0; cMethods < aMethods.Length; cMethods++ )
- {
- if ( m_InputType == aMethods[cMethods].DeclaringType )
- {
- // Retrieve the delegate type from the add_XXX method.
- MethodInfo AddMeth = m_EventItfType.GetMethod( "add_" + aMethods[cMethods].Name );
- ParameterInfo[] aParams = AddMeth.GetParameters();
- Debug.Assert(aParams.Length == 1, "All event interface methods must take a single delegate derived type and have a void return type");
- Type DelegateCls = aParams[0].ParameterType;
-
- // Define the delegate instance field.
- afbDelegates[cMethods] = OutputTypeBuilder.DefineField(
- "m_" + aMethods[cMethods].Name + "Delegate",
- DelegateCls,
- FieldAttributes.Public
- );
-
- // Define the event method itself.
- DefineEventMethod( OutputTypeBuilder, aMethods[cMethods], DelegateCls, afbDelegates[cMethods] );
- }
- }
-
- // Create the cookie field.
- FieldBuilder fbCookie = OutputTypeBuilder.DefineField(
- "m_dwCookie",
- typeof(Int32),
- FieldAttributes.Public
- );
-
- // Define the constructor.
- DefineConstructor( OutputTypeBuilder, fbCookie, afbDelegates );
-
- return OutputTypeBuilder.CreateType();
- }
-
- private void DefineBlankMethod(TypeBuilder OutputTypeBuilder, MethodInfo Method)
- {
- ParameterInfo[] PIs = Method.GetParameters();
- Type[] parameters = new Type[PIs.Length];
- for (int i=0; i < PIs.Length; i++)
- {
- parameters[i] = PIs[i].ParameterType;
- }
-
- MethodBuilder Meth = OutputTypeBuilder.DefineMethod(Method.Name,
- Method.Attributes & ~MethodAttributes.Abstract,
- Method.CallingConvention,
- Method.ReturnType,
- parameters);
-
- ILGenerator il = Meth.GetILGenerator();
-
- AddReturn(Method.ReturnType, il, Meth);
-
- il.Emit(OpCodes.Ret);
- }
-
- private void DefineEventMethod( TypeBuilder OutputTypeBuilder, MethodInfo Method, Type DelegateCls, FieldBuilder fbDelegate )
- {
- // Retrieve the method info for the invoke method on the delegate.
- MethodInfo DelegateInvokeMethod = DelegateCls.GetMethod( "Invoke" );
- Debug.Assert(DelegateInvokeMethod != null, "Unable to find method Delegate.Invoke()");
-
- // Retrieve the return type.
- Type ReturnType = Method.ReturnType;
-
- // Define the actual event method.
- ParameterInfo[] paramInfos = Method.GetParameters();
- Type[] parameterTypes;
- if (paramInfos != null)
- {
- parameterTypes = new Type[paramInfos.Length];
- for (int i = 0; i < paramInfos.Length; i++)
- {
- parameterTypes[i] = paramInfos[i].ParameterType;
- }
- }
- else
- parameterTypes = null;
-
- MethodAttributes attr = MethodAttributes.Public | MethodAttributes.Virtual;
- MethodBuilder Meth = OutputTypeBuilder.DefineMethod( Method.Name,
- attr,
- CallingConventions.Standard,
- ReturnType,
- parameterTypes);
-
- // We explicitly do not specify parameter name and attributes since this Type
- // is not meant to be exposed to the user. It is only used internally to do the
- // connection point to TCE mapping.
-
- ILGenerator il = Meth.GetILGenerator();
-
- // Create the exit branch.
- Label ExitLabel = il.DefineLabel();
-
- // Generate the code that verifies that the delegate is not null.
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbDelegate );
- il.Emit( OpCodes.Brfalse, ExitLabel );
-
- // The delegate is not NULL so we need to invoke it.
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldfld, fbDelegate );
-
- // Generate the code to load the arguments before we call invoke.
- ParameterInfo[] aParams = Method.GetParameters();
- for ( int cParams = 0; cParams < aParams.Length; cParams++ )
- {
- il.Emit( OpCodes.Ldarg, (short)(cParams + 1) );
- }
-
- // Generate a tail call to invoke. This will cause the callvirt to return
- // directly to the caller of the current method instead of actually coming
- // back to the current method and returning. This will cause the value returned
- // from the call to the COM server to be returned to the caller of this method.
-
- il.Emit( OpCodes.Callvirt, DelegateInvokeMethod );
- il.Emit( OpCodes.Ret );
-
- // This is the label that will be jumped to if no delegate is present.
- il.MarkLabel( ExitLabel );
-
- AddReturn(ReturnType, il, Meth);
-
- il.Emit( OpCodes.Ret );
-
- }
-
- private void AddReturn(Type ReturnType, ILGenerator il, MethodBuilder Meth)
- {
- // Place a dummy return value on the stack before we return.
- if ( ReturnType == typeof(void) )
- {
- // There is nothing to place on the stack.
- }
- else if ( ReturnType.IsPrimitive )
- {
- switch (System.Type.GetTypeCode(ReturnType))
- {
- case TypeCode.Boolean:
- case TypeCode.Char:
- case TypeCode.Byte:
- case TypeCode.SByte:
- case TypeCode.Int16:
- case TypeCode.UInt16:
- case TypeCode.Int32:
- case TypeCode.UInt32:
- il.Emit( OpCodes.Ldc_I4_0 );
- break;
-
- case TypeCode.Int64:
- case TypeCode.UInt64:
- il.Emit( OpCodes.Ldc_I4_0 );
- il.Emit( OpCodes.Conv_I8 );
- break;
-
- case TypeCode.Single:
- il.Emit( OpCodes.Ldc_R4, 0 );
- break;
-
- case TypeCode.Double:
- il.Emit( OpCodes.Ldc_R4, 0 );
- il.Emit( OpCodes.Conv_R8 );
- break;
-
- default:
- // "TypeCode" does not include IntPtr, so special case it.
- if ( ReturnType == typeof(IntPtr) )
- il.Emit( OpCodes.Ldc_I4_0 );
- else
- Debug.Assert(false, "Unexpected type for Primitive type.");
- break;
- }
- }
- else if ( ReturnType.IsValueType )
- {
- // Allocate stack space for the return value type. Zero-init.
- Meth.InitLocals = true;
- LocalBuilder ltRetVal = il.DeclareLocal( ReturnType );
-
- // Load the value class on the stack.
- il.Emit( OpCodes.Ldloc_S, ltRetVal );
-
- }
- else
- {
- // The return type is a normal type.
- il.Emit( OpCodes.Ldnull );
- }
- }
-
- private void DefineConstructor( TypeBuilder OutputTypeBuilder, FieldBuilder fbCookie, FieldBuilder[] afbDelegates )
- {
- // Retrieve the constructor info for the base classe's constructor.
- ConstructorInfo DefaultBaseClsCons = typeof(Object).GetConstructor(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public, null, Array.Empty<Type>(), null );
- Debug.Assert(DefaultBaseClsCons != null, "Unable to find the constructor for class " + m_InputType.Name);
-
- // Define the default constructor.
- MethodBuilder Cons = OutputTypeBuilder.DefineMethod( ".ctor",
- MethodAttributes.Assembly | MethodAttributes.SpecialName,
- CallingConventions.Standard,
- null,
- null);
-
- ILGenerator il = Cons.GetILGenerator();
-
- // Generate the code to call the constructor of the base class.
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Call, DefaultBaseClsCons );
-
- // Generate the code to set the cookie field to 0.
- il.Emit( OpCodes.Ldarg, (short)0 );
- il.Emit( OpCodes.Ldc_I4, 0 );
- il.Emit( OpCodes.Stfld, fbCookie );
-
- // Generate the code to set all the delegates to NULL.
- for ( int cDelegates = 0; cDelegates < afbDelegates.Length; cDelegates++ )
- {
- if (afbDelegates[cDelegates] != null)
- {
- il.Emit( OpCodes.Ldarg,(short)0 );
- il.Emit( OpCodes.Ldnull );
- il.Emit( OpCodes.Stfld, afbDelegates[cDelegates] );
- }
- }
-
- // Emit the return opcode.
- il.Emit( OpCodes.Ret );
-
- }
-
- private Type m_InputType;
- private Type m_EventItfType;
- private ModuleBuilder m_OutputModule;
- }
-}
diff --git a/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/NameSpaceExtractor.cs b/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/NameSpaceExtractor.cs
deleted file mode 100644
index 8018ad4c66..0000000000
--- a/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/NameSpaceExtractor.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace System.Runtime.InteropServices.TCEAdapterGen {
-
- using System;
- internal static class NameSpaceExtractor
- {
- private static char NameSpaceSeperator = '.';
-
- public static String ExtractNameSpace(String FullyQualifiedTypeName)
- {
- int TypeNameStartPos = FullyQualifiedTypeName.LastIndexOf(NameSpaceSeperator);
- if (TypeNameStartPos == -1)
- return "";
- else
- return FullyQualifiedTypeName.Substring(0, TypeNameStartPos);
- }
- }
-}
diff --git a/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/TCEAdapterGenerator.cs b/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/TCEAdapterGenerator.cs
deleted file mode 100644
index c6e4415246..0000000000
--- a/src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/TCEAdapterGenerator.cs
+++ /dev/null
@@ -1,141 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace System.Runtime.InteropServices.TCEAdapterGen {
- using System.Runtime.InteropServices;
- using System;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.Collections;
- using System.Threading;
-
- internal class TCEAdapterGenerator
- {
- public void Process(ModuleBuilder ModBldr, ArrayList EventItfList)
- {
- // Store the input/output module.
- m_Module = ModBldr;
-
- // Generate the TCE adapters for all the event sources.
- int NumEvItfs = EventItfList.Count;
- for ( int cEventItfs = 0; cEventItfs < NumEvItfs; cEventItfs++ )
- {
- // Retrieve the event interface info.
- EventItfInfo CurrEventItf = (EventItfInfo)EventItfList[cEventItfs];
-
- // Retrieve the information from the event interface info.
- Type EventItfType = CurrEventItf.GetEventItfType();
- Type SrcItfType = CurrEventItf.GetSrcItfType();
- String EventProviderName = CurrEventItf.GetEventProviderName();
-
- // Generate the sink interface helper.
- Type SinkHelperType = new EventSinkHelperWriter( m_Module, SrcItfType, EventItfType ).Perform();
-
- // Generate the event provider.
- new EventProviderWriter( m_Module, EventProviderName, EventItfType, SrcItfType, SinkHelperType ).Perform();
- }
- }
-
- internal static void SetClassInterfaceTypeToNone(TypeBuilder tb)
- {
- // Create the ClassInterface(ClassInterfaceType.None) CA builder if we haven't created it yet.
- if (s_NoClassItfCABuilder == null)
- {
- Type []aConsParams = new Type[1];
- aConsParams[0] = typeof(ClassInterfaceType);
- ConstructorInfo Cons = typeof(ClassInterfaceAttribute).GetConstructor(aConsParams);
-
- Object[] aArgs = new Object[1];
- aArgs[0] = ClassInterfaceType.None;
- s_NoClassItfCABuilder = new CustomAttributeBuilder(Cons, aArgs);
- }
-
- // Set the class interface type to none.
- tb.SetCustomAttribute(s_NoClassItfCABuilder);
- }
-
- internal static TypeBuilder DefineUniqueType(String strInitFullName, TypeAttributes attrs, Type BaseType, Type[] aInterfaceTypes, ModuleBuilder mb)
- {
- String strFullName = strInitFullName;
- int PostFix = 2;
-
- // Find the first unique name for the type.
- for (; mb.GetType(strFullName) != null; strFullName = strInitFullName + "_" + PostFix, PostFix++);
-
- // Define a type with the determined unique name.
- return mb.DefineType(strFullName, attrs, BaseType, aInterfaceTypes);
- }
-
- internal static void SetHiddenAttribute(TypeBuilder tb)
- {
- if (s_HiddenCABuilder == null)
- {
- // Hide the type from Object Browsers
- Type []aConsParams = new Type[1];
- aConsParams[0] = typeof(TypeLibTypeFlags);
- ConstructorInfo Cons = typeof(TypeLibTypeAttribute).GetConstructor(aConsParams);
-
- Object []aArgs = new Object[1];
- aArgs[0] = TypeLibTypeFlags.FHidden;
- s_HiddenCABuilder = new CustomAttributeBuilder(Cons, aArgs);
- }
-
- tb.SetCustomAttribute(s_HiddenCABuilder);
- }
-
- internal static MethodInfo[] GetNonPropertyMethods(Type type)
- {
- MethodInfo[] aMethods = type.GetMethods();
- ArrayList methods = new ArrayList(aMethods);
-
- PropertyInfo[] props = type.GetProperties();
-
- foreach(PropertyInfo prop in props)
- {
- MethodInfo[] accessors = prop.GetAccessors();
- foreach (MethodInfo accessor in accessors)
- {
- for (int i=0; i < methods.Count; i++)
- {
- if ((MethodInfo)methods[i] == accessor)
- methods.RemoveAt(i);
- }
- }
- }
-
- MethodInfo[] retMethods = new MethodInfo[methods.Count];
- methods.CopyTo(retMethods);
-
- return retMethods;
- }
-
- internal static MethodInfo[] GetPropertyMethods(Type type)
- {
- MethodInfo[] aMethods = type.GetMethods();
- ArrayList methods = new ArrayList();
-
- PropertyInfo[] props = type.GetProperties();
-
- foreach(PropertyInfo prop in props)
- {
- MethodInfo[] accessors = prop.GetAccessors();
- foreach (MethodInfo accessor in accessors)
- {
- methods.Add(accessor);
- }
- }
-
- MethodInfo[] retMethods = new MethodInfo[methods.Count];
- methods.CopyTo(retMethods);
-
- return retMethods;
- }
-
-
- private ModuleBuilder m_Module = null;
- private Hashtable m_SrcItfToSrcItfInfoMap = new Hashtable();
- private static volatile CustomAttributeBuilder s_NoClassItfCABuilder = null;
- private static volatile CustomAttributeBuilder s_HiddenCABuilder = null;
- }
-}