예제 #1
0
파일: TableHeap.cs 프로젝트: hj1980/Mosa
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="result">The result.</param>
        public void Read(TokenTypes token, out FieldLayoutRow result)
        {
            if ((token & TokenTypes.TableMask) != TokenTypes.FieldLayout)
                throw new ArgumentException ("Invalid token type for FieldLayoutRow.", "token");

            using (BinaryReader reader = CreateReaderForToken (token))
            {
                result = new FieldLayoutRow (reader.ReadUInt32 (), ReadIndexValue (reader, TokenTypes.Field));
            }
        }
예제 #2
0
 void IMetadataProvider.Read(TokenTypes token, out FieldLayoutRow result)
 {
     TableHeap theap = (TableHeap)_streams[(int)HeapType.Tables];
     theap.Read(token, out result);
 }
        /// <summary>
        /// Loads all fields defined in the module.
        /// </summary>
        /// <param name="declaringType">The type, which declared the method.</param>
        /// <param name="first">The first field token to load.</param>
        /// <param name="last">The last field token to load (non-inclusive.)</param>
        /// <param name="offset">The offset in the fields array.</param>
        private void LoadFields(RuntimeType declaringType, TokenTypes first, TokenTypes last, ref int offset)
        {
            TokenTypes maxRVA = metadata.GetMaxTokenValue(TokenTypes.FieldRVA);
            TokenTypes maxLayout = metadata.GetMaxTokenValue(TokenTypes.FieldLayout);
            TokenTypes tokenRva = TokenTypes.FieldRVA + 1;
            TokenTypes tokenLayout = TokenTypes.FieldLayout + 1;

            FieldRVARow fieldRVA = new FieldRVARow();
            FieldLayoutRow fieldLayout = new FieldLayoutRow();

            if (TokenTypes.FieldRVA < maxRVA)
                fieldRVA = metadata.ReadFieldRVARow(tokenRva);

            if (TokenTypes.FieldLayout < maxLayout)
                fieldLayout = metadata.ReadFieldLayoutRow(tokenLayout);

            for (TokenTypes token = first; token < last; token++)
            {
                // Read the stackFrameIndex
                FieldRow field = metadata.ReadFieldRow(token);
                uint rva = 0;
                uint layout = 0;

                // Static fields have an optional RVA, non-static may have a layout assigned
                if ((field.Flags & FieldAttributes.HasFieldRVA) == FieldAttributes.HasFieldRVA)
                {
                    // Move to the RVA of this field
                    while (fieldRVA.FieldTableIdx < token && tokenRva <= maxRVA)
                        fieldRVA = metadata.ReadFieldRVARow(tokenRva++);

                    // Does this field have an RVA?
                    if (token == fieldRVA.FieldTableIdx && tokenRva <= maxRVA)
                    {
                        rva = fieldRVA.Rva;
                        tokenRva++;
                        if (tokenRva < maxRVA)
                        {
                            fieldRVA = metadata.ReadFieldRVARow(tokenRva);
                        }
                    }
                }

                if ((field.Flags & FieldAttributes.HasDefault) == FieldAttributes.HasDefault)
                {
                    // FIXME: Has a default value.
                    //Debug.Assert(false);
                }

                // Layout only exists for non-static fields
                if ((field.Flags & FieldAttributes.Static) != FieldAttributes.Static)
                {
                    // Move to the layout of this field
                    while (fieldLayout.Field < token && tokenLayout <= maxLayout)
                        fieldLayout = metadata.ReadFieldLayoutRow(tokenLayout++);

                    // Does this field have layout?
                    if (token == fieldLayout.Field && tokenLayout <= maxLayout)
                    {
                        layout = fieldLayout.Offset;
                        tokenLayout++;
                        if (tokenLayout < maxLayout)
                        {
                            fieldLayout = metadata.ReadFieldLayoutRow(tokenLayout);
                        }
                    }
                }

                // Load the field metadata
                fields[offset++] = new CilRuntimeField(this, field, layout, rva, declaringType);
            }

            /* FIXME:
             * Load FieldMarshal tables
             * as needed afterwards. All Generics have been loaded, fields can receive
             * their signature in the load method above.
             */
        }