diff options
Diffstat (limited to 'src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs')
-rw-r--r-- | src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs | 111 |
1 files changed, 35 insertions, 76 deletions
diff --git a/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs b/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs index 15dece9fcb..ed0763bfda 100644 --- a/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs +++ b/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs @@ -7,12 +7,12 @@ namespace System.Reflection.Emit { using System; - using TextWriter = System.IO.TextWriter; using System.Diagnostics.SymbolStore; using System.Runtime.InteropServices; using System.Reflection; using System.Security.Permissions; using System.Globalization; + using System.Diagnostics; using System.Diagnostics.Contracts; [ClassInterface(ClassInterfaceType.None)] @@ -210,20 +210,17 @@ namespace System.Reflection.Emit } } - [System.Security.SecurityCritical] // auto-generated private int GetMethodToken(MethodBase method, Type[] optionalParameterTypes, bool useMethodDef) { return ((ModuleBuilder)m_methodBuilder.Module).GetMethodTokenInternal(method, optionalParameterTypes, useMethodDef); } - [System.Security.SecurityCritical] // auto-generated internal virtual SignatureHelper GetMemberRefSignature(CallingConventions call, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes) { return GetMemberRefSignature(call, returnType, parameterTypes, optionalParameterTypes, 0); } - [System.Security.SecurityCritical] // auto-generated private SignatureHelper GetMemberRefSignature(CallingConventions call, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes, int cGenericParameters) { @@ -414,7 +411,7 @@ namespace System.Reflection.Emit { if (m_RelocFixupCount == 0) { - Contract.Assert(m_RelocFixupList == null); + Debug.Assert(m_RelocFixupList == null); return null; } @@ -472,11 +469,10 @@ namespace System.Reflection.Emit PutInteger4(arg); } - [System.Security.SecuritySafeCritical] // auto-generated public virtual void Emit(OpCode opcode, MethodInfo meth) { if (meth == null) - throw new ArgumentNullException("meth"); + throw new ArgumentNullException(nameof(meth)); Contract.EndContractBlock(); if (opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj)) @@ -504,7 +500,6 @@ namespace System.Reflection.Emit } - [System.Security.SecuritySafeCritical] // auto-generated public virtual void EmitCalli(OpCode opcode, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes) { @@ -593,14 +588,13 @@ namespace System.Reflection.Emit PutInteger4(modBuilder.GetSignatureToken(sig).Token); } - [System.Security.SecuritySafeCritical] // auto-generated public virtual void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[] optionalParameterTypes) { if (methodInfo == null) - throw new ArgumentNullException("methodInfo"); + throw new ArgumentNullException(nameof(methodInfo)); if (!(opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj))) - throw new ArgumentException(Environment.GetResourceString("Argument_NotMethodCallOpcode"), "opcode"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotMethodCallOpcode"), nameof(opcode)); Contract.EndContractBlock(); @@ -634,7 +628,7 @@ namespace System.Reflection.Emit public virtual void Emit(OpCode opcode, SignatureHelper signature) { if (signature == null) - throw new ArgumentNullException("signature"); + throw new ArgumentNullException(nameof(signature)); Contract.EndContractBlock(); int stackchange = 0; @@ -653,7 +647,7 @@ namespace System.Reflection.Emit // SignatureHelper. if (opcode.StackBehaviourPop == StackBehaviour.Varpop) { - Contract.Assert(opcode.Equals(OpCodes.Calli), + Debug.Assert(opcode.Equals(OpCodes.Calli), "Unexpected opcode encountered for StackBehaviour VarPop."); // Pop the arguments.. stackchange -= signature.ArgumentCount; @@ -666,12 +660,11 @@ namespace System.Reflection.Emit PutInteger4(tempVal); } - [System.Security.SecuritySafeCritical] // auto-generated [System.Runtime.InteropServices.ComVisible(true)] public virtual void Emit(OpCode opcode, ConstructorInfo con) { if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); Contract.EndContractBlock(); int stackchange = 0; @@ -687,7 +680,7 @@ namespace System.Reflection.Emit if (opcode.StackBehaviourPush == StackBehaviour.Varpush) { // Instruction must be one of call or callvirt. - Contract.Assert(opcode.Equals(OpCodes.Call) || + Debug.Assert(opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt), "Unexpected opcode encountered for StackBehaviour of VarPush."); stackchange++; @@ -695,7 +688,7 @@ namespace System.Reflection.Emit if (opcode.StackBehaviourPop == StackBehaviour.Varpop) { // Instruction must be one of call, callvirt or newobj. - Contract.Assert(opcode.Equals(OpCodes.Call) || + Debug.Assert(opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj), "Unexpected opcode encountered for StackBehaviour of VarPop."); @@ -710,7 +703,6 @@ namespace System.Reflection.Emit PutInteger4(tk); } - [System.Security.SecuritySafeCritical] // auto-generated public virtual void Emit(OpCode opcode, Type cls) { // Puts opcode onto the stream and then the metadata token represented @@ -750,7 +742,6 @@ namespace System.Reflection.Emit m_ILStream[m_length++] = (byte) (arg>>56); } - [System.Security.SecuritySafeCritical] // auto-generated unsafe public virtual void Emit(OpCode opcode, float arg) { EnsureCapacity(7); InternalEmit(opcode); @@ -761,7 +752,6 @@ namespace System.Reflection.Emit m_ILStream[m_length++] = (byte) (tempVal>>24); } - [System.Security.SecuritySafeCritical] // auto-generated unsafe public virtual void Emit(OpCode opcode, double arg) { EnsureCapacity(11); InternalEmit(opcode); @@ -805,7 +795,7 @@ namespace System.Reflection.Emit public virtual void Emit(OpCode opcode, Label[] labels) { if (labels == null) - throw new ArgumentNullException("labels"); + throw new ArgumentNullException(nameof(labels)); Contract.EndContractBlock(); // Emitting a switch table @@ -854,13 +844,13 @@ namespace System.Reflection.Emit if (local == null) { - throw new ArgumentNullException("local"); + throw new ArgumentNullException(nameof(local)); } Contract.EndContractBlock(); int tempVal = local.GetLocalIndex(); if (local.GetMethodBuilder() != m_methodBuilder) { - throw new ArgumentException(Environment.GetResourceString("Argument_UnmatchedMethodForLocal"), "local"); + throw new ArgumentException(Environment.GetResourceString("Argument_UnmatchedMethodForLocal"), nameof(local)); } // If the instruction is a ldloc, ldloca a stloc, morph it to the optimal form. if (opcode.Equals(OpCodes.Ldloc)) @@ -1020,7 +1010,7 @@ namespace System.Reflection.Emit public virtual void BeginExceptFilterBlock() { - // Begins a eception filter block. Emits a branch instruction to the end of the current exception block. + // Begins an exception filter block. Emits a branch instruction to the end of the current exception block. if (m_currExcStackCount == 0) throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock")); @@ -1051,7 +1041,7 @@ namespace System.Reflection.Emit } else { // execute this branch if previous clause is Catch or Fault if (exceptionType==null) { - throw new ArgumentNullException("exceptionType"); + throw new ArgumentNullException(nameof(exceptionType)); } Label endLabel = current.GetEndLabel(); @@ -1153,7 +1143,7 @@ namespace System.Reflection.Emit // Emits the il to throw an exception if (excType==null) { - throw new ArgumentNullException("excType"); + throw new ArgumentNullException(nameof(excType)); } if (!excType.IsSubclassOf(typeof(Exception)) && excType!=typeof(Exception)) { @@ -1212,9 +1202,9 @@ namespace System.Reflection.Emit throw new ArgumentException(Environment.GetResourceString("NotSupported_OutputStreamUsingTypeBuilder")); } parameterTypes[0] = (Type)cls; - MethodInfo mi = typeof(TextWriter).GetMethod("WriteLine", parameterTypes); + MethodInfo mi = prop.ReturnType.GetMethod("WriteLine", parameterTypes); if (mi==null) { - throw new ArgumentException(Environment.GetResourceString("Argument_EmitWriteLineType"), "localBuilder"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmitWriteLineType"), nameof(localBuilder)); } Emit(OpCodes.Callvirt, mi); @@ -1231,7 +1221,7 @@ namespace System.Reflection.Emit if (fld == null) { - throw new ArgumentNullException("fld"); + throw new ArgumentNullException(nameof(fld)); } Contract.EndContractBlock(); @@ -1250,9 +1240,9 @@ namespace System.Reflection.Emit throw new NotSupportedException(Environment.GetResourceString("NotSupported_OutputStreamUsingTypeBuilder")); } parameterTypes[0] = (Type)cls; - MethodInfo mi = typeof(TextWriter).GetMethod("WriteLine", parameterTypes); + MethodInfo mi = prop.ReturnType.GetMethod("WriteLine", parameterTypes); if (mi==null) { - throw new ArgumentException(Environment.GetResourceString("Argument_EmitWriteLineType"), "fld"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmitWriteLineType"), nameof(fld)); } Emit(OpCodes.Callvirt, mi); } @@ -1283,7 +1273,7 @@ namespace System.Reflection.Emit } if (localType==null) { - throw new ArgumentNullException("localType"); + throw new ArgumentNullException(nameof(localType)); } if (methodBuilder.m_bIsBaked) { @@ -1304,10 +1294,10 @@ namespace System.Reflection.Emit // for the current active lexical scope. if (usingNamespace == null) - throw new ArgumentNullException("usingNamespace"); + throw new ArgumentNullException(nameof(usingNamespace)); if (usingNamespace.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "usingNamespace"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(usingNamespace)); Contract.EndContractBlock(); int index; @@ -1335,7 +1325,7 @@ namespace System.Reflection.Emit { if (startLine == 0 || startLine < 0 || endLine == 0 || endLine < 0) { - throw new ArgumentOutOfRangeException("startLine"); + throw new ArgumentOutOfRangeException(nameof(startLine)); } Contract.EndContractBlock(); m_LineNumberInfo.AddLineNumberInfo(document, m_length, startLine, startColumn, endLine, endColumn); @@ -1362,28 +1352,6 @@ namespace System.Reflection.Emit #endregion #endregion - -#if !FEATURE_CORECLR - void _ILGenerator.GetTypeInfoCount(out uint pcTInfo) - { - throw new NotImplementedException(); - } - - void _ILGenerator.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo) - { - throw new NotImplementedException(); - } - - void _ILGenerator.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId) - { - throw new NotImplementedException(); - } - - void _ILGenerator.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr) - { - throw new NotImplementedException(); - } -#endif } internal struct __FixupData @@ -1472,7 +1440,7 @@ namespace System.Reflection.Emit m_catchAddr[m_currentCatch] = -1; if (m_currentCatch > 0) { - Contract.Assert(m_catchEndAddr[m_currentCatch-1] == -1,"m_catchEndAddr[m_currentCatch-1] == -1"); + Debug.Assert(m_catchEndAddr[m_currentCatch-1] == -1,"m_catchEndAddr[m_currentCatch-1] == -1"); m_catchEndAddr[m_currentCatch-1] = catchorfilterAddr; } } @@ -1489,7 +1457,7 @@ namespace System.Reflection.Emit { if (m_type[m_currentCatch] != Filter) { - Contract.Assert(m_catchEndAddr[m_currentCatch-1] == -1,"m_catchEndAddr[m_currentCatch-1] == -1"); + Debug.Assert(m_catchEndAddr[m_currentCatch-1] == -1,"m_catchEndAddr[m_currentCatch-1] == -1"); m_catchEndAddr[m_currentCatch-1] = catchEndAddr; } } @@ -1531,9 +1499,9 @@ namespace System.Reflection.Emit } internal void Done(int endAddr) { - Contract.Assert(m_currentCatch > 0,"m_currentCatch > 0"); - Contract.Assert(m_catchAddr[m_currentCatch-1] > 0,"m_catchAddr[m_currentCatch-1] > 0"); - Contract.Assert(m_catchEndAddr[m_currentCatch-1] == -1,"m_catchEndAddr[m_currentCatch-1] == -1"); + Debug.Assert(m_currentCatch > 0,"m_currentCatch > 0"); + Debug.Assert(m_catchAddr[m_currentCatch-1] > 0,"m_catchAddr[m_currentCatch-1] > 0"); + Debug.Assert(m_catchEndAddr[m_currentCatch-1] == -1,"m_catchEndAddr[m_currentCatch-1] == -1"); m_catchEndAddr[m_currentCatch-1] = endAddr; m_currentState = State_Done; } @@ -1596,8 +1564,8 @@ namespace System.Reflection.Emit // not having a nesting relation. internal bool IsInner(__ExceptionInfo exc) { Contract.Requires(exc != null); - Contract.Assert(m_currentCatch > 0,"m_currentCatch > 0"); - Contract.Assert(exc.m_currentCatch > 0,"exc.m_currentCatch > 0"); + Debug.Assert(m_currentCatch > 0,"m_currentCatch > 0"); + Debug.Assert(exc.m_currentCatch > 0,"exc.m_currentCatch > 0"); int exclast = exc.m_currentCatch - 1; int last = m_currentCatch - 1; @@ -1606,7 +1574,7 @@ namespace System.Reflection.Emit return true; else if (exc.m_catchEndAddr[exclast] == m_catchEndAddr[last]) { - Contract.Assert(exc.GetEndAddress() != GetEndAddress(), + Debug.Assert(exc.GetEndAddress() != GetEndAddress(), "exc.GetEndAddress() != GetEndAddress()"); if (exc.GetEndAddress() > GetEndAddress()) return true; @@ -1762,9 +1730,6 @@ namespace System.Reflection.Emit } } - #if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated - #endif internal void EmitScopeTree(ISymbolWriter symWriter) { int i; @@ -1821,7 +1786,7 @@ namespace System.Reflection.Emit // make sure that arrays are large enough to hold addition info i = FindDocument(document); - Contract.Assert(i < m_DocumentCount, "Bad document look up!"); + Debug.Assert(i < m_DocumentCount, "Bad document look up!"); m_Documents[i].AddLineNumberInfo(document, iOffset, iStartLine, iStartColumn, iEndLine, iEndColumn); } @@ -1874,9 +1839,6 @@ namespace System.Reflection.Emit } } - #if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated - #endif internal void EmitLineNumberInfo(ISymbolWriter symWriter) { for (int i = 0; i < m_DocumentCount; i++) @@ -1912,7 +1874,7 @@ namespace System.Reflection.Emit int iEndLine, int iEndColumn) { - Contract.Assert(document == m_document, "Bad document look up!"); + Debug.Assert(document == m_document, "Bad document look up!"); // make sure that arrays are large enough to hold addition info EnsureCapacity(); @@ -1968,9 +1930,6 @@ namespace System.Reflection.Emit } } - #if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated - #endif internal void EmitLineNumberInfo(ISymbolWriter symWriter) { int[] iOffsetsTemp; |