< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 81
Coverable lines: 81
Total lines: 168
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 58
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
ConvertToHandle(...)0%440%
ConvertToTag(...)0%54540%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/PortablePdb/HasCustomDebugInformationTag.cs

#LineLine coverage
 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
 4using System.Runtime.CompilerServices;
 5
 6namespace 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 =>
 048        [
 049            TokenTypeIds.MethodDef,
 050            TokenTypeIds.FieldDef,
 051            TokenTypeIds.TypeRef,
 052            TokenTypeIds.TypeDef,
 053            TokenTypeIds.ParamDef,
 054            TokenTypeIds.InterfaceImpl,
 055            TokenTypeIds.MemberRef,
 056            TokenTypeIds.Module,
 057            TokenTypeIds.DeclSecurity,
 058            TokenTypeIds.Property,
 059            TokenTypeIds.Event,
 060            TokenTypeIds.Signature,
 061            TokenTypeIds.ModuleRef,
 062            TokenTypeIds.TypeSpec,
 063            TokenTypeIds.Assembly,
 064            TokenTypeIds.AssemblyRef,
 065            TokenTypeIds.File,
 066            TokenTypeIds.ExportedType,
 067            TokenTypeIds.ManifestResource,
 068            TokenTypeIds.GenericParam,
 069            TokenTypeIds.GenericParamConstraint,
 070            TokenTypeIds.MethodSpec,
 071
 072            TokenTypeIds.Document,
 073            TokenTypeIds.LocalScope,
 074            TokenTypeIds.LocalVariable,
 075            TokenTypeIds.LocalConstant,
 076            TokenTypeIds.ImportScope,
 077
 078            InvalidTokenType,
 079            InvalidTokenType,
 080            InvalidTokenType,
 081            InvalidTokenType,
 082            InvalidTokenType
 083        ];
 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)
 0116        {
 0117            uint tokenType = TagToTokenTypeArray[(int)(taggedReference & TagMask)];
 0118            uint rowId = (taggedReference >> NumberOfBits);
 119
 0120            if (tokenType == InvalidTokenType || ((rowId & ~TokenTypeIds.RIDMask) != 0))
 0121            {
 0122                Throw.InvalidCodedIndex();
 123            }
 124
 0125            return new EntityHandle(tokenType | rowId);
 0126        }
 127
 128        internal static uint ConvertToTag(EntityHandle handle)
 0129        {
 0130            uint tokenType = handle.Type;
 0131            uint rowId = (uint)handle.RowId;
 0132            return (tokenType >> TokenTypeIds.RowIdBitCount) switch
 0133            {
 0134                TokenTypeIds.MethodDef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | MethodDef,
 0135                TokenTypeIds.FieldDef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Field,
 0136                TokenTypeIds.TypeRef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | TypeRef,
 0137                TokenTypeIds.TypeDef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | TypeDef,
 0138                TokenTypeIds.ParamDef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Param,
 0139                TokenTypeIds.InterfaceImpl >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | InterfaceImpl,
 0140                TokenTypeIds.MemberRef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | MemberRef,
 0141                TokenTypeIds.Module >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Module,
 0142                TokenTypeIds.DeclSecurity >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | DeclSecurity,
 0143                TokenTypeIds.Property >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Property,
 0144                TokenTypeIds.Event >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Event,
 0145                TokenTypeIds.Signature >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | StandAloneSig,
 0146                TokenTypeIds.ModuleRef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | ModuleRef,
 0147                TokenTypeIds.TypeSpec >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | TypeSpec,
 0148                TokenTypeIds.Assembly >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Assembly,
 0149                TokenTypeIds.AssemblyRef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | AssemblyRef,
 0150                TokenTypeIds.File >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | File,
 0151                TokenTypeIds.ExportedType >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | ExportedType,
 0152                TokenTypeIds.ManifestResource >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | ManifestResource,
 0153                TokenTypeIds.GenericParam >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | GenericParam,
 0154                TokenTypeIds.GenericParamConstraint >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | GenericPara
 0155                TokenTypeIds.MethodSpec >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | MethodSpec,
 0156
 0157                TokenTypeIds.Document >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Document,
 0158                TokenTypeIds.LocalScope >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | LocalScope,
 0159                TokenTypeIds.LocalVariable >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | LocalVariable,
 0160                TokenTypeIds.LocalConstant >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | LocalConstant,
 0161                TokenTypeIds.ImportScope >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Import,
 0162
 0163                _ => 0,
 0164            };
 0165        }
 166    }
 167}
 168