| | | 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 HasConstantTag |
| | | 9 | | { |
| | | 10 | | internal const int NumberOfBits = 2; |
| | | 11 | | internal const int LargeRowSize = 0x00000001 << (16 - NumberOfBits); |
| | | 12 | | internal const uint Field = 0x00000000; |
| | | 13 | | internal const uint Param = 0x00000001; |
| | | 14 | | internal const uint Property = 0x00000002; |
| | | 15 | | internal const uint TagMask = 0x00000003; |
| | | 16 | | internal const TableMask TablesReferenced = |
| | | 17 | | TableMask.Field |
| | | 18 | | | TableMask.Param |
| | | 19 | | | TableMask.Property; |
| | | 20 | | internal const uint TagToTokenTypeByteVector = TokenTypeIds.FieldDef >> 24 | TokenTypeIds.ParamDef >> 16 | Token |
| | | 21 | | |
| | | 22 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 23 | | internal static EntityHandle ConvertToHandle(uint hasConstant) |
| | 0 | 24 | | { |
| | 0 | 25 | | uint tokenType = (TagToTokenTypeByteVector >> ((int)(hasConstant & TagMask) << 3)) << TokenTypeIds.RowIdBitC |
| | 0 | 26 | | uint rowId = (hasConstant >> NumberOfBits); |
| | | 27 | | |
| | 0 | 28 | | if (tokenType == 0 || (rowId & ~TokenTypeIds.RIDMask) != 0) |
| | 0 | 29 | | { |
| | 0 | 30 | | Throw.InvalidCodedIndex(); |
| | | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | return new EntityHandle(tokenType | rowId); |
| | 0 | 34 | | } |
| | | 35 | | |
| | | 36 | | internal static uint ConvertToTag(EntityHandle token) |
| | 0 | 37 | | { |
| | 0 | 38 | | HandleKind tokenKind = token.Kind; |
| | 0 | 39 | | uint rowId = (uint)token.RowId; |
| | 0 | 40 | | if (tokenKind == HandleKind.FieldDefinition) |
| | 0 | 41 | | { |
| | 0 | 42 | | return rowId << NumberOfBits | Field; |
| | | 43 | | } |
| | 0 | 44 | | else if (tokenKind == HandleKind.Parameter) |
| | 0 | 45 | | { |
| | 0 | 46 | | return rowId << NumberOfBits | Param; |
| | | 47 | | } |
| | 0 | 48 | | else if (tokenKind == HandleKind.PropertyDefinition) |
| | 0 | 49 | | { |
| | 0 | 50 | | return rowId << NumberOfBits | Property; |
| | | 51 | | } |
| | | 52 | | |
| | 0 | 53 | | return 0; |
| | 0 | 54 | | } |
| | | 55 | | } |
| | | 56 | | } |
| | | 57 | | |