| | | 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 HasCustomDebugInformationTag |
| | | 9 | | { |
| | | 10 | | internal const int NumberOfBits = 5; |
| | | 11 | | internal const int LargeRowSize = 0x00000001 << (16 - NumberOfBits); |
| | | 12 | | |
| | | 13 | | internal const uint MethodDef = 0x00000000; |
| | | 14 | | internal const uint Field = 0x00000001; |
| | | 15 | | internal const uint TypeRef = 0x00000002; |
| | | 16 | | internal const uint TypeDef = 0x00000003; |
| | | 17 | | internal const uint Param = 0x00000004; |
| | | 18 | | internal const uint InterfaceImpl = 0x00000005; |
| | | 19 | | internal const uint MemberRef = 0x00000006; |
| | | 20 | | internal const uint Module = 0x00000007; |
| | | 21 | | internal const uint DeclSecurity = 0x00000008; |
| | | 22 | | internal const uint Property = 0x00000009; |
| | | 23 | | internal const uint Event = 0x0000000A; |
| | | 24 | | internal const uint StandAloneSig = 0x0000000B; |
| | | 25 | | internal const uint ModuleRef = 0x0000000C; |
| | | 26 | | internal const uint TypeSpec = 0x0000000D; |
| | | 27 | | internal const uint Assembly = 0x0000000E; |
| | | 28 | | internal const uint AssemblyRef = 0x0000000F; |
| | | 29 | | internal const uint File = 0x00000010; |
| | | 30 | | internal const uint ExportedType = 0x00000011; |
| | | 31 | | internal const uint ManifestResource = 0x00000012; |
| | | 32 | | internal const uint GenericParam = 0x00000013; |
| | | 33 | | internal const uint GenericParamConstraint = 0x00000014; |
| | | 34 | | internal const uint MethodSpec = 0x00000015; |
| | | 35 | | |
| | | 36 | | internal const uint Document = 0x00000016; |
| | | 37 | | internal const uint LocalScope = 0x00000017; |
| | | 38 | | internal const uint LocalVariable = 0x00000018; |
| | | 39 | | internal const uint LocalConstant = 0x00000019; |
| | | 40 | | internal const uint Import = 0x0000001a; |
| | | 41 | | |
| | | 42 | | internal const uint TagMask = 0x0000001F; |
| | | 43 | | |
| | | 44 | | // Arbitrary value not equal to any of the token types in the array. This includes 0 which is TokenTypeIds.Modul |
| | | 45 | | internal const uint InvalidTokenType = uint.MaxValue; |
| | | 46 | | |
| | | 47 | | internal static ReadOnlySpan<uint> TagToTokenTypeArray => |
| | 0 | 48 | | [ |
| | 0 | 49 | | TokenTypeIds.MethodDef, |
| | 0 | 50 | | TokenTypeIds.FieldDef, |
| | 0 | 51 | | TokenTypeIds.TypeRef, |
| | 0 | 52 | | TokenTypeIds.TypeDef, |
| | 0 | 53 | | TokenTypeIds.ParamDef, |
| | 0 | 54 | | TokenTypeIds.InterfaceImpl, |
| | 0 | 55 | | TokenTypeIds.MemberRef, |
| | 0 | 56 | | TokenTypeIds.Module, |
| | 0 | 57 | | TokenTypeIds.DeclSecurity, |
| | 0 | 58 | | TokenTypeIds.Property, |
| | 0 | 59 | | TokenTypeIds.Event, |
| | 0 | 60 | | TokenTypeIds.Signature, |
| | 0 | 61 | | TokenTypeIds.ModuleRef, |
| | 0 | 62 | | TokenTypeIds.TypeSpec, |
| | 0 | 63 | | TokenTypeIds.Assembly, |
| | 0 | 64 | | TokenTypeIds.AssemblyRef, |
| | 0 | 65 | | TokenTypeIds.File, |
| | 0 | 66 | | TokenTypeIds.ExportedType, |
| | 0 | 67 | | TokenTypeIds.ManifestResource, |
| | 0 | 68 | | TokenTypeIds.GenericParam, |
| | 0 | 69 | | TokenTypeIds.GenericParamConstraint, |
| | 0 | 70 | | TokenTypeIds.MethodSpec, |
| | 0 | 71 | | |
| | 0 | 72 | | TokenTypeIds.Document, |
| | 0 | 73 | | TokenTypeIds.LocalScope, |
| | 0 | 74 | | TokenTypeIds.LocalVariable, |
| | 0 | 75 | | TokenTypeIds.LocalConstant, |
| | 0 | 76 | | TokenTypeIds.ImportScope, |
| | 0 | 77 | | |
| | 0 | 78 | | InvalidTokenType, |
| | 0 | 79 | | InvalidTokenType, |
| | 0 | 80 | | InvalidTokenType, |
| | 0 | 81 | | InvalidTokenType, |
| | 0 | 82 | | InvalidTokenType |
| | 0 | 83 | | ]; |
| | | 84 | | |
| | | 85 | | internal const TableMask TablesReferenced = |
| | | 86 | | TableMask.MethodDef |
| | | 87 | | | TableMask.Field |
| | | 88 | | | TableMask.TypeRef |
| | | 89 | | | TableMask.TypeDef |
| | | 90 | | | TableMask.Param |
| | | 91 | | | TableMask.InterfaceImpl |
| | | 92 | | | TableMask.MemberRef |
| | | 93 | | | TableMask.Module |
| | | 94 | | | TableMask.DeclSecurity |
| | | 95 | | | TableMask.Property |
| | | 96 | | | TableMask.Event |
| | | 97 | | | TableMask.StandAloneSig |
| | | 98 | | | TableMask.ModuleRef |
| | | 99 | | | TableMask.TypeSpec |
| | | 100 | | | TableMask.Assembly |
| | | 101 | | | TableMask.AssemblyRef |
| | | 102 | | | TableMask.File |
| | | 103 | | | TableMask.ExportedType |
| | | 104 | | | TableMask.ManifestResource |
| | | 105 | | | TableMask.GenericParam |
| | | 106 | | | TableMask.GenericParamConstraint |
| | | 107 | | | TableMask.MethodSpec |
| | | 108 | | | TableMask.Document |
| | | 109 | | | TableMask.LocalScope |
| | | 110 | | | TableMask.LocalVariable |
| | | 111 | | | TableMask.LocalConstant |
| | | 112 | | | TableMask.ImportScope; |
| | | 113 | | |
| | | 114 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 115 | | internal static EntityHandle ConvertToHandle(uint taggedReference) |
| | 0 | 116 | | { |
| | 0 | 117 | | uint tokenType = TagToTokenTypeArray[(int)(taggedReference & TagMask)]; |
| | 0 | 118 | | uint rowId = (taggedReference >> NumberOfBits); |
| | | 119 | | |
| | 0 | 120 | | if (tokenType == InvalidTokenType || ((rowId & ~TokenTypeIds.RIDMask) != 0)) |
| | 0 | 121 | | { |
| | 0 | 122 | | Throw.InvalidCodedIndex(); |
| | | 123 | | } |
| | | 124 | | |
| | 0 | 125 | | return new EntityHandle(tokenType | rowId); |
| | 0 | 126 | | } |
| | | 127 | | |
| | | 128 | | internal static uint ConvertToTag(EntityHandle handle) |
| | 0 | 129 | | { |
| | 0 | 130 | | uint tokenType = handle.Type; |
| | 0 | 131 | | uint rowId = (uint)handle.RowId; |
| | 0 | 132 | | return (tokenType >> TokenTypeIds.RowIdBitCount) switch |
| | 0 | 133 | | { |
| | 0 | 134 | | TokenTypeIds.MethodDef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | MethodDef, |
| | 0 | 135 | | TokenTypeIds.FieldDef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Field, |
| | 0 | 136 | | TokenTypeIds.TypeRef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | TypeRef, |
| | 0 | 137 | | TokenTypeIds.TypeDef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | TypeDef, |
| | 0 | 138 | | TokenTypeIds.ParamDef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Param, |
| | 0 | 139 | | TokenTypeIds.InterfaceImpl >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | InterfaceImpl, |
| | 0 | 140 | | TokenTypeIds.MemberRef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | MemberRef, |
| | 0 | 141 | | TokenTypeIds.Module >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Module, |
| | 0 | 142 | | TokenTypeIds.DeclSecurity >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | DeclSecurity, |
| | 0 | 143 | | TokenTypeIds.Property >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Property, |
| | 0 | 144 | | TokenTypeIds.Event >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Event, |
| | 0 | 145 | | TokenTypeIds.Signature >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | StandAloneSig, |
| | 0 | 146 | | TokenTypeIds.ModuleRef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | ModuleRef, |
| | 0 | 147 | | TokenTypeIds.TypeSpec >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | TypeSpec, |
| | 0 | 148 | | TokenTypeIds.Assembly >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Assembly, |
| | 0 | 149 | | TokenTypeIds.AssemblyRef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | AssemblyRef, |
| | 0 | 150 | | TokenTypeIds.File >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | File, |
| | 0 | 151 | | TokenTypeIds.ExportedType >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | ExportedType, |
| | 0 | 152 | | TokenTypeIds.ManifestResource >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | ManifestResource, |
| | 0 | 153 | | TokenTypeIds.GenericParam >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | GenericParam, |
| | 0 | 154 | | TokenTypeIds.GenericParamConstraint >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | GenericPara |
| | 0 | 155 | | TokenTypeIds.MethodSpec >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | MethodSpec, |
| | 0 | 156 | | |
| | 0 | 157 | | TokenTypeIds.Document >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Document, |
| | 0 | 158 | | TokenTypeIds.LocalScope >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | LocalScope, |
| | 0 | 159 | | TokenTypeIds.LocalVariable >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | LocalVariable, |
| | 0 | 160 | | TokenTypeIds.LocalConstant >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | LocalConstant, |
| | 0 | 161 | | TokenTypeIds.ImportScope >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Import, |
| | 0 | 162 | | |
| | 0 | 163 | | _ => 0, |
| | 0 | 164 | | }; |
| | 0 | 165 | | } |
| | | 166 | | } |
| | | 167 | | } |
| | | 168 | | |