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

DefType.RuntimeDetermined.cs « RuntimeDetermined « TypeSystem « Common « tools « coreclr « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 62799f6ba6145ba8240a1a732120c268fdc2e54f (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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Internal.TypeSystem
{
    public partial class DefType
    {
        public override bool IsRuntimeDeterminedSubtype
        {
            get
            {
                // Handles situation when shared code refers to uninstantiated generic
                // type definitions (think: LDTOKEN).
                // Walking the instantiation would make us assert. This is simply
                // not a runtime determined type.
                if (IsGenericDefinition)
                    return false;

                foreach (TypeDesc type in Instantiation)
                {
                    if (type.IsRuntimeDeterminedSubtype)
                        return true;
                }
                return false;
            }
        }

        /// <summary>
        /// Converts the type to the shared runtime determined form where the types this type is instantiatied
        /// over become bound to the generic parameters of this type.
        /// </summary>
        public DefType ConvertToSharedRuntimeDeterminedForm()
        {
            Instantiation instantiation = Instantiation;
            if (instantiation.Length > 0)
            {
                MetadataType typeDefinition = (MetadataType)GetTypeDefinition();

                bool changed;
                Instantiation sharedInstantiation = RuntimeDeterminedTypeUtilities.ConvertInstantiationToSharedRuntimeForm(
                    instantiation, typeDefinition.Instantiation, out changed);
                if (changed)
                {
                    return Context.GetInstantiatedType(typeDefinition, sharedInstantiation);
                }
            }

            return this;
        }

        public override TypeDesc GetNonRuntimeDeterminedTypeFromRuntimeDeterminedSubtypeViaSubstitution(Instantiation typeInstantiation, Instantiation methodInstantiation)
        {
            TypeDesc typeDefinition = GetTypeDefinition();
            if (this == typeDefinition)
                return this;

            Instantiation instantiation = Instantiation;
            TypeDesc[] clone = null;

            for (int i = 0; i < instantiation.Length; i++)
            {
                TypeDesc uninst = instantiation[i];
                TypeDesc inst = uninst.GetNonRuntimeDeterminedTypeFromRuntimeDeterminedSubtypeViaSubstitution(typeInstantiation, methodInstantiation);
                if (inst != uninst)
                {
                    if (clone == null)
                    {
                        clone = new TypeDesc[instantiation.Length];
                        for (int j = 0; j < clone.Length; j++)
                        {
                            clone[j] = instantiation[j];
                        }
                    }
                    clone[i] = inst;
                }
            }

            if (clone != null)
            {
                return Context.GetInstantiatedType((MetadataType)typeDefinition, new Instantiation(clone));
            }

            return this;
        }
    }
}