Example #1
0
 public override void FromRawData(byte [] buff, int offs, int numRows)
 {
     for (int i = numRows; --i >= 0;)
     {
         Row row = new MemberRefRow(this);
         row.FromRawData(buff, offs);
         Add(row);
         offs += MemberRefRow.LogicalSize;
     }
 }
Example #2
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="result">The result.</param>
        public void Read(TokenTypes token, out MemberRefRow result)
        {
            if ((token & TokenTypes.TableMask) != TokenTypes.MemberRef)
            {
                throw new ArgumentException("Invalid token type for MemberRefRow.", "token");
            }

            using (BinaryReader reader = CreateReaderForToken(token))
            {
                result = new MemberRefRow(ReadIndexValue(reader, IndexType.MemberRefParent), ReadIndexValue(reader, IndexType.StringHeap), ReadIndexValue(reader, IndexType.BlobHeap));
            }
        }
        public static IMemberReference Resolve(MemberRefRow row, MetadataSystem metadata)
        {
            var blob = metadata.ResolveBlob(row.Signature);

            blob.MoveTo(ByteBuffer.START_POSITION);

            var sig = blob.ReadByte();

            blob.MoveTo(ByteBuffer.START_POSITION);

            if (sig == FIELD_SIG)
            {
                return(FieldReferenceResolver.Resolve(row, blob, metadata));
            }

            return(MethodReferenceResolver.Resolve(row, blob, metadata));
        }
 public virtual void VisitMemberRefRow(MemberRefRow row)
 {
 }
        public MemberReference GetMemberRefAt(uint rid, GenericContext context)
        {
            int             index  = (int)rid - 1;
            MemberReference member = m_memberRefs [rid - 1];

            if (member != null)
            {
                return(member);
            }

            MemberRefTable mrTable = m_tableReader.GetMemberRefTable();
            MemberRefRow   mrefRow = mrTable [index];

            Signature sig = m_sigReader.GetMemberRefSig(mrefRow.Class.TokenType, mrefRow.Signature);

            switch (mrefRow.Class.TokenType)
            {
            case TokenType.TypeDef:
            case TokenType.TypeRef:
            case TokenType.TypeSpec:
                TypeReference  declaringType = GetTypeDefOrRef(mrefRow.Class, context);
                GenericContext nc            = context.Clone();

                if (declaringType is GenericInstanceType)
                {
                    TypeReference ct = declaringType;
                    while (ct is GenericInstanceType)
                    {
                        ct = (ct as GenericInstanceType).ElementType;
                    }

                    nc.Type          = ct;
                    nc.AllowCreation = ct.GetType() == typeof(TypeReference);
                }

                if (sig is FieldSig)
                {
                    FieldSig fs = sig as FieldSig;
                    member = new FieldReference(
                        m_root.Streams.StringsHeap [mrefRow.Name],
                        declaringType,
                        GetTypeRefFromSig(fs.Type, nc));
                }
                else
                {
                    string    name = m_root.Streams.StringsHeap [mrefRow.Name];
                    MethodSig ms   = sig as MethodSig;

                    MethodReference methref = new MethodReference(
                        name, ms.HasThis, ms.ExplicitThis, ms.MethCallConv);
                    methref.DeclaringType = declaringType;

                    if (sig is MethodDefSig)
                    {
                        int arity = (sig as MethodDefSig).GenericParameterCount;
                        for (int i = 0; i < arity; i++)
                        {
                            methref.GenericParameters.Add(new GenericParameter(i, methref));
                        }
                    }

                    nc.Method = methref;

                    methref.ReturnType = GetMethodReturnType(ms, nc);

                    methref.ReturnType.Method = methref;
                    for (int j = 0; j < ms.ParamCount; j++)
                    {
                        Param p = ms.Parameters [j];
                        ParameterDefinition pdef = BuildParameterDefinition(
                            string.Concat("A_", j), j, new ParamAttributes(), p, nc);
                        pdef.Method = methref;
                        methref.Parameters.Add(pdef);
                    }
                    member    = methref;
                    nc.Method = methref;
                }
                break;

            case TokenType.Method:
                // really not sure about this
                MethodDefinition methdef = GetMethodDefAt(mrefRow.Class.RID);
                member = new MethodReference(
                    methdef.Name, methdef.HasThis,
                    methdef.ExplicitThis, methdef.CallingConvention);
                member.DeclaringType = methdef.DeclaringType;
                break;

            case TokenType.ModuleRef:
                break;                 // TODO, implement that, or not
            }

            member.MetadataToken = MetadataToken.FromMetadataRow(TokenType.MemberRef, index);
            m_module.MemberReferences.Add(member);
            m_memberRefs [index] = member;

            return(member);
        }
Example #6
0
        void IMetadataProvider.Read(TokenTypes token, out MemberRefRow result)
        {
            TableHeap theap = (TableHeap)_streams[(int)HeapType.Tables];

            theap.Read(token, out result);
        }
 public virtual void VisitMemberRefRow(MemberRefRow row)
 {
 }
Example #8
0
        /// <summary>
        /// Loads the interfaces.
        /// </summary>
        protected void LoadMemberReferences()
        {
            Token maxToken = GetMaxTokenValue(TableType.MemberRef);

            foreach (Token token in new Token(TableType.MemberRef, 1).Upto(maxToken))
            {
                MemberRefRow row  = metadataProvider.ReadMemberRefRow(token);
                string       name = GetString(row.NameStringIdx);

                RuntimeType ownerType = null;

                switch (row.Class.Table)
                {
                case TableType.TypeDef:
                    ownerType = types[row.Class.RID - 1];
                    break;

                case TableType.TypeRef:
                    ownerType = typeRef[row.Class.RID - 1];
                    break;

                case TableType.TypeSpec:
                    ownerType = typeSpecs[row.Class.RID - 1];
                    break;

                default:
                    throw new NotSupportedException(String.Format(@"LoadMemberReferences() does not support token table {0}", row.Class.Table));
                }

                if (ownerType == null)
                {
                    throw new InvalidOperationException(String.Format(@"Failed to retrieve owner type for Token {0:x} (Table {1})", row.Class, row.Class.Table));
                }

                Signature signature = GetMemberRefSignature(row.SignatureBlobIdx);

                CilGenericType genericOwnerType = ownerType as CilGenericType;

                RuntimeMember runtimeMember = null;
                if (signature is FieldSignature)
                {
                    foreach (RuntimeField field in ownerType.Fields)
                    {
                        if (field.Name == name)
                        {
                            runtimeMember = field;
                            break;
                        }
                    }
                }
                else
                {
                    MethodSignature methodSignature = signature as MethodSignature;
                    Debug.Assert(signature is MethodSignature);

                    if ((genericOwnerType != null) && (genericOwnerType.GenericArguments.Length != 0))
                    {
                        methodSignature = new MethodSignature(methodSignature, genericOwnerType.GenericArguments);
                    }

                    foreach (RuntimeMethod method in ownerType.Methods)
                    {
                        if (method.Name == name)
                        {
                            if (method.Signature.Matches(methodSignature))
                            {
                                runtimeMember = method;
                                break;
                            }
                        }
                    }

                    // Special case: string.get_Chars is same as string.get_Item
                    if (runtimeMember == null && name == "get_Chars" && ownerType.FullName == "System.String")
                    {
                        name = "get_Item";

                        foreach (RuntimeMethod method in ownerType.Methods)
                        {
                            if (method.Name == name)
                            {
                                if (method.Signature.Matches(methodSignature))
                                {
                                    runtimeMember = method;
                                    break;
                                }
                            }
                        }
                    }
                }

                if (runtimeMember == null)
                {
                    throw new InvalidOperationException(String.Format(@"Failed to locate field {0}.{1}", ownerType.FullName, name));
                }

                memberRef[token.RID - 1] = runtimeMember;
            }
        }
 public MemberRefRowExt(IMetadataProvider metadata, MemberRefRow row)
     : base(metadata)
 {
     this.row = row;
 }
Example #10
0
        public static FieldReference Resolve(MemberRefRow row, ByteBuffer signature, MetadataSystem metadata)
        {
            var resolver = new FieldReferenceResolver(row, signature, metadata);

            return(new FieldReference(resolver));
        }
Example #11
0
 private FieldReferenceResolver(MemberRefRow row, ByteBuffer signature, MetadataSystem metadata)
 {
     _row       = row;
     _signature = signature;
     _metadata  = metadata;
 }
Example #12
0
        private static Token GetLocalTypeRefToken(IMetadataModule module, Token ctorToken)
        {
            MemberRefRow memberRef = module.Metadata.ReadMemberRefRow(ctorToken);

            return(memberRef.Class);
        }