Welcome to mirror list, hosted at ThFree Co, Russian Federation.

UnboxingMethodDesc.cs « JitInterface « Common « tools « coreclr « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e21794718c8b2e4b97d89f87000e826d3d324154 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using Internal.TypeSystem;

namespace Internal.JitInterface
{
    /// <summary>
    /// Represents the unboxing entrypoint of a valuetype instance method.
    /// This class is for internal purposes within the JitInterface. It's not expected
    /// for it to escape the JitInterface.
    /// </summary>
    internal sealed class UnboxingMethodDesc : MethodDelegator
    {
        private readonly UnboxingMethodDescFactory _factory;

        public MethodDesc Target => _wrappedMethod;

        public UnboxingMethodDesc(MethodDesc wrappedMethod, UnboxingMethodDescFactory factory)
            : base(wrappedMethod)
        {
            Debug.Assert(wrappedMethod.OwningType.IsValueType);
            Debug.Assert(!wrappedMethod.Signature.IsStatic);
            _factory = factory;
        }

        public override MethodDesc GetCanonMethodTarget(CanonicalFormKind kind)
        {
            MethodDesc realCanonTarget = _wrappedMethod.GetCanonMethodTarget(kind);
            if (realCanonTarget != _wrappedMethod)
                return _factory.GetUnboxingMethod(realCanonTarget);

            return this;
        }

        public override MethodDesc GetMethodDefinition()
        {
            MethodDesc realMethodDefinition = _wrappedMethod.GetMethodDefinition();
            if (realMethodDefinition != _wrappedMethod)
                return _factory.GetUnboxingMethod(realMethodDefinition);

            return this;
        }

        public override MethodDesc GetTypicalMethodDefinition()
        {
            MethodDesc realTypicalMethodDefinition = _wrappedMethod.GetTypicalMethodDefinition();
            if (realTypicalMethodDefinition != _wrappedMethod)
                return _factory.GetUnboxingMethod(realTypicalMethodDefinition);

            return this;
        }

        public override MethodDesc InstantiateSignature(Instantiation typeInstantiation, Instantiation methodInstantiation)
        {
            MethodDesc realInstantiateSignature = _wrappedMethod.InstantiateSignature(typeInstantiation, methodInstantiation);
            if (realInstantiateSignature != _wrappedMethod)
                return _factory.GetUnboxingMethod(realInstantiateSignature);

            return this;
        }

        public override string ToString()
        {
            return "Unboxing MethodDesc: " + _wrappedMethod.ToString();
        }

#if !SUPPORT_JIT
        protected override int ClassCode => throw new NotImplementedException();

        protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
        {
            throw new NotImplementedException();
        }
#endif
    }

    internal static class UnboxingMethodDescExtensions
    {
        public static bool IsUnboxingThunk(this MethodDesc method)
        {
            return method is UnboxingMethodDesc;
        }

        public static MethodDesc GetUnboxedMethod(this MethodDesc method)
        {
            return ((UnboxingMethodDesc)method).Target;
        }
    }
}