/// <summary>
        /// Parses an SZArray attribute value.
        /// </summary>
        /// <param name="reader">The binary reader used to read from the attribute blob.</param>
        /// <param name="sigType">Type of the SZArray.</param>
        /// <returns>
        /// An Array, which represents the SZArray definition.
        /// </returns>
        private static object ParseSZArrayArg(BinaryReader reader, SZArraySigType sigType)
        {
            // Return value
            Array result;

            // Determine the number of elements
            int numElements = reader.ReadInt32();

            if (-1 == numElements)
            {
                return(null);
            }

            // Retrieve the array element type
            Type elementType = GetTypeFromSigType(sigType);

            Debug.Assert(null != elementType, @"Failed to get System.Type for SigType.");

            result = Array.CreateInstance(elementType, numElements);
            for (int idx = 0; idx < numElements; idx++)
            {
                object item = ParseElem(reader, sigType.ElementType);
                result.SetValue(item, idx);
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Read the type specification
            Token token = decoder.DecodeTokenType();

            // FIXME: If ctx.Operands1 is an integral constant, we can infer the maximum size of the array
            // and instantiate an ArrayTypeSpecification with max. sizes. This way we could eliminate bounds
            // checks in an optimization stage later on, if we find that a value never exceeds the array
            // bounds.
            var resultType = new SZArraySigType(null, new ClassSigType(token));

            ctx.Result = decoder.Compiler.CreateTemporary(resultType);
        }
        /// <summary>
        /// Parses a fixed argument in an attribute blob definition.
        /// </summary>
        /// <param name="reader">The binary reader to read it From.</param>
        /// <param name="sigType">The signature type of the value to read.</param>
        /// <returns></returns>
        private static object ParseFixedArg(BinaryReader reader, SigType sigType)
        {
            // Return value
            object result = null;

            // A vector?
            SZArraySigType arraySigType = sigType as SZArraySigType;

            if (arraySigType != null)
            {
                result = ParseSZArrayArg(reader, arraySigType);
            }
            else
            {
                result = ParseElem(reader, sigType);
            }

            return(result);
        }