예제 #1
0
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="index">The index.</param>
        protected override void ParseSignature(byte[] buffer, ref int index)
        {
            if (0x0A != buffer[index])
            {
                throw new InvalidOperationException(@"Invalid signature.");
            }
            index++;

            int genArgCount = Utilities.ReadCompressedInt32(buffer, ref index);

            _types = new SigType[genArgCount];
            for (int i = 0; i < genArgCount; i++)
            {
                _types[i] = SigType.ParseTypeSignature(buffer, ref index);
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodSignature"/> class.
        /// </summary>
        /// <param name="returnType">Type of the return value.</param>
        /// <param name="parameters">The parameter types.</param>
        public MethodSignature(SigType returnType, SigType[] parameters)
        {
            if (returnType == null)
            {
                throw new ArgumentNullException(@"returnType");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(@"parameters");
            }

            this.token = TokenTypes.Assembly;
            this._callingConvention     = CallingConvention.Default;
            this._hasExplicitThis       = this._hasThis = false;
            this._parameters            = parameters;
            this._returnType            = returnType;
            this._genericParameterCount = 0;
        }
예제 #3
0
        protected void ApplyGenericArguments(SigType[] genericArguments)
        {
            for (int i = 0; i < parameters.Length; i++)
            {
                if (parameters[i] is VarSigType)
                {
                    if ((parameters[i] as VarSigType).Index < genericArguments.Length)
                    {
                        parameters[i] = genericArguments[(parameters[i] as VarSigType).Index];
                    }
                }
            }

            if (returnType is VarSigType)
            {
                returnType = genericArguments[(returnType as VarSigType).Index];
            }
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodSignature"/> class.
        /// </summary>
        /// <param name="returnType">Type of the return value.</param>
        /// <param name="parameters">The parameter types.</param>
        public MethodSignature(SigType returnType, SigType[] parameters)
        {
            if (returnType == null)
            {
                throw new ArgumentNullException(@"returnType");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(@"parameters");
            }

            this.methodCallingConvention = MethodCallingConvention.Default;
            this.hasExplicitThis         = false;
            this.hasThis               = false;
            this.parameters            = parameters;
            this.returnType            = returnType;
            this.genericParameterCount = 0;
        }
예제 #5
0
파일: CustomMod.cs 프로젝트: djlw78/Mosa
        /// <summary>
        /// Parses the custom mods.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        public static CustomMod[] ParseCustomMods(byte[] buffer, ref int index)
        {
            List <CustomMod> mods = new List <CustomMod>();

            for (int i = index; i < buffer.Length; i++)
            {
                CilElementType type = (CilElementType)buffer[i++];
                if (type != CilElementType.Optional && type != CilElementType.Required)
                {
                    break;
                }

                index++;
                TokenTypes modType = SigType.ReadTypeDefOrRefEncoded(buffer, ref index);
                mods.Add(new CustomMod((CustomModType)(type - CilElementType.Required + 1), modType));
            }

            return(mods.ToArray());
        }
예제 #6
0
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        protected sealed override void ParseSignature(SignatureReader reader)
        {
            byte value = reader.ReadByte();

            // Check for instance signature
            if (HAS_THIS == (value & HAS_THIS))
            {
                hasThis = true;
            }

            if (HAS_EXPLICIT_THIS == (value & HAS_EXPLICIT_THIS))
            {
                hasExplicitThis = true;
            }

            if (GENERIC == (value & GENERIC))
            {
                methodCallingConvention = MethodCallingConvention.Generic;
                genericParameterCount   = reader.ReadCompressedInt32();
            }
            else if (VARARG == (value & VARARG))
            {
                methodCallingConvention = MethodCallingConvention.VarArg;
            }
            else if ((value & 0x1F) != 0x00)
            {
                throw new InvalidOperationException(@"Invalid method definition signature.");
            }

            // Number of parameters
            int paramCount = reader.ReadCompressedInt32();

            parameters = new SigType[paramCount];

            // Read the return type
            returnType = SigType.ParseTypeSignature(reader);

            // Read all parameters
            for (int i = 0; i < paramCount; i++)
            {
                parameters[i] = SigType.ParseTypeSignature(reader);
            }
        }
예제 #7
0
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="index">The index.</param>
        protected override void ParseSignature(byte[] buffer, ref int index)
        {
            // Check signature identifier
            if (buffer[index++] != 0x07)
            {
                throw new ArgumentException(@"Token doesn't represent a local variable signature.", @"token");
            }

            // Retrieve the number of locals
            int count = Utilities.ReadCompressedInt32(buffer, ref index);

            if (0 != count)
            {
                _types = new SigType[count];
                for (int i = 0; i < count; i++)
                {
                    _types[i] = SigType.ParseTypeSignature(buffer, ref index);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="index">The index.</param>
        protected sealed override void ParseSignature(byte[] buffer, ref int index)
        {
            // Check for instance signature
            if (HAS_THIS == (buffer[index] & HAS_THIS))
            {
                _hasThis = true;
            }
            if (HAS_EXPLICIT_THIS == (buffer[index] & HAS_EXPLICIT_THIS))
            {
                _hasExplicitThis = true;
            }
            if (GENERIC == (buffer[index] & GENERIC))
            {
                _callingConvention     = CallingConvention.Generic;
                _genericParameterCount = Utilities.ReadCompressedInt32(buffer, ref index);
            }
            else if (VARARG == (buffer[index] & VARARG))
            {
                _callingConvention = CallingConvention.Vararg;
            }
            else if (0x00 != (buffer[index] & 0x1F))
            {
                throw new InvalidOperationException(@"Invalid method definition signature.");
            }

            index++;

            // Number of parameters
            int paramCount = Utilities.ReadCompressedInt32(buffer, ref index);

            _parameters = new SigType[paramCount];

            // Read the return type
            _returnType = SigType.ParseTypeSignature(buffer, ref index);

            // Read all parameters
            for (int i = 0; i < paramCount; i++)
            {
                _parameters[i] = SigType.ParseTypeSignature(buffer, ref index);
            }
        }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericInstSigType"/> class.
 /// </summary>
 /// <param name="baseType">Type of the base.</param>
 /// <param name="genericArgs">The generic args.</param>
 public GenericInstSigType(SigType baseType, SigType[] genericArgs) :
     base(CilElementType.GenericInst)
 {
     _baseType    = baseType;
     _genericArgs = genericArgs;
 }
예제 #10
0
 /// <summary>
 /// Parses the signature.
 /// </summary>
 /// <param name="reader">The reader.</param>
 protected override void ParseSignature(SignatureReader reader)
 {
     type = SigType.ParseTypeSignature(reader);
 }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SZArraySigType"/> class.
 /// </summary>
 /// <param name="customMods">The custom mods.</param>
 /// <param name="type">The type.</param>
 public SZArraySigType(CustomMod[] customMods, SigType type) :
     base(CilElementType.SZArray)
 {
     _customMods  = customMods;
     _elementType = type;
 }
예제 #12
0
 /// <summary>
 /// Parses the signature.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 /// <param name="index">The index.</param>
 protected override void ParseSignature(byte[] buffer, ref int index)
 {
     _type = SigType.ParseTypeSignature(buffer, ref index);
 }