GetLocalVarSigHelper() public static method

public static GetLocalVarSigHelper ( ) : System.Reflection.Emit.SignatureHelper
return System.Reflection.Emit.SignatureHelper
Esempio n. 1
0
        internal byte[] GetLocalSignature(out int signatureLength)
        {
            if (m_localSignature != null)
            {
                signatureLength = m_localSignature.Length;
                return(m_localSignature);
            }

            if (m_ilGenerator != null)
            {
                if (m_ilGenerator.m_localCount != 0)
                {
                    // If user is using ILGenerator::DeclareLocal, then get local signaturefrom there.
                    return(m_ilGenerator.m_localSignature.InternalGetSignature(out signatureLength));
                }
            }

            return(SignatureHelper.GetLocalVarSigHelper(m_module).InternalGetSignature(out signatureLength));
        }
        internal ILGenerator(MethodInfo methodBuilder, int size)
        {
            if (size < 0x10)
            {
                this.m_ILStream = new byte[0x10];
            }
            else
            {
                this.m_ILStream = new byte[size];
            }
            this.m_length            = 0;
            this.m_labelCount        = 0;
            this.m_fixupCount        = 0;
            this.m_labelList         = null;
            this.m_fixupData         = null;
            this.m_exceptions        = null;
            this.m_exceptionCount    = 0;
            this.m_currExcStack      = null;
            this.m_currExcStackCount = 0;
            this.m_RelocFixupList    = new int[0x40];
            this.m_RelocFixupCount   = 0;
            this.m_RVAFixupList      = new int[0x40];
            this.m_RVAFixupCount     = 0;
            this.m_ScopeTree         = new ScopeTree();
            this.m_LineNumberInfo    = new LineNumberInfo();
            this.m_methodBuilder     = methodBuilder;
            this.m_localCount        = 0;
            MethodBuilder builder = this.m_methodBuilder as MethodBuilder;

            if (builder == null)
            {
                this.m_localSignature = SignatureHelper.GetLocalVarSigHelper(null);
            }
            else
            {
                this.m_localSignature = SignatureHelper.GetLocalVarSigHelper(builder.GetTypeBuilder().Module);
            }
        }
Esempio n. 3
0
		internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
		{
			if (sequencePointLists != null) {
				SequencePointList first = (SequencePointList) sequencePointLists [0];
				SequencePointList last = (SequencePointList) sequencePointLists [sequencePointLists.Count - 1];
				symbolWriter.SetMethodSourceRange (first.Document, first.StartLine, first.StartColumn, last.Document, last.EndLine, last.EndColumn);
				
				foreach (SequencePointList list in sequencePointLists)
					symbolWriter.DefineSequencePoints (list.Document, list.GetOffsets(), list.GetLines(), list.GetColumns(), list.GetEndLines(), list.GetEndColumns());
				
				if (locals != null) {
					foreach (LocalBuilder local in locals) {
						if (local.Name != null && local.Name.Length > 0) {
							SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
							sighelper.AddArgument (local.LocalType);
							byte[] signature = sighelper.GetSignature ();
							symbolWriter.DefineLocalVariable (local.Name, FieldAttributes.Public, signature, SymAddressKind.ILOffset, local.position, 0, 0, local.StartOffset, local.EndOffset);
						}
					}
				}
				sequencePointLists = null;
			}
		}
        private void Init(
            String name,
            MethodAttributes attributes,
            CallingConventions callingConvention,
            Type returnType,
            Type[]              parameterTypes,
            Module mod,
            TypeBuilder type,
            bool bIsGlobalMethod)
        {
            m_strName        = name;
            m_localSignature = SignatureHelper.GetLocalVarSigHelper(mod);
            m_module         = mod;
            m_containingType = type;
            if (returnType == null)
            {
                m_returnType = typeof(void);
            }
            else
            {
                m_returnType = returnType;
            }

            if ((attributes & MethodAttributes.Static) == 0)
            {
                // turn on the has this calling convention
                callingConvention = callingConvention | CallingConventions.HasThis;
            }
            else if ((attributes & MethodAttributes.Virtual) != 0)
            {
                //A method can't be both static and virtual
                throw new ArgumentException(Environment.GetResourceString("Arg_NoStaticVirtual"));
            }
            if ((attributes & MethodAttributes.SpecialName) != MethodAttributes.SpecialName)
            {
                if ((type.Attributes & TypeAttributes.Interface) == TypeAttributes.Interface)
                {
                    // methods on interface have to be abstract + virtual except special name methods(such as type initializer
                    if ((attributes & (MethodAttributes.Abstract | MethodAttributes.Virtual)) != (MethodAttributes.Abstract | MethodAttributes.Virtual))
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_BadAttributeOnInterfaceMethod"));
                    }
                }
            }

            m_callingConvention = callingConvention;
            m_returnType        = returnType;

            if (parameterTypes != null)
            {
                m_parameterTypes = new Type[parameterTypes.Length];
                Array.Copy(parameterTypes, m_parameterTypes, parameterTypes.Length);
            }
            else
            {
                m_parameterTypes = null;
            }

            m_signature       = SignatureHelper.GetMethodSigHelper(mod, callingConvention, returnType, parameterTypes);
            m_iAttributes     = attributes;
            m_bIsGlobalMethod = bIsGlobalMethod;
            m_bIsBaked        = false;
            m_fInitLocals     = true;

            m_localSymInfo = new LocalSymInfo();
            m_ubBody       = null;
            m_ilGenerator  = null;


            // default is managed IL
            // Manged IL has bit flag 0x0020 set off

            m_dwMethodImplFlags = MethodImplAttributes.IL;
        }
Esempio n. 5
0
 private void Init(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers, ModuleBuilder mod, TypeBuilder type, bool bIsGlobalMethod)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (name.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
     }
     if (name[0] == '\0')
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name");
     }
     if (mod == null)
     {
         throw new ArgumentNullException("mod");
     }
     if (parameterTypes != null)
     {
         foreach (Type type2 in parameterTypes)
         {
             if (type2 == null)
             {
                 throw new ArgumentNullException("parameterTypes");
             }
         }
     }
     this.m_strName        = name;
     this.m_module         = mod;
     this.m_containingType = type;
     this.m_localSignature = SignatureHelper.GetLocalVarSigHelper(mod);
     this.m_returnType     = returnType;
     if ((attributes & MethodAttributes.Static) == MethodAttributes.PrivateScope)
     {
         callingConvention |= CallingConventions.HasThis;
     }
     else if ((attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope)
     {
         throw new ArgumentException(Environment.GetResourceString("Arg_NoStaticVirtual"));
     }
     if ((((attributes & MethodAttributes.SpecialName) != MethodAttributes.SpecialName) && ((type.Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.ClassSemanticsMask)) && (((attributes & (MethodAttributes.Abstract | MethodAttributes.Virtual)) != (MethodAttributes.Abstract | MethodAttributes.Virtual)) && ((attributes & MethodAttributes.Static) == MethodAttributes.PrivateScope)))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_BadAttributeOnInterfaceMethod"));
     }
     this.m_callingConvention = callingConvention;
     if (parameterTypes != null)
     {
         this.m_parameterTypes = new Type[parameterTypes.Length];
         Array.Copy(parameterTypes, this.m_parameterTypes, parameterTypes.Length);
     }
     else
     {
         this.m_parameterTypes = null;
     }
     this.m_returnTypeRequiredCustomModifiers    = returnTypeRequiredCustomModifiers;
     this.m_returnTypeOptionalCustomModifiers    = returnTypeOptionalCustomModifiers;
     this.m_parameterTypeRequiredCustomModifiers = parameterTypeRequiredCustomModifiers;
     this.m_parameterTypeOptionalCustomModifiers = parameterTypeOptionalCustomModifiers;
     this.m_iAttributes       = attributes;
     this.m_bIsGlobalMethod   = bIsGlobalMethod;
     this.m_bIsBaked          = false;
     this.m_fInitLocals       = true;
     this.m_localSymInfo      = new LocalSymInfo();
     this.m_ubBody            = null;
     this.m_ilGenerator       = null;
     this.m_dwMethodImplFlags = MethodImplAttributes.IL;
 }
Esempio n. 6
0
        private void Init(String name, MethodAttributes attributes, CallingConventions callingConvention,
                          Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers,
                          Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers,
                          Module mod, TypeBuilder type, bool bIsGlobalMethod)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (name.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
            }

            if (name[0] == '\0')
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name");
            }

            if (mod == null)
            {
                throw new ArgumentNullException("mod");
            }

            if (parameterTypes != null)
            {
                foreach (Type t in parameterTypes)
                {
                    if (t == null)
                    {
                        throw new ArgumentNullException("parameterTypes");
                    }
                }
            }

            m_link = type.m_currentMethod;
            type.m_currentMethod = this;
            m_strName            = name;
            m_module             = mod;
            m_containingType     = type;
            m_localSignature     = SignatureHelper.GetLocalVarSigHelper(mod);

            //
            //if (returnType == null)
            //{
            //    m_returnType = typeof(void);
            //}
            //else
            {
                m_returnType = returnType;
            }

            if ((attributes & MethodAttributes.Static) == 0)
            {
                // turn on the has this calling convention
                callingConvention = callingConvention | CallingConventions.HasThis;
            }
            else if ((attributes & MethodAttributes.Virtual) != 0)
            {
                // A method can't be both static and virtual
                throw new ArgumentException(Environment.GetResourceString("Arg_NoStaticVirtual"));
            }

            if ((attributes & MethodAttributes.SpecialName) != MethodAttributes.SpecialName)
            {
                if ((type.Attributes & TypeAttributes.Interface) == TypeAttributes.Interface)
                {
                    // methods on interface have to be abstract + virtual except special name methods such as type initializer
                    if ((attributes & (MethodAttributes.Abstract | MethodAttributes.Virtual)) !=
                        (MethodAttributes.Abstract | MethodAttributes.Virtual) &&
                        (attributes & MethodAttributes.Static) == 0)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_BadAttributeOnInterfaceMethod"));
                    }
                }
            }

            m_callingConvention = callingConvention;

            if (parameterTypes != null)
            {
                m_parameterTypes = new Type[parameterTypes.Length];
                Array.Copy(parameterTypes, m_parameterTypes, parameterTypes.Length);
            }
            else
            {
                m_parameterTypes = null;
            }

            m_returnTypeRequiredCustomModifiers    = returnTypeRequiredCustomModifiers;
            m_returnTypeOptionalCustomModifiers    = returnTypeOptionalCustomModifiers;
            m_parameterTypeRequiredCustomModifiers = parameterTypeRequiredCustomModifiers;
            m_parameterTypeOptionalCustomModifiers = parameterTypeOptionalCustomModifiers;

//            m_signature = SignatureHelper.GetMethodSigHelper(mod, callingConvention,
//                returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers,
//                parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);

            m_iAttributes     = attributes;
            m_bIsGlobalMethod = bIsGlobalMethod;
            m_bIsBaked        = false;
            m_fInitLocals     = true;

            m_localSymInfo = new LocalSymInfo();
            m_ubBody       = null;
            m_ilGenerator  = null;

            // Default is managed IL. Manged IL has bit flag 0x0020 set off
            m_dwMethodImplFlags = MethodImplAttributes.IL;

            //int i = MetadataTokenInternal;
        }