| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Runtime.CompilerServices; |
| | | 5 | | |
| | | 6 | | namespace System.Reflection.Metadata.Ecma335 |
| | | 7 | | { |
| | | 8 | | internal static class MemberRefParentTag |
| | | 9 | | { |
| | | 10 | | internal const int NumberOfBits = 3; |
| | | 11 | | internal const int LargeRowSize = 0x00000001 << (16 - NumberOfBits); |
| | | 12 | | internal const uint TypeDef = 0x00000000; |
| | | 13 | | internal const uint TypeRef = 0x00000001; |
| | | 14 | | internal const uint ModuleRef = 0x00000002; |
| | | 15 | | internal const uint MethodDef = 0x00000003; |
| | | 16 | | internal const uint TypeSpec = 0x00000004; |
| | | 17 | | internal const uint TagMask = 0x00000007; |
| | | 18 | | internal const TableMask TablesReferenced = |
| | | 19 | | TableMask.TypeDef |
| | | 20 | | | TableMask.TypeRef |
| | | 21 | | | TableMask.ModuleRef |
| | | 22 | | | TableMask.MethodDef |
| | | 23 | | | TableMask.TypeSpec; |
| | | 24 | | internal const ulong TagToTokenTypeByteVector = |
| | | 25 | | (ulong)TokenTypeIds.TypeDef >> 24 |
| | | 26 | | | (ulong)TokenTypeIds.TypeRef >> 16 |
| | | 27 | | | (ulong)TokenTypeIds.ModuleRef >> 8 |
| | | 28 | | | (ulong)TokenTypeIds.MethodDef |
| | | 29 | | | (ulong)TokenTypeIds.TypeSpec << 8; |
| | | 30 | | |
| | | 31 | | [MethodImplAttribute(MethodImplOptions.AggressiveInlining)] |
| | | 32 | | internal static EntityHandle ConvertToHandle(uint memberRef) |
| | 0 | 33 | | { |
| | 0 | 34 | | uint tokenType = unchecked((uint)((TagToTokenTypeByteVector >> ((int)(memberRef & TagMask) << 3)) << TokenTy |
| | 0 | 35 | | uint rowId = (memberRef >> NumberOfBits); |
| | | 36 | | |
| | 0 | 37 | | if (tokenType == 0 || (rowId & ~TokenTypeIds.RIDMask) != 0) |
| | 0 | 38 | | { |
| | 0 | 39 | | Throw.InvalidCodedIndex(); |
| | | 40 | | } |
| | | 41 | | |
| | 0 | 42 | | return new EntityHandle(tokenType | rowId); |
| | 0 | 43 | | } |
| | | 44 | | } |
| | | 45 | | } |
| | | 46 | | |